4 https://bugzilla.mozilla.org/show_bug.cgi?id=
8 <title>Test for Bug
</title>
10 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 <link rel=
"stylesheet" type=
"text/css" href=
"chrome://mochikit/content/tests/SimpleTest/test.css">
12 <script type=
"application/javascript" src=
"inspector-helpers.js"></script>
13 <script type=
"application/javascript">
16 const {isCssPropertyKnown} = require(
"devtools/server/actors/css-properties");
18 window.onload = function() {
19 SimpleTest.waitForExplicitFinish();
25 var gInspectee = null;
27 addAsyncTest(async function setup() {
28 const url = document.getElementById(
"inspectorContent").href;
30 const { target, doc } = await attachURL(url);
31 const inspector = await target.getFront(
"inspector");
34 gWalker = inspector.walker;
35 gStyles = await inspector.getPageStyle();
40 addAsyncTest(async function modifyProperties() {
41 const localNode = gInspectee.querySelector(
"#inheritable-rule-inheritable-style");
43 const node = await gWalker.querySelector(gWalker.rootNode,
44 "#inheritable-rule-inheritable-style");
46 const applied = await gStyles.getApplied(node,
47 { inherited: false, filter:
"user" });
49 const elementStyle = applied[
0].rule;
50 is(elementStyle.cssText, localNode.style.cssText,
"Got expected css text");
52 // Change an existing property...
53 await setProperty(elementStyle,
0,
"color",
"black");
54 // Create a new property
55 await setProperty(elementStyle,
1,
"background-color",
"green");
57 // Create a new property and then change it immediately.
58 await setProperty(elementStyle,
2,
"border",
"1px solid black");
59 await setProperty(elementStyle,
2,
"border",
"2px solid black");
61 is(elementStyle.cssText,
62 "color: black; background-color: green; border: 2px solid black;",
63 "Should have expected cssText");
64 is(elementStyle.cssText, localNode.style.cssText,
65 "Local node and style front match.");
67 // Remove all the properties
68 await removeProperty(elementStyle,
0,
"color");
69 await removeProperty(elementStyle,
0,
"background-color");
70 await removeProperty(elementStyle,
0,
"border");
72 is(elementStyle.cssText,
"",
"Should have expected cssText");
73 is(elementStyle.cssText, localNode.style.cssText,
74 "Local node and style front match.");
79 async function setProperty(rule, index, name, value) {
80 const changes = rule.startModifyingProperties(isCssPropertyKnown);
81 changes.setProperty(index, name, value);
82 await changes.apply();
85 async function removeProperty(rule, index, name) {
86 const changes = rule.startModifyingProperties(isCssPropertyKnown);
87 changes.removeProperty(index, name);
88 await changes.apply();
91 addTest(function cleanup() {
101 <a target=
"_blank" href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug
</a>
102 <a id=
"inspectorContent" target=
"_blank" href=
"inspector-styles-data.html">Test Document
</a>
104 <div id=
"content" style=
"display: none">