KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > gargoylesoftware > htmlunit > html > ClickableElementTest


1 /*
2  * Copyright (c) 2002, 2005 Gargoyle Software Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The end-user documentation included with the redistribution, if any, must
13  * include the following acknowledgment:
14  *
15  * "This product includes software developed by Gargoyle Software Inc.
16  * (http://www.GargoyleSoftware.com/)."
17  *
18  * Alternately, this acknowledgment may appear in the software itself, if
19  * and wherever such third-party acknowledgments normally appear.
20  * 4. The name "Gargoyle Software" must not be used to endorse or promote
21  * products derived from this software without prior written permission.
22  * For written permission, please contact info@GargoyleSoftware.com.
23  * 5. Products derived from this software may not be called "HtmlUnit", nor may
24  * "HtmlUnit" appear in their name, without prior written permission of
25  * Gargoyle Software Inc.
26  *
27  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
28  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
29  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GARGOYLE
30  * SOFTWARE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
33  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  */

38 package com.gargoylesoftware.htmlunit.html;
39
40 import java.util.ArrayList;
41 import java.util.Arrays;
42 import java.util.List;
43
44 import com.gargoylesoftware.htmlunit.BrowserVersion;
45 import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
46 import com.gargoylesoftware.htmlunit.MockWebConnection;
47 import com.gargoylesoftware.htmlunit.WebClient;
48 import com.gargoylesoftware.htmlunit.WebTestCase;
49
50 /**
51  * Tests for ClickableElementTest
52  *
53  * @version $Revision: 1.12 $
54  * @author David K. Taylor
55  */

