summaryrefslogtreecommitdiffstats
path: root/layout/inspector/tests/chrome/test_bug727834.xhtml
blob: 03c72c4cff6c514e51315a86392f6181541c7f75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?xml version="1.0"?>
<!--
vim: set ts=2 et sw=2 tw=80:
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
-->
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<?xml-stylesheet type="text/css" href="test_bug727834.css"?>
<window title="Mozilla Bug 727834"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        onload="RunTests();">
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  <script type="application/javascript"><![CDATA[
/** Test for Bug 727834 - Add an API to (re)parse a style sheet in place **/

function RunTests() {
  SimpleTest.waitForExplicitFinish();

  let body = document.querySelector("body");
  let testSheet = document.styleSheets[2];
  let rule = document.styleSheets[2].cssRules[0];

  is(testSheet.cssRules.length, 1,
     "style sheet has 1 rule");
  is(rule.style.paddingTop, "100px",
     "original first rule has padding-top 100px");
  is(window.getComputedStyle(body).paddingTop, "100px",
     "original first rule applies");

  InspectorUtils.parseStyleSheet(testSheet,
    "@import url(test_bug727834.css); body{background: red;}");

  is(testSheet.cssRules.length, 2,
     "style sheet now has 2 rules");
  is(window.getComputedStyle(body).backgroundColor, "rgb(255, 0, 0)",
     "background is now red");

  let exceptionName;
  try {
    rule.style.paddingLeft = "100px";
  } catch (ex) {
    exceptionName = ex.name;
  } finally {
    is(exceptionName, "NS_ERROR_NOT_AVAILABLE",
       "original rule is not available for modification anymore");
  }
  is(window.getComputedStyle(body).paddingLeft, "0px",
     "original rule does not apply to document");

  rule = testSheet.cssRules[0];

  is(rule.parentStyleSheet, testSheet,
     "rule's parent style sheet is not null");

  InspectorUtils.parseStyleSheet(testSheet,
    "body{background: lime;}");

  is(testSheet.cssRules.length, 1,
     "style sheet now has 1 rule");
  is(window.getComputedStyle(body).backgroundColor, "rgb(0, 255, 0)",
     "background is now lime");
  is(rule.parentStyleSheet, null,
     "detached rule's parent style sheet is null");

  SimpleTest.executeSoon(function () {
    InspectorUtils.parseStyleSheet(testSheet,
      "@import url(test_bug727834.css); body{background: blue;}");

    is(testSheet.cssRules.length, 2,
       "style sheet now has 2 rules");
    is(window.getComputedStyle(body).backgroundColor, "rgb(0, 0, 255)",
       "background is now blue");
    is(testSheet.cssRules[0].parentStyleSheet, testSheet,
       "parent style sheet is the test sheet");

    SimpleTest.finish();
  });
}
  ]]></script>
  <body xmlns="http://www.w3.org/1999/xhtml">
    <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=727834">
      Mozilla Bug 727834 - Add an API to (re)parse a style sheet in place
    </a>
  </body>
</window>