1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.css;
16
17 import static java.nio.charset.StandardCharsets.ISO_8859_1;
18 import static org.junit.jupiter.api.Assertions.fail;
19
20 import java.io.File;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.List;
24 import java.util.Map;
25
26 import org.apache.commons.io.FileUtils;
27 import org.htmlunit.BrowserVersion;
28 import org.htmlunit.WebDriverTestCase;
29 import org.htmlunit.css.StyleAttributes;
30 import org.htmlunit.css.StyleAttributes.Definition;
31 import org.htmlunit.javascript.configuration.AbstractJavaScriptConfiguration;
32 import org.htmlunit.javascript.configuration.ClassConfiguration;
33 import org.htmlunit.javascript.configuration.ClassConfiguration.PropertyInfo;
34 import org.htmlunit.junit.annotation.Alerts;
35 import org.htmlunit.junit.annotation.HtmlUnitNYI;
36 import org.junit.jupiter.api.Test;
37 import org.openqa.selenium.By;
38 import org.openqa.selenium.WebDriver;
39 import org.openqa.selenium.WebElement;
40
41
42
43
44
45
46
47
48
49
50
51
52 public class CSSStyleDeclarationTest extends WebDriverTestCase {
53
54
55
56
57 @Test
58 @Alerts(DEFAULT = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
59 "[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]"},
60 FF = {"[object CSSStyleProperties]", "[object CSSStyleProperties]",
61 "[object CSSStyleProperties]", "[object CSSStyleProperties]"},
62 FF_ESR = {"[object CSS2Properties]", "[object CSS2Properties]",
63 "[object CSS2Properties]", "[object CSS2Properties]"})
64 @HtmlUnitNYI(FF = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
65 "[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]"},
66 FF_ESR = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]",
67 "[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]"})
68
69 public void scriptableToString() throws Exception {
70 final String html = DOCTYPE_HTML
71 + "<html><body>\n"
72
73 + "<style>\n"
74 + " p { background-color: #FFFFFF; }\n"
75 + "</style>\n"
76
77 + "<div id='myDiv' style='background-color: #FFFFFF;'></div>\n"
78
79 + "<script>\n"
80 + LOG_TITLE_FUNCTION
81 + " var styleSheet = document.styleSheets[0];\n"
82 + " var decl = styleSheet.cssRules[0].style;\n"
83 + " log(Object.prototype.toString.call(decl));\n"
84 + " log(decl);\n"
85
86 + " decl = document.getElementById('myDiv').style;\n"
87 + " log(Object.prototype.toString.call(decl));\n"
88 + " log(decl);\n"
89 + "</script>\n"
90
91 + "</body></html>";
92
93 loadPageVerifyTitle2(html);
94 }
95
96
97
98
99 @Test
100 @Alerts({"background-color: rgb(255, 255, 255);", "background-color: rgb(255, 255, 255);"})
101 @HtmlUnitNYI(CHROME = {"background-color: rgb(255, 255, 255);", "background-color:#FFFFFF;"},
102 EDGE = {"background-color: rgb(255, 255, 255);", "background-color:#FFFFFF;"},
103 FF = {"background-color: rgb(255, 255, 255);", "background-color:#FFFFFF;"},
104 FF_ESR = {"background-color: rgb(255, 255, 255);", "background-color:#FFFFFF;"})
105
106 public void cssText() throws Exception {
107 final String html = DOCTYPE_HTML
108 + "<html><body>\n"
109
110 + LOG_TEXTAREA
111
112 + "<style>\n"
113 + " p { background-color:#FFFFFF; }\n"
114 + "</style>\n"
115
116 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
117
118 + "<script>\n"
119 + LOG_TEXTAREA_FUNCTION
120 + " var styleSheet = document.styleSheets[0];\n"
121 + " var decl = styleSheet.cssRules[0].style;\n"
122 + " log(decl.cssText);\n"
123
124 + " decl = document.getElementById('myDiv').style;\n"
125 + " log(decl.cssText);\n"
126 + "</script>\n"
127
128 + "</body></html>";
129
130 loadPageVerifyTextArea2(html);
131 }
132
133
134
135
136 @Test
137 @Alerts({"", ""})
138 public void cssTextEmpty() throws Exception {
139 final String html = DOCTYPE_HTML
140 + "<html><body>\n"
141
142 + LOG_TEXTAREA
143
144 + "<style>\n"
145 + " p { }\n"
146 + "</style>\n"
147
148 + "<div id='myDiv' style=''></div>\n"
149
150 + "<script>\n"
151 + LOG_TEXTAREA_FUNCTION
152 + " var styleSheet = document.styleSheets[0];\n"
153 + " var decl = styleSheet.cssRules[0].style;\n"
154 + " log(decl.cssText);\n"
155
156 + " decl = document.getElementById('myDiv').style;\n"
157 + " log(decl.cssText);\n"
158 + "</script>\n"
159
160 + "</body></html>";
161
162 loadPageVerifyTextArea2(html);
163 }
164
165
166
167
168 @Test
169 @Alerts({"background-color: rgb(255, 255, 255); color: red;",
170 "background-color: rgb(255, 255, 255); color: red;"})
171 @HtmlUnitNYI(CHROME = {"background-color: rgb(255, 255, 255); color: red;",
172 "background-color: #FFFFFF;color: red;"},
173 EDGE = {"background-color: rgb(255, 255, 255); color: red;",
174 "background-color: #FFFFFF;color: red;"},
175 FF = {"background-color: rgb(255, 255, 255); color: red;",
176 "background-color: #FFFFFF;color: red;"},
177 FF_ESR = {"background-color: rgb(255, 255, 255); color: red;",
178 "background-color: #FFFFFF;color: red;"})
179
180
181
182 public void cssTextMultipleProperties() throws Exception {
183 final String html = DOCTYPE_HTML
184 + "<html><body>\n"
185
186 + LOG_TEXTAREA
187
188 + "<style>\n"
189 + " p { background-color: #FFFFFF;color: red; }\n"
190 + "</style>\n"
191
192 + "<div id='myDiv' style='background-color: #FFFFFF;color: red;'></div>\n"
193
194 + "<script>\n"
195 + LOG_TEXTAREA_FUNCTION
196 + " var styleSheet = document.styleSheets[0];\n"
197 + " var decl = styleSheet.cssRules[0].style;\n"
198 + " log(decl.cssText);\n"
199
200 + " decl = document.getElementById('myDiv').style;\n"
201 + " log(decl.cssText);\n"
202 + "</script>\n"
203
204 + "</body></html>";
205
206 loadPageVerifyTextArea2(html);
207 }
208
209
210
211
212 @Test
213 @Alerts({"color: rgb(0, 0, 0);", "color: rgb(0, 0, 0);"})
214 @HtmlUnitNYI(CHROME = {"color: rgb(0, 0, 0);", "color:#000000;"},
215 EDGE = {"color: rgb(0, 0, 0);", "color:#000000;"},
216 FF = {"color: rgb(0, 0, 0);", "color:#000000;"},
217 FF_ESR = {"color: rgb(0, 0, 0);", "color:#000000;"})
218
219 public void cssTextSet() throws Exception {
220 final String html = DOCTYPE_HTML
221 + "<html><body>\n"
222
223 + LOG_TEXTAREA
224
225 + "<style>\n"
226 + " p { background-color:#FFFFFF; }\n"
227 + "</style>\n"
228
229 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
230
231 + "<script>\n"
232 + LOG_TEXTAREA_FUNCTION
233 + " var styleSheet = document.styleSheets[0];\n"
234 + " var decl = styleSheet.cssRules[0].style;\n"
235 + " try {"
236 + " decl.cssText = 'color:#000000;';\n"
237 + " log(decl.cssText);\n"
238 + " } catch(e) {\n"
239 + " logEx(e);\n"
240 + " }\n"
241
242 + " decl = document.getElementById('myDiv').style;\n"
243 + " try {"
244 + " decl.cssText = 'color:#000000;';\n"
245 + " log(decl.cssText);\n"
246 + " } catch(e) {\n"
247 + " logEx(e);\n"
248 + " }\n"
249 + "</script>\n"
250
251 + "</body></html>";
252
253 loadPageVerifyTextArea2(html);
254 }
255
256
257
258
259 @Test
260 @Alerts({"", ""})
261 public void cssTextSetNull() throws Exception {
262 final String html = DOCTYPE_HTML
263 + "<html><body>\n"
264
265 + LOG_TEXTAREA
266
267 + "<style>\n"
268 + " p { background-color:#FFFFFF; }\n"
269 + "</style>\n"
270
271 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
272
273 + "<script>\n"
274 + LOG_TEXTAREA_FUNCTION
275 + " var styleSheet = document.styleSheets[0];\n"
276 + " var decl = styleSheet.cssRules[0].style;\n"
277 + " try {"
278 + " decl.cssText = null;\n"
279 + " log(decl.cssText);\n"
280 + " } catch(e) {\n"
281 + " logEx(e);\n"
282 + " }\n"
283
284 + " decl = document.getElementById('myDiv').style;\n"
285 + " try {"
286 + " decl.cssText = null;\n"
287 + " log(decl.cssText);\n"
288 + " } catch(e) {\n"
289 + " logEx(e);\n"
290 + " }\n"
291 + "</script>\n"
292
293 + "</body></html>";
294
295 loadPageVerifyTextArea2(html);
296 }
297
298
299
300
301 @Test
302 @Alerts({"", ""})
303 public void cssTextSetEmpty() throws Exception {
304 final String html = DOCTYPE_HTML
305 + "<html><body>\n"
306
307 + LOG_TEXTAREA
308
309 + "<style>\n"
310 + " p { background-color:#FFFFFF; }\n"
311 + "</style>\n"
312
313 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
314
315 + "<script>\n"
316 + LOG_TEXTAREA_FUNCTION
317 + " var styleSheet = document.styleSheets[0];\n"
318 + " var decl = styleSheet.cssRules[0].style;\n"
319 + " try {"
320 + " decl.cssText = '';\n"
321 + " log(decl.cssText);\n"
322 + " } catch(e) {\n"
323 + " logEx(e);\n"
324 + " }\n"
325
326 + " decl = document.getElementById('myDiv').style;\n"
327 + " try {"
328 + " decl.cssText = '';\n"
329 + " log(decl.cssText);\n"
330 + " } catch(e) {\n"
331 + " logEx(e);\n"
332 + " }\n"
333 + "</script>\n"
334
335 + "</body></html>";
336
337 loadPageVerifyTextArea2(html);
338 }
339
340
341
342
343 @Test
344 @Alerts({"", ""})
345 @HtmlUnitNYI(CHROME = {"", "abc"},
346 EDGE = {"", "abc"},
347 FF = {"", "abc"},
348 FF_ESR = {"", "abc"})
349 public void cssTextSetInvalid() throws Exception {
350 final String html = DOCTYPE_HTML
351 + "<html><body>\n"
352
353 + LOG_TEXTAREA
354
355 + "<style>\n"
356 + " p { background-color:#FFFFFF; }\n"
357 + "</style>\n"
358
359 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
360
361 + "<script>\n"
362 + LOG_TEXTAREA_FUNCTION
363 + " var styleSheet = document.styleSheets[0];\n"
364 + " var decl = styleSheet.cssRules[0].style;\n"
365 + " try {"
366 + " decl.cssText = 'abc';\n"
367 + " log(decl.cssText);\n"
368 + " } catch(e) {\n"
369 + " logEx(e);\n"
370 + " }\n"
371
372 + " decl = document.getElementById('myDiv').style;\n"
373 + " try {"
374 + " decl.cssText = 'abc';\n"
375 + " log(decl.cssText);\n"
376 + " } catch(e) {\n"
377 + " logEx(e);\n"
378 + " }\n"
379 + "</script>\n"
380
381 + "</body></html>";
382
383 loadPageVerifyTextArea2(html);
384 }
385
386
387
388
389 @Test
390 @Alerts({"1", "1"})
391 public void length() throws Exception {
392 final String html = DOCTYPE_HTML
393 + "<html><body>\n"
394
395 + LOG_TEXTAREA
396
397 + "<style>\n"
398 + " p { background-color:#FFFFFF; }\n"
399 + "</style>\n"
400
401 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
402
403 + "<script>\n"
404 + LOG_TEXTAREA_FUNCTION
405 + " var styleSheet = document.styleSheets[0];\n"
406 + " var decl = styleSheet.cssRules[0].style;\n"
407 + " log(decl.length);\n"
408
409 + " decl = document.getElementById('myDiv').style;\n"
410 + " log(decl.length);\n"
411 + "</script>\n"
412
413 + "</body></html>";
414
415 loadPageVerifyTextArea2(html);
416 }
417
418
419
420
421 @Test
422 @Alerts({"0", "0"})
423 public void lengthEmpty() throws Exception {
424 final String html = DOCTYPE_HTML
425 + "<html><body>\n"
426
427 + LOG_TEXTAREA
428
429 + "<style>\n"
430 + " p { }\n"
431 + "</style>\n"
432
433 + "<div id='myDiv' style=''></div>\n"
434
435 + "<script>\n"
436 + LOG_TEXTAREA_FUNCTION
437 + " var styleSheet = document.styleSheets[0];\n"
438 + " var decl = styleSheet.cssRules[0].style;\n"
439 + " log(decl.length);\n"
440
441 + " decl = document.getElementById('myDiv').style;\n"
442 + " log(decl.length);\n"
443 + "</script>\n"
444
445 + "</body></html>";
446
447 loadPageVerifyTextArea2(html);
448 }
449
450
451
452
453 @Test
454 @Alerts({"2", "2"})
455 public void lengthMultipleProperties() throws Exception {
456 final String html = DOCTYPE_HTML
457 + "<html><body>\n"
458
459 + LOG_TEXTAREA
460
461 + "<style>\n"
462 + " p { background-color:#FFFFFF;color: red; }\n"
463 + "</style>\n"
464
465 + "<div id='myDiv' style='background-color:#FFFFFF;color: red;'></div>\n"
466
467 + "<script>\n"
468 + LOG_TEXTAREA_FUNCTION
469 + " var styleSheet = document.styleSheets[0];\n"
470 + " var decl = styleSheet.cssRules[0].style;\n"
471 + " log(decl.length);\n"
472
473 + " decl = document.getElementById('myDiv').style;\n"
474 + " log(decl.length);\n"
475 + "</script>\n"
476
477 + "</body></html>";
478
479 loadPageVerifyTextArea2(html);
480 }
481
482
483
484
485 @Test
486 @Alerts({"1", "1"})
487 public void lengthSet() throws Exception {
488 final String html = DOCTYPE_HTML
489 + "<html><body>\n"
490
491 + LOG_TEXTAREA
492
493 + "<style>\n"
494 + " p { background-color:#FFFFFF; }\n"
495 + "</style>\n"
496
497 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
498
499 + "<script>\n"
500 + LOG_TEXTAREA_FUNCTION
501 + " var styleSheet = document.styleSheets[0];\n"
502 + " var decl = styleSheet.cssRules[0].style;\n"
503 + " try {"
504 + " decl.length = 2;\n"
505 + " log(decl.length);\n"
506 + " } catch(e) {\n"
507 + " logEx(e);\n"
508 + " }\n"
509
510 + " decl = document.getElementById('myDiv').style;\n"
511 + " try {"
512 + " decl.length = 2;\n"
513 + " log(decl.length);\n"
514 + " } catch(e) {\n"
515 + " logEx(e);\n"
516 + " }\n"
517 + "</script>\n"
518
519 + "</body></html>";
520
521 loadPageVerifyTextArea2(html);
522 }
523
524
525
526
527 @Test
528 @Alerts({"[object CSSStyleRule]", "null"})
529 public void parentRule() throws Exception {
530 final String html = DOCTYPE_HTML
531 + "<html><body>\n"
532
533 + "<style>\n"
534 + " p { background-color:#FFFFFF; };\n"
535 + "</style>\n"
536
537 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
538
539 + "<script>\n"
540 + LOG_TITLE_FUNCTION
541 + " var styleSheet = document.styleSheets[0];\n"
542 + " var decl = styleSheet.cssRules[0].style;\n"
543 + " log(decl.parentRule);\n"
544
545 + " decl = document.getElementById('myDiv').style;\n"
546 + " log(decl.parentRule);\n"
547 + "</script>\n"
548
549 + "</body></html>";
550
551 loadPageVerifyTitle2(html);
552 }
553
554
555
556
557 @Test
558 @Alerts({"[object CSSStyleRule]", "p", "null"})
559 public void parentRuleSet() throws Exception {
560 final String html = DOCTYPE_HTML
561 + "<html><body>\n"
562
563 + "<style>\n"
564 + " p { background-color:#FFFFFF; };\n"
565 + " div { color:#000000; };\n"
566 + "</style>\n"
567
568 + "<div id='myDiv' style='background-color:#FFFFFF;'></div>\n"
569
570 + "<script>\n"
571 + LOG_TITLE_FUNCTION
572 + " var styleSheet = document.styleSheets[0];\n"
573 + " var decl = styleSheet.cssRules[0].style;\n"
574 + " try {"
575 + " decl.parentRule = styleSheet.cssRules[1];\n"
576 + " log(decl.parentRule);\n"
577 + " log(decl.parentRule.selectorText);\n"
578 + " } catch(e) {\n"
579 + " logEx(e);\n"
580 + " }\n"
581
582 + " decl = document.getElementById('myDiv').style;\n"
583 + " try {"
584 + " decl.parentRule = styleSheet.cssRules[1];\n"
585 + " log(decl.parentRule);\n"
586 + " } catch(e) {\n"
587 + " logEx(e);\n"
588 + " }\n"
589 + "</script>\n"
590
591 + "</body></html>";
592
593 loadPageVerifyTitle2(html);
594 }
595
596
597
598
599 @Test
600 @Alerts({"black", "pink", "color: pink;", "color: pink;"})
601 public void style_OneCssAttribute() throws Exception {
602 final String html = DOCTYPE_HTML
603 + "<html><head><script>\n"
604 + LOG_TITLE_FUNCTION
605 + "function doTest() {\n"
606 + " var node = document.getElementById('div1');\n"
607 + " var style = node.style;\n"
608 + " log(style.color);\n"
609 + " style.color = 'pink';\n"
610 + " log(style.color);\n"
611 + " log(node.getAttribute('style'));\n"
612 + "}\n</script></head>\n"
613 + "<body onload='doTest()'><div id='div1' style='color: black'>foo</div></body></html>";
614
615 final String style = getExpectedAlerts()[getExpectedAlerts().length - 1];
616
617 setExpectedAlerts(Arrays.copyOf(getExpectedAlerts(), getExpectedAlerts().length - 1));
618 final WebDriver driver = loadPageVerifyTitle2(html);
619
620 assertEquals(style, driver.findElement(By.id("div1")).getAttribute("style"));
621 }
622
623
624
625
626 @Test
627 @Alerts({"black", "pink", "color: pink; background: blue;"})
628 @HtmlUnitNYI(CHROME = {"black", "pink", "color: pink; background: blue; foo: bar;"},
629 EDGE = {"black", "pink", "color: pink; background: blue; foo: bar;"},
630 FF = {"black", "pink", "color: pink; background: blue; foo: bar;"},
631 FF_ESR = {"black", "pink", "color: pink; background: blue; foo: bar;"})
632 public void style_MultipleCssAttributes() throws Exception {
633 final String html = DOCTYPE_HTML
634 + "<html><head><script>\n"
635 + LOG_TITLE_FUNCTION
636 + "function doTest() {\n"
637 + " var style = document.getElementById('div1').style;\n"
638 + " log(style.color);\n"
639 + " style.color = 'pink';\n"
640 + " log(style.color);\n"
641 + "}\n</script></head>\n"
642 + "<body onload='doTest()'>\n"
643 + "<div id='div1' style='color: black;background:blue;foo:bar'>foo</div></body></html>";
644
645 final String style = getExpectedAlerts()[getExpectedAlerts().length - 1];
646
647 setExpectedAlerts(Arrays.copyOf(getExpectedAlerts(), getExpectedAlerts().length - 1));
648 final WebDriver driver = loadPageVerifyTitle2(html);
649
650 assertEquals(style, driver.findElement(By.id("div1")).getAttribute("style"));
651 }
652
653
654
655
656 @Test
657 @Alerts({"null", "", "pink", "color: pink;"})
658 public void style_OneUndefinedCssAttribute() throws Exception {
659 final String html = DOCTYPE_HTML
660 + "<html><head><script>\n"
661 + LOG_TITLE_FUNCTION
662 + "function doTest() {\n"
663 + " var style = document.getElementById('div1').style;\n"
664 + " log(document.getElementById('nonexistingid'));\n"
665 + " log(style.color);\n"
666 + " style.color = 'pink';\n"
667 + " log(style.color);\n"
668 + "}\n</script></head>\n"
669 + "<body onload='doTest()'><div id='div1'>foo</div></body></html>";
670
671 final String style = getExpectedAlerts()[getExpectedAlerts().length - 1];
672
673 setExpectedAlerts(Arrays.copyOf(getExpectedAlerts(), getExpectedAlerts().length - 1));
674 final WebDriver driver = loadPageVerifyTitle2(html);
675
676 assertEquals(style, driver.findElement(By.id("div1")).getAttribute("style"));
677 }
678
679
680
681
682
683
684 @Test
685 @Alerts({"", "hidden", "undefined"})
686 public void mozillaStyle() throws Exception {
687 final String content = DOCTYPE_HTML
688 + "<html><head><script>\n"
689 + LOG_TITLE_FUNCTION
690 + "function doTest() {\n"
691 + " var oDiv = document.getElementById('div1');\n"
692 + " log(oDiv.style.visibility);\n"
693 + " oDiv.style.visibility = 'hidden';\n"
694 + " log(oDiv.style.visibility);\n"
695 + " log(oDiv.style.behavior);\n"
696 + "}\n</script></head>\n"
697 + "<body onload='doTest()'>\n"
698 + "<div id='div1'>foo</div></body></html>";
699 loadPageVerifyTitle2(content);
700 }
701
702
703
704
705 @Test
706 @Alerts("undefined")
707 public void behavior() throws Exception {
708 final String html = DOCTYPE_HTML
709 + "<html><head><script>\n"
710 + LOG_TITLE_FUNCTION
711 + "function doTest() {\n"
712 + " var oDiv = document.getElementById('div1');\n"
713 + " log(oDiv.style.behavior);\n"
714 + "}\n"
715 + "</script></head>\n"
716 + "<body onload='doTest()'>\n"
717 + "<div id='div1'>foo</div></body></html>";
718
719 loadPageVerifyTitle2(html);
720 }
721
722
723
724
725
726 @Test
727 public void onclickAccessStyle() throws Exception {
728 final String html = DOCTYPE_HTML
729 + "<html><head><title>Color Change Page</title>\n"
730 + "<script>\n"
731 + "function test(obj) {\n"
732 + " obj.style.backgroundColor = 'yellow';\n"
733 + "}\n"
734 + "</script>\n"
735 + "</head>\n"
736 + "<body>\n"
737 + "<span id='red' onclick='test(this)'>foo</span>\n"
738 + "</body></html>";
739
740 final WebDriver driver = loadPage2(html);
741 driver.findElement(By.id("red")).click();
742 }
743
744
745
746
747 @Test
748 @Alerts({"string", "string", "string", "undefined"})
749 public void accessProperties() throws Exception {
750 final String html = DOCTYPE_HTML
751 + "<html><head><script>\n"
752 + LOG_TITLE_FUNCTION
753 + "function doTest() {\n"
754 + " var oDiv = document.getElementById('div1');\n"
755 + " log(typeof oDiv.style.visibility);\n"
756 + " log(typeof oDiv.style.color);\n"
757 + " log(typeof oDiv.style.backgroundImage);\n"
758 + " log(typeof oDiv.style.foo);\n"
759 + "}\n</script></head>\n"
760 + "<body onload='doTest()'>\n"
761 + "<div id='div1'>foo</div></body></html>";
762 loadPageVerifyTitle2(html);
763 }
764
765
766
767
768
769 @Test
770 @Alerts("123")
771 public void setStylePropertyNonString() throws Exception {
772 final String html = DOCTYPE_HTML
773 + "<html><head><script>\n"
774 + LOG_TITLE_FUNCTION
775 + "function doTest() {\n"
776 + " var oDiv1 = document.getElementById('div1');\n"
777 + " oDiv1.style.pixelLeft = 123;\n"
778 + " log(oDiv1.style.pixelLeft);\n"
779 + "}\n</script></head>\n"
780 + "<body onload='doTest()'>\n"
781 + "<div id='div1'>foo</div></body></html>";
782 loadPageVerifyTitle2(html);
783 }
784
785
786
787
788 @Test
789 @Alerts("blue")
790 public void getPropertyValue() throws Exception {
791 final String html = DOCTYPE_HTML
792 + "<html><head><script>\n"
793 + LOG_TITLE_FUNCTION
794 + "function doTest() {\n"
795 + " try {\n"
796 + " var oDiv1 = document.getElementById('div1');\n"
797 + " log(oDiv1.style.getPropertyValue('background'));\n"
798 + " } catch(e) { logEx(e); }\n"
799 + "}\n"
800 + "</script></head>\n"
801 + "<body onload='doTest()'>\n"
802 + "<div id='div1' style='background: blue'>foo</div></body></html>";
803 loadPageVerifyTitle2(html);
804 }
805
806
807
808
809 @Test
810 @Alerts({"*blue* string", ""})
811 public void removeProperty() throws Exception {
812 final String html = DOCTYPE_HTML
813 + "<html><head><script>\n"
814 + LOG_TITLE_FUNCTION
815 + "function doTest() {\n"
816 + " var oDiv1 = document.getElementById('div1');\n"
817 + " if (oDiv1.style.removeProperty) {\n"
818 + " var value = oDiv1.style.removeProperty('color');\n"
819 + " log('*' + value + '* ' + typeof(value));\n"
820 + " log(oDiv1.style.cssText);\n"
821 + " }\n"
822 + "}\n"
823 + "</script></head>\n"
824 + "<body onload='doTest()'>\n"
825 + "<div id='div1' style='color: blue'>foo</div></body></html>";
826 loadPageVerifyTitle2(html);
827 }
828
829
830
831
832 @Test
833 @Alerts({"** string", "blue"})
834 public void removePropertyUnknown() throws Exception {
835 final String html = DOCTYPE_HTML
836 + "<html><head><script>\n"
837 + LOG_TITLE_FUNCTION
838 + "function doTest() {\n"
839 + " var oDiv1 = document.getElementById('div1');\n"
840 + " if (oDiv1.style.removeProperty) {\n"
841 + " var value = oDiv1.style.removeProperty('font-size');\n"
842 + " log('*' + value + '* ' + typeof(value));\n"
843 + " log(oDiv1.style.getPropertyValue('color'));\n"
844 + " }\n"
845 + "}\n"
846 + "</script></head>\n"
847 + "<body onload='doTest()'>\n"
848 + "<div id='div1' style='color: blue'>foo</div></body></html>";
849 loadPageVerifyTitle2(html);
850 }
851
852
853
854
855 @Test
856 @Alerts({"** string", "blue"})
857 public void removePropertyUndefined() throws Exception {
858 final String html = DOCTYPE_HTML
859 + "<html>\n"
860 + "<head>\n"
861 + "<script>\n"
862 + LOG_TITLE_FUNCTION
863 + "function doTest() {\n"
864 + " var oDiv1 = document.getElementById('div1');\n"
865 + " if (!oDiv1.style.removeProperty) {\n"
866 + " log('removeProperty not available');\n"
867 + " return;\n"
868 + " }\n"
869 + " var value = oDiv1.style.removeProperty(undefined);\n"
870 + " log('*' + value + '* ' + typeof(value));\n"
871 + " log(oDiv1.style.getPropertyValue('color'));\n"
872 + "}\n"
873 + "</script></head>\n"
874 + "<body onload='doTest()'>\n"
875 + "<div id='div1' style='color: blue'>foo</div></body></html>";
876 loadPageVerifyTitle2(html);
877 }
878
879
880
881
882 @Test
883 @Alerts({"30px", "", "30px", "arial", "", "arial"})
884 public void getPropertyValue_WithDash() throws Exception {
885 final String html = DOCTYPE_HTML
886 + "<html><body onload='test()'><script>\n"
887 + LOG_TITLE_FUNCTION
888 + " function prop(elem, prop) {\n"
889 + " try{\n"
890 + " var p = span.style.getPropertyValue(prop);\n"
891 + " log(p);\n"
892 + " } catch(e) { logEx(e); }\n"
893 + " }\n"
894
895 + " function test() {\n"
896 + " var span = document.getElementById('span');\n"
897 + " span.style['fontSize'] = '30px';\n"
898 + " log(span.style.fontSize);\n"
899 + " prop(span, 'fontSize');\n"
900 + " prop(span, 'font-size');\n"
901 + " span.style['fontFamily'] = 'arial';\n"
902 + " log(span.style.fontFamily);\n"
903 + " prop(span, 'fontFamily');\n"
904 + " prop(span, 'font-family');\n"
905 + " }\n"
906 + "</script>\n"
907 + "<span id='span'>x</span>\n"
908 + "</body></html>";
909 loadPageVerifyTitle2(html);
910 }
911
912
913
914
915 @Test
916 @Alerts({"", ""})
917 @HtmlUnitNYI(CHROME = {"", "alpha(opacity=50)"},
918 EDGE = {"", "alpha(opacity=50)"},
919 FF = {"", "alpha(opacity=50)"},
920 FF_ESR = {"", "alpha(opacity=50)"})
921 public void styleFilter() throws Exception {
922 final String html = DOCTYPE_HTML
923 + "<html><body onload='test()'><script>\n"
924 + LOG_TITLE_FUNCTION
925 + " function test() {\n"
926 + " var div1 = document.getElementById('div1');\n"
927 + " log(div1.style.filter);\n"
928 + " var div2 = document.getElementById('div2');\n"
929 + " log(div2.style.filter);\n"
930 + " }\n"
931 + "</script>\n"
932 + "<div id='div1'>foo</div>\n"
933 + "<div id='div2' style='filter:alpha(opacity=50)'>bar</div>\n"
934 + "</body></html>";
935 loadPageVerifyTitle2(html);
936 }
937
938
939
940
941
942
943 @Test
944 @Alerts({"", "0.5", "0.4", "0.33333", "-3", "3", "", "", ""})
945 public void initOpacity() throws Exception {
946 final String html = DOCTYPE_HTML
947 + "<html><body>\n"
948 + "<div id='o1' style='opacity: '>d</div>\n"
949 + "<div id='o2' style='opacity:0.5'>d</div>\n"
950 + "<div id='o3' style='opacity:.4'>d</div>\n"
951 + "<div id='o4' style='opacity: 0.33333'>d</div>\n"
952 + "<div id='o5' style='opacity: -3'>d</div>\n"
953 + "<div id='o6' style='opacity: 3'>d</div>\n"
954 + "<div id='o7' style='opacity: 10px'>d</div>\n"
955 + "<div id='o8' style='opacity: foo'>d</div>\n"
956 + "<div id='o9' style='opacity: auto'>d</div>\n"
957
958 + "<script>\n"
959 + LOG_TITLE_FUNCTION
960 + "for (var i = 1; i < 10; i++) {\n"
961 + " d = document.getElementById('o' + i);\n"
962 + " log(d.style.opacity);\n"
963 + "}\n"
964 + "</script>\n"
965 + "</body></html>";
966 loadPageVerifyTitle2(html);
967 }
968
969
970
971
972
973
974 @Test
975 @Alerts("- 0.5 0.4 0.33333 -3 3 8 7 7 7 7 7 ")
976 public void setOpacity() throws Exception {
977 final String html = DOCTYPE_HTML
978 + "<html><body>\n"
979 + "<div id='d'>d</div>\n"
980 + "<script>\n"
981 + LOG_TITLE_FUNCTION
982 + "var d = document.getElementById('d');\n"
983 + "var s = '-';\n"
984 + "s += d.style.opacity + ' ';\n"
985 + "d.style.opacity = 0.5;\n"
986 + "s += d.style.opacity + ' ';\n"
987 + "d.style.opacity = .4;\n"
988 + "s += d.style.opacity + ' ';\n"
989 + "d.style.opacity = 0.33333;\n"
990 + "s += d.style.opacity + ' ';\n"
991 + "d.style.opacity = -3;\n"
992 + "s += d.style.opacity + ' ';\n"
993 + "d.style.opacity = 3;\n"
994 + "s += d.style.opacity + ' ';\n"
995 + "d.style.opacity = '8';\n"
996 + "s += d.style.opacity + ' ';\n"
997 + "d.style.opacity = ' 7 ';\n"
998 + "s += d.style.opacity + ' ';\n"
999 + "d.style.opacity = NaN;\n"
1000 + "s += d.style.opacity + ' ';\n"
1001 + "d.style.opacity = '10px';\n"
1002 + "s += d.style.opacity + ' ';\n"
1003 + "d.style.opacity = 'foo';\n"
1004 + "s += d.style.opacity + ' ';\n"
1005 + "d.style.opacity = 'auto';\n"
1006 + "s += d.style.opacity + ' ';\n"
1007 + "d.style.opacity = '';\n"
1008 + "s += d.style.opacity;\n"
1009 + "log(s);\n"
1010 + "</script>\n"
1011 + "</body></html>";
1012 loadPageVerifyTitle2(html);
1013 }
1014
1015
1016
1017
1018 @Test
1019 @Alerts({"undefined", "TypeError"})
1020 public void setExpression() throws Exception {
1021 final String html = DOCTYPE_HTML
1022 + "<html><head><script>\n"
1023 + LOG_TITLE_FUNCTION
1024 + "function test() {\n"
1025 + " try {\n"
1026 + " var div1 = document.getElementById('div1');\n"
1027 + " log(typeof div1.style.setExpression);\n"
1028 + " div1.style.setExpression('title','id');\n"
1029 + " } catch(e) { logEx(e); }\n"
1030 + "}\n"
1031 + "</script></head><body onload='test()'>\n"
1032 + " <div id='div1'/>\n"
1033 + "</body></html>";
1034 loadPageVerifyTitle2(html);
1035 }
1036
1037
1038
1039
1040 @Test
1041 @Alerts({"undefined", "TypeError"})
1042 public void removeExpression() throws Exception {
1043 final String html = DOCTYPE_HTML
1044 + "<html><head><script>\n"
1045 + LOG_TITLE_FUNCTION
1046 + "function test() {\n"
1047 + " try {\n"
1048 + " var div1 = document.getElementById('div1');\n"
1049 + " log(typeof div1.style.removeExpression);\n"
1050 + " div1.style.setExpression('title','id');\n"
1051 + " div1.style.removeExpression('title');\n"
1052 + " } catch(e) { logEx(e); }\n"
1053 + "}\n"
1054 + "</script></head><body onload='test()'>\n"
1055 + " <div id='div1'/>\n"
1056 + "</body></html>";
1057 loadPageVerifyTitle2(html);
1058 }
1059
1060
1061
1062
1063 @Test
1064 @Alerts({"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""})
1065 public void borderStyles_noStyle() throws Exception {
1066 final String html = DOCTYPE_HTML
1067 + "<html><head><script>\n"
1068 + LOG_TITLE_FUNCTION
1069 + "function doTest() {\n"
1070 + " var oDiv = document.getElementById('div1');\n"
1071 + " log(oDiv.style.borderBottom);\n"
1072 + " log(oDiv.style.borderBottomColor);\n"
1073 + " log(oDiv.style.borderBottomStyle);\n"
1074 + " log(oDiv.style.borderBottomWidth);\n"
1075 + " log(oDiv.style.borderLeft);\n"
1076 + " log(oDiv.style.borderLeftColor);\n"
1077 + " log(oDiv.style.borderLeftStyle);\n"
1078 + " log(oDiv.style.borderLeftWidth);\n"
1079 + " log(oDiv.style.borderRight);\n"
1080 + " log(oDiv.style.borderRightColor);\n"
1081 + " log(oDiv.style.borderRightStyle);\n"
1082 + " log(oDiv.style.borderRightWidth);\n"
1083 + " log(oDiv.style.borderTop);\n"
1084 + " log(oDiv.style.borderTopColor);\n"
1085 + " log(oDiv.style.borderTopStyle);\n"
1086 + " log(oDiv.style.borderTopWidth);\n"
1087 + "}\n"
1088 + "</script></head>\n"
1089 + "<body onload='doTest()'>\n"
1090 + "<div id='div1'>foo</div></body></html>";
1091 loadPageVerifyTitle2(html);
1092 }
1093
1094
1095
1096
1097 @Test
1098 @Alerts({"3px", "4px", "2px", "1px"})
1099 public void borderXxxWidth() throws Exception {
1100 final String html = DOCTYPE_HTML
1101 + "<html><head><script>\n"
1102 + LOG_TITLE_FUNCTION
1103 + "function doTest() {\n"
1104 + " var oDiv = document.getElementById('div1');\n"
1105 + " log(oDiv.style.borderBottomWidth);\n"
1106 + " log(oDiv.style.borderLeftWidth);\n"
1107 + " log(oDiv.style.borderRightWidth);\n"
1108 + " log(oDiv.style.borderTopWidth);\n"
1109 + "}\n"
1110 + "</script></head>\n"
1111 + "<body onload='doTest()'>\n"
1112 + "<div id='div1' style='border-width: 1px 2px 3px 4px'>foo</div></body></html>";
1113 loadPageVerifyTitle2(html);
1114 }
1115
1116
1117
1118
1119 @Test
1120 @Alerts({"thin", "medium", "thick", "thick"})
1121 public void borderXxxWidthConstants() throws Exception {
1122 final String html = DOCTYPE_HTML
1123 + "<html><head><script>\n"
1124 + LOG_TITLE_FUNCTION
1125 + "function doTest() {\n"
1126 + " var oDiv = document.getElementById('div1');\n"
1127 + " log(oDiv.style.borderRightWidth);\n"
1128 + " oDiv = document.getElementById('div2');\n"
1129 + " log(oDiv.style.borderLeftWidth);\n"
1130 + " oDiv = document.getElementById('div3');\n"
1131 + " log(oDiv.style.borderBottomWidth);\n"
1132 + " log(oDiv.style.borderTopWidth);\n"
1133 + "}\n"
1134 + "</script></head>\n"
1135 + "<body onload='doTest()'>\n"
1136 + "<div id='div1' style='border: thin'>foo</div>\n"
1137 + "<div id='div2' style='border: medium'>foo</div>\n"
1138 + "<div id='div3' style='border: thick'>foo</div>\n"
1139 + "</body></html>";
1140 loadPageVerifyTitle2(html);
1141 }
1142
1143
1144
1145
1146 @Test
1147 @Alerts("undefined")
1148 public void initUnsupportdProperty() throws Exception {
1149 final String html = DOCTYPE_HTML
1150 + "<html><body>\n"
1151 + "<div id='my' style='htmlunit: foo'>d</div>\n"
1152
1153 + "<script>\n"
1154 + LOG_TITLE_FUNCTION
1155 + " d = document.getElementById('my');\n"
1156 + " log(d.style.htmlunit);\n"
1157 + "</script>\n"
1158 + "</body></html>";
1159 loadPageVerifyTitle2(html);
1160 }
1161
1162
1163
1164
1165 @Test
1166 @Alerts({"undefined", "foo"})
1167 public void setUnsupportdProperty() throws Exception {
1168 final String html = DOCTYPE_HTML
1169 + "<html><body>\n"
1170 + "<div id='my' style=''>d</div>\n"
1171
1172 + "<script>\n"
1173 + LOG_TITLE_FUNCTION
1174 + " d = document.getElementById('my');\n"
1175 + " log(d.style.htmlunit);\n"
1176 + " d.style.htmlunit = 'foo';\n"
1177 + " log(d.style.htmlunit);\n"
1178 + "</script>\n"
1179 + "</body></html>";
1180 loadPageVerifyTitle2(html);
1181 }
1182
1183
1184
1185
1186 @Test
1187 @Alerts({"string", "", "1", "2", "2", "2", "2", "5", "5", "5", "5"})
1188 public void zIndex() throws Exception {
1189 final String html = DOCTYPE_HTML
1190 + "<html><head><script>\n"
1191 + LOG_TITLE_FUNCTION
1192 + "function test() {\n"
1193 + " var style = document.getElementById('myDiv').style;\n"
1194 + " log(typeof style.zIndex);\n"
1195 + " log(style.zIndex);\n"
1196 + " style.zIndex = 1;\n"
1197 + " log(style.zIndex);\n"
1198 + " style.zIndex = 2.0;\n"
1199 + " log(style.zIndex);\n"
1200 + " style.zIndex = 3.1;\n"
1201 + " log(style.zIndex);\n"
1202 + " style.zIndex = 4.5;\n"
1203 + " log(style.zIndex);\n"
1204 + " style.zIndex = 4.6;\n"
1205 + " log(style.zIndex);\n"
1206 + " style.zIndex = '5';\n"
1207 + " log(style.zIndex);\n"
1208 + " style.zIndex = '6.0';\n"
1209 + " log(style.zIndex);\n"
1210 + " style.zIndex = '7.1';\n"
1211 + " log(style.zIndex);\n"
1212 + " style.zIndex = '8.6';\n"
1213 + " log(style.zIndex);\n"
1214 + "}\n"
1215 + "</script></head>\n"
1216 + "<body onload='test()'>\n"
1217 + " <div id='myDiv'/>\n"
1218 + "</body></html>";
1219
1220 loadPageVerifyTitle2(html);
1221 }
1222
1223
1224
1225
1226 @Test
1227 @Alerts({"string", "", "string", "", "string", "4", "string", "", "string", "", "string", ""})
1228 public void zIndexDefault() throws Exception {
1229 final String html = DOCTYPE_HTML
1230 + "<html><head><script>\n"
1231 + LOG_TITLE_FUNCTION
1232 + "function test() {\n"
1233 + " var style = document.getElementById('divUndefined').style;\n"
1234 + " log(typeof style.zIndex);\n"
1235 + " log(style.zIndex);\n"
1236
1237 + " style = document.getElementById('divBlank').style;\n"
1238 + " log(typeof style.zIndex);\n"
1239 + " log(style.zIndex);\n"
1240
1241 + " style = document.getElementById('divInteger').style;\n"
1242 + " log(typeof style.zIndex);\n"
1243 + " log(style.zIndex);\n"
1244
1245 + " style = document.getElementById('divFloat').style;\n"
1246 + " log(typeof style.zIndex);\n"
1247 + " log(style.zIndex);\n"
1248
1249 + " style = document.getElementById('divFloat2').style;\n"
1250 + " log(typeof style.zIndex);\n"
1251 + " log(style.zIndex);\n"
1252
1253 + " style = document.getElementById('invalidDiv').style;\n"
1254 + " log(typeof style.zIndex);\n"
1255 + " log(style.zIndex);\n"
1256
1257 + "}\n"
1258 + "</script></head>\n"
1259 + "<body onload='test()'>\n"
1260 + " <div id='divUndefined'/>\n"
1261 + " <div id='divBlank' style='z-index: '/>\n"
1262 + " <div id='divInteger' style='z-index: 4'/>\n"
1263 + " <div id='divFloat' style='z-index: 4.2'/>\n"
1264 + " <div id='divFloat2' style='z-index: 4.7'/>\n"
1265 + " <div id='invalidDiv' style='z-index: unfug'/>\n"
1266 + "</body></html>";
1267
1268 loadPageVerifyTitle2(html);
1269 }
1270
1271
1272
1273
1274 @Test
1275 @Alerts({"", "", "1", "1"})
1276 public void zIndexSetUndefined() throws Exception {
1277 final String html = DOCTYPE_HTML
1278 + "<html><head><script>\n"
1279 + LOG_TITLE_FUNCTION
1280 + "function test() {\n"
1281 + " var style = document.getElementById('myDiv').style;\n"
1282 + " var un_defined;\n"
1283 + " log(style.zIndex);\n"
1284
1285 + " try {\n"
1286 + " style.zIndex = un_defined;\n"
1287 + " } catch(e) { logEx(e); }\n"
1288 + " log(style.zIndex);\n"
1289
1290 + " style.zIndex = 1;\n"
1291 + " log(style.zIndex);\n"
1292
1293 + " try {\n"
1294 + " style.zIndex = un_defined;\n"
1295 + " } catch(e) { logEx(e); }\n"
1296 + " log(style.zIndex);\n"
1297
1298 + "}\n"
1299 + "</script></head>\n"
1300 + "<body onload='test()'>\n"
1301 + " <div id='myDiv'/>\n"
1302 + "</body></html>";
1303
1304 loadPageVerifyTitle2(html);
1305 }
1306
1307
1308
1309
1310 @Test
1311 @Alerts({"", "", "1", ""})
1312 public void zIndexSetNull() throws Exception {
1313 final String html = DOCTYPE_HTML
1314 + "<html><head><script>\n"
1315 + LOG_TITLE_FUNCTION
1316 + "function test() {\n"
1317 + " var style = document.getElementById('myDiv').style;\n"
1318 + " log(style.zIndex);\n"
1319
1320 + " try {\n"
1321 + " style.zIndex = null;\n"
1322 + " } catch(e) { logEx(e); }\n"
1323 + " log(style.zIndex);\n"
1324
1325 + " style.zIndex = 1;\n"
1326 + " log(style.zIndex);\n"
1327
1328 + " try {\n"
1329 + " style.zIndex = null;\n"
1330 + " } catch(e) { logEx(e); }\n"
1331 + " log(style.zIndex);\n"
1332
1333 + "}\n"
1334 + "</script></head>\n"
1335 + "<body onload='test()'>\n"
1336 + " <div id='myDiv'/>\n"
1337 + "</body></html>";
1338
1339 loadPageVerifyTitle2(html);
1340 }
1341
1342
1343
1344
1345 @Test
1346 @Alerts({"", "7", "7", "", "4", "1"})
1347 public void zIndexSetString() throws Exception {
1348 final String html = DOCTYPE_HTML
1349 + "<html><head><script>\n"
1350 + LOG_TITLE_FUNCTION
1351 + "function test() {\n"
1352 + " var style = document.getElementById('myDiv').style;\n"
1353 + " var unknown;\n"
1354 + " log(style.zIndex);\n"
1355
1356 + " style.zIndex = '7';\n"
1357 + " log(style.zIndex);\n"
1358
1359 + " style.zIndex = '7.6';\n"
1360 + " log(style.zIndex);\n"
1361
1362 + " style.zIndex = '';\n"
1363 + " log(style.zIndex);\n"
1364
1365 + " style.zIndex = '4';\n"
1366 + " try {\n"
1367 + " style.zIndex = ' ';\n"
1368 + " } catch(e) { logEx(e); }\n"
1369 + " log(style.zIndex);\n"
1370
1371 + " style.zIndex = '1';\n"
1372 + " try {\n"
1373 + " style.zIndex = 'NAN';\n"
1374 + " } catch(e) { logEx(e); }\n"
1375 + " log(style.zIndex);\n"
1376
1377 + "}\n"
1378 + "</script></head>\n"
1379 + "<body onload='test()'>\n"
1380 + " <div id='myDiv'/>\n"
1381 + "</body></html>";
1382
1383 loadPageVerifyTitle2(html);
1384 }
1385
1386
1387
1388
1389 @Test
1390 @Alerts({"", "", "1", "1"})
1391 public void zIndexSetInvalid() throws Exception {
1392 final String html = DOCTYPE_HTML
1393 + "<html><head><script>\n"
1394 + LOG_TITLE_FUNCTION
1395 + "function test() {\n"
1396 + " var style = document.getElementById('myDiv').style;\n"
1397 + " log(style.zIndex);\n"
1398 + " try {\n"
1399 + " style.zIndex = 'hallo';\n"
1400 + " } catch(e) { logEx(e); }\n"
1401 + " log(style.zIndex);\n"
1402
1403 + " style.zIndex = 1;\n"
1404 + " log(style.zIndex);\n"
1405 + " try {\n"
1406 + " style.zIndex = 'hallo';\n"
1407 + " } catch(e) { logEx(e); }\n"
1408 + " log(style.zIndex);\n"
1409 + "}\n"
1410
1411 + "</script></head>\n"
1412 + "<body onload='test()'>\n"
1413 + " <div id='myDiv'/>\n"
1414 + "</body></html>";
1415
1416 loadPageVerifyTitle2(html);
1417 }
1418
1419
1420
1421
1422 @Test
1423 @Alerts({"", "", "15px", "italic", "", "italic"})
1424 public void cssText2() throws Exception {
1425 final String html = DOCTYPE_HTML
1426 + "<html><head><script>\n"
1427 + LOG_TITLE_FUNCTION
1428 + " function test() {\n"
1429 + " var style = document.getElementById('myDiv').style;\n"
1430 + " log(style.fontSize);\n"
1431 + " log(style.fontStyle);\n"
1432 + " style.cssText = 'font-size: 15px; font-style: italic';\n"
1433 + " log(style.fontSize);\n"
1434 + " log(style.fontStyle);\n"
1435 + " style.cssText = 'font-style: italic';\n"
1436 + " log(style.fontSize);\n"
1437 + " log(style.fontStyle);\n"
1438 + " }\n"
1439 + "</script></head><body onload='test()'>\n"
1440 + " <div id='myDiv'/>\n"
1441 + "</body></html>";
1442 loadPageVerifyTitle2(html);
1443 }
1444
1445
1446
1447
1448 @Test
1449 @Alerts({"1px", "solid", "red"})
1450 public void border() throws Exception {
1451 final String html = DOCTYPE_HTML
1452 + "<html><head><script>\n"
1453 + LOG_TITLE_FUNCTION
1454 + " function test() {\n"
1455 + " var style = document.getElementById('myDiv').style;\n"
1456 + " if (style.getPropertyValue) {\n"
1457 + " log(style.getPropertyValue('border-top-width'));\n"
1458 + " log(style.getPropertyValue('border-top-style'));\n"
1459 + " log(style.getPropertyValue('border-top-color'));\n"
1460 + " }\n"
1461 + " }\n"
1462 + "</script></head><body onload='test()'>\n"
1463 + " <div id='myDiv' style='border: red 1px solid'/>\n"
1464 + "</body></html>";
1465 loadPageVerifyTitle2(html);
1466 }
1467
1468
1469
1470
1471 @Test
1472 @Alerts({"true", "false"})
1473 public void display() throws Exception {
1474 final String html = DOCTYPE_HTML
1475 + "<html><head><script>\n"
1476 + LOG_TITLE_FUNCTION
1477 + " function test() {\n"
1478 + " var myDiv = document.getElementById('myDiv');\n"
1479 + " myDiv.style.display = 'none';\n"
1480 + " log(myDiv.style.display == 'none');\n"
1481 + " myDiv.style.display = '';\n"
1482 + " log(myDiv.style.display == 'none');\n"
1483 + " }\n"
1484 + "</script></head><body onload='test()'>\n"
1485 + " <div id='myDiv'/>\n"
1486 + "</body></html>";
1487 loadPageVerifyTitle2(html);
1488 }
1489
1490
1491
1492
1493 @Test
1494 @Alerts({"", "", "none", "rgb(0, 128, 0)"})
1495 public void displayDefaultOverwritesNone() throws Exception {
1496 final String html = DOCTYPE_HTML
1497 + "<html>\n"
1498 + "<head>\n"
1499 + " <style>\n"
1500 + " tt { display: none; color: green; }\n"
1501 + " </style>\n"
1502 + " <script>\n"
1503 + LOG_TITLE_FUNCTION
1504 + " function test() {\n"
1505 + " var e = document.createElement('tt');\n"
1506 + " var style = window.getComputedStyle(e, null);\n"
1507 + " log(style['display']);\n"
1508 + " log(style['color']);\n"
1509 + " document.body.appendChild(e);\n"
1510 + " log(style['display']);\n"
1511 + " log(style['color']);\n"
1512 + " }\n"
1513 + " </script>\n"
1514 + "</head>\n"
1515 + "<body onload='test()'>\n"
1516 + "</body></html>";
1517 loadPageVerifyTitle2(html);
1518 }
1519
1520
1521
1522
1523 @Test
1524 @Alerts({"", "inline"})
1525 public void displayDefault() throws Exception {
1526 final String html = DOCTYPE_HTML
1527 + "<html>\n"
1528 + "<head>\n"
1529 + " <script>\n"
1530 + LOG_TITLE_FUNCTION
1531 + " function test() {\n"
1532 + " var e = document.createElement('tt');\n"
1533 + " var style = window.getComputedStyle(e, null);\n"
1534 + " log(style['display']);\n"
1535 + " document.body.appendChild(e);\n"
1536 + " log(style['display']);\n"
1537 + " }\n"
1538 + " </script>\n"
1539 + "</head>\n"
1540 + "<body onload='test()'>\n"
1541 + "</body></html>";
1542 loadPageVerifyTitle2(html);
1543 }
1544
1545
1546
1547
1548 @Test
1549 @Alerts({"", "rgb(0, 0, 0)"})
1550 public void colorDefault() throws Exception {
1551 final String html = DOCTYPE_HTML
1552 + "<html>\n"
1553 + "<head>\n"
1554 + " <script>\n"
1555 + LOG_TITLE_FUNCTION
1556 + " function test() {\n"
1557 + " var e = document.createElement('tt');\n"
1558 + " var style = window.getComputedStyle(e, null);\n"
1559 + " log(style['color']);\n"
1560 + " document.body.appendChild(e);\n"
1561 + " log(style['color']);\n"
1562 + " }\n"
1563 + " </script>\n"
1564 + "</head>\n"
1565 + "<body onload='test()'>\n"
1566 + "</body></html>";
1567 loadPageVerifyTitle2(html);
1568 }
1569
1570
1571
1572
1573 @Test
1574 @Alerts({"1px", "2px"})
1575 public void resettingValue() throws Exception {
1576 final String html = DOCTYPE_HTML
1577 + "<html><head><script>\n"
1578 + LOG_TITLE_FUNCTION
1579 + " function test() {\n"
1580 + " var myDiv = document.getElementById('myDiv');\n"
1581 + " myDiv.style.marginTop = '1px';\n"
1582 + " log(myDiv.style.marginTop);\n"
1583 + " myDiv.style.marginTop = '2px';\n"
1584 + " log(myDiv.style.marginTop);\n"
1585 + " }\n"
1586 + "</script></head><body onload='test()'>\n"
1587 + " <div id='myDiv'/>\n"
1588 + "</body></html>";
1589
1590 loadPageVerifyTitle2(html);
1591 }
1592
1593
1594
1595
1596 @Test
1597 @Alerts({"2px", "30px"})
1598 public void resettingValue2() throws Exception {
1599 final String html = DOCTYPE_HTML
1600 + "<html><head><script>\n"
1601 + LOG_TITLE_FUNCTION
1602 + " function test() {\n"
1603 + " var myDiv = document.getElementById('myDiv');\n"
1604 + " myDiv.style.marginTop = '2px';\n"
1605 + " log(myDiv.style.marginTop);\n"
1606 + " myDiv.style.left = '-1px';\n"
1607 + " myDiv.style.marginTop = '30px';\n"
1608 + " log(myDiv.style.marginTop);\n"
1609 + " }\n"
1610 + "</script></head><body onload='test()'>\n"
1611 + " <div id='myDiv'/>\n"
1612 + "</body></html>";
1613
1614 loadPageVerifyTitle2(html);
1615 }
1616
1617
1618
1619
1620
1621
1622 @Test
1623 @Alerts({"L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px",
1624 "L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px"})
1625 public void marginAllvsMarginSingle() throws Exception {
1626 final String html = DOCTYPE_HTML
1627 + "<html>\n"
1628 + " <head>\n"
1629 + " <style>\n"
1630 + " #m1 { margin: 3px; }\n"
1631 + " #m2 { margin-left: 3px; margin: 5px; }\n"
1632 + " #m3 { margin: 2px; margin-left: 7px; }\n"
1633 + " </style>\n"
1634 + " <script>\n"
1635 + LOG_TITLE_FUNCTION
1636 + " function test() {\n"
1637 + " alertComputedMargins('m1');\n"
1638 + " alertComputedMargins('m2');\n"
1639 + " alertComputedMargins('m3');\n"
1640 + " alertNonComputedMargins('m4');\n"
1641 + " alertNonComputedMargins('m5');\n"
1642 + " alertNonComputedMargins('m6');\n"
1643 + " }\n"
1644 + " function alertComputedMargins(id) {\n"
1645 + " var e = document.getElementById(id);\n"
1646 + " var s = getComputedStyle(e, null);\n"
1647 + " log('L:' + s.marginLeft + ',R:' + s.marginRight +\n"
1648 + " ',T:' + s.marginTop + ',B:' + s.marginBottom);\n"
1649 + " }\n"
1650 + " function alertNonComputedMargins(id) {\n"
1651 + " var e = document.getElementById(id);\n"
1652 + " var s = e.style;\n"
1653 + " log('L:' + s.marginLeft + ',R:' + s.marginRight +\n"
1654 + " ',T:' + s.marginTop + ',B:' + s.marginBottom);\n"
1655 + " }\n"
1656 + " </script>\n"
1657 + " </head>\n"
1658 + " <body onload='test()'>\n"
1659 + " <div id='m1'>m1</div>\n"
1660 + " <div id='m2'>m2</div>\n"
1661 + " <div id='m3'>m3</div>\n"
1662 + " <div id='m4' style='margin: 3px;'>m4</div>\n"
1663 + " <div id='m5' style='margin-left: 3px; margin: 5px;'>m5</div>\n"
1664 + " <div id='m6' style='margin: 2px; margin-left: 7px;'>m6</div>\n"
1665 + " </body>\n"
1666 + "</html>";
1667 loadPageVerifyTitle2(html);
1668 }
1669
1670
1671
1672
1673
1674
1675 @Test
1676 @Alerts({"L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px",
1677 "L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px"})
1678 public void paddingAllvsPaddingSingle() throws Exception {
1679 final String html = DOCTYPE_HTML
1680 + "<html>\n"
1681 + " <head>\n"
1682 + " <style>\n"
1683 + " #m1 { padding: 3px; }\n"
1684 + " #m2 { padding-left: 3px; padding: 5px; }\n"
1685 + " #m3 { padding: 2px; padding-left: 7px; }\n"
1686 + " </style>\n"
1687 + " <script>\n"
1688 + LOG_TITLE_FUNCTION
1689 + " function test() {\n"
1690 + " alertComputedPaddings('m1');\n"
1691 + " alertComputedPaddings('m2');\n"
1692 + " alertComputedPaddings('m3');\n"
1693 + " alertNonComputedPaddings('m4');\n"
1694 + " alertNonComputedPaddings('m5');\n"
1695 + " alertNonComputedPaddings('m6');\n"
1696 + " }\n"
1697 + " function alertComputedPaddings(id) {\n"
1698 + " var e = document.getElementById(id);\n"
1699 + " var s = e.currentStyle ? e.currentStyle : getComputedStyle(e, null);\n"
1700 + " log('L:' + s.paddingLeft + ',R:' + s.paddingRight +\n"
1701 + " ',T:' + s.paddingTop + ',B:' + s.paddingBottom);\n"
1702 + " }\n"
1703 + " function alertNonComputedPaddings(id) {\n"
1704 + " var e = document.getElementById(id);\n"
1705 + " var s = e.style;\n"
1706 + " log('L:' + s.paddingLeft + ',R:' + s.paddingRight +\n"
1707 + " ',T:' + s.paddingTop + ',B:' + s.paddingBottom);\n"
1708 + " }\n"
1709 + " </script>\n"
1710 + " </head>\n"
1711 + " <body onload='test()'>\n"
1712 + " <div id='m1'>m1</div>\n"
1713 + " <div id='m2'>m2</div>\n"
1714 + " <div id='m3'>m3</div>\n"
1715 + " <div id='m4' style='padding: 3px;'>m4</div>\n"
1716 + " <div id='m5' style='padding-left: 3px; padding: 5px;'>m5</div>\n"
1717 + " <div id='m6' style='padding: 2px; padding-left: 7px;'>m6</div>\n"
1718 + " </body>\n"
1719 + "</html>";
1720 loadPageVerifyTitle2(html);
1721 }
1722
1723
1724
1725
1726
1727
1728 @Test
1729 @Alerts({"L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px",
1730 "L:3px,R:3px,T:3px,B:3px", "L:5px,R:5px,T:5px,B:5px", "L:7px,R:2px,T:2px,B:2px"})
1731 public void paddingAllvsPaddingSingle2() throws Exception {
1732 final String html = DOCTYPE_HTML
1733 + "<html>\n"
1734 + " <head>\n"
1735 + " <style>\n"
1736 + " #m1 { padding: 3px; }\n"
1737 + " #m2 { padding-left: 3px; padding: 5px; }\n"
1738 + " #m3 { padding: 2px; padding-left: 7px; }\n"
1739 + " </style>\n"
1740 + " <script>\n"
1741 + LOG_TITLE_FUNCTION
1742 + " function test() {\n"
1743 + " alertComputedPaddings('m1');\n"
1744 + " alertComputedPaddings('m2');\n"
1745 + " alertComputedPaddings('m3');\n"
1746 + " alertNonComputedPaddings('m4');\n"
1747 + " alertNonComputedPaddings('m5');\n"
1748 + " alertNonComputedPaddings('m6');\n"
1749 + " }\n"
1750 + " function alertComputedPaddings(id) {\n"
1751 + " var e = document.getElementById(id);\n"
1752 + " var s = e.currentStyle ? e.currentStyle : getComputedStyle(e, null);\n"
1753 + " log('L:' + s['padding-left'] + ',R:' + s['padding-right'] +\n"
1754 + " ',T:' + s['padding-top'] + ',B:' + s['padding-bottom']);\n"
1755 + " }\n"
1756 + " function alertNonComputedPaddings(id) {\n"
1757 + " var e = document.getElementById(id);\n"
1758 + " var s = e.style;\n"
1759 + " log('L:' + s['padding-left'] + ',R:' + s['padding-right'] +\n"
1760 + " ',T:' + s['padding-top'] + ',B:' + s['padding-bottom']);\n"
1761 + " }\n"
1762 + " </script>\n"
1763 + " </head>\n"
1764 + " <body onload='test()'>\n"
1765 + " <div id='m1'>m1</div>\n"
1766 + " <div id='m2'>m2</div>\n"
1767 + " <div id='m3'>m3</div>\n"
1768 + " <div id='m4' style='padding: 3px;'>m4</div>\n"
1769 + " <div id='m5' style='padding-left: 3px; padding: 5px;'>m5</div>\n"
1770 + " <div id='m6' style='padding: 2px; padding-left: 7px;'>m6</div>\n"
1771 + " </body>\n"
1772 + "</html>";
1773 loadPageVerifyTitle2(html);
1774 }
1775
1776
1777
1778
1779
1780 @Test
1781 public void styleShorthand() throws Exception {
1782 styleShorthand("margin: 10px", "marginTop", "10px");
1783 styleShorthand("margin: 10px", "marginLeft", "10px");
1784 styleShorthand("margin: 10px", "marginRight", "10px");
1785 styleShorthand("margin: 10px", "marginBottom", "10px");
1786
1787 styleShorthand("margin: 10px 20px", "marginTop", "10px");
1788 styleShorthand("margin: 10px 20px", "marginLeft", "20px");
1789 styleShorthand("margin: 10px 20px", "marginRight", "20px");
1790 styleShorthand("margin: 10px 20px", "marginBottom", "10px");
1791
1792 styleShorthand("margin: 10px 20px 30px", "marginTop", "10px");
1793 styleShorthand("margin: 10px 20px 30px", "marginLeft", "20px");
1794 styleShorthand("margin: 10px 20px 30px", "marginRight", "20px");
1795 styleShorthand("margin: 10px 20px 30px", "marginBottom", "30px");
1796
1797 styleShorthand("margin: 10px 20px 30px 40px", "marginTop", "10px");
1798 styleShorthand("margin: 10px 20px 30px 40px", "marginLeft", "40px");
1799 styleShorthand("margin: 10px 20px 30px 40px", "marginRight", "20px");
1800 styleShorthand("margin: 10px 20px 30px 40px", "marginBottom", "30px");
1801
1802 styleShorthand("padding: 10px", "paddingTop", "10px");
1803 styleShorthand("padding: 10px", "paddingLeft", "10px");
1804 styleShorthand("padding: 10px", "paddingRight", "10px");
1805 styleShorthand("padding: 10px", "paddingBottom", "10px");
1806
1807 styleShorthand("padding: 10px 20px", "paddingTop", "10px");
1808 styleShorthand("padding: 10px 20px", "paddingLeft", "20px");
1809 styleShorthand("padding: 10px 20px", "paddingRight", "20px");
1810 styleShorthand("padding: 10px 20px", "paddingBottom", "10px");
1811
1812 styleShorthand("padding: 10px 20px 30px", "paddingTop", "10px");
1813 styleShorthand("padding: 10px 20px 30px", "paddingLeft", "20px");
1814 styleShorthand("padding: 10px 20px 30px", "paddingRight", "20px");
1815 styleShorthand("padding: 10px 20px 30px", "paddingBottom", "30px");
1816
1817 styleShorthand("padding: 10px 20px 30px 40px", "paddingTop", "10px");
1818 styleShorthand("padding: 10px 20px 30px 40px", "paddingLeft", "40px");
1819 styleShorthand("padding: 10px 20px 30px 40px", "paddingRight", "20px");
1820 styleShorthand("padding: 10px 20px 30px 40px", "paddingBottom", "30px");
1821 }
1822
1823 private void styleShorthand(final String style, final String attribute, final String expectedValue)
1824 throws Exception {
1825 final String html = DOCTYPE_HTML
1826 + "<html><head>\n"
1827 + "<script>\n"
1828 + " function log(msg) {\n"
1829 + " var ta = document.getElementById('myTextArea');\n"
1830 + " ta.value += msg + '; ';\n"
1831 + " }\n"
1832 + "function test() {\n"
1833 + " var style = document.getElementById('d').style;\n"
1834 + " log(style." + attribute + ");\n"
1835 + "}\n</script>\n"
1836 + "</head>\n"
1837 + "<body onload='test()'><div id='d' style='" + style + "'>foo</div>\n"
1838 + " <textarea id='myTextArea' cols='80' rows='30'></textarea>\n"
1839 + "</body></html>";
1840
1841 final WebDriver driver = loadPage2(html);
1842
1843 final WebElement textArea = driver.findElement(By.id("myTextArea"));
1844 assertEquals(expectedValue + "; ", textArea.getDomProperty("value"));
1845 }
1846
1847
1848
1849
1850 @Test
1851 @Alerts({})
1852 public void getAttribute() throws Exception {
1853 getAttribute("\"font\"");
1854 }
1855
1856
1857
1858
1859 @Test
1860 @Alerts({})
1861 public void getAttributeFont() throws Exception {
1862 getAttribute("'font'");
1863 }
1864
1865
1866
1867
1868 @Test
1869 @Alerts({})
1870 public void getAttributeColor() throws Exception {
1871 getAttribute("'color'");
1872 }
1873
1874
1875
1876
1877 @Test
1878 @Alerts({})
1879 public void getAttributeColorCase() throws Exception {
1880 getAttribute("'ColoR'");
1881 }
1882
1883
1884
1885
1886 @Test
1887 @Alerts({})
1888 public void getAttributeFont0() throws Exception {
1889 getAttribute("'font', 0");
1890 }
1891
1892
1893
1894
1895 @Test
1896 @Alerts({})
1897 public void getAttributeColor0() throws Exception {
1898 getAttribute("'color', 0");
1899 }
1900
1901
1902
1903
1904 @Test
1905 @Alerts({})
1906 public void getAttributeColorCase0() throws Exception {
1907 getAttribute("'coLOr', 0");
1908 }
1909
1910
1911
1912
1913 @Test
1914 @Alerts({})
1915 public void getAttributeFont1() throws Exception {
1916 getAttribute("'font', 1");
1917 }
1918
1919
1920
1921
1922 @Test
1923 @Alerts({})
1924 public void getAttributeColor1() throws Exception {
1925 getAttribute("'color', 1");
1926 }
1927
1928
1929
1930
1931 @Test
1932 @Alerts({})
1933 public void getAttributeColorCase1() throws Exception {
1934 getAttribute("'ColOR', 1");
1935 }
1936
1937 private void getAttribute(final String params) throws Exception {
1938 final String html = DOCTYPE_HTML
1939 + "<html><head><script>\n"
1940 + LOG_TITLE_FUNCTION
1941 + "function test() {\n"
1942 + " if (document.all['a'].style.getAttribute) {\n"
1943 + " log(document.all['a'].style.getAttribute(" + params + "));\n"
1944 + " }\n"
1945 + "}\n"
1946 + "</script></head>\n"
1947 + "<body onload='test()'>\n"
1948 + "<a id='a' href='#' style='color:green'>go</a></body></html>";
1949
1950 loadPageVerifyTitle2(html);
1951 }
1952
1953
1954
1955
1956 @Test
1957 @Alerts("not supported")
1958 public void setAttributeFont() throws Exception {
1959 setAttribute("'font', 'blah'");
1960 }
1961
1962
1963
1964
1965 @Test
1966 @Alerts("not supported")
1967 public void setAttributeColor() throws Exception {
1968 setAttribute("'color', 'red'");
1969 }
1970
1971
1972
1973
1974 @Test
1975 @Alerts("not supported")
1976 public void setAttributeColorCase() throws Exception {
1977 setAttribute("'ColoR', 'red'");
1978 }
1979
1980
1981
1982
1983 @Test
1984 @Alerts("not supported")
1985 public void setAttributeFont0() throws Exception {
1986 setAttribute("'font', 'blah', 0");
1987 }
1988
1989
1990
1991
1992 @Test
1993 @Alerts("not supported")
1994 public void setAttributeColor0() throws Exception {
1995 setAttribute("'color', 'red', 0");
1996 }
1997
1998
1999
2000
2001 @Test
2002 @Alerts("not supported")
2003 public void setAttributeColorCase0() throws Exception {
2004 setAttribute("'ColoR', 'red', 0");
2005 }
2006
2007
2008
2009
2010 @Test
2011 @Alerts("not supported")
2012 public void setAttributeFont1() throws Exception {
2013 setAttribute("'font', 'blah', 1");
2014 }
2015
2016
2017
2018
2019 @Test
2020 @Alerts("not supported")
2021 public void setAttributeColor1() throws Exception {
2022 setAttribute("'color', 'red', 1");
2023 }
2024
2025
2026
2027
2028 @Test
2029 @Alerts("not supported")
2030 public void setAttributeColorCase1() throws Exception {
2031 setAttribute("'ColoR', 'red', 1");
2032 }
2033
2034 private void setAttribute(final String params) throws Exception {
2035 final String html = DOCTYPE_HTML
2036 + "<html><body onload='test()'>\n"
2037 + "<a id='a' href='#' style='color:green'>go</a>\n"
2038 + "<script>\n"
2039 + LOG_TITLE_FUNCTION
2040 + " function test() {\n"
2041 + " if (document.all['a'].style.getAttribute) {\n"
2042 + " log(\"" + params + "\");\n"
2043 + " log(document.all['a'].style.getAttribute('color'));\n"
2044 + " document.all['a'].style.setAttribute(" + params + ");\n"
2045 + " log(document.all['a'].style.getAttribute('color'));\n"
2046 + " }\n"
2047 + " else {\n"
2048 + " log('not supported');\n"
2049 + " }\n"
2050 + " }\n"
2051 + "</script>\n"
2052 + "</body></html>";
2053
2054 loadPageVerifyTitle2(html);
2055 }
2056
2057
2058
2059
2060 @Test
2061 @Alerts("not supported")
2062 public void removeAttributeFont() throws Exception {
2063 removeAttribute("'font'");
2064 }
2065
2066
2067
2068
2069 @Test
2070 @Alerts("not supported")
2071 public void removeAttributeColor() throws Exception {
2072 removeAttribute("'color'");
2073 }
2074
2075
2076
2077
2078 @Test
2079 @Alerts("not supported")
2080 public void removeAttributeColorCase() throws Exception {
2081 removeAttribute("'ColoR'");
2082 }
2083
2084
2085
2086
2087 @Test
2088 @Alerts("not supported")
2089 public void removeAttributeFont0() throws Exception {
2090 removeAttribute("'font', 0");
2091 }
2092
2093
2094
2095
2096 @Test
2097 @Alerts("not supported")
2098 public void removeAttributeColor0() throws Exception {
2099 removeAttribute("'color', 0");
2100 }
2101
2102
2103
2104
2105 @Test
2106 @Alerts("not supported")
2107 public void removeAttributeColorCase0() throws Exception {
2108 removeAttribute("'ColoR', 0");
2109 }
2110
2111
2112
2113
2114 @Test
2115 @Alerts("not supported")
2116 public void removeAttributeFont1() throws Exception {
2117 removeAttribute("'font', 1");
2118 }
2119
2120
2121
2122
2123 @Test
2124 @Alerts("not supported")
2125 public void removeAttributeColor1() throws Exception {
2126 removeAttribute("'color', 1");
2127 }
2128
2129
2130
2131
2132 @Test
2133 @Alerts("not supported")
2134 public void removeAttributeColorCase1() throws Exception {
2135 removeAttribute("'ColoR', 1");
2136 }
2137
2138 private void removeAttribute(final String params) throws Exception {
2139 final String html = DOCTYPE_HTML
2140 + "<html><body onload='test()'>\n"
2141 + "<a id='a' href='#' style='color:green'>go</a>\n"
2142 + "<script>\n"
2143 + LOG_TITLE_FUNCTION
2144 + " function test() {\n"
2145 + " if (document.all['a'].style.getAttribute) {\n"
2146 + " log(\"" + params + "\");\n"
2147 + " log(document.all['a'].style.getAttribute('color'));\n"
2148 + " log(document.all['a'].style.removeAttribute(" + params + "));\n"
2149 + " log(document.all['a'].style.getAttribute('color'));\n"
2150 + " }\n"
2151 + " else {\n"
2152 + " log('not supported');\n"
2153 + " }\n"
2154 + " }\n"
2155 + "</script>\n"
2156 + "</body></html>";
2157
2158 loadPageVerifyTitle2(html);
2159 }
2160
2161
2162
2163
2164 @Test
2165 @Alerts({"red ", "black ", "blue important", "gray ", "green "})
2166 public void setProperty() throws Exception {
2167 final String[] expected = getExpectedAlerts();
2168 setPropertyBackgroundColor("'background-color', 'red', ''", expected[0]);
2169 setPropertyBackgroundColor("'background-ColoR', 'black', ''", expected[1]);
2170 setPropertyBackgroundColor("'background-color', 'blue', 'important'", expected[2]);
2171 setPropertyBackgroundColor("'background-color', 'gray', null", expected[3]);
2172 setPropertyBackgroundColor("'background-color', 'green', undefined", expected[4]);
2173 }
2174
2175
2176
2177
2178 @Test
2179 @Alerts({"green ", "black important", "green "})
2180 public void setPropertyImportant() throws Exception {
2181 final String[] expected = getExpectedAlerts();
2182 setPropertyBackgroundColor("'background-color', 'white', 'crucial'", expected[0]);
2183 setPropertyBackgroundColor("'background-color', 'black', 'imPORTant'", expected[1]);
2184 setPropertyBackgroundColor("'background-color', 'blue', 'important '", expected[2]);
2185 }
2186
2187 private void setPropertyBackgroundColor(final String params, final String... expected) throws Exception {
2188 final String html = DOCTYPE_HTML
2189 + "<html><body onload='test()'>\n"
2190 + "<a id='a' href='#' style='background-color:green'>go</a>\n"
2191 + "<script>\n"
2192 + LOG_TITLE_FUNCTION
2193 + " function test() {\n"
2194 + " var node = document.getElementById('a');\n"
2195 + " try {\n"
2196 + " node.style.setProperty(" + params + ");\n"
2197 + " log(node.style.backgroundColor + ' ' + node.style.getPropertyPriority('background-color'));\n"
2198 + " } catch(e) { log(e); }\n"
2199 + " }\n"
2200 + "</script>\n"
2201 + "</body></html>";
2202
2203 setExpectedAlerts(expected);
2204 loadPageVerifyTitle2(html);
2205 }
2206
2207
2208
2209
2210 @Test
2211 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2212 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2213 public void setWidthProperty() throws Exception {
2214 setLengthProperty("width", "width");
2215 }
2216
2217
2218
2219
2220 @Test
2221 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2222 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2223 public void setWidth() throws Exception {
2224 setLength("width", "width");
2225 }
2226
2227
2228
2229
2230 @Test
2231 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2232 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2233 public void setHeightProperty() throws Exception {
2234 setLengthProperty("height", "height");
2235 }
2236
2237
2238
2239
2240 @Test
2241 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2242 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2243 public void setHeight() throws Exception {
2244 setLength("height", "height");
2245 }
2246
2247
2248
2249
2250 @Test
2251 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2252 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2253 public void setTopProperty() throws Exception {
2254 setLengthProperty("top", "top");
2255 }
2256
2257
2258
2259
2260 @Test
2261 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2262 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2263 public void setTop() throws Exception {
2264 setLength("top", "top");
2265 }
2266
2267
2268
2269
2270 @Test
2271 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2272 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2273 public void setLeftProperty() throws Exception {
2274 setLengthProperty("left", "left");
2275 }
2276
2277
2278
2279
2280 @Test
2281 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2282 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2283 public void setLeft() throws Exception {
2284 setLength("left", "left");
2285 }
2286
2287
2288
2289
2290 @Test
2291 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2292 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2293 public void setBottomProperty() throws Exception {
2294 setLengthProperty("bottom", "bottom");
2295 }
2296
2297
2298
2299
2300 @Test
2301 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2302 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2303 public void setBottom() throws Exception {
2304 setLength("bottom", "bottom");
2305 }
2306
2307
2308
2309
2310 @Test
2311 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2312 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2313 public void setRightProperty() throws Exception {
2314 setLengthProperty("right", "right");
2315 }
2316
2317
2318
2319
2320 @Test
2321 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2322 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2323 public void setRight() throws Exception {
2324 setLength("right", "right");
2325 }
2326
2327
2328
2329
2330 @Test
2331 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2332 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2333 public void setMarginTopProperty() throws Exception {
2334 setLengthProperty("margin-top", "marginTop");
2335 }
2336
2337
2338
2339
2340 @Test
2341 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2342 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2343 public void setMarginTop() throws Exception {
2344 setLength("margin-top", "marginTop");
2345 }
2346
2347
2348
2349
2350 @Test
2351 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2352 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2353 public void setMarginLeftProperty() throws Exception {
2354 setLengthProperty("margin-left", "marginLeft");
2355 }
2356
2357
2358
2359
2360 @Test
2361 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2362 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2363 public void setMarginLeft() throws Exception {
2364 setLength("margin-left", "marginLeft");
2365 }
2366
2367
2368
2369
2370 @Test
2371 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2372 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2373 public void setMarginBottomProperty() throws Exception {
2374 setLengthProperty("margin-bottom", "marginBottom");
2375 }
2376
2377
2378
2379
2380 @Test
2381 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2382 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2383 public void setMarginBottom() throws Exception {
2384 setLength("margin-bottom", "marginBottom");
2385 }
2386
2387
2388
2389
2390 @Test
2391 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2392 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2393 public void setMarginRightProperty() throws Exception {
2394 setLengthProperty("margin-right", "marginRight");
2395 }
2396
2397
2398
2399
2400 @Test
2401 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2402 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2403 public void setMarginRight() throws Exception {
2404 setLength("margin-right", "marginRight");
2405 }
2406
2407
2408
2409
2410 @Test
2411 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2412 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2413 public void setPaddingTopProperty() throws Exception {
2414 setLengthProperty("padding-top", "paddingTop");
2415 }
2416
2417
2418
2419
2420 @Test
2421 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2422 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2423 public void setPaddingTop() throws Exception {
2424 setLength("padding-top", "paddingTop");
2425 }
2426
2427
2428
2429
2430 @Test
2431 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2432 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2433 public void setPaddingLeftProperty() throws Exception {
2434 setLengthProperty("padding-left", "paddingLeft");
2435 }
2436
2437
2438
2439
2440 @Test
2441 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2442 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2443 public void setPaddingLeft() throws Exception {
2444 setLength("padding-left", "paddingLeft");
2445 }
2446
2447
2448
2449
2450 @Test
2451 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2452 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2453 public void setPaddingBottomProperty() throws Exception {
2454 setLengthProperty("padding-bottom", "paddingBottom");
2455 }
2456
2457
2458
2459
2460 @Test
2461 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2462 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2463 public void setPaddingBottom() throws Exception {
2464 setLength("padding-bottom", "paddingBottom");
2465 }
2466
2467
2468
2469
2470 @Test
2471 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2472 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2473 public void setPaddingRightProperty() throws Exception {
2474 setLengthProperty("padding-right", "paddingRight");
2475 }
2476
2477
2478
2479
2480 @Test
2481 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2482 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2483 public void setPaddingRight() throws Exception {
2484 setLength("padding-right", "paddingRight");
2485 }
2486
2487
2488
2489
2490 @Test
2491 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2492 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2493 public void setBorderTopWidthProperty() throws Exception {
2494 setLengthProperty("border-top-width", "borderTopWidth");
2495 }
2496
2497
2498
2499
2500 @Test
2501 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2502 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2503 public void setBorderTopWidth() throws Exception {
2504 setLength("border-top-width", "borderTopWidth");
2505 }
2506
2507
2508
2509
2510 @Test
2511 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2512 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2513 public void setBorderLeftWidthProperty() throws Exception {
2514 setLengthProperty("border-left-width", "borderLeftWidth");
2515 }
2516
2517
2518
2519
2520 @Test
2521 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2522 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2523 public void setBorderLeftWidth() throws Exception {
2524 setLength("border-left-width", "borderLeftWidth");
2525 }
2526
2527
2528
2529
2530 @Test
2531 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2532 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2533 public void setBorderBottomWidthProperty() throws Exception {
2534 setLengthProperty("border-bottom-width", "borderBottomWidth");
2535 }
2536
2537
2538
2539
2540 @Test
2541 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2542 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2543 public void setBorderBottomWidth() throws Exception {
2544 setLength("border-bottom-width", "borderBottomWidth");
2545 }
2546
2547
2548
2549
2550 @Test
2551 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2552 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2553 public void setBorderRightWidthProperty() throws Exception {
2554 setLengthProperty("border-right-width", "borderRightWidth");
2555 }
2556
2557
2558
2559
2560 @Test
2561 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2562 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2563 public void setBorderRightWidth() throws Exception {
2564 setLength("border-right-width", "borderRightWidth");
2565 }
2566
2567
2568
2569
2570 @Test
2571 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2572 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2573 public void setMaxWidthProperty() throws Exception {
2574 setLengthProperty("max-width", "maxWidth");
2575 }
2576
2577
2578
2579
2580 @Test
2581 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2582 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2583 public void setMaxWidth() throws Exception {
2584 setLength("max-width", "maxWidth");
2585 }
2586
2587
2588
2589
2590 @Test
2591 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2592 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2593 public void setMinWidthProperty() throws Exception {
2594 setLengthProperty("min-width", "minWidth");
2595 }
2596
2597
2598
2599
2600 @Test
2601 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2602 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2603 public void setMinWidth() throws Exception {
2604 setLength("min-width", "minWidth");
2605 }
2606
2607
2608
2609
2610 @Test
2611 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2612 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2613 public void setMaxHeightProperty() throws Exception {
2614 setLengthProperty("max-height", "maxHeight");
2615 }
2616
2617
2618
2619
2620 @Test
2621 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2622 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2623 public void setMaxHeight() throws Exception {
2624 setLength("max-height", "maxHeight");
2625 }
2626
2627
2628
2629
2630 @Test
2631 @Alerts({"17px", "5px", "6em", "auto", "7%", "initial", "inherit",
2632 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2633 public void setMinHeightProperty() throws Exception {
2634 setLengthProperty("min-height", "minHeight");
2635 }
2636
2637
2638
2639
2640 @Test
2641 @Alerts({"17px", "5px", "6em", "auto", "70%", "initial", "inherit",
2642 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2643 public void setMinHeight() throws Exception {
2644 setLength("min-height", "minHeight");
2645 }
2646
2647
2648
2649
2650 @Test
2651 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2652 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2653 public void setTextIndentProperty() throws Exception {
2654 setLengthProperty("text-indent", "textIndent");
2655 }
2656
2657
2658
2659
2660 @Test
2661 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2662 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2663 public void setTextIndent() throws Exception {
2664 setLength("text-indent", "textIndent");
2665 }
2666
2667
2668
2669
2670 @Test
2671 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2672 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2673 public void setFontSizeProperty() throws Exception {
2674 setLengthProperty("font-size", "fontSize");
2675 }
2676
2677
2678
2679
2680 @Test
2681 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2682 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2683 public void setFontSize() throws Exception {
2684 setLength("font-size", "fontSize");
2685 }
2686
2687
2688
2689
2690 @Test
2691 @Alerts(DEFAULT = {"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2692 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2693 FF = {"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2694 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2695 FF_ESR = {"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2696 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2697 public void setWordSpacingProperty() throws Exception {
2698 setLengthProperty("word-spacing", "wordSpacing");
2699 }
2700
2701
2702
2703
2704 @Test
2705 @Alerts(DEFAULT = {"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2706 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px", "17px"},
2707 FF = {"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2708 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px", "17px"},
2709 FF_ESR = {"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2710 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px", "17px"})
2711 public void setWordSpacing() throws Exception {
2712 setLength("word-spacing", "wordSpacing");
2713 }
2714
2715
2716
2717
2718 @Test
2719 @Alerts(DEFAULT = {"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2720 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2721 FF = {"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2722 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2723 FF_ESR = {"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2724 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2725 public void setLetterSpacingProperty() throws Exception {
2726 setLengthProperty("letter-spacing", "letterSpacing");
2727 }
2728
2729
2730
2731
2732 @Test
2733 @Alerts(DEFAULT = {"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2734 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2735 FF = {"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2736 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"},
2737 FF_ESR = {"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2738 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2739 public void setLetterSpacing() throws Exception {
2740 setLength("letter-spacing", "letterSpacing");
2741 }
2742
2743
2744
2745
2746 @Test
2747 @Alerts({"17px", "5px", "6em", "17px", "7%", "initial", "inherit",
2748 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2749 public void setVerticalAlignProperty() throws Exception {
2750 setLengthProperty("vertical-align", "verticalAlign");
2751 }
2752
2753
2754
2755
2756 @Test
2757 @Alerts({"17px", "5px", "6em", "17px", "70%", "initial", "inherit",
2758 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2759 public void setVerticalAlign() throws Exception {
2760 setLength("vertical-align", "verticalAlign");
2761 }
2762
2763
2764
2765
2766 @Test
2767 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2768 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2769 public void setOutlineWidthProperty() throws Exception {
2770 setLengthProperty("outline-width", "outlineWidth");
2771 }
2772
2773
2774
2775
2776 @Test
2777 @Alerts({"thin", "medium", "thick"})
2778 public void setOutlineWidthProperty2() throws Exception {
2779 final String[] expected = getExpectedAlerts();
2780 setLengthProperty("outline-width", "outlineWidth", "'thin', ''", expected[0]);
2781 setLengthProperty("outline-width", "outlineWidth", "'medium', ''", expected[1]);
2782 setLengthProperty("outline-width", "outlineWidth", "'thick', ''", expected[2]);
2783 }
2784
2785
2786
2787
2788 @Test
2789 @Alerts({"17px", "5px", "6em", "17px", "17px", "initial", "inherit",
2790 "17px", "17px", "17px", "", "17px", "", "17px", "17px", "17px"})
2791 public void setOutlineWidth() throws Exception {
2792 setLength("outline-width", "outlineWidth");
2793 }
2794
2795
2796
2797
2798 @Test
2799 @Alerts({"thin", "medium", "thick"})
2800 public void setOutlineWidth2() throws Exception {
2801 final String[] expected = getExpectedAlerts();
2802 setLength("outline-width", "outlineWidth", "'thin'", expected[0]);
2803 setLength("outline-width", "outlineWidth", "'medium'", expected[1]);
2804 setLength("outline-width", "outlineWidth", "'thick'", expected[2]);
2805 }
2806
2807 private void setLengthProperty(final String cssProp, final String prop) throws Exception {
2808 final String[] expected = getExpectedAlerts();
2809 setLengthProperty(cssProp, prop, "'4', ''", expected[0]);
2810 setLengthProperty(cssProp, prop, "'5px', ''", expected[1]);
2811 setLengthProperty(cssProp, prop, "'6em', ''", expected[2]);
2812 setLengthProperty(cssProp, prop, "'auto', ''", expected[3]);
2813 setLengthProperty(cssProp, prop, "'7%', ''", expected[4]);
2814 setLengthProperty(cssProp, prop, "'initial', ''", expected[5]);
2815 setLengthProperty(cssProp, prop, "'inherit', ''", expected[6]);
2816 setLengthProperty(cssProp, prop, "'ellen', ''", expected[7]);
2817 setLengthProperty(cssProp, prop, "undefined, ''", expected[8]);
2818 setLengthProperty(cssProp, prop, "'undefined', ''", expected[9]);
2819 setLengthProperty(cssProp, prop, "'', null", expected[10]);
2820 setLengthProperty(cssProp, prop, "NaN, ''", expected[11]);
2821 setLengthProperty(cssProp, prop, "null, ''", expected[12]);
2822 setLengthProperty(cssProp, prop, "'NaNpx', ''", expected[13]);
2823 setLengthProperty(cssProp, prop, "true, ''", expected[14]);
2824 setLengthProperty(cssProp, prop, "Infinity, ''", expected[15]);
2825 }
2826
2827 private void setLength(final String cssProp, final String prop) throws Exception {
2828 final String[] expected = getExpectedAlerts();
2829 setLength(cssProp, prop, "4", expected[0]);
2830 setLength(cssProp, prop, "'5px'", expected[1]);
2831 setLength(cssProp, prop, "'6em'", expected[2]);
2832 setLength(cssProp, prop, "'auto'", expected[3]);
2833 setLength(cssProp, prop, "'70%'", expected[4]);
2834 setLength(cssProp, prop, "'initial'", expected[5]);
2835 setLength(cssProp, prop, "'inherit'", expected[6]);
2836 setLength(cssProp, prop, "'ellen'", expected[7]);
2837 setLength(cssProp, prop, "undefined", expected[8]);
2838 setLength(cssProp, prop, "'undefined'", expected[9]);
2839 setLength(cssProp, prop, "''", expected[10]);
2840 setLength(cssProp, prop, "NaN", expected[11]);
2841 setLength(cssProp, prop, "null", expected[12]);
2842 setLength(cssProp, prop, "'NaNpx'", expected[13]);
2843 setLength(cssProp, prop, "true", expected[14]);
2844 setLength(cssProp, prop, "Infinity", expected[15]);
2845 }
2846
2847 private void setLengthProperty(final String cssProp, final String prop,
2848 final String params, final String... expected) throws Exception {
2849 final String html = DOCTYPE_HTML
2850 + "<html><body onload='test()'>\n"
2851 + "<a id='a' href='#' style='" + cssProp + ":17px'>go</a>\n"
2852 + "<script>\n"
2853 + LOG_TITLE_FUNCTION
2854 + " function test() {\n"
2855 + " var node = document.getElementById('a');\n"
2856 + " try {\n"
2857 + " node.style.setProperty('" + cssProp + "', " + params + ");\n"
2858 + " log(node.style." + prop + ");\n"
2859 + " } catch(e) { log(e); }\n"
2860 + " }\n"
2861 + "</script>\n"
2862 + "</body></html>";
2863
2864 loadPageVerifyTitle2(html, expected);
2865 }
2866
2867 private void setLength(final String cssProp, final String prop,
2868 final String params, final String... expected) throws Exception {
2869 final String html = DOCTYPE_HTML
2870 + "<html><body onload='test()'>\n"
2871 + "<a id='a' href='#' style='" + cssProp + ":17px'>go</a>\n"
2872 + "<script>\n"
2873 + LOG_TITLE_FUNCTION
2874 + " function test() {\n"
2875 + " var node = document.getElementById('a');\n"
2876 + " try {\n"
2877 + " node.style." + prop + " = " + params + ";\n"
2878 + " log(node.style." + prop + ");\n"
2879 + " } catch(e) { log(e); }\n"
2880 + " }\n"
2881 + "</script>\n"
2882 + "</body></html>";
2883
2884 loadPageVerifyTitle2(html, expected);
2885 }
2886
2887
2888
2889
2890 @Test
2891 @Alerts({"", "important", "", "important"})
2892 public void getPropertyPriority() throws Exception {
2893 final String html = DOCTYPE_HTML
2894 + "<html><body onload='test()'>\n"
2895 + "<a id='a1' href='#' style='color:green'>go</a>\n"
2896 + "<a id='a2' href='#' style='color:blue !important'>go</a>\n"
2897
2898 + "<a id='a3' href='#' style='background-color:green'>go</a>\n"
2899 + "<a id='a4' href='#' style='background-color:blue !important'>go</a>\n"
2900
2901 + "<script>\n"
2902 + LOG_TITLE_FUNCTION
2903 + " function test() {\n"
2904 + " var node = document.getElementById('a1');\n"
2905 + " log(node.style.getPropertyPriority('color'));\n"
2906
2907 + " node = document.getElementById('a2');\n"
2908 + " log(node.style.getPropertyPriority('color'));\n"
2909
2910 + " node = document.getElementById('a3');\n"
2911 + " log(node.style.getPropertyPriority('background-color'));\n"
2912
2913 + " node = document.getElementById('a4');\n"
2914 + " log(node.style.getPropertyPriority('background-color'));\n"
2915 + " }\n"
2916 + "</script>\n"
2917 + "</body></html>";
2918
2919 loadPageVerifyTitle2(html);
2920 }
2921
2922
2923
2924
2925 @Test
2926 @Alerts("")
2927 public void getPropertyPriorityNoStyle() throws Exception {
2928 final String html = DOCTYPE_HTML
2929 + "<html><body onload='test()'>\n"
2930 + "<a id='a1' href='#'>go</a>\n"
2931
2932 + "<script>\n"
2933 + LOG_TITLE_FUNCTION
2934 + " function test() {\n"
2935 + " var node = document.getElementById('a1');\n"
2936 + " log(node.style.getPropertyPriority('color'));\n"
2937 + " }\n"
2938 + "</script>\n"
2939 + "</body></html>";
2940
2941 loadPageVerifyTitle2(html);
2942 }
2943
2944
2945
2946
2947 @Test
2948 @Alerts({"black", "pink", "color: pink;", "color: pink;"})
2949 public void caseInsensitive() throws Exception {
2950 final String html = DOCTYPE_HTML
2951 + "<html><head><script>\n"
2952 + LOG_TITLE_FUNCTION
2953 + "function doTest() {\n"
2954 + " var node = document.getElementById('div1');\n"
2955 + " var style = node.style;\n"
2956 + " log(style.color);\n"
2957 + " style.color = 'pink';\n"
2958 + " log(style.color);\n"
2959 + " log(node.getAttribute('style'));\n"
2960 + "}\n"
2961 + "</script></head>\n"
2962 + "<body onload='doTest()'><div id='div1' style='COLOR: BLACK'>foo</div></body></html>";
2963
2964 final String style = getExpectedAlerts()[getExpectedAlerts().length - 1];
2965
2966 setExpectedAlerts(Arrays.copyOf(getExpectedAlerts(), getExpectedAlerts().length - 1));
2967 final WebDriver driver = loadPageVerifyTitle2(html);
2968 assertEquals(style, driver.findElement(By.id("div1")).getAttribute("style"));
2969 }
2970
2971
2972
2973
2974 @Test
2975 @Alerts({"5px", "undefined", "1em", "undefined"})
2976 public void pixelLeft() throws Exception {
2977 final String html = DOCTYPE_HTML
2978 + "<html><body>\n"
2979 + "<div id='a' style='left: 5px; border: 1px solid black;'>a</div>\n"
2980 + "<div id='b' style='left: 1em; border: 1px solid black;'>b</div>\n"
2981 + "<script>\n"
2982 + LOG_TITLE_FUNCTION
2983 + " var a = document.getElementById('a');\n"
2984 + " var b = document.getElementById('b');\n"
2985 + " log(a.style.left);\n"
2986 + " log(a.style.pixelLeft);\n"
2987 + " log(b.style.left);\n"
2988 + " log(b.style.pixelLeft);\n"
2989 + " if(a.style.pixelLeft) {\n"
2990 + " a.style.pixelLeft = 30;\n"
2991 + " log(a.style.left);\n"
2992 + " log(a.style.pixelLeft);\n"
2993 + " }\n"
2994 + "</script>\n"
2995 + "</body></html>";
2996 loadPageVerifyTitle2(html);
2997 }
2998
2999
3000
3001
3002 @Test
3003 @Alerts({"5px", "undefined", "1em", "undefined"})
3004 public void pixelRight() throws Exception {
3005 final String html = DOCTYPE_HTML
3006 + "<html><body>\n"
3007 + "<div id='a' style='right: 5px; border: 1px solid black;'>a</div>\n"
3008 + "<div id='b' style='right: 1em; border: 1px solid black;'>b</div>\n"
3009 + "<script>\n"
3010 + LOG_TITLE_FUNCTION
3011 + " var a = document.getElementById('a');\n"
3012 + " var b = document.getElementById('b');\n"
3013 + " log(a.style.right);\n"
3014 + " log(a.style.pixelRight);\n"
3015 + " log(b.style.right);\n"
3016 + " log(b.style.pixelRight);\n"
3017 + " if(a.style.pixelRight) {\n"
3018 + " a.style.pixelRight = 30;\n"
3019 + " log(a.style.right);\n"
3020 + " log(a.style.pixelRight);\n"
3021 + " }\n"
3022 + "</script>\n"
3023 + "</body></html>";
3024 loadPageVerifyTitle2(html);
3025 }
3026
3027
3028
3029
3030 @Test
3031 @Alerts({"5px", "undefined", "1em", "undefined"})
3032 public void pixelTop() throws Exception {
3033 final String html = DOCTYPE_HTML
3034 + "<html><body>\n"
3035 + "<div id='a' style='top: 5px; border: 1px solid black;'>a</div>\n"
3036 + "<div id='b' style='top: 1em; border: 1px solid black;'>b</div>\n"
3037 + "<script>\n"
3038 + LOG_TITLE_FUNCTION
3039 + " var a = document.getElementById('a');\n"
3040 + " var b = document.getElementById('b');\n"
3041 + " log(a.style.top);\n"
3042 + " log(a.style.pixelTop);\n"
3043 + " log(b.style.top);\n"
3044 + " log(b.style.pixelTop);\n"
3045 + " if(a.style.pixelTop) {\n"
3046 + " a.style.pixelTop = 30;\n"
3047 + " log(a.style.top);\n"
3048 + " log(a.style.pixelTop);\n"
3049 + " }\n"
3050 + "</script>\n"
3051 + "</body></html>";
3052 loadPageVerifyTitle2(html);
3053 }
3054
3055
3056
3057
3058 @Test
3059 @Alerts({"5px", "undefined", "1em", "undefined"})
3060 public void pixelBottom() throws Exception {
3061 final String html = DOCTYPE_HTML
3062 + "<html><body>\n"
3063 + "<div id='a' style='bottom: 5px; border: 1px solid black;'>a</div>\n"
3064 + "<div id='b' style='bottom: 1em; border: 1px solid black;'>b</div>\n"
3065 + "<script>\n"
3066 + LOG_TITLE_FUNCTION
3067 + " var a = document.getElementById('a');\n"
3068 + " var b = document.getElementById('b');\n"
3069 + " log(a.style.bottom);\n"
3070 + " log(a.style.pixelBottom);\n"
3071 + " log(b.style.bottom);\n"
3072 + " log(b.style.pixelBottom);\n"
3073 + " if(a.style.pixelBottom) {\n"
3074 + " a.style.pixelBottom = 30;\n"
3075 + " log(a.style.bottom);\n"
3076 + " log(a.style.pixelBottom);\n"
3077 + " }\n"
3078 + "</script>\n"
3079 + "</body></html>";
3080 loadPageVerifyTitle2(html);
3081 }
3082
3083
3084
3085
3086
3087
3088 @Test
3089 @Alerts(DEFAULT = {"undefined", "none"},
3090 CHROME = {"undefined", "before", "none", "TypeError"},
3091 EDGE = {"undefined", "before", "none", "TypeError"})
3092 @HtmlUnitNYI(CHROME = {"function", "before", "none", "after", "none"},
3093 EDGE = {"function", "before", "none", "after", "none"},
3094 FF = {"function", "before", "none", "after", "none"},
3095 FF_ESR = {"function", "before", "none", "after", "none"})
3096 public void interceptSetter() throws Exception {
3097 final String html = DOCTYPE_HTML
3098 + "<html>\n"
3099 + "<body>\n"
3100 + "<div id='d'>foo</div>\n"
3101 + "<script>\n"
3102 + LOG_TITLE_FUNCTION
3103 + " try {\n"
3104 + " var css = window.CSSStyleDeclaration;\n"
3105 + " var oldDisplay = css.prototype.__lookupSetter__('display');\n"
3106 + " log(typeof oldDisplay);\n"
3107
3108 + " var newDisplay = function(x){\n"
3109 + " log('before');\n"
3110 + " log(x);\n"
3111 + " oldDisplay.call(this, x);\n"
3112 + " log('after');\n"
3113 + " };\n"
3114 + " css.prototype.__defineSetter__('display', newDisplay);\n"
3115
3116 + " var div = document.getElementById('d');\n"
3117 + " div.style.display = 'none';\n"
3118 + " log(div.style.display);\n"
3119 + " } catch(e) { logEx(e); }\n"
3120 + "</script>\n"
3121 + "</body></html>";
3122 loadPageVerifyTitle2(html);
3123 }
3124
3125
3126
3127
3128 @Test
3129 @Alerts({"", "", "", ""})
3130 public void setToNull() throws Exception {
3131 final String html = DOCTYPE_HTML
3132 + "<html><head><script>\n"
3133 + LOG_TITLE_FUNCTION
3134 + "function test() {\n"
3135 + " var div1 = document.getElementById('div1');\n"
3136 + " log(div1.style.border);\n"
3137 + " try {\n"
3138 + " div1.style.border = null;\n"
3139 + " } catch(e) {logEx(e);}\n"
3140 + " log(div1.style.border);\n"
3141 + " log(div1.style.display);\n"
3142 + " try {\n"
3143 + " div1.style.display = null;\n"
3144 + " } catch(e) {logEx(e);}\n"
3145 + " log(div1.style.display);\n"
3146 + "}\n"
3147 + "</script></head>\n"
3148 + "<body onload='test()'>\n"
3149 + "<div id='div1'>foo</div></body></html>";
3150
3151 loadPageVerifyTitle2(html);
3152 }
3153
3154
3155
3156
3157 @Test
3158 @Alerts({"1", "width", "undefined", "undefined"})
3159 public void length2() throws Exception {
3160 final String html = DOCTYPE_HTML
3161 + "<html><head>\n"
3162 + "<script>\n"
3163 + LOG_TITLE_FUNCTION
3164 + " function test() {\n"
3165 + " var a = document.createElement('div');\n"
3166 + " a.style.cssText = 'width: 100%';\n"
3167 + " log(a.style.length);\n"
3168 + " log(a.style[0]);\n"
3169 + " log(a.style[1]);\n"
3170 + " log(a.style[-1]);\n"
3171 + " }\n"
3172 + "</script>\n"
3173 + "</head><body onload='test()'>\n"
3174 + "</body></html>";
3175 loadPageVerifyTitle2(html);
3176 }
3177
3178
3179
3180
3181 @Test
3182 @Alerts({"true", "true", "border-box"})
3183 public void boxSizing() throws Exception {
3184 final String html = DOCTYPE_HTML
3185 + "<html><head>\n"
3186 + "<script>\n"
3187 + LOG_TITLE_FUNCTION
3188 + " function test() {\n"
3189 + " var style = document.getElementById('test').style;\n"
3190 + " log(style.boxSizing === '');\n"
3191
3192 + " style = document.createElement('div').style;\n"
3193 + " log(style.boxSizing === '');\n"
3194 + " style.boxSizing = 'border-box';\n"
3195 + " log(style.boxSizing);\n"
3196 + " }\n"
3197 + "</script>\n"
3198 + "</head>\n"
3199 + "<body onload='test()'>\n"
3200 + " <div id='test'></div>\n"
3201 + "</body></html>";
3202
3203 loadPageVerifyTitle2(html);
3204 }
3205
3206
3207
3208
3209
3210 @Test
3211 @Alerts({"auto", ""})
3212 public void jQueryPixelPosition() throws Exception {
3213 final String html = DOCTYPE_HTML
3214 + "<html><head>\n"
3215 + "<script>\n"
3216 + LOG_TITLE_FUNCTION
3217 + " function test() {\n"
3218 + " var div = document.getElementById('test');\n"
3219 + " var style = window.getComputedStyle(div, null);\n"
3220 + " log(style.top);\n"
3221
3222 + " div = document.createElement('div');\n"
3223 + " style = window.getComputedStyle(div, null);\n"
3224 + " log(style.top);\n"
3225 + " }\n"
3226 + "</script>\n"
3227 + "</head>\n"
3228 + "<body onload='test()'>\n"
3229 + " <div id='test'></div>\n"
3230 + "</body></html>";
3231
3232 loadPageVerifyTitle2(html);
3233 }
3234
3235
3236
3237
3238
3239
3240
3241 @Test
3242 public void styleAttributes() throws Exception {
3243 final List<String> allProperties = new ArrayList<>();
3244 for (final BrowserVersion browserVersion : allBrowsers()) {
3245 final ClassConfiguration config
3246 = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
3247 for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
3248 if (!definition.name().endsWith("_")) {
3249 final String propertyName = definition.getPropertyName();
3250 final PropertyInfo info = config.getPropertyMap().get(propertyName);
3251 if (info != null) {
3252 allProperties.add(propertyName);
3253 }
3254 }
3255 }
3256 }
3257
3258 final BrowserVersion browserVersion = getBrowserVersion();
3259 final ClassConfiguration config
3260 = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
3261 for (final Definition definition : StyleAttributes.getDefinitions(browserVersion)) {
3262 if (!definition.name().endsWith("_")) {
3263 final String propertyName = definition.getPropertyName();
3264 final PropertyInfo info = config.getPropertyMap().get(propertyName);
3265 if (allProperties.contains(propertyName)
3266 && (info == null || info.getReadMethod() == null || info.getWriteMethod() == null)) {
3267 fail("CSSStyleDeclaration: " + propertyName + " must support " + browserVersion.getNickname());
3268 }
3269 }
3270 }
3271
3272 for (final String propertyName : config.getPropertyMap().keySet()) {
3273 if (!"length".equals(propertyName) && !"parentRule".equals(propertyName) && !"cssText".equals(propertyName)
3274 && StyleAttributes.getDefinition(propertyName, browserVersion) == null) {
3275 fail("CSSStyleDeclaration: incorrectly defines " + propertyName
3276 + " for " + browserVersion.getNickname());
3277 }
3278 }
3279 }
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289 @Test
3290 public void defaultImplementation() throws Exception {
3291 final BrowserVersion browserVersion = getBrowserVersion();
3292 final ClassConfiguration config
3293 = AbstractJavaScriptConfiguration.getClassConfiguration(CSSStyleDeclaration.class, browserVersion);
3294 final Map<String, PropertyInfo> propertyMap = config.getPropertyMap();
3295 final File cssFolder = new File("src/main/java/org/htmlunit/javascript/host/css/");
3296 final List<String> cssLines = FileUtils.readLines(new File(cssFolder, "CSSStyleDeclaration.java"), ISO_8859_1);
3297 final List<String> computedLines = FileUtils.readLines(new File(cssFolder, "ComputedCSSStyleDeclaration.java"),
3298 ISO_8859_1);
3299 for (final Map.Entry<String, PropertyInfo> entry : propertyMap.entrySet()) {
3300 final PropertyInfo info = entry.getValue();
3301 if (info.getReadMethod() == null) {
3302 fail(browserVersion.getNickname() + " CSSStyleDeclaration: no getter for " + entry.getKey());
3303 }
3304 if (info.getWriteMethod() == null && !"length".equals(entry.getKey())) {
3305 fail(browserVersion.getNickname() + " CSSStyleDeclaration: no setter for " + entry.getKey());
3306 }
3307 if (isDefaultGetter(cssLines, info) && isDefaultSetter(cssLines, info)
3308 && isDefaultGetterComputed(computedLines, info)) {
3309 fail(browserVersion.getNickname()
3310 + " CSSStyleDeclaration: default implementation for " + entry.getKey());
3311 }
3312 }
3313 }
3314
3315 private static boolean isDefaultGetter(final List<String> lines, final PropertyInfo info) {
3316 for (int i = 0; i < lines.size(); i++) {
3317 final String line = lines.get(i);
3318 final String nextLine = i + 1 < lines.size() ? lines.get(i + 1) : null;
3319 if (line.startsWith(" public ")
3320 && line.contains(" " + info.getReadMethod().getName() + "(")
3321 && nextLine != null && nextLine.contains(" return getStyleAttribute(")
3322 && lines.get(i + 2).equals(" }")) {
3323 final String styleName = nextLine.substring(nextLine.indexOf('(' + 1), nextLine.indexOf(')'));
3324 try {
3325 final String attributeName = Definition.valueOf(styleName).getAttributeName();
3326 final String methodName = "get"
3327 + Character.toUpperCase(attributeName.charAt(0)) + attributeName.substring(1);
3328 if (info.getReadMethod().getName().equals(methodName)) {
3329 return true;
3330 }
3331 }
3332 catch (final Exception e) {
3333
3334 }
3335 }
3336 }
3337 return false;
3338 }
3339
3340 private static boolean isDefaultSetter(final List<String> lines, final PropertyInfo info) {
3341 for (int i = 0; i < lines.size(); i++) {
3342 final String line = lines.get(i);
3343 if (line.startsWith(" public void ")
3344 && line.contains(" " + info.getWriteMethod().getName() + "(")
3345 && lines.get(i + 1).contains(" setStyleAttribute(")
3346 && lines.get(i + 2).equals(" }")) {
3347 return true;
3348 }
3349 }
3350 return false;
3351 }
3352
3353 private static boolean isDefaultGetterComputed(final List<String> lines, final PropertyInfo info) {
3354 for (int i = 0; i < lines.size(); i++) {
3355 final String line = lines.get(i);
3356 if (line.startsWith(" public ") && line.contains(" " + info.getReadMethod().getName() + "(")) {
3357 final String nextLine = lines.get(i + 1);
3358 if (nextLine.contains(" return defaultIfEmpty(super." + info.getReadMethod().getName() + "(),")
3359 && nextLine.indexOf(',', nextLine.indexOf(',') + 1) == -1
3360 && lines.get(i + 2).equals(" }")) {
3361 return true;
3362 }
3363 }
3364 }
3365 return false;
3366 }
3367
3368
3369
3370
3371 @Test
3372 @Alerts(DEFAULT = {"", "2", "", "2", "5", "5", "5", "5"},
3373 FF = {"undefined", "undefined", "0", "undefined", "5", "undefined", "0", "undefined"},
3374 FF_ESR = {"undefined", "undefined", "0", "undefined", "5", "undefined", "0", "undefined"})
3375 public void widows() throws Exception {
3376 final String html = DOCTYPE_HTML
3377 + "<html><head>\n"
3378 + "<script>\n"
3379 + LOG_TITLE_FUNCTION
3380 + " function test() {\n"
3381 + " var div = document.getElementById('mydiv');\n"
3382 + " debug(div);\n"
3383 + " div.style.widows = 0;\n"
3384 + " debug(div);\n"
3385 + " div.style.widows = 5;\n"
3386 + " debug(div);\n"
3387 + " div.style.widows = 0;\n"
3388 + " debug(div);\n"
3389 + " }\n"
3390 + " function debug(div) {\n"
3391 + " log(div.style.widows);\n"
3392 + " log(window.getComputedStyle(div, null).widows);\n"
3393 + " }\n"
3394 + "</script>\n"
3395 + "</head>\n"
3396 + "<body onload='test()'>\n"
3397 + " <div id='mydiv'></div>\n"
3398 + "</body></html>";
3399 loadPageVerifyTitle2(html);
3400 }
3401
3402
3403
3404
3405 @Test
3406 @Alerts(DEFAULT = {"", "2", "", "2", "5", "5", "5", "5"},
3407 FF = {"undefined", "undefined", "0", "undefined", "5", "undefined", "0", "undefined"},
3408 FF_ESR = {"undefined", "undefined", "0", "undefined", "5", "undefined", "0", "undefined"})
3409 public void orphans() throws Exception {
3410 final String html = DOCTYPE_HTML
3411 + "<html><head>\n"
3412 + "<script>\n"
3413 + LOG_TITLE_FUNCTION
3414 + " function test() {\n"
3415 + " var div = document.getElementById('mydiv');\n"
3416 + " debug(div);\n"
3417 + " div.style.orphans = 0;\n"
3418 + " debug(div);\n"
3419 + " div.style.orphans = 5;\n"
3420 + " debug(div);\n"
3421 + " div.style.orphans = 0;\n"
3422 + " debug(div);\n"
3423 + " }\n"
3424 + " function debug(div) {\n"
3425 + " log(div.style.orphans);\n"
3426 + " log(window.getComputedStyle(div, null).orphans);\n"
3427 + " }\n"
3428 + "</script>\n"
3429 + "</head>\n"
3430 + "<body onload='test()'>\n"
3431 + " <div id='mydiv'></div>\n"
3432 + "</body></html>";
3433 loadPageVerifyTitle2(html);
3434 }
3435
3436
3437
3438
3439 @Test
3440 @Alerts({"", "static", "", "static", "", "static", "absolute", "absolute", "", "static"})
3441 public void position() throws Exception {
3442 final String html = DOCTYPE_HTML
3443 + "<html><head>\n"
3444 + "<script>\n"
3445 + LOG_TITLE_FUNCTION
3446 + " function test() {\n"
3447 + " var div = document.getElementById('mydiv');\n"
3448 + " debug(div);\n"
3449 + " div.style.position = 'fake';\n"
3450 + " debug(div);\n"
3451 + " div.style.position = ' ';\n"
3452 + " debug(div);\n"
3453 + " div.style.position = 'AbSoLuTe';\n"
3454 + " debug(div);\n"
3455 + " div.style.position = '';\n"
3456 + " debug(div);\n"
3457 + " }\n"
3458 + " function debug(div) {\n"
3459 + " log(div.style.position);\n"
3460 + " log(window.getComputedStyle(div, null).position);\n"
3461 + " }\n"
3462 + "</script>\n"
3463 + "</head>\n"
3464 + "<body onload='test()'>\n"
3465 + " <div id='mydiv'></div>\n"
3466 + "</body></html>";
3467 loadPageVerifyTitle2(html);
3468 }
3469
3470
3471
3472
3473 @Test
3474 @Alerts(DEFAULT = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]", "green", "abc"},
3475 FF = {"[object CSSStyleProperties]", "[object CSSStyleProperties]", "green", "abc"},
3476 FF_ESR = {"[object CSS2Properties]", "[object CSS2Properties]", "green", "abc"})
3477 @HtmlUnitNYI(FF = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]", "green", "abc"},
3478 FF_ESR = {"[object CSSStyleDeclaration]", "[object CSSStyleDeclaration]", "green", "abc"})
3479 public void setStyle() throws Exception {
3480 final String html = DOCTYPE_HTML
3481 + "<html><head>\n"
3482 + "<script>\n"
3483 + LOG_TITLE_FUNCTION
3484 + " function test() {\n"
3485 + " var div = document.getElementById('mydiv');\n"
3486 + " log(div.style);\n"
3487 + " div.style = 'color: green; font-family: abc';\n"
3488 + " log(div.style);\n"
3489 + " log(div.style.color);\n"
3490 + " log(div.style.fontFamily);\n"
3491 + " }\n"
3492 + "</script>\n"
3493 + "</head>\n"
3494 + "<body onload='test()'>\n"
3495 + " <div id='mydiv'></div>\n"
3496 + "</body></html>";
3497 loadPageVerifyTitle2(html);
3498 }
3499
3500
3501
3502
3503 @Test
3504 @Alerts({"1", "false", "true", "false", "false"})
3505 public void in() throws Exception {
3506 final String html = DOCTYPE_HTML
3507 + "<html><head>\n"
3508 + "<script>\n"
3509 + LOG_TITLE_FUNCTION
3510 + " function test() {\n"
3511 + " var node = document.getElementById('div1');\n"
3512 + " var style = node.style;\n"
3513 + " log(style.length);\n"
3514 + " log(-1 in style);\n"
3515 + " log(0 in style);\n"
3516 + " log(1 in style);\n"
3517 + " log(42 in style);\n"
3518 + " }\n"
3519 + "</script>\n"
3520 + "</head>\n"
3521 + "<body onload='test()'>\n"
3522 + " <div id='div1' style='color: black'>foo</div>\n"
3523 + "</body></html>";
3524 loadPageVerifyTitle2(html);
3525 }
3526
3527
3528
3529
3530 @Test
3531 @Alerts("0px")
3532 public void widthAbsolute() throws Exception {
3533 final String html = DOCTYPE_HTML
3534 + "<html>\n"
3535 + "</head>\n"
3536 + " <style type='text/css'>div {position: absolute;}</style>\n"
3537 + "</head>\n"
3538 + "<body>\n"
3539 + " <div id='tester'></div>\n"
3540 + " <script>\n"
3541 + LOG_TITLE_FUNCTION
3542 + " var myDiv = document.getElementById('tester');\n"
3543 + " var myDivStyle = window.getComputedStyle(myDiv, null);\n"
3544 + " log(myDivStyle.width);\n"
3545 + " </script>\n"
3546 + "</body></html>";
3547
3548 loadPageVerifyTitle2(html);
3549 }
3550
3551
3552
3553
3554 @Test
3555 @Alerts("TypeError")
3556 public void ctor() throws Exception {
3557 final String html = DOCTYPE_HTML
3558 + "<html>\n"
3559 + "</head>\n"
3560 + " <style type='text/css'>div {position: absolute;}</style>\n"
3561 + "</head>\n"
3562 + "<body>\n"
3563 + " <div id='tester'></div>\n"
3564 + " <script>\n"
3565 + LOG_TITLE_FUNCTION
3566 + " try {"
3567 + " var c = new CSSStyleDeclaration();\n"
3568 + " log(c);\n"
3569 + " } catch(e) { logEx(e); }\n"
3570 + " </script>\n"
3571 + "</body></html>";
3572
3573 loadPageVerifyTitle2(html);
3574 }
3575
3576
3577
3578
3579
3580 @Test
3581 @Alerts({"background-color", "string", "font-weight", "", "string", "", "string"})
3582 public void item() throws Exception {
3583 final String html = DOCTYPE_HTML
3584 + "<html><body>\n"
3585
3586 + "<style>\n"
3587 + " p { background-color: #FFFFFF; }\n"
3588 + "</style>\n"
3589
3590 + "<div id='myDiv' style='background-color: #FFFFFF; font-weight: bold;'></div>\n"
3591
3592 + "<script>\n"
3593 + LOG_TITLE_FUNCTION
3594 + " decl = document.getElementById('myDiv').style;\n"
3595 + " log(decl.item(0));\n"
3596 + " log(typeof decl.item(0));\n"
3597
3598 + " log(decl.item(1));\n"
3599 + " log(decl.item(2));\n"
3600 + " log(typeof decl.item(2));\n"
3601 + " try {\n"
3602 + " log(decl.item(-1));\n"
3603 + " log(typeof decl.item(-1));\n"
3604 + " } catch(e) { logEx(e); }\n"
3605 + "</script>\n"
3606
3607 + "</body></html>";
3608
3609 loadPageVerifyTitle2(html);
3610 }
3611
3612
3613
3614
3615 @Test
3616 @Alerts("\"abCD\"")
3617 public void content() throws Exception {
3618 final String html = DOCTYPE_HTML
3619 + "<html>\n"
3620 + "</head>\n"
3621 + " <style type='text/css'>#myDiv::before { content: 'abCD' }</style>\n"
3622 + "</head>\n"
3623 + "<body>\n"
3624 + " <div id='myDiv'></div>\n"
3625 + " <script>\n"
3626 + LOG_TITLE_FUNCTION
3627 + " var myDiv = document.getElementById('myDiv');\n"
3628 + " var myDivStyle = window.getComputedStyle(myDiv, '::before');\n"
3629 + " log(myDivStyle.content);\n"
3630 + " </script>\n"
3631 + "</body></html>";
3632
3633 loadPageVerifyTitle2(html);
3634 }
3635 }