View Javadoc
1   /*
2    * Copyright (c) 2002-2025 Gargoyle Software Inc.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * https://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  package org.htmlunit.javascript.host.html;
16  
17  import org.htmlunit.WebDriverTestCase;
18  import org.htmlunit.junit.annotation.Alerts;
19  import org.junit.jupiter.api.Test;
20  import org.openqa.selenium.By;
21  import org.openqa.selenium.WebDriver;
22  import org.openqa.selenium.WebElement;
23  import org.openqa.selenium.interactions.Actions;
24  
25  /**
26   * Tests for {@link HTMLTextAreaElement}.
27   *
28   * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
29   * @author Marc Guillemot
30   * @author Ahmed Ashour
31   * @author Daniel Gredler
32   * @author Ronald Brill
33   * @author Frank Danek
34   * @author Carsten Steul
35   */
36  public class HTMLTextAreaElementTest extends WebDriverTestCase {
37  
38      /**
39       * @throws Exception if the test fails
40       */
41      @Test
42      @Alerts({"1234", "PoohBear"})
43      public void getValue() throws Exception {
44          final String html = DOCTYPE_HTML
45              + "<html>\n"
46              + "<head>\n"
47              + "  <script>\n"
48              + LOG_TITLE_FUNCTION
49              + "    function doTest() {\n"
50              + "      log(document.form1.textarea1.value);\n"
51              + "      document.form1.textarea1.value = 'PoohBear';\n"
52              + "      log(document.form1.textarea1.value);\n"
53              + "    }\n"
54              + "  </script>\n"
55              + "</head>\n"
56              + "<body onload='doTest()'>\n"
57              + "  <p>hello world</p>\n"
58              + "  <form name='form1' method='post' >\n"
59              + "    <textarea name='textarea1' cols='45' rows='4'>1234</textarea>\n"
60              + "  </form>\n"
61              + "</body></html>";
62  
63          loadPageVerifyTitle2(html);
64      }
65  
66      /**
67       * @throws Exception if the test fails
68       */
69      @Test
70      @Alerts("foo")
71      public void onChange() throws Exception {
72          final String html = DOCTYPE_HTML
73              + "<html>\n"
74              + "<head></head>\n"
75              + "<body>\n"
76              + "  <p>hello world</p>\n"
77              + "  <form name='form1'>\n"
78              + "    <textarea name='textarea1' onchange='alert(this.value)'></textarea>\n"
79              + "    <input name='myButton' type='button' onclick='document.form1.textarea1.value=\"from button\"'>\n"
80              + "  </form>\n"
81              + "</body></html>";
82  
83          final WebDriver driver = loadPage2(html);
84  
85          final WebElement textarea = driver.findElement(By.name("textarea1"));
86          textarea.sendKeys("foo");
87          driver.findElement(By.name("myButton")).click();
88  
89          verifyAlerts(driver, getExpectedAlerts());
90      }
91  
92      /**
93       * Tests that setValue doesn't has side effect. Test for bug 1155063.
94       * @throws Exception if the test fails
95       */
96      @Test
97      @Alerts({"TEXTAREA", "INPUT"})
98      public void setValue() throws Exception {
99          final String html = DOCTYPE_HTML
100             + "<html>\n"
101             + "<head></head>\n"
102             + "<body>\n"
103             + "  <form name='form1'>\n"
104             + "    <textarea name='question'></textarea>\n"
105             + "    <input type='button' name='btn_submit' value='Next'>\n"
106             + "  </form>\n"
107             + "  <script>\n"
108             + LOG_TITLE_FUNCTION
109             + "    document.form1.question.value = 'some text';\n"
110             + "    log(document.form1.elements[0].tagName);\n"
111             + "    log(document.form1.elements[1].tagName);\n"
112             + "  </script>\n"
113             + "</body>\n"
114             + "</html>";
115 
116         loadPageVerifyTitle2(html);
117     }
118 
119     /**
120      * @throws Exception if test fails
121      */
122     @Test
123     @Alerts({"11", "0"})
124     public void textLength() throws Exception {
125         final String html = DOCTYPE_HTML
126             + "<html>\n"
127             + "<head></head>\n"
128             + "<body>\n"
129             + "  <textarea id='myTextArea'></textarea>\n"
130             + "  <script>\n"
131             + LOG_TITLE_FUNCTION
132             + "    var textarea = document.getElementById('myTextArea');\n"
133             + "    textarea.value = 'hello there';\n"
134             + "    log(textarea.textLength);\n"
135             + "    textarea.value = '';\n"
136             + "    log(textarea.textLength);\n"
137             + "  </script>\n"
138             + "</body>\n"
139             + "</html>";
140 
141         loadPageVerifyTitle2(html);
142     }
143 
144     /**
145      * @throws Exception if test fails
146      */
147     @Test
148     @Alerts({"0,0", "11,11", "3,11", "3,10", "7,7"})
149     public void selection() throws Exception {
150         selection(3, 10);
151     }
152 
153     /**
154      * @throws Exception if test fails
155      */
156     @Test
157     @Alerts({"0,0", "11,11", "11,11", "11,11", "7,7"})
158     public void selection_outOfBounds() throws Exception {
159         selection(-3, 15);
160     }
161 
162     /**
163      * @throws Exception if test fails
164      */
165     @Test
166     @Alerts({"0,0", "11,11", "10,11", "5,5", "7,7"})
167     public void selection_reverseOrder() throws Exception {
168         selection(10, 5);
169     }
170 
171     private void selection(final int selectionStart, final int selectionEnd) throws Exception {
172         final String html = DOCTYPE_HTML
173             + "<html>\n"
174             + "<head></head>\n"
175             + "<body>\n"
176             + "  <textarea id='myTextArea'></textarea>\n"
177             + "  <script>\n"
178             + LOG_TITLE_FUNCTION
179             + "    var textarea = document.getElementById('myTextArea');\n"
180             + "    log(textarea.selectionStart + ',' + textarea.selectionEnd);\n"
181             + "    textarea.value = 'Hello there';\n"
182             + "    log(textarea.selectionStart + ',' + textarea.selectionEnd);\n"
183             + "    textarea.selectionStart = " + selectionStart + ";\n"
184             + "    log(textarea.selectionStart + ',' + textarea.selectionEnd);\n"
185             + "    textarea.selectionEnd = " + selectionEnd + ";\n"
186             + "    log(textarea.selectionStart + ',' + textarea.selectionEnd);\n"
187             + "    textarea.value = 'nothing';\n"
188             + "    log(textarea.selectionStart + ',' + textarea.selectionEnd);\n"
189             + "  </script>\n"
190             + "</body>\n"
191             + "</html>";
192 
193         loadPageVerifyTitle2(html);
194     }
195 
196     /**
197      * @throws Exception if an error occurs
198      */
199     @Test
200     @Alerts("no")
201     public void doScroll() throws Exception {
202         final String html = DOCTYPE_HTML
203             + "<html>\n"
204             + "  <head>\n"
205             + "    <script>\n"
206             + LOG_TITLE_FUNCTION
207             + "      function test() {\n"
208             + "        var t = document.getElementById('t');\n"
209             + "        if(t.doScroll) {\n"
210             + "          log('yes');\n"
211             + "          t.doScroll();\n"
212             + "          t.doScroll('down');\n"
213             + "        } else {\n"
214             + "          log('no');\n"
215             + "        }\n"
216             + "      }\n"
217             + "    </script>\n"
218             + "  </head>\n"
219             + "  <body onload='test()'><textarea id='t'>abc</textarea></body>\n"
220             + "</html>";
221 
222         loadPageVerifyTitle2(html);
223     }
224 
225     /**
226      * Test that the new line immediately following opening tag is ignored.
227      * @throws Exception if the test fails
228      */
229     @Test
230     @Alerts("Hello\\nworld\\n")
231     public void value_ignoreFirstNewLine() throws Exception {
232         value("\nHello\nworld\n");
233     }
234 
235     /**
236      * @throws Exception if the test fails
237      */
238     @Test
239     @Alerts("\\s\\nHello\\nworld\\n")
240     public void value_spaceBeforeFirstNewLine() throws Exception {
241         value(" \nHello\nworld\n");
242     }
243 
244     private void value(final String textAreaBody) throws Exception {
245         final String html = DOCTYPE_HTML
246             + "<html>\n"
247             + "<head>\n"
248             + "  <script>\n"
249             + LOG_TITLE_FUNCTION_NORMALIZE
250             + "    function doTest() {\n"
251             + "      log(document.form1.textarea1.value);\n"
252             + "    }\n"
253             + "  </script>\n"
254             + "</head>\n"
255             + "<body onload='doTest()'>\n"
256             + "  <form name='form1' method='post' >\n"
257             + "    <textarea name='textarea1'>" + textAreaBody + "</textarea>\n"
258             + "    </textarea>\n"
259             + "  </form>\n"
260             + "</body></html>";
261 
262         loadPageVerifyTitle2(html);
263     }
264 
265     /**
266      * @throws Exception if an error occurs
267      */
268     @Test
269     @Alerts({"\\sfoo\\s\\n\\sbar\\s", "\\sfoo\\s\\n\\sbar\\s"})
270     public void defaultValue() throws Exception {
271         final String html = DOCTYPE_HTML
272             + "<html>\n"
273             + "<head>\n"
274             + "  <script>\n"
275             + LOG_TITLE_FUNCTION_NORMALIZE
276             + "    function test() {\n"
277             + "      var t = document.getElementById('textArea');\n"
278             + "      log(t.defaultValue);\n"
279             + "      log(t.value);\n"
280             + "    }\n"
281             + "  </script>\n"
282             + "</head>\n"
283             + "<body onload='test()'>\n"
284             + "  <form id='form1'>\n"
285             + "    <textarea id='textArea'>\n foo \n bar </textarea>\n"
286             + "  </form>\n"
287             + "</body></html>";
288 
289         loadPageVerifyTitle2(html);
290     }
291 
292     /**
293      * @throws Exception if an error occurs
294      */
295     @Test
296     @Alerts({"true", "false"})
297     public void readOnly() throws Exception {
298         final String html = DOCTYPE_HTML
299             + "<html>\n"
300             + "<head>\n"
301             + "  <script>\n"
302             + LOG_TITLE_FUNCTION
303             + "  function test() {\n"
304             + "    var t = document.getElementById('textArea');\n"
305             + "    log(t.readOnly);\n"
306             + "    t.readOnly = false;\n"
307             + "    log(t.readOnly);\n"
308             + "  }\n"
309             + "</script>\n"
310             + "</head>\n"
311             + "<body onload='test()'>\n"
312             + "  <form id='form1'>\n"
313             + "    <textarea id='textArea' readonly>\n foo \n bar </textarea>\n"
314             + "  </form>\n"
315             + "</body></html>";
316 
317         loadPageVerifyTitle2(html);
318     }
319 
320     /**
321      * @throws Exception if an error occurs
322      */
323     @Test
324     @Alerts({"", "A", "a", "A", "a8", "8Afoo", "8", "@"})
325     public void accessKey() throws Exception {
326         final String html = DOCTYPE_HTML
327             + "<html>\n"
328             + "<head></head>\n"
329             + "<body>\n"
330             + "  <textarea id='a1'>a1</textarea>\n"
331             + "  <textarea id='a2' accesskey='A'>a2</textarea>\n"
332 
333             + "  <script>\n"
334             + LOG_TITLE_FUNCTION
335             + "    var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n"
336             + "    log(a1.accessKey);\n"
337             + "    log(a2.accessKey);\n"
338 
339             + "    a1.accessKey = 'a';\n"
340             + "    log(a1.accessKey);\n"
341 
342             + "    a1.accessKey = 'A';\n"
343             + "    log(a1.accessKey);\n"
344 
345             + "    a1.accessKey = 'a8';\n"
346             + "    log(a1.accessKey);\n"
347 
348             + "    a1.accessKey = '8Afoo';\n"
349             + "    log(a1.accessKey);\n"
350 
351             + "    a1.accessKey = '8';\n"
352             + "    log(a1.accessKey);\n"
353 
354             + "    a1.accessKey = '@';\n"
355             + "    log(a1.accessKey);\n"
356             + "  </script>\n"
357             + "</body></html>";
358 
359         loadPageVerifyTitle2(html);
360     }
361 
362     /**
363      * @throws Exception if an error occurs
364      */
365     @Test
366     @Alerts({"20", "5", "8", "4", "20", "20", "20", "3"})
367     public void cols() throws Exception {
368         final String html = DOCTYPE_HTML
369             + "<html><head>\n"
370             + "<script>\n"
371             + LOG_TITLE_FUNCTION
372             + "  function setCols(e, value) {\n"
373             + "    try {\n"
374             + "      e.cols = value;\n"
375             + "    } catch(e) { logEx(e); }\n"
376             + "  }\n"
377             + "</script>\n"
378             + "</head>\n"
379 
380             + "<body>\n"
381             + "  <textarea id='a1'>a1</textarea>\n"
382             + "  <textarea id='a2' cols='5'>a2</textarea>\n"
383 
384             + "  <script>\n"
385             + "    var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n"
386             + "    log(a1.cols);\n"
387             + "    log(a2.cols);\n"
388 
389             + "    setCols(a1, '8');\n"
390             + "    log(a1.cols);\n"
391 
392             + "    setCols(a1, 4);\n"
393             + "    log(a1.cols);\n"
394 
395             + "    setCols(a1, 'a');\n"
396             + "    log(a1.cols);\n"
397 
398             + "    setCols(a1, '');\n"
399             + "    log(a1.cols);\n"
400 
401             + "    setCols(a1, -1);\n"
402             + "    log(a1.cols);\n"
403 
404             + "    setCols(a1, 3.4);\n"
405             + "    log(a1.cols);\n"
406             + "</script></body></html>";
407 
408         loadPageVerifyTitle2(html);
409     }
410 
411     /**
412      * @throws Exception if an error occurs
413      */
414     @Test
415     @Alerts({"2", "5", "8", "4", "2", "2", "2", "3"})
416     public void rows() throws Exception {
417         final String html = DOCTYPE_HTML
418             + "<html><head>\n"
419             + "<script>\n"
420             + LOG_TITLE_FUNCTION
421             + "  function setRows(e, value) {\n"
422             + "    try {\n"
423             + "      e.rows = value;\n"
424             + "    } catch(e) { logEx(e); }\n"
425             + "  }\n"
426             + "</script>\n"
427             + "</head>\n"
428 
429             + "<body>\n"
430             + "  <textarea id='a1'>a1</textarea>\n"
431             + "  <textarea id='a2' rows='5'>a2</textarea>\n"
432 
433             + "  <script>\n"
434             + "    var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n"
435             + "    log(a1.rows);\n"
436             + "    log(a2.rows);\n"
437 
438             + "    setRows(a1, '8');\n"
439             + "    log(a1.rows);\n"
440 
441             + "    setRows(a1, 4);\n"
442             + "    log(a1.rows);\n"
443 
444             + "    setRows(a1, 'a');\n"
445             + "    log(a1.rows);\n"
446 
447             + "    setRows(a1, '');\n"
448             + "    log(a1.rows);\n"
449 
450             + "    setRows(a1, -1);\n"
451             + "    log(a1.rows);\n"
452 
453             + "    setRows(a1, 3.4);\n"
454             + "    log(a1.rows);\n"
455             + "  </script>\n"
456             + "</body></html>";
457 
458         loadPageVerifyTitle2(html);
459     }
460 
461     /**
462      * @throws Exception if the test fails
463      */
464     @Test
465     @Alerts({"9", "9", "2", "7"})
466     public void selectionRange() throws Exception {
467         final String html = DOCTYPE_HTML
468             + "<html>\n"
469             + "<head>\n"
470             + "  <script>\n"
471             + LOG_TITLE_FUNCTION
472             + "    function test() {\n"
473             + "      var ta = document.getElementById('myInput');\n"
474             + "      ta.setSelectionRange(15, 15);\n"
475             + "      log(ta.selectionStart);\n"
476             + "      log(ta.selectionEnd);\n"
477             + "      ta.setSelectionRange(2, 7);\n"
478             + "      log(ta.selectionStart);\n"
479             + "      log(ta.selectionEnd);\n"
480             + "    }\n"
481             + "  </script>\n"
482             + "</head>\n"
483             + "<body onload='test()'>\n"
484             + "  <textarea id='myInput'>some test</textarea>\n"
485             + "</body></html>";
486 
487         loadPageVerifyTitle2(html);
488     }
489 
490     /**
491      * @throws Exception if an error occurs
492      */
493     @Test
494     @Alerts({"test", "4", "42", "2", "[object HTMLTextAreaElement]", "28"})
495     public void getAttributeAndSetValue() throws Exception {
496         final String html = DOCTYPE_HTML
497             + "<html>\n"
498             + "  <head>\n"
499             + "    <script>\n"
500             + LOG_TITLE_FUNCTION
501             + "      function test() {\n"
502             + "        var t = document.getElementById('t');\n"
503             + "        t.value = 'test';\n"
504             + "        log(t.value);\n"
505             + "        if (t.value != null)\n"
506             + "          log(t.value.length);\n"
507 
508             + "        t.value = 42;\n"
509             + "        log(t.value);\n"
510             + "        if (t.value != null)\n"
511             + "          log(t.value.length);\n"
512 
513             + "        t.value = document.getElementById('t');\n"
514             + "        log(t.value);\n"
515             + "        if (t.value != null)\n"
516             + "          log(t.value.length);\n"
517             + "      }\n"
518             + "    </script>\n"
519             + "  </head>\n"
520             + "  <body onload='test()'>\n"
521             + "    <textarea id='t'>abc</textarea>\n"
522             + "  </body>\n"
523             + "</html>";
524 
525         loadPageVerifyTitle2(html);
526     }
527 
528     /**
529      * @throws Exception if an error occurs
530      */
531     @Test
532     @Alerts({"null", "4", "", "0"})
533     public void getAttributeAndSetValueNull() throws Exception {
534         final String html = DOCTYPE_HTML
535             + "<html>\n"
536             + "  <head>\n"
537             + "    <script>\n"
538             + LOG_TITLE_FUNCTION
539             + "      function test() {\n"
540             + "        var t = document.getElementById('t');\n"
541             + "        t.value = 'null';\n"
542             + "        log(t.value);\n"
543             + "        if (t.value != null)\n"
544             + "          log(t.value.length);\n"
545 
546             + "        t.value = null;\n"
547             + "        log(t.value);\n"
548             + "        if (t.value != null)\n"
549             + "          log(t.value.length);\n"
550             + "      }\n"
551             + "    </script>\n"
552             + "  </head>\n"
553             + "  <body onload='test()'>\n"
554             + "    <textarea id='t'>abc</textarea>\n"
555             + "  </body>\n"
556             + "</html>";
557 
558         loadPageVerifyTitle2(html);
559     }
560 
561     /**
562      * @throws Exception if an error occurs
563      */
564     @Test
565     @Alerts({"12", "2", "[object HTMLTextAreaElement]", "28"})
566     public void getAttributeAndSetValueOther() throws Exception {
567         final String html = DOCTYPE_HTML
568             + "<html>\n"
569             + "  <head>\n"
570             + "    <script>\n"
571             + LOG_TITLE_FUNCTION
572             + "      function test() {\n"
573             + "        var t = document.getElementById('t');\n"
574             + "        t.value = 12;\n"
575             + "        log(t.value);\n"
576             + "        if (t.value != null)\n"
577             + "          log(t.value.length);\n"
578 
579             + "        t.value = t;\n"
580             + "        log(t.value);\n"
581             + "        if (t.value != null)\n"
582             + "          log(t.value.length);\n"
583             + "      }\n"
584             + "    </script>\n"
585             + "  </head>\n"
586             + "  <body onload='test()'>\n"
587             + "    <textarea id='t'>abc</textarea>\n"
588             + "  </body>\n"
589             + "</html>";
590 
591         loadPageVerifyTitle2(html);
592     }
593 
594     /**
595      * @throws Exception if the test fails
596      */
597     @Test
598     @Alerts({"-1", "null", "32", "32", "-1", "ms"})
599     public void maxLength() throws Exception {
600         final String html = DOCTYPE_HTML
601             + "<html>\n"
602             + "<head>\n"
603             + "  <script>\n"
604             + LOG_TITLE_FUNCTION
605             + "    function test() {\n"
606             + "      log(document.form1.textarea1.maxLength);\n"
607             + "      log(document.form1.textarea1.getAttribute('maxLength'));\n"
608             + "      log(document.form1.textarea2.maxLength);\n"
609             + "      log(document.form1.textarea2.getAttribute('maxLength'));\n"
610             + "      log(document.form1.textarea3.maxLength);\n"
611             + "      log(document.form1.textarea3.getAttribute('maxLength'));\n"
612             + "    }\n"
613             + "  </script>\n"
614             + "</head>\n"
615             + "<body onload='test()'>\n"
616             + "  <form name='form1' method='post'>\n"
617             + "    <textarea name='textarea1'></textarea>\n"
618             + "    <textarea name='textarea2' maxLength='32'></textarea>\n"
619             + "    <textarea name='textarea3' maxLength='ms'></textarea>\n"
620             + "  </form>\n"
621             + "</body></html>";
622 
623         loadPageVerifyTitle2(html);
624     }
625 
626     /**
627      * @throws Exception if the test fails
628      */
629     @Test
630     @Alerts({"-1", "null", "32", "32", "-1", "ms"})
631     public void minLength() throws Exception {
632         final String html = DOCTYPE_HTML
633             + "<html>\n"
634             + "<head>\n"
635             + "  <script>\n"
636             + LOG_TITLE_FUNCTION
637             + "    function test() {\n"
638             + "      log(document.form1.textarea1.minLength);\n"
639             + "      log(document.form1.textarea1.getAttribute('minLength'));\n"
640             + "      log(document.form1.textarea2.minLength);\n"
641             + "      log(document.form1.textarea2.getAttribute('minLength'));\n"
642             + "      log(document.form1.textarea3.minLength);\n"
643             + "      log(document.form1.textarea3.getAttribute('minLength'));\n"
644             + "    }\n"
645             + "  </script>\n"
646             + "</head>\n"
647             + "<body onload='test()'>\n"
648             + "  <form name='form1' method='post'>\n"
649             + "    <textarea name='textarea1'></textarea>\n"
650             + "    <textarea name='textarea2' minLength='32'></textarea>\n"
651             + "    <textarea name='textarea3' minLength='ms'></textarea>\n"
652             + "  </form>\n"
653             + "</body></html>";
654 
655         loadPageVerifyTitle2(html);
656     }
657 
658     /**
659      * @throws Exception if the test fails
660      */
661     @Test
662     @Alerts({"10", "10", "IndexSizeError/DOMException", "10", "10", "0", "0"})
663     public void setMaxLength() throws Exception {
664         final String html = DOCTYPE_HTML
665             + "<html>\n"
666             + "<head>\n"
667             + "  <script>\n"
668             + LOG_TITLE_FUNCTION
669             + "    function setMaxLength(length){\n"
670             + "      try {\n"
671             + "        document.form1.textarea1.maxLength = length;\n"
672             + "      } catch(e) { logEx(e); }\n"
673             + "    }\n"
674             + "  </script>\n"
675             + "</head>\n"
676             + "<body>\n"
677             + "  <form name='form1' method='post' >\n"
678             + "    <textarea id='textarea1'></textarea>\n"
679             + "    <script>\n"
680             + "      var a = document.getElementById('textarea1');\n"
681 
682             + "      setMaxLength(10);\n"
683             + "      log(a.maxLength);\n"
684             + "      log(a.getAttribute('maxLength'));\n"
685 
686             + "      setMaxLength(-1);\n"
687             + "      log(a.maxLength);\n"
688             + "      log(a.getAttribute('maxLength'));\n"
689 
690             + "      setMaxLength('abc');\n"
691             + "      log(a.maxLength);\n"
692             + "      log(a.getAttribute('maxLength'));\n"
693 
694             + "    </script>\n"
695             + "  </form>\n"
696             + "</body></html>";
697 
698         loadPageVerifyTitle2(html);
699     }
700 
701     /**
702      * @throws Exception if the test fails
703      */
704     @Test
705     @Alerts("[object HTMLFormElement]")
706     public void form() throws Exception {
707         final String html = DOCTYPE_HTML
708             + "<html>\n"
709             + "<body>\n"
710             + "  <form>\n"
711             + "    <textarea id='a'></textarea>\n"
712             + "  </form>"
713             + "  <script>\n"
714             + LOG_TITLE_FUNCTION
715             + "    log(document.getElementById('a').form);\n"
716             + "  </script>"
717             + "</body>"
718             + "</html>";
719 
720         loadPageVerifyTitle2(html);
721     }
722 
723     /**
724      * @throws Exception if an error occurs
725      */
726     @Test
727     @Alerts("mouse over [tester]")
728     public void mouseOverTextarea() throws Exception {
729         shutDownAll();
730         mouseOver("<textarea id='tester' onmouseover='dumpEvent(event);'>HtmlUnit</textarea>");
731     }
732 
733     /**
734      * @throws Exception if an error occurs
735      */
736     @Test
737     @Alerts("mouse over [tester]")
738     public void mouseOverTextareaDisabled() throws Exception {
739         shutDownAll();
740         mouseOver("<textarea id='tester' onmouseover='dumpEvent(event);' disabled >HtmlUnit</textarea>");
741     }
742 
743     private void mouseOver(final String element) throws Exception {
744         final String html = DOCTYPE_HTML
745             + "<html>\n"
746             + "  <head>\n"
747             + "    <script>\n"
748             + "    function dumpEvent(event) {\n"
749             + "      // target\n"
750             + "      var eTarget;\n"
751             + "      if (event.target) {\n"
752             + "        eTarget = event.target;\n"
753             + "      } else if (event.srcElement) {\n"
754             + "        eTarget = event.srcElement;\n"
755             + "      }\n"
756             + "      // defeat Safari bug\n"
757             + "      if (eTarget.nodeType == 3) {\n"
758             + "        eTarget = eTarget.parentNode;\n"
759             + "      }\n"
760             + "      var msg = 'mouse over';\n"
761             + "      if (eTarget.name) {\n"
762             + "        msg = msg + ' [' + eTarget.name + ']';\n"
763             + "      } else {\n"
764             + "        msg = msg + ' [' + eTarget.id + ']';\n"
765             + "      }\n"
766             + "      document.title += msg;\n"
767             + "    }\n"
768             + "    </script>\n"
769             + "  </head>\n"
770             + "<body>\n"
771             + "  <form id='form1'>\n"
772             + "    " + element + "\n"
773             + "  </form>\n"
774             + "</body></html>";
775 
776         final WebDriver driver = loadPage2(html);
777 
778         final Actions actions = new Actions(driver);
779         actions.moveToElement(driver.findElement(By.id("tester")));
780         actions.perform();
781 
782         assertTitle(driver, getExpectedAlerts()[0]);
783     }
784 
785     /**
786      * @throws Exception if the test fails
787      */
788     @Test
789     @Alerts({"HtmlUnit", "</> htmx rocks!"})
790     public void innerHtml() throws Exception {
791         final String html = DOCTYPE_HTML
792             + "<html>\n"
793             + "  <head>\n"
794             + "    <title>Page Title</title>\n"
795             + "    <script>\n"
796             + LOG_TEXTAREA_FUNCTION
797             + "      function test() {\n"
798             + "        var textarea = document.getElementsByTagName('textarea')[0];\n"
799             + "        log(textarea.value);\n"
800             + "        textarea.innerHTML = '</> htmx rocks!';\n"
801             + "        log(textarea.value);\n"
802             + "      }\n"
803             + "    </script>\n"
804             + "  </head>\n"
805             + "  <body onload='test()'>"
806             + "    <textarea>HtmlUnit</textarea>\n"
807             + LOG_TEXTAREA
808             + "  </body>\n"
809             + "</html>";
810 
811         loadPageVerifyTextArea2(html);
812     }
813 
814     /**
815      * @throws Exception if the test fails
816      */
817     @Test
818     @Alerts({"HtmlUnit", "<div>htmx rocks</div>"})
819     public void innerHtmlTag() throws Exception {
820         final String html = DOCTYPE_HTML
821             + "<html>\n"
822             + "  <head>\n"
823             + "    <title>Page Title</title>\n"
824             + "    <script>\n"
825             + LOG_TEXTAREA_FUNCTION
826             + "      function test() {\n"
827             + "        var textarea = document.getElementsByTagName('textarea')[0];\n"
828             + "        log(textarea.value);\n"
829             + "        textarea.innerHTML = '<div>htmx rocks</div>';\n"
830             + "        log(textarea.value);\n"
831             + "      }\n"
832             + "    </script>\n"
833             + "  </head>\n"
834             + "  <body onload='test()'>\n"
835             + "    <textarea>HtmlUnit</textarea>\n"
836             + LOG_TEXTAREA
837             + "  </body>\n"
838             + "</html>";
839 
840         loadPageVerifyTextArea2(html);
841     }
842 
843     /**
844      * @throws Exception if the test fails
845      */
846     @Test
847     @Alerts({"", "</> htmx rocks!"})
848     public void innerHtmlEscaping() throws Exception {
849         final String html = DOCTYPE_HTML
850             + "<html>\n"
851             + "  <head>\n"
852             + "    <title>Page Title</title>\n"
853             + "    <script>\n"
854             + LOG_TEXTAREA_FUNCTION
855             + "      function test() {\n"
856             + "        var textarea = document.getElementsByTagName('textarea')[0];\n"
857             + "        log(textarea.value);\n"
858             + "        textarea.innerHTML = '&lt;/> htmx rocks!';\n"
859             + "        log(textarea.value);\n"
860             + "      }\n"
861             + "    </script>\n"
862             + "  </head>\n"
863             + "  <body onload='test()'>\n"
864             + "    <textarea></textarea>\n"
865             + LOG_TEXTAREA
866             + "  </body>\n"
867             + "</html>";
868 
869         loadPageVerifyTextArea2(html);
870     }
871 
872     /**
873      * @throws Exception if an error occurs
874      */
875     @Test
876     @Alerts({"true", "false", "true", "false", "true"})
877     public void willValidate() throws Exception {
878         final String html = DOCTYPE_HTML
879                 + "<html><head>\n"
880                 + "  <script>\n"
881                 + LOG_TITLE_FUNCTION
882                 + "    function test() {\n"
883                 + "      log(document.getElementById('i1').willValidate);\n"
884                 + "      log(document.getElementById('i2').willValidate);\n"
885                 + "      log(document.getElementById('i3').willValidate);\n"
886                 + "      log(document.getElementById('i4').willValidate);\n"
887                 + "      log(document.getElementById('i5').willValidate);\n"
888                 + "    }\n"
889                 + "  </script>\n"
890                 + "</head>\n"
891                 + "<body onload='test()'>\n"
892                 + "  <form>\n"
893                 + "    <textarea id='i1'>button</textarea>"
894                 + "    <textarea id='i2' disabled></textarea>"
895                 + "    <textarea id='i3' hidden></textarea>"
896                 + "    <textarea id='i4' readonly></textarea>"
897                 + "    <textarea id='i5' style='display: none'></textarea>"
898                 + "  </form>\n"
899                 + "</body></html>";
900 
901         loadPageVerifyTitle2(html);
902     }
903 }