1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_bug493881.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/** 1.5 + * Test for Bug 493881: Changes to legacy HTML color properties before the BODY is loaded 1.6 + * should be ignored. Additionally, after BODY loads, setting any of these properties to undefined 1.7 + * should cause them to be returned as the string "undefined". 1.8 + */ 1.9 + 1.10 +SimpleTest.waitForExplicitFinish(); 1.11 + 1.12 +var legacyProps = ["fgColor", "bgColor", "linkColor", "vlinkColor", "alinkColor"]; 1.13 +var testColors = ["blue", "silver", "green", "orange", "red"]; 1.14 +var rgbTestColors = ["rgb(255, 0, 0)", "rgb(192, 192, 192)", "rgb(0, 128, 0)", "rgb(255, 165, 0)", "rgb(255, 0, 0)"]; 1.15 +var idPropList = [ {id: "plaintext", prop: "color"}, 1.16 + {id: "body", prop: "background-color"}, 1.17 + {id: "nonvisitedlink", prop: "color"}, 1.18 + {id: "visitedlink", prop: "color"} ]; 1.19 +var initialValues = []; 1.20 + 1.21 +function setAndTestProperty(prop, color) { 1.22 + var initial = document[prop]; 1.23 + document[prop] = color; 1.24 + is(document[prop], initial, "document[" + prop + "] not ignored before body"); 1.25 + return initial; 1.26 +} 1.27 + 1.28 +/** 1.29 + * Attempt to set legacy color properties before BODY exists, and verify that such 1.30 + * attempts are ignored. 1.31 + */ 1.32 +for (var i = 0; i < legacyProps.length; i++) { 1.33 + initialValues[i] = setAndTestProperty(legacyProps[i], testColors[i]); 1.34 +} 1.35 + 1.36 +/** 1.37 + * After BODY loads, run some more tests. 1.38 + */ 1.39 +addLoadEvent( function() { 1.40 + // Verify that the legacy color properties still have their original values. 1.41 + for (var i = 0; i < legacyProps.length; i++) { 1.42 + is(document[legacyProps[i]], initialValues[i], "document[" + legacyProps[i] + "] altered after body load"); 1.43 + } 1.44 + 1.45 + // Verify that legacy color properties applied before BODY are really ignored when rendering. 1.46 + // Save current computed style colors for later use. 1.47 + for (i = 0; i < idPropList.length; i++) { 1.48 + var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); 1.49 + var color = style.getPropertyValue(idPropList[i].prop); 1.50 + idPropList[i].initialComputedColor = color; 1.51 + isnot(color, rgbTestColors[i], "element rendered using before-body style"); 1.52 + } 1.53 + // XXX: Can't get links to visually activate via script events, so can't verify 1.54 + // that the alinkColor property was not applied. 1.55 + 1.56 + // Verify that setting legacy color props to undefined after BODY loads will cause them 1.57 + // to be read as the string "undefined". 1.58 + for (var i = 0; i < legacyProps.length; i++) { 1.59 + document[legacyProps[i]] = undefined; 1.60 + is(document[legacyProps[i]], "undefined", 1.61 + "Unexpected value of " + legacyProps[i] + " after setting to undefined"); 1.62 + } 1.63 + 1.64 + // Verify that setting legacy color props to undefined led to result 1.65 + // of parsing undefined as a color. 1.66 + for (i = 0; i < idPropList.length; i++) { 1.67 + var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); 1.68 + var color = style.getPropertyValue(idPropList[i].prop); 1.69 + is(color, "rgb(0, 239, 14)", 1.70 + "element's style should get result of parsing undefined as a color"); 1.71 + } 1.72 + 1.73 + // Mark the test as finished. 1.74 + setTimeout(SimpleTest.finish, 0); 1.75 +});