test_bug727834.xhtml (2969B)
1 <?xml version="1.0"?> 2 <!-- 3 vim: set ts=2 et sw=2 tw=80: 4 Any copyright is dedicated to the Public Domain. 5 http://creativecommons.org/publicdomain/zero/1.0/ 6 --> 7 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> 8 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 9 <?xml-stylesheet type="text/css" href="test_bug727834.css"?> 10 <window title="Mozilla Bug 727834" 11 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 12 onload="RunTests();"> 13 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 14 <script type="application/javascript"><![CDATA[ 15 /** Test for Bug 727834 - Add an API to (re)parse a style sheet in place */ 16 17 function RunTests() { 18 SimpleTest.waitForExplicitFinish(); 19 20 let body = document.querySelector("body"); 21 let testSheet = document.styleSheets[2]; 22 let rule = document.styleSheets[2].cssRules[0]; 23 24 is(testSheet.cssRules.length, 1, 25 "style sheet has 1 rule"); 26 is(rule.style.paddingTop, "100px", 27 "original first rule has padding-top 100px"); 28 is(window.getComputedStyle(body).paddingTop, "100px", 29 "original first rule applies"); 30 31 InspectorUtils.parseStyleSheet(testSheet, 32 "@import url(test_bug727834.css); body{background: red;}"); 33 34 is(testSheet.cssRules.length, 2, 35 "style sheet now has 2 rules"); 36 is(window.getComputedStyle(body).backgroundColor, "rgb(255, 0, 0)", 37 "background is now red"); 38 39 let exceptionName; 40 try { 41 rule.style.paddingLeft = "100px"; 42 } catch (ex) { 43 exceptionName = ex.name; 44 } finally { 45 is(exceptionName, "NS_ERROR_NOT_AVAILABLE", 46 "original rule is not available for modification anymore"); 47 } 48 is(window.getComputedStyle(body).paddingLeft, "0px", 49 "original rule does not apply to document"); 50 51 rule = testSheet.cssRules[0]; 52 53 is(rule.parentStyleSheet, testSheet, 54 "rule's parent style sheet is not null"); 55 56 InspectorUtils.parseStyleSheet(testSheet, 57 "body{background: lime;}"); 58 59 is(testSheet.cssRules.length, 1, 60 "style sheet now has 1 rule"); 61 is(window.getComputedStyle(body).backgroundColor, "rgb(0, 255, 0)", 62 "background is now lime"); 63 is(rule.parentStyleSheet, null, 64 "detached rule's parent style sheet is null"); 65 66 SimpleTest.executeSoon(function () { 67 InspectorUtils.parseStyleSheet(testSheet, 68 "@import url(test_bug727834.css); body{background: blue;}"); 69 70 is(testSheet.cssRules.length, 2, 71 "style sheet now has 2 rules"); 72 is(window.getComputedStyle(body).backgroundColor, "rgb(0, 0, 255)", 73 "background is now blue"); 74 is(testSheet.cssRules[0].parentStyleSheet, testSheet, 75 "parent style sheet is the test sheet"); 76 77 SimpleTest.finish(); 78 }); 79 } 80 ]]></script> 81 <body xmlns="http://www.w3.org/1999/xhtml"> 82 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=727834"> 83 Mozilla Bug 727834 - Add an API to (re)parse a style sheet in place 84 </a> 85 </body> 86 </window>