michael@0: /** michael@0: * Test for Bug 493881: Changes to legacy HTML color properties before the BODY is loaded michael@0: * should be ignored. Additionally, after BODY loads, setting any of these properties to undefined michael@0: * should cause them to be returned as the string "undefined". michael@0: */ michael@0: michael@0: SimpleTest.waitForExplicitFinish(); michael@0: michael@0: var legacyProps = ["fgColor", "bgColor", "linkColor", "vlinkColor", "alinkColor"]; michael@0: var testColors = ["blue", "silver", "green", "orange", "red"]; michael@0: var rgbTestColors = ["rgb(255, 0, 0)", "rgb(192, 192, 192)", "rgb(0, 128, 0)", "rgb(255, 165, 0)", "rgb(255, 0, 0)"]; michael@0: var idPropList = [ {id: "plaintext", prop: "color"}, michael@0: {id: "body", prop: "background-color"}, michael@0: {id: "nonvisitedlink", prop: "color"}, michael@0: {id: "visitedlink", prop: "color"} ]; michael@0: var initialValues = []; michael@0: michael@0: function setAndTestProperty(prop, color) { michael@0: var initial = document[prop]; michael@0: document[prop] = color; michael@0: is(document[prop], initial, "document[" + prop + "] not ignored before body"); michael@0: return initial; michael@0: } michael@0: michael@0: /** michael@0: * Attempt to set legacy color properties before BODY exists, and verify that such michael@0: * attempts are ignored. michael@0: */ michael@0: for (var i = 0; i < legacyProps.length; i++) { michael@0: initialValues[i] = setAndTestProperty(legacyProps[i], testColors[i]); michael@0: } michael@0: michael@0: /** michael@0: * After BODY loads, run some more tests. michael@0: */ michael@0: addLoadEvent( function() { michael@0: // Verify that the legacy color properties still have their original values. michael@0: for (var i = 0; i < legacyProps.length; i++) { michael@0: is(document[legacyProps[i]], initialValues[i], "document[" + legacyProps[i] + "] altered after body load"); michael@0: } michael@0: michael@0: // Verify that legacy color properties applied before BODY are really ignored when rendering. michael@0: // Save current computed style colors for later use. michael@0: for (i = 0; i < idPropList.length; i++) { michael@0: var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); michael@0: var color = style.getPropertyValue(idPropList[i].prop); michael@0: idPropList[i].initialComputedColor = color; michael@0: isnot(color, rgbTestColors[i], "element rendered using before-body style"); michael@0: } michael@0: // XXX: Can't get links to visually activate via script events, so can't verify michael@0: // that the alinkColor property was not applied. michael@0: michael@0: // Verify that setting legacy color props to undefined after BODY loads will cause them michael@0: // to be read as the string "undefined". michael@0: for (var i = 0; i < legacyProps.length; i++) { michael@0: document[legacyProps[i]] = undefined; michael@0: is(document[legacyProps[i]], "undefined", michael@0: "Unexpected value of " + legacyProps[i] + " after setting to undefined"); michael@0: } michael@0: michael@0: // Verify that setting legacy color props to undefined led to result michael@0: // of parsing undefined as a color. michael@0: for (i = 0; i < idPropList.length; i++) { michael@0: var style = window.getComputedStyle(document.getElementById(idPropList[i].id), null); michael@0: var color = style.getPropertyValue(idPropList[i].prop); michael@0: is(color, "rgb(0, 239, 14)", michael@0: "element's style should get result of parsing undefined as a color"); michael@0: } michael@0: michael@0: // Mark the test as finished. michael@0: setTimeout(SimpleTest.finish, 0); michael@0: });