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.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28
29
30 @RunWith(BrowserRunner.class)
31 public class HTMLLegendElementTest extends WebDriverTestCase {
32
33
34
35
36 @Test
37 @Alerts({"", "A", "a", "A", "a8", "8Afoo", "8", "@"})
38 public void accessKey() throws Exception {
39 final String html = DOCTYPE_HTML
40 + "<html><body><legend id='a1'>a1</legend><legend id='a2' accesskey='A'>a2</legend><script>\n"
41 + LOG_TITLE_FUNCTION
42 + "var a1 = document.getElementById('a1'), a2 = document.getElementById('a2');\n"
43 + "log(a1.accessKey);\n"
44 + "log(a2.accessKey);\n"
45 + "a1.accessKey = 'a';\n"
46 + "a2.accessKey = 'A';\n"
47 + "log(a1.accessKey);\n"
48 + "log(a2.accessKey);\n"
49 + "a1.accessKey = 'a8';\n"
50 + "a2.accessKey = '8Afoo';\n"
51 + "log(a1.accessKey);\n"
52 + "log(a2.accessKey);\n"
53 + "a1.accessKey = '8';\n"
54 + "a2.accessKey = '@';\n"
55 + "log(a1.accessKey);\n"
56 + "log(a2.accessKey);\n"
57 + "</script></body></html>";
58
59 loadPageVerifyTitle2(html);
60 }
61
62
63
64
65 @Test
66 @Alerts("[object HTMLFormElement]")
67 public void form() throws Exception {
68 final String html = DOCTYPE_HTML
69 + "<html><body><form><fieldset><legend id='a'>a</legend></fieldset></form><script>\n"
70 + LOG_TITLE_FUNCTION
71 + "log(document.getElementById('a').form);\n"
72 + "</script></body></html>";
73
74 loadPageVerifyTitle2(html);
75 }
76
77
78
79
80 @Test
81 @Alerts({"left", "right", "bottom", "top", "wrong", ""})
82 public void getAlign() throws Exception {
83 final String html = DOCTYPE_HTML
84 + "<html><body>\n"
85 + " <form><fieldset>\n"
86 + " <legend id='i1' align='left' ></legend>\n"
87 + " <legend id='i2' align='right' ></legend>\n"
88 + " <legend id='i3' align='bottom' ></legend>\n"
89 + " <legend id='i4' align='top' ></legend>\n"
90 + " <legend id='i5' align='wrong' ></legend>\n"
91 + " <legend id='i6' ></legend>\n"
92 + " </fieldset></form>\n"
93
94 + "<script>\n"
95 + LOG_TITLE_FUNCTION
96 + " for (var i = 1; i <= 6; i++) {\n"
97 + " log(document.getElementById('i' + i).align);\n"
98 + " }\n"
99 + "</script>\n"
100 + "</body></html>";
101
102 loadPageVerifyTitle2(html);
103 }
104
105
106
107
108 @Test
109 @Alerts({"CenTer", "8", "foo", "left", "right", "bottom", "top"})
110 public void setAlign() throws Exception {
111 final String html = DOCTYPE_HTML
112 + "<html><body>\n"
113 + " <form><fieldset>\n"
114 + " <legend id='i1' align='left' ></legend>\n"
115 + " </fieldset></form>\n"
116
117 + "<script>\n"
118 + LOG_TITLE_FUNCTION
119 + " function setAlign(elem, value) {\n"
120 + " try {\n"
121 + " elem.align = value;\n"
122 + " } catch(e) { logEx(e); }\n"
123 + " log(elem.align);\n"
124 + " }\n"
125
126 + " var elem = document.getElementById('i1');\n"
127 + " setAlign(elem, 'CenTer');\n"
128
129 + " setAlign(elem, '8');\n"
130 + " setAlign(elem, 'foo');\n"
131
132 + " setAlign(elem, 'left');\n"
133 + " setAlign(elem, 'right');\n"
134 + " setAlign(elem, 'bottom');\n"
135 + " setAlign(elem, 'top');\n"
136 + "</script>\n"
137 + "</body></html>";
138
139 loadPageVerifyTitle2(html);
140 }
141 }