56 public class ClickableElementTest extends WebTestCase {
57     /**
58      * Create an instance
59      *
60      * @param name The name of the test
61      */

62     public ClickableElementTest( final String name ) {
63         super( name );
64     }
65
66
67     /**
68      * Full page driver for onClick tests.
69      *
70      * @param htmlContent HTML fragment for body of page with clickable element
71      * identified by clickId ID attribute. Must have onClick that raises
72      * an alert of "foo".
73      * @throws Exception if the test fails
74      */

75     private void onClickPageTest(final String htmlContent) throws Exception {
76         final List expectedAlerts = Arrays.asList( new String[]{"foo"} );
77         onClickPageTest(htmlContent, 1, expectedAlerts);
78     }
79
80     /**
81      * Full page driver for onClick tests.
82      *
83      * @param htmlContent HTML fragment for body of page with clickable element
84      * identified by clickId ID attribute.
85      * @param numClicks number of times to click element
86      * @param expectedAlerts List of expected popup values
87      * @throws Exception if the test fails
88      */

89     private void onClickPageTest(final String htmlContent, final int numClicks, final List expectedAlerts)
90         throws Exception {
91         final BrowserVersion bv = new BrowserVersion("Netscape", "7", "", "1.2");
92         final WebClient client = new WebClient(bv);
93
94         final MockWebConnection webConnection = new MockWebConnection( client );
95         webConnection.setDefaultResponse( htmlContent );
96         client.setWebConnection( webConnection );
97
98         final List collectedAlerts = new ArrayList();
99         final CollectingAlertHandler alertHandler = new CollectingAlertHandler(collectedAlerts);
100         client.setAlertHandler(alertHandler);
101
102         final HtmlPage page = ( HtmlPage ) client.getPage(URL_GARGOYLE);
103         final ClickableElement clickable = ( ClickableElement )page.getHtmlElementById( "clickId" );
104
105         for (int i=0; i<numClicks; i++) {
106             clickable.click();
107         }
108
109         assertEquals( expectedAlerts, collectedAlerts );
110     }
111
112
113     /**
114      * Body driver for onClick tests.
115      *
116      * @param htmlBody HTML text body
117      * @throws Exception if the test fails
118      */

119     private void onClickBodyTest(final String htmlBody) throws Exception {
120         onClickPageTest("<html><head><title>foo</title></head>" + htmlBody
121                  + "</html>");
122     }
123
124
125     /**
126      * Simple tag name driver for onClick tests.
127      *
128      * @param tagName HTML tag name for simple tag with text body
129      * @throws Exception if the test fails
130      */

131     private void onClickSimpleTest(final String tagName) throws Exception {
132         onClickBodyTest("<body><" + tagName + " id='clickId' onClick='alert(\"foo\")'>Text</" + tagName + "></body>");
133     }
134
135
136     /**
137      * Test onClick handler and click method of anchor element.
138      *
139      * @throws Exception if the test fails
140      */

141     public void testAnchor_onClick() throws Exception {
142         onClickSimpleTest("a");
143     }
144
145
146     /**
147      * Test onClick handler and click method of abbreviation element.
148      *
149      * @throws Exception if the test fails
150      */

151     public void testAbbreviation_onClick() throws Exception {
152         onClickSimpleTest("abbr");
153     }
154
155
156     /**
157      * Test onClick handler and click method of acronym element.
158      *
159      * @throws Exception if the test fails
160      */

161     public void testAcronym_onClick() throws Exception {
162         onClickSimpleTest("acronym");
163     }
164
165
166     /**
167      * Test onClick handler and click method of address element.
168      *
169      * @throws Exception if the test fails
170      */

171     public void testAddress_onClick() throws Exception {
172         onClickSimpleTest("address");
173     }
174
175
176     /**
177      * Test onClick handler and click method of area element.
178      *
179      * @throws Exception if the test fails
180      */

181     public void testArea_onClick() throws Exception {
182         onClickBodyTest("<body><map><area id='clickId' onClick='alert(\"foo\")'/></map></body>");
183     }
184
185
186     /**
187      * Test onClick handler and click method of bold element.
188      *
189      * @throws Exception if the test fails
190      */

191     public void testBold_onClick() throws Exception {
192         onClickSimpleTest("b");
193     }
194
195
196     /**
197      * Test onClick handler and click method of big element.
198      *
199      * @throws Exception if the test fails
200      */

201     public void testBig_onClick() throws Exception {
202         onClickSimpleTest("big");
203     }
204
205
206     /**
207      * Test onClick handler and click method of blockquote element.
208      *
209      * @throws Exception if the test fails
210      */

211     public void testBlockquote_onClick() throws Exception {
212         onClickSimpleTest("blockquote");
213     }
214
215
216     /**
217      * Test onClick handler and click method of body element.
218      *
219      * @throws Exception if the test fails
220      */

221     public void testBody_onClick() throws Exception {
222         onClickBodyTest("<body id='clickId' onClick='alert(\"foo\")'>Text</body>");
223     }
224
225
226     /**
227      * Test onClick handler and click method of button element.
228      *
229      * @throws Exception if the test fails
230      */

231     public void testButton_onClick() throws Exception {
232         onClickBodyTest("<body><form><button id='clickId' onClick='alert(\"foo\")'>Item</button></form></body>");
233     }
234
235     /**
236      * Test onClick handler can be called multiple times
237      *
238      * @throws Exception if the test fails
239      */

240     public void testButton_onClickTwice() throws Exception {
241         final List expectedAlerts = Arrays.asList(new String[] {"foo0", "foo1"});
242         onClickPageTest("<body><form>" +
243                 "<button id='clickId' onClick='alert(\"foo\" + count++)'>Item</button>" +
244                 "<script> var count = 0 </script>" +
245                 "</form></body>", 2, expectedAlerts);
246     }
247
248     /**
249      * Test onClick handler and click method of cite element.
250      *
251      * @throws Exception if the test fails
252      */

253     public void testCite_onClick() throws Exception {
254         onClickSimpleTest("cite");
255     }
256
257
258     /**
259      * Test onClick handler and click method of code element.
260      *
261      * @throws Exception if the test fails
262      */

263     public void testCode_onClick() throws Exception {
264         onClickSimpleTest("code");
265     }
266
267
268     /**
269      * Test onClick handler and click method of table column element.
270      *
271      * @throws Exception if the test fails
272      */

273     public void testTableColumn_onClick() throws Exception {
274         onClickBodyTest("<body><table><caption>Caption</caption><colgroup>"
275             + "<col id='clickId' onClick='alert(\"foo\")'/></colgroup><thead><tr><th>"
276             + "Header</th></tr></thead><tbody><tr><td>Data</td></tr></tbody><tfoot><tr>"
277             + "th>Header</th></tr></tfoot></table></body>");
278     }
279
280
281     /**
282      * Test onClick handler and click method of table column group element.
283      *
284      * @throws Exception if the test fails
285      */

286     public void testTableColumnGroup_onClick() throws Exception {
287         onClickBodyTest("<body><table><caption>Caption</caption>"
288             + "<colgroup id='clickId' onClick='alert(\"foo\")'><col/></colgroup><thead>"
289             + "<tr><th>Header</th></tr></thead><tbody><tr><td>Data</td></tr></tbody><tfoot>"
290             + "<tr><th>Header</th></tr></tfoot></table></body>");
291     }
292
293
294     /**
295      * Test onClick handler and click method of center element.
296      *
297      * @throws Exception if the test fails
298      */

299     public void testCenter_onClick() throws Exception {
300         onClickSimpleTest("center");
301     }
302
303
304     /**
305      * Test onClick handler and click method of table caption element.
306      *
307      * @throws Exception if the test fails
308      */

309     public void testTableCaption_onClick() throws Exception {
310         onClickBodyTest("<body><table><caption id='clickId' onClick='alert(\"foo\")'>"
311             + "Caption</caption><colgroup><col/></colgroup><thead><tr><th>Header</th></tr>"
312             + "</thead><tbody><tr><td>Data</td></tr></tbody><tfoot><tr><th>Header</th></tr>"
313             + "</tfoot></table></body>");
314     }
315
316
317     /**
318      * Test onClick handler and click method of definition description dd element.
319      *
320      * @throws Exception if the test fails
321      */

322     public void testDefinitionDescription_onClick() throws Exception {
323         onClickBodyTest("<body><dl><dt>Term</dt><dd id='clickId' onClick='alert(\"foo\")'>Definition</dd></dl></body>");
324     }
325
326
327     /**
328      * Test onClick handler and click method of definition element.
329      *
330      * @throws Exception if the test fails
331      */

332     public void testDefinition_onClick() throws Exception {
333         onClickSimpleTest("dfn");
334     }
335
336
337     /**
338      * Test onClick handler and click method of directory element.
339      *
340      * @throws Exception if the test fails
341      */

342     public void testDirectory_onClick() throws Exception {
343         onClickSimpleTest("dir");
344     }
345
346
347     /**
348      * Test onClick handler and click method of definition list dl element.
349      *
350      * @throws Exception if the test fails
351      */

352     public void testDefinitionList_onClick() throws Exception {
353         onClickBodyTest("<body><dl id='clickId' onClick='alert(\"foo\")'><dt>Term</dt><dd>Definition</dd></dl></body>");
354     }
355
356
357     /**
358      * Test onClick handler and click method of definition term dt element.
359      *
360      * @throws Exception if the test fails
361      */

362     public void testDefinitionTerm_onClick() throws Exception {
363         onClickBodyTest("<body><dl><dt id='clickId' onClick='alert(\"foo\")'>Term</dt><dd>Definition</dd></dl></body>");
364     }
365
366
367     /**
368      * Test onClick handler and click method of deleted text element.
369      *
370      * @throws Exception if the test fails
371      */

372     public void testDeletedText_onClick() throws Exception {
373         onClickSimpleTest("del");
374     }
375
376
377     /**
378      * Test onClick handler and click method of Text Direction element.
379      *
380      * @throws Exception if the test fails
381      */

382     public void testTextDirection_onClick() throws Exception {
383         onClickSimpleTest("dir");
384     }
385
386
387     /**
388      * Test onClick handler and click method of division element.
389      *
390      * @throws Exception if the test fails
391      */

392     public void testDivision_onClick() throws Exception {
393         onClickSimpleTest("div");
394     }
395
396
397     /**
398      * Test onClick handler and click method of emphasis element.
399      *
400      * @throws Exception if the test fails
401      */

402     public void testEmphasis_onClick() throws Exception {
403         onClickSimpleTest("em");
404     }
405
406
407     /**
408      * Test onClick handler and click method of field set element.
409      *
410      * @throws Exception if the test fails
411      */

412     public void testFieldSet_onClick() throws Exception {
413         onClickBodyTest("<body><form><fieldset id='clickId' onClick='alert(\"foo\")'>"
414             + "<legend>Legend</legend></fieldset></form></body>");
415     }
416
417
418     /**
419      * Test onClick handler and click method of form element.
420      *
421      * @throws Exception if the test fails
422      */

423     public void testForm_onClick() throws Exception {
424         onClickSimpleTest("form");
425     }
426
427
428     /**
429      * Test onClick handler and click method of italics element.
430      *
431      * @throws Exception if the test fails
432      */

433     public void testItalics_onClick() throws Exception {
434         onClickSimpleTest("i");
435     }
436
437
438     /**
439      * Test onClick handler and click method of image element.
440      *
441      * @throws Exception if the test fails
442      */

443     public void testImage_onClick() throws Exception {
444         onClickSimpleTest("img");
445     }
446
447
448     /**
449      * Test onClick handler and click method of header1 element.
450      *
451      * @throws Exception if the test fails
452      */

453     public void testHeader1_onClick() throws Exception {
454         onClickSimpleTest("h1");
455     }
456
457
458     /**
459      * Test onClick handler and click method of header2 element.
460      *
461      * @throws Exception if the test fails
462      */

463     public void testHeader2_onClick() throws Exception {
464         onClickSimpleTest("h2");
465     }
466
467
468     /**
469      * Test onClick handler and click method of header3 element.
470      *
471      * @throws Exception if the test fails
472      */

473     public void testHeader3_onClick() throws Exception {
474         onClickSimpleTest("h3");
475     }
476
477
478     /**
479      * Test onClick handler and click method of header4 element.
480      *
481      * @throws Exception if the test fails
482      */

483     public void testHeader4_onClick() throws Exception {
484         onClickSimpleTest("h4");
485     }
486
487
488     /**
489      * Test onClick handler and click method of header5 element.
490      *
491      * @throws Exception if the test fails
492      */

493     public void testHeader5_onClick() throws Exception {
494         onClickSimpleTest("h5");
495     }
496
497
498     /**
499      * Test onClick handler and click method of header6 element.
500      *
501      * @throws Exception if the test fails
502      */

503     public void testHeader6_onClick() throws Exception {
504         onClickSimpleTest("h6");
505     }
506
507
508     /**
509      * Test onClick handler and click method of horizontal rule element.
510      *
511      * @throws Exception if the test fails
512      */

513     public void testHorizontalRule_onClick() throws Exception {
514         onClickSimpleTest("hr");
515     }
516
517     /**
518      * Test onClick handler and click method of input element.
519      *
520      * @throws Exception if the test fails
521      */

522     public void testInput_onClick() throws Exception {
523         onClickBodyTest("<body><form><input id='clickId' onClick='alert(\"foo\")'>Item</input></form></body>");
524     }
525
526
527     /**
528      * Test onClick handler and click method of inserted text element.
529      *
530      * @throws Exception if the test fails
531      */

532     public void testInsertedText_onClick() throws Exception {
533         onClickSimpleTest("ins");
534     }
535
536
537     /**
538      * Test onClick handler and click method of keyboard element.
539      *
540      * @throws Exception if the test fails
541      */

542     public void testKeyboard_onClick() throws Exception {
543         onClickSimpleTest("kbd");
544     }
545
546
547     /**
548      * Test onClick handler and click method of label element.
549      *
550      * @throws Exception if the test fails
551      */

552     public void testLabel_onClick() throws Exception {
553         onClickBodyTest("<body><form><label id='clickId' onClick='alert(\"foo\")'>Item</label></form></body>");
554     }
555
556
557     /**
558      * Test onClick handler and click method of legend element.
559      *
560      * @throws Exception if the test fails
561      */

562     public void testLegend_onClick() throws Exception {
563         onClickBodyTest("<body><form><fieldset><legend id='clickId' onClick='alert(\"foo\")'>"
564             + "Legend</legend></fieldset></form></body>");
565     }
566
567
568     /**
569      * Test onClick handler and click method of link element.
570      *
571      * @throws Exception if the test fails
572      */

573     public void XXtestLink_onClick() throws Exception {
574         onClickPageTest("<html><head><title>foo</title><link id='clickId' onClick='alert(\"foo\")'/>"
575             + "</head><body></body></html>");
576     }
577
578
579     /**
580      * Test onClick handler and click method of List Item element.
581      *
582      * @throws Exception if the test fails
583      */

584     public void testListItem_onClick() throws Exception {
585         onClickBodyTest("<body><ol><li id='clickId' onClick='alert(\"foo\")'>Item</li></ol></body>");
586     }
587
588
589     /**
590      * Test onClick handler and click method of map element.
591      *
592      * @throws Exception if the test fails
593      */

594     public void testMap_onClick() throws Exception {
595         onClickBodyTest("<body><map id='clickId' onClick='alert(\"foo\")'><area/></map></body>");
596     }
597
598
599     /**
600      * Test onClick handler and click method of menu element.
601      *
602      * @throws Exception if the test fails
603      */

604     public void testMenu_onClick() throws Exception {
605         onClickBodyTest("<body><menu id='clickId' onClick='alert(\"foo\")'><li>Item</li></menu></body>");
606     }
607
608
609     /**
610      * Test onClick handler and click method of no frames element.
611      *
612      * @throws Exception if the test fails
613      */

614     public void XXtestNoFrames_onClick() throws Exception {
615         onClickPageTest("<html><head><title>foo</title></head><frameset><frame/>"
616             + "<noframes id='clickId' onClick='alert(\"foo\")'/></frameset></html>");
617     }
618
619
620     /**
621      * Test onClick handler and click method of no script element.
622      *
623      * @throws Exception if the test fails
624      */

625     public void testNoScript_onClick() throws Exception {
626         onClickBodyTest("<body><script>var i=0;</script><noscript id='clickId' "
627             + "onClick='alert(\"foo\")'>Item</noscript></body>");
628     }
629
630
631     /**
632      * Test onClick handler and click method of object element.
633      *
634      * @throws Exception if the test fails
635      */

636     public void testObject_onClick() throws Exception {
637         onClickSimpleTest("object");
638     }
639
640
641     /**
642      * Test onClick handler and click method of option element.
643      *
644      * @throws Exception if the test fails
645      */

646     public void testOption_onClick() throws Exception {
647         onClickBodyTest("<body><form><select><option id='clickId' onClick='alert(\"foo\")'>"
648             + "Option</option></select></form></body>");
649     }
650
651
652     /**
653      * Test onClick handler and click method of Option Group element.
654      *
655      * @throws Exception if the test fails
656      */

657     public void testOptionGroup_onClick() throws Exception {
658         onClickBodyTest("<body><form><select><optgroup id='clickId' onClick='alert(\"foo\")'>"
659             + "<option>Option</option></optgroup></select></form></body>");
660     }
661
662
663     /**
664      * Test onClick handler and click method of Ordered List element.
665      *
666      * @throws Exception if the test fails
667      */

668     public void testOrderedList_onClick() throws Exception {
669         onClickBodyTest("<body><ol id='clickId' onClick='alert(\"foo\")'><li>Item</li></ol></body>");
670     }
671
672
673     /**
674      * Test onClick handler and click method of paragraph element.
675      *
676      * @throws Exception if the test fails
677      */

678     public void testParagraph_onClick() throws Exception {
679         onClickSimpleTest("p");
680     }
681
682
683     /**
684      * Test onClick handler and click method of pre element.
685      *
686      * @throws Exception if the test fails
687      */

688     public void testPre_onClick() throws Exception {
689         onClickSimpleTest("pre");
690     }
691
692
693     /**
694      * Test onClick handler and click method of inline Quotation element.
695      *
696      * @throws Exception if the test fails
697      */

698     public void testQuotation_onClick() throws Exception {
699         onClickSimpleTest("q");
700     }
701
702
703     /**
704      * Test onClick handler and click method of strikethrough element.
705      *
706      * @throws Exception if the test fails
707      */

708     public void testStrikethrough_onClick() throws Exception {
709         onClickSimpleTest("s");
710     }
711
712
713     /**
714      * Test onClick handler and click method of sample element.
715      *
716      * @throws Exception if the test fails
717      */

718     public void testSample_onClick() throws Exception {
719         onClickSimpleTest("samp");
720     }
721
722
723     /**
724      * Test onClick handler and click method of select element.
725      *
726      * @throws Exception if the test fails
727      */

728     public void testSelect_onClick() throws Exception {
729         onClickBodyTest("<body><form><select id='clickId' onClick='alert(\"foo\")'>"
730             + "<option>Option</option></select></form></body>");
731     }
732
733
734     /**
735      * Test onClick handler and click method of small element.
736      *
737      * @throws Exception if the test fails
738      */

739     public void testSmall_onClick() throws Exception {
740         onClickSimpleTest("small");
741     }
742
743
744     /**
745      * Test onClick handler and click method of span element.
746      *
747      * @throws Exception if the test fails
748      */

749     public void testSpan_onClick() throws Exception {
750         onClickSimpleTest("span");
751     }
752
753
754     /**
755      * Test onClick handler and click method of strike element.
756      *
757      * @throws Exception if the test fails
758      */

759     public void testStrike_onClick() throws Exception {
760         onClickSimpleTest("strike");
761     }
762
763
764     /**
765      * Test onClick handler and click method of subscript element.
766      *
767      * @throws Exception if the test fails
768      */

769     public void testSubscript_onClick() throws Exception {
770         onClickSimpleTest("sub");
771     }
772
773
774     /**
775      * Test onClick handler and click method of superscript element.
776      *
777      * @throws Exception if the test fails
778      */

779     public void testSuperscript_onClick() throws Exception {
780         onClickSimpleTest("sup");
781     }
782
783
784     /**
785      * Test onClick handler and click method of table element.
786      *
787      * @throws Exception if the test fails
788      */

789     public void testTable_onClick() throws Exception {
790         onClickBodyTest("<body><table id='clickId' onClick='alert(\"foo\")'><caption>"
791             + "Caption</caption><colgroup><col/></colgroup><thead><tr><th>Header</th></tr>"
792             + "</thead><tbody><tr><td>Data</td></tr></tbody><tfoot><tr><th>Header</th></tr>"
793             + "</tfoot></table></body>");
794     }
795
796
797     /**
798      * Test onClick handler and click method of table body element.
799      *
800      * @throws Exception if the test fails
801      */

802     public void testTableBody_onClick() throws Exception {
803         onClickBodyTest("<body><table><caption>Caption</caption><colgroup><col/>"
804             + "</colgroup><thead><tr><th>Header</th></tr></thead>"
805             + "<tbody id='clickId' onClick='alert(\"foo\")'><tr><td>Data</td></tr>"
806             + "</tbody><tfoot><tr><th>Header</th></tr></tfoot></table></body>");
807     }
808
809
810     /**
811      * Test onClick handler and click method of table data cell element.
812      *
813      * @throws Exception if the test fails
814      */

815     public void testTableDataCell_onClick() throws Exception {
816         onClickBodyTest("<body><table><caption>Caption</caption><colgroup><col/>"
817             + "</colgroup><thead><tr><th>Header</th></tr></thead><tbody><tr>"
818             + "<td id='clickId' onClick='alert(\"foo\")'>Data</td></tr></tbody>"
819             + "<tfoot><tr><th>Header</th></tr></tfoot></table></body>");
820     }
821
822
823     /**
824      * Test onClick handler and click method of textarea element.
825      *
826      * @throws Exception if the test fails
827      */

828     public void testTextarea_onClick() throws Exception {
829         onClickBodyTest("<body><form><textarea id='clickId' onClick='alert(\"foo\")'>Item</textarea></form></body>");
830     }
831
832
833     /**
834      * Test onClick handler and click method of table footer element.
835      *
836      * @throws Exception if the test fails
837      */

838     public void testTableFooter_onClick() throws Exception {
839         onClickBodyTest("<body><table><caption>Caption</caption><colgroup><col/>"
840             + "</colgroup><thead><tr><th>Header</th></tr></thead><tbody><tr><td>Data</td>"
841             + "</tr></tbody><tfoot id='clickId' onClick='alert(\"foo\")'><tr><th>Header</th>"
842             + "</tr></tfoot></table></body>");
843     }
844
845
846     /**
847      * Test onClick handler and click method of table header cell element.
848      *
849      * @throws Exception if the test fails
850      */

851     public void testTableHeaderCell_onClick() throws Exception {
852         onClickBodyTest("<body><table><caption>Caption</caption><colgroup>"
853             + "<col/></colgroup><thead><tr><th id='clickId' onClick='alert(\"foo\")'>"
854             + "Header</th></tr></thead><tbody><tr><td>Data</td></tr></tbody><tfoot><tr>"
855             + "<th>Header</th></tr></tfoot></table></body>");
856     }
857
858
859     /**
860      * Test onClick handler and click method of table header element.
861      *
862      * @throws Exception if the test fails
863      */

864     public void testTableHeader_onClick() throws Exception {
865         onClickBodyTest("<body><table><caption>Caption</caption><colgroup><col/>"
866             + "</colgroup><thead id='clickId' onClick='alert(\"foo\")'><tr><th>Header</th>"
867             + "</tr></thead><tbody><tr><td>Data</td></tr></tbody><tfoot><tr><th>Header</th>"
868             + "</tr></tfoot></table></body>");
869     }
870
871
872     /**
873      * Test onClick handler and click method of table row element.
874      *
875      * @throws Exception if the test fails
876      */

877     public void testTableRow_onClick() throws Exception {
878         onClickBodyTest("<body><table><caption>Caption</caption><colgroup><col/>"
879             + "</colgroup><thead><tr><th>Header</th></tr></thead><tbody>"
880             + "<tr id='clickId' onClick='alert(\"foo\")'><td>Data</td></tr></tbody>"
881             + "<tfoot><tr><th>Header</th></tr></tfoot></table></body>");
882     }
883
884     /**
885      * Test when HtmlTableRow.onclick is set by a javascript
886      *
887      * @throws Exception if the test fails
888      */

889     public void testTableRow_onClickSetOnLoad() throws Exception {
890         onClickPageTest("<html><head>"
891                         + "<script language='JavaScript'>"
892                         + "function doFoo() { alert('foo'); }"
893                         + "function doOnload() { document.getElementById('clickId').onclick = doFoo;}"
894                         + "</script>"
895                         + "</head><body onload=\"doOnload();\">"
896                         + "<table><tbody><tr id='clickId'><td>cell value</td></tr></tbody></table>"
897                         + "</body></html>");
898     }
899
900     /**
901      *
902      * @throws Exception if the test fails
903      */

904     public void testCheckbox_onClickUpdatesStateFirst() throws Exception {
905         onClickPageTest("<html><head>"
906                         + "<script language='JavaScript'>"
907                         + "function doFoo(event) { if (this.checked) alert('foo'); else alert('bar'); }"
908                         + "function doOnload() { document.getElementById('clickId').onclick = doFoo;}"
909                         + "</script>"
910                         + "</head><body onload=\"doOnload();\">"
911                         + "<input type='checkbox' id='clickId'>"
912                         + "</body></html>");
913     }
914
915     /**
916      * Test when HtmlTableRow.onclick is set by a javascript
917      *
918      * @throws Exception if the test fails
919      */

920     public void testTableRow_onClickSetByNestedScript() throws Exception {
921         onClickBodyTest("<body><table><tbody><tr id='clickId'><td>cell value</td></tr></tbody></table>"
922                         + "<script language='JavaScript'>"
923                                 + "function doFoo(event) { alert('foo'); }"
924                                 + "document.getElementById('clickId').onclick = doFoo;</script></body>");
925     }
926
927     /**
928      * Test onClick handler and click method of teletype element.
929      *
930      * @throws Exception if the test fails
931      */

932     public void testTeletype_onClick() throws Exception {
933         onClickSimpleTest("tt");
934     }
935
936
937     /**
938      * Test onClick handler and click method of underline element.
939      *
940      * @throws Exception if the test fails
941      */

942     public void testUnderline_onClick() throws Exception {
943         onClickSimpleTest("u");
944     }
945
946
947     /**
948      * Test onClick handler and click method of unordered List element.
949      *
950      * @throws Exception if the test fails
951      */

952     public void testUnorderedList_onClick() throws Exception {
953         onClickBodyTest("<body><ul id='clickId' onClick='alert(\"foo\")'><li>Item</li></ul></body>");
954     }
955
956
957     /**
958      * Test onClick handler and click method of variable element.
959      *
960      * @throws Exception if the test fails
961      */

962     public void testVariable_onClick() throws Exception {
963         onClickSimpleTest("var");
964     }
965 }
966
Popular Tags