|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 https://bugzilla.mozilla.org/show_bug.cgi?id= |
|
5 --> |
|
6 <head> |
|
7 <meta charset="utf-8"> |
|
8 <title>Test for Bug </title> |
|
9 |
|
10 <script type="application/javascript" 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;version=1.8" src="inspector-helpers.js"></script> |
|
13 <script type="application/javascript;version=1.8"> |
|
14 Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); |
|
15 const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); |
|
16 |
|
17 const inspector = devtools.require("devtools/server/actors/inspector"); |
|
18 |
|
19 window.onload = function() { |
|
20 SimpleTest.waitForExplicitFinish(); |
|
21 runNextTest(); |
|
22 } |
|
23 |
|
24 var gWalker = null; |
|
25 var gStyles = null; |
|
26 var gClient = null; |
|
27 |
|
28 addTest(function setup() { |
|
29 let url = document.getElementById("inspectorContent").href; |
|
30 attachURL(url, function(err, client, tab, doc) { |
|
31 gInspectee = doc; |
|
32 let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); |
|
33 let inspector = InspectorFront(client, tab); |
|
34 promiseDone(inspector.getWalker().then(walker => { |
|
35 ok(walker, "getWalker() should return an actor."); |
|
36 gClient = client; |
|
37 gWalker = walker; |
|
38 return inspector.getPageStyle(); |
|
39 }).then(styles => { |
|
40 gStyles = styles; |
|
41 }).then(runNextTest)); |
|
42 }); |
|
43 }); |
|
44 |
|
45 addTest(function modifyProperties() { |
|
46 let localNode = gInspectee.querySelector("#inheritable-rule-inheritable-style"); |
|
47 let elementStyle = null; |
|
48 promiseDone(gWalker.querySelector(gWalker.rootNode, "#inheritable-rule-inheritable-style").then(node => { |
|
49 return gStyles.getApplied(node, { inherited: false, filter: "user" }); |
|
50 }).then(applied => { |
|
51 elementStyle = applied[0].rule; |
|
52 is(elementStyle.cssText, localNode.style.cssText, "Got expected css text"); |
|
53 |
|
54 // Will start with "color:blue" |
|
55 let changes = elementStyle.startModifyingProperties(); |
|
56 |
|
57 // Change an existing property... |
|
58 changes.setProperty("color", "black"); |
|
59 // Create a new property |
|
60 changes.setProperty("background-color", "green"); |
|
61 |
|
62 // Create a new property and then change it immediately. |
|
63 changes.setProperty("border", "1px solid black"); |
|
64 changes.setProperty("border", "2px solid black"); |
|
65 |
|
66 return changes.apply(); |
|
67 }).then(() => { |
|
68 is(elementStyle.cssText, "color: black; background-color: green; border: 2px solid black;", "Should have expected cssText"); |
|
69 is(elementStyle.cssText, localNode.style.cssText, "Local node and style front match."); |
|
70 |
|
71 // Remove all the properties |
|
72 let changes = elementStyle.startModifyingProperties(); |
|
73 changes.removeProperty("color"); |
|
74 changes.removeProperty("background-color"); |
|
75 changes.removeProperty("border"); |
|
76 |
|
77 return changes.apply(); |
|
78 }).then(() => { |
|
79 is(elementStyle.cssText, "", "Should have expected cssText"); |
|
80 is(elementStyle.cssText, localNode.style.cssText, "Local node and style front match."); |
|
81 }).then(runNextTest)); |
|
82 }); |
|
83 |
|
84 addTest(function cleanup() { |
|
85 delete gStyles; |
|
86 delete gWalker; |
|
87 delete gClient; |
|
88 runNextTest(); |
|
89 }); |
|
90 |
|
91 </script> |
|
92 </head> |
|
93 <body> |
|
94 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> |
|
95 <a id="inspectorContent" target="_blank" href="inspector-styles-data.html">Test Document</a> |
|
96 <p id="display"></p> |
|
97 <div id="content" style="display: none"> |
|
98 |
|
99 </div> |
|
100 <pre id="test"> |
|
101 </pre> |
|
102 </body> |
|
103 </html> |