1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/inspector/tests/chrome/test_bug727834.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +<?xml version="1.0"?> 1.5 +<!-- 1.6 +vim: set ts=2 et sw=2 tw=80: 1.7 +Any copyright is dedicated to the Public Domain. 1.8 +http://creativecommons.org/publicdomain/zero/1.0/ 1.9 +--> 1.10 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.11 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.12 +<?xml-stylesheet type="text/css" href="test_bug727834.css"?> 1.13 +<window title="Mozilla Bug 727834" 1.14 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.15 + onload="RunTests();"> 1.16 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.17 + <script type="application/javascript"><![CDATA[ 1.18 +/** Test for Bug 727834 - Add an API to (re)parse a style sheet in place **/ 1.19 + 1.20 +function RunTests() { 1.21 + SimpleTest.waitForExplicitFinish(); 1.22 + 1.23 + let DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"] 1.24 + .getService(Components.interfaces.inIDOMUtils); 1.25 + let body = document.querySelector("body"); 1.26 + let testSheet = document.styleSheets[2]; 1.27 + let rule = document.styleSheets[2].cssRules[0]; 1.28 + 1.29 + is(testSheet.cssRules.length, 1, 1.30 + "style sheet has 1 rule"); 1.31 + is(rule.style.paddingTop, "100px", 1.32 + "original first rule has padding-top 100px"); 1.33 + is(window.getComputedStyle(body).paddingTop, "100px", 1.34 + "original first rule applies"); 1.35 + 1.36 + DOMUtils.parseStyleSheet(testSheet, 1.37 + "@import url(test_bug727834.css); body{background: red;}"); 1.38 + 1.39 + is(testSheet.cssRules.length, 2, 1.40 + "style sheet now has 2 rules"); 1.41 + is(window.getComputedStyle(body).backgroundColor, "rgb(255, 0, 0)", 1.42 + "background is now red"); 1.43 + 1.44 + let exceptionName; 1.45 + try { 1.46 + rule.style.paddingLeft = "100px"; 1.47 + } catch (ex) { 1.48 + exceptionName = ex.name; 1.49 + } finally { 1.50 + is(exceptionName, "NS_ERROR_NOT_AVAILABLE", 1.51 + "original rule is not available for modification anymore"); 1.52 + } 1.53 + is(window.getComputedStyle(body).paddingLeft, "0px", 1.54 + "original rule does not apply to document"); 1.55 + 1.56 + rule = testSheet.cssRules[0]; 1.57 + 1.58 + is(rule.parentStyleSheet, testSheet, 1.59 + "rule's parent style sheet is not null"); 1.60 + 1.61 + DOMUtils.parseStyleSheet(testSheet, 1.62 + "body{background: lime;}"); 1.63 + 1.64 + is(testSheet.cssRules.length, 1, 1.65 + "style sheet now has 1 rule"); 1.66 + is(window.getComputedStyle(body).backgroundColor, "rgb(0, 255, 0)", 1.67 + "background is now lime"); 1.68 + is(rule.parentStyleSheet, null, 1.69 + "detached rule's parent style sheet is null"); 1.70 + 1.71 + SimpleTest.executeSoon(function () { 1.72 + DOMUtils.parseStyleSheet(testSheet, 1.73 + "@import url(test_bug727834.css); body{background: blue;}"); 1.74 + 1.75 + is(testSheet.cssRules.length, 2, 1.76 + "style sheet now has 2 rules"); 1.77 + is(window.getComputedStyle(body).backgroundColor, "rgb(0, 0, 255)", 1.78 + "background is now blue"); 1.79 + is(testSheet.cssRules[0].parentStyleSheet, testSheet, 1.80 + "parent style sheet is the test sheet"); 1.81 + 1.82 + SimpleTest.finish(); 1.83 + }); 1.84 +} 1.85 + ]]></script> 1.86 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.87 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=727834"> 1.88 + Mozilla Bug 727834 - Add an API to (re)parse a style sheet in place 1.89 + </a> 1.90 + </body> 1.91 +</window>