|
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 type="application/javascript" 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 DOMUtils = Components.classes["@mozilla.org/inspector/dom-utils;1"] |
|
21 .getService(Components.interfaces.inIDOMUtils); |
|
22 let body = document.querySelector("body"); |
|
23 let testSheet = document.styleSheets[2]; |
|
24 let rule = document.styleSheets[2].cssRules[0]; |
|
25 |
|
26 is(testSheet.cssRules.length, 1, |
|
27 "style sheet has 1 rule"); |
|
28 is(rule.style.paddingTop, "100px", |
|
29 "original first rule has padding-top 100px"); |
|
30 is(window.getComputedStyle(body).paddingTop, "100px", |
|
31 "original first rule applies"); |
|
32 |
|
33 DOMUtils.parseStyleSheet(testSheet, |
|
34 "@import url(test_bug727834.css); body{background: red;}"); |
|
35 |
|
36 is(testSheet.cssRules.length, 2, |
|
37 "style sheet now has 2 rules"); |
|
38 is(window.getComputedStyle(body).backgroundColor, "rgb(255, 0, 0)", |
|
39 "background is now red"); |
|
40 |
|
41 let exceptionName; |
|
42 try { |
|
43 rule.style.paddingLeft = "100px"; |
|
44 } catch (ex) { |
|
45 exceptionName = ex.name; |
|
46 } finally { |
|
47 is(exceptionName, "NS_ERROR_NOT_AVAILABLE", |
|
48 "original rule is not available for modification anymore"); |
|
49 } |
|
50 is(window.getComputedStyle(body).paddingLeft, "0px", |
|
51 "original rule does not apply to document"); |
|
52 |
|
53 rule = testSheet.cssRules[0]; |
|
54 |
|
55 is(rule.parentStyleSheet, testSheet, |
|
56 "rule's parent style sheet is not null"); |
|
57 |
|
58 DOMUtils.parseStyleSheet(testSheet, |
|
59 "body{background: lime;}"); |
|
60 |
|
61 is(testSheet.cssRules.length, 1, |
|
62 "style sheet now has 1 rule"); |
|
63 is(window.getComputedStyle(body).backgroundColor, "rgb(0, 255, 0)", |
|
64 "background is now lime"); |
|
65 is(rule.parentStyleSheet, null, |
|
66 "detached rule's parent style sheet is null"); |
|
67 |
|
68 SimpleTest.executeSoon(function () { |
|
69 DOMUtils.parseStyleSheet(testSheet, |
|
70 "@import url(test_bug727834.css); body{background: blue;}"); |
|
71 |
|
72 is(testSheet.cssRules.length, 2, |
|
73 "style sheet now has 2 rules"); |
|
74 is(window.getComputedStyle(body).backgroundColor, "rgb(0, 0, 255)", |
|
75 "background is now blue"); |
|
76 is(testSheet.cssRules[0].parentStyleSheet, testSheet, |
|
77 "parent style sheet is the test sheet"); |
|
78 |
|
79 SimpleTest.finish(); |
|
80 }); |
|
81 } |
|
82 ]]></script> |
|
83 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
84 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=727834"> |
|
85 Mozilla Bug 727834 - Add an API to (re)parse a style sheet in place |
|
86 </a> |
|
87 </body> |
|
88 </window> |