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.html.HtmlDirectory;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.jupiter.api.Test;
21 import org.openqa.selenium.By;
22 import org.openqa.selenium.WebDriver;
23 import org.openqa.selenium.WebElement;
24 import org.openqa.selenium.htmlunit.HtmlUnitDriver;
25
26
27
28
29
30
31
32
33 public class HTMLDirectoryElementTest extends WebDriverTestCase {
34
35
36
37
38 @Test
39 @Alerts("[object HTMLDirectoryElement]")
40 public void simpleScriptable() throws Exception {
41 final String html = DOCTYPE_HTML
42 + "<html><head>\n"
43 + "<script>\n"
44 + LOG_TITLE_FUNCTION
45 + " function test() {\n"
46 + " log(document.getElementById('myId'));\n"
47 + " }\n"
48 + "</script>\n"
49 + "</head><body onload='test()'>\n"
50 + " <dir id='myId'/>\n"
51 + "</body></html>";
52
53 final WebDriver driver = loadPageVerifyTitle2(html);
54 if (driver instanceof HtmlUnitDriver) {
55 final WebElement element = driver.findElement(By.id("myId"));
56 assertTrue(toHtmlElement(element) instanceof HtmlDirectory);
57 }
58 }
59
60
61
62
63 @Test
64 @Alerts({"false", "true", "true", "true", "null", "", "blah", "2",
65 "true", "false", "true", "false", "", "null", "", "null"})
66 public void compact() throws Exception {
67 final String html = DOCTYPE_HTML
68 + "<html>\n"
69 + " <head>\n"
70 + " <script>\n"
71 + LOG_TITLE_FUNCTION
72 + " function test() {\n"
73 + " log(document.getElementById('dir1').compact);\n"
74 + " log(document.getElementById('dir2').compact);\n"
75 + " log(document.getElementById('dir3').compact);\n"
76 + " log(document.getElementById('dir4').compact);\n"
77 + " log(document.getElementById('dir1').getAttribute('compact'));\n"
78 + " log(document.getElementById('dir2').getAttribute('compact'));\n"
79 + " log(document.getElementById('dir3').getAttribute('compact'));\n"
80 + " log(document.getElementById('dir4').getAttribute('compact'));\n"
81
82 + " document.getElementById('dir1').compact = true;\n"
83 + " document.getElementById('dir2').compact = false;\n"
84 + " document.getElementById('dir3').compact = 'xyz';\n"
85 + " document.getElementById('dir4').compact = null;\n"
86 + " log(document.getElementById('dir1').compact);\n"
87 + " log(document.getElementById('dir2').compact);\n"
88 + " log(document.getElementById('dir3').compact);\n"
89 + " log(document.getElementById('dir4').compact);\n"
90 + " log(document.getElementById('dir1').getAttribute('compact'));\n"
91 + " log(document.getElementById('dir2').getAttribute('compact'));\n"
92 + " log(document.getElementById('dir3').getAttribute('compact'));\n"
93 + " log(document.getElementById('dir4').getAttribute('compact'));\n"
94 + " }\n"
95 + " </script>\n"
96 + " </head>\n"
97 + " <body onload='test()'>\n"
98 + " <dir id='dir1'><li>a</li><li>b</li></dir>\n"
99 + " <dir compact='' id='dir2'><li>a</li><li>b</li></dir>\n"
100 + " <dir compact='blah' id='dir3'><li>a</li><li>b</li></dir>\n"
101 + " <dir compact='2' id='dir4'><li>a</li><li>b</li></dir>\n"
102 + " </body>\n"
103 + "</html>";
104
105 loadPageVerifyTitle2(html);
106 }
107
108
109
110
111 @Test
112 @Alerts({"undefined", "undefined", "undefined", "undefined",
113 "null", "", "blah", "A", "1", "a", "A", "i", "I", "u"})
114 public void type() throws Exception {
115 final String html = DOCTYPE_HTML
116 + "<html>\n"
117 + " <head>\n"
118 + " <script>\n"
119 + LOG_TITLE_FUNCTION
120 + " function test() {\n"
121 + " log(document.getElementById('dir1').type);\n"
122 + " log(document.getElementById('dir2').type);\n"
123 + " log(document.getElementById('dir3').type);\n"
124 + " log(document.getElementById('dir4').type);\n"
125 + " log(document.getElementById('dir1').getAttribute('type'));\n"
126 + " log(document.getElementById('dir2').getAttribute('type'));\n"
127 + " log(document.getElementById('dir3').getAttribute('type'));\n"
128 + " log(document.getElementById('dir4').getAttribute('type'));\n"
129
130 + " document.getElementById('dir1').type = '1';\n"
131 + " log(document.getElementById('dir1').type);\n"
132
133 + " document.getElementById('dir1').type = 'a';\n"
134 + " log(document.getElementById('dir1').type);\n"
135
136 + " document.getElementById('dir1').type = 'A';\n"
137 + " log(document.getElementById('dir1').type);\n"
138
139 + " document.getElementById('dir1').type = 'i';\n"
140 + " log(document.getElementById('dir1').type);\n"
141
142 + " document.getElementById('dir1').type = 'I';\n"
143 + " log(document.getElementById('dir1').type);\n"
144
145 + " try { document.getElementById('dir1').type = 'u' } catch(e) {logEx(e);}\n"
146 + " log(document.getElementById('dir1').type);\n"
147 + " }\n"
148 + " </script>\n"
149 + " </head>\n"
150 + " <body onload='test()'>\n"
151 + " <dir id='dir1'><li>a</li><li>b</li></dir>\n"
152 + " <dir type='' id='dir2'><li>a</li><li>b</li></dir>\n"
153 + " <dir type='blah' id='dir3'><li>a</li><li>b</li></dir>\n"
154 + " <dir type='A' id='dir4'><li>a</li><li>b</li></dir>\n"
155 + " </body>\n"
156 + "</html>";
157
158 loadPageVerifyTitle2(html);
159 }
160 }