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.annotation.Alerts;
19 import org.junit.jupiter.api.Test;
20
21
22
23
24
25
26
27
28 public class HTMLTableCaptionElementTest extends WebDriverTestCase {
29
30
31
32
33 @Test
34 @Alerts({"left", "right", "bottom", "top", "wrong", ""})
35 public void getAlign() throws Exception {
36 final String html = DOCTYPE_HTML
37 + "<html><body>\n"
38 + " <table>\n"
39 + " <caption id='c1' align='left' ></caption>\n"
40 + " <caption id='c2' align='right' ></caption>\n"
41 + " <caption id='c3' align='bottom' ></caption>\n"
42 + " <caption id='c4' align='top' ></caption>\n"
43 + " <caption id='c5' align='wrong' ></caption>\n"
44 + " <caption id='c6' ></caption>\n"
45 + " </table>\n"
46
47 + "<script>\n"
48 + LOG_TITLE_FUNCTION
49 + " for (var i = 1; i <= 6; i++) {\n"
50 + " log(document.getElementById('c' + i).align);\n"
51 + " }\n"
52 + "</script>\n"
53 + "</body></html>";
54
55 loadPageVerifyTitle2(html);
56 }
57
58
59
60
61 @Test
62 @Alerts({"CenTer", "8", "foo", "left", "right", "bottom", "top"})
63 public void setAlign() throws Exception {
64 final String html = DOCTYPE_HTML
65 + "<html><body>\n"
66 + " <table>\n"
67 + " <caption id='c1' align='left' ></caption>\n"
68 + " </table>\n"
69
70 + "<script>\n"
71 + LOG_TITLE_FUNCTION
72 + " function setAlign(elem, value) {\n"
73 + " try {\n"
74 + " elem.align = value;\n"
75 + " } catch(e) { logEx(e); }\n"
76 + " log(elem.align);\n"
77 + " }\n"
78
79 + " var elem = document.getElementById('c1');\n"
80 + " setAlign(elem, 'CenTer');\n"
81
82 + " setAlign(elem, '8');\n"
83 + " setAlign(elem, 'foo');\n"
84
85 + " setAlign(elem, 'left');\n"
86 + " setAlign(elem, 'right');\n"
87 + " setAlign(elem, 'bottom');\n"
88 + " setAlign(elem, 'top');\n"
89 + "</script>\n"
90 + "</body></html>";
91
92 loadPageVerifyTitle2(html);
93 }
94
95
96
97
98 @Test
99 @Alerts({"undefined", "undefined", "undefined", "middle", "8", "BOTtom"})
100 public void vAlign() throws Exception {
101 final String html = DOCTYPE_HTML
102 + "<html><body><table>\n"
103 + " <caption id='c1' valign='top'>a</caption>\n"
104 + " <caption id='c2' valign='baseline'>b</caption>\n"
105 + " <caption id='c3' valign='3'>c</caption>\n"
106 + " <tr>\n"
107 + " <td>a</td>\n"
108 + " <td>b</td>\n"
109 + " <td>c</td>\n"
110 + " </tr>\n"
111 + "</table>\n"
112 + "<script>\n"
113 + LOG_TITLE_FUNCTION
114 + " function set(e, value) {\n"
115 + " try {\n"
116 + " e.vAlign = value;\n"
117 + " } catch(e) { logEx(e); }\n"
118 + " }\n"
119 + " var c1 = document.getElementById('c1');\n"
120 + " var c2 = document.getElementById('c2');\n"
121 + " var c3 = document.getElementById('c3');\n"
122 + " log(c1.vAlign);\n"
123 + " log(c2.vAlign);\n"
124 + " log(c3.vAlign);\n"
125 + " set(c1, 'middle');\n"
126 + " set(c2, 8);\n"
127 + " set(c3, 'BOTtom');\n"
128 + " log(c1.vAlign);\n"
129 + " log(c2.vAlign);\n"
130 + " log(c3.vAlign);\n"
131 + "</script>\n"
132 + "</body></html>";
133
134 loadPageVerifyTitle2(html);
135 }
136
137
138
139
140 @Test
141 @Alerts({"<caption id=\"cap\">a</caption>", "new"})
142 public void outerHTML() throws Exception {
143 final String html = DOCTYPE_HTML
144 + "<html>\n"
145 + " <head>\n"
146 + " <script>\n"
147 + LOG_TITLE_FUNCTION
148 + " function test() {\n"
149 + " log(document.getElementById('cap').outerHTML);\n"
150 + " document.getElementById('cap').outerHTML = '<div id=\"new\">text<div>';\n"
151 + " log(document.getElementById('new').id);\n"
152 + " }\n"
153 + " </script>\n"
154 + " </head>\n"
155 + " <body onload='test()'>\n"
156 + " <table>\n"
157 + " <caption id='cap'>a</caption>\n"
158 + " <tr>\n"
159 + " <td>cell1</td>\n"
160 + " </tr>\n"
161 + " </table>\n"
162 + " </body>\n"
163 + "</html>";
164
165 loadPageVerifyTitle2(html);
166 }
167 }