|
1 /** |
|
2 * Test for Bug 493881: Changes to legacy HTML color properties before the BODY is loaded |
|
3 * should be ignored. Additionally, after BODY loads, setting any of these properties to undefined |
|
4 * should cause them to be returned as the string "undefined". |
|
5 */ |
|
6 |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 |
|
9 var legacyProps = ["fgColor", "bgColor", "linkColor", "vlinkColor", "alinkColor"]; |
|
10 var testColors = ["blue", "silver", "green", "orange", "red"]; |
|
11 var rgbTestColors = ["rgb(255, 0, 0)", "rgb(192, 192, 192)", "rgb(0, 128, 0)", "rgb(255, 165, 0)", "rgb(255, 0, 0)"]; |
|
12 var idPropList = [ {id: "plaintext", prop: "color"}, |
|
13 {id: "body", prop: "background-color"}, |
|
14 {id: "nonvisitedlink", prop: "color"}, |
|
15 {id: "visitedlink", prop: "color"} ]; |
|
16 var initialValues = []; |
|
17 |
|
18 function setAndTestProperty(prop, color) { |
|
19 var initial = document[prop]; |
|
20 document[prop] = color; |
|
21 is(document[prop], initial, "document[" + prop + "] not ignored before body"); |
|
22 return initial; |
|
23 } |
|
24 |
|
25 /** |
|
26 * Attempt to set legacy color properties before BODY exists, and verify that such |
|
27 * attempts are ignored. |
|
28 */ |
|
29 for (var i = 0; i < legacyProps.length; i++) { |
|
30 initialValues[i] = setAndTestProperty(legacyProps[i], testColors[i]); |
|
31 } |
|
32 |
|
33 /** |
|
34 * After BODY loads, run some more tests. |
|
35 */ |
|
36 addLoadEvent( function() { |
|
37 // Verify that the legacy color properties still have their original values. |
|
38 for (var i = 0; i < legacyProps.length; i++) { |
|
39 is(document[legacyProps[i]], initialValues[i], "document[" + legacyProps[i] + "] altered after body load"); |
|
40 } |
|
41 |
|
42 // Verify that legacy color properties applied before BODY are really ignored when rendering. |
|
43 // Save current computed style colors for later use. |
|
44 for (i = 0; i < idPropList.length; i++) { |
|
45 var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); |
|
46 var color = style.getPropertyValue(idPropList[i].prop); |
|
47 idPropList[i].initialComputedColor = color; |
|
48 isnot(color, rgbTestColors[i], "element rendered using before-body style"); |
|
49 } |
|
50 // XXX: Can't get links to visually activate via script events, so can't verify |
|
51 // that the alinkColor property was not applied. |
|
52 |
|
53 // Verify that setting legacy color props to undefined after BODY loads will cause them |
|
54 // to be read as the string "undefined". |
|
55 for (var i = 0; i < legacyProps.length; i++) { |
|
56 document[legacyProps[i]] = undefined; |
|
57 is(document[legacyProps[i]], "undefined", |
|
58 "Unexpected value of " + legacyProps[i] + " after setting to undefined"); |
|
59 } |
|
60 |
|
61 // Verify that setting legacy color props to undefined led to result |
|
62 // of parsing undefined as a color. |
|
63 for (i = 0; i < idPropList.length; i++) { |
|
64 var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); |
|
65 var color = style.getPropertyValue(idPropList[i].prop); |
|
66 is(color, "rgb(0, 239, 14)", |
|
67 "element's style should get result of parsing undefined as a color"); |
|
68 } |
|
69 |
|
70 // Mark the test as finished. |
|
71 setTimeout(SimpleTest.finish, 0); |
|
72 }); |