1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.html;
16
17 import org.htmlunit.SimpleWebTestCase;
18 import org.htmlunit.html.HtmlPage;
19 import org.htmlunit.html.HtmlTextArea;
20 import org.htmlunit.junit.BrowserRunner;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23
24
25
26
27
28
29
30
31
32 @RunWith(BrowserRunner.class)
33 public class HTMLTextAreaElement2Test extends SimpleWebTestCase {
34
35
36
37
38
39 @Test
40 public void type_onchange() throws Exception {
41 final String content = DOCTYPE_HTML
42 + "<html><head><title>foo</title>\n"
43 + "<script>\n"
44 + " function changed(e) {\n"
45 + " log('changed: ' + e.value);\n"
46 + " }\n"
47 + " function keypressed(e) {\n"
48 + " log('keypressed: ' + e.value);\n"
49 + " }\n"
50 + " function log(msg) {\n"
51 + " document.getElementById('log').value += msg + '; ';\n"
52 + " }\n"
53 + "</script></head>\n"
54 + "<body>\n"
55 + "<form id='form1'>\n"
56 + "<textarea id='textArea1' onchange='changed(this)' onkeypress='keypressed(this)'></textarea>\n"
57 + "<textarea id='log'></textarea>\n"
58 + "</form>\n"
59 + "</body></html>";
60 final HtmlPage page = loadPage(content);
61 final HtmlTextArea textArea = page.getHtmlElementById("textArea1");
62 textArea.type("hello");
63 page.setFocusedElement(null);
64
65 final HtmlTextArea log = page.getHtmlElementById("log");
66 final String expectation = "keypressed: ; "
67 + "keypressed: h; "
68 + "keypressed: he; "
69 + "keypressed: hel; "
70 + "keypressed: hell; "
71 + "changed: hello;";
72 assertEquals(expectation, log.asNormalizedText());
73 }
74
75 }