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