2013-07-24 02:51:58 +04:00
|
|
|
<!DOCTYPE HTML>
|
|
|
|
<html>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=
|
|
|
|
-->
|
|
|
|
<head>
|
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Test for Bug </title>
|
|
|
|
|
|
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
|
|
|
<script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
|
|
|
|
<script type="application/javascript;version=1.8">
|
2015-08-06 15:38:10 +03:00
|
|
|
const inspector = require("devtools/server/actors/inspector");
|
2016-05-26 18:48:00 +03:00
|
|
|
const {isCssPropertyKnown} = require("devtools/server/actors/css-properties");
|
2013-07-24 02:51:58 +04:00
|
|
|
|
|
|
|
window.onload = function() {
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
runNextTest();
|
|
|
|
}
|
|
|
|
|
|
|
|
var gWalker = null;
|
|
|
|
var gStyles = null;
|
|
|
|
var gClient = null;
|
|
|
|
|
2016-04-29 10:30:02 +03:00
|
|
|
addAsyncTest(function* setup() {
|
2013-07-24 02:51:58 +04:00
|
|
|
let url = document.getElementById("inspectorContent").href;
|
2016-04-29 10:30:02 +03:00
|
|
|
let inspector;
|
|
|
|
|
|
|
|
yield new Promise(resolve => {
|
|
|
|
attachURL(url, function(err, client, tab, doc) {
|
|
|
|
gInspectee = doc;
|
2013-07-24 02:51:58 +04:00
|
|
|
gClient = client;
|
2016-05-17 15:59:21 +03:00
|
|
|
let {InspectorFront} = require("devtools/shared/fronts/inspector");
|
2016-04-29 10:30:02 +03:00
|
|
|
inspector = InspectorFront(client, tab);
|
|
|
|
resolve();
|
|
|
|
});
|
2013-07-24 02:51:58 +04:00
|
|
|
});
|
2016-04-29 10:30:02 +03:00
|
|
|
|
|
|
|
gWalker = yield inspector.getWalker();
|
|
|
|
gStyles = yield inspector.getPageStyle();
|
|
|
|
|
|
|
|
runNextTest();
|
2013-07-24 02:51:58 +04:00
|
|
|
});
|
|
|
|
|
2016-04-29 10:30:02 +03:00
|
|
|
addAsyncTest(function* modifyProperties() {
|
2013-07-24 02:51:58 +04:00
|
|
|
let localNode = gInspectee.querySelector("#inheritable-rule-inheritable-style");
|
2016-04-29 10:30:02 +03:00
|
|
|
|
|
|
|
let node = yield gWalker.querySelector(gWalker.rootNode,
|
|
|
|
"#inheritable-rule-inheritable-style");
|
|
|
|
|
|
|
|
let applied = yield gStyles.getApplied(node,
|
|
|
|
{ inherited: false, filter: "user" });
|
|
|
|
|
|
|
|
let elementStyle = applied[0].rule;
|
|
|
|
is(elementStyle.cssText, localNode.style.cssText, "Got expected css text");
|
|
|
|
|
|
|
|
// Change an existing property...
|
|
|
|
yield setProperty(elementStyle, 0, "color", "black");
|
|
|
|
// Create a new property
|
|
|
|
yield setProperty(elementStyle, 1, "background-color", "green");
|
|
|
|
|
|
|
|
// Create a new property and then change it immediately.
|
|
|
|
yield setProperty(elementStyle, 2, "border", "1px solid black");
|
|
|
|
yield setProperty(elementStyle, 2, "border", "2px solid black");
|
|
|
|
|
|
|
|
is(elementStyle.cssText,
|
|
|
|
"color: black; background-color: green; border: 2px solid black;",
|
|
|
|
"Should have expected cssText");
|
|
|
|
is(elementStyle.cssText, localNode.style.cssText,
|
|
|
|
"Local node and style front match.");
|
|
|
|
|
|
|
|
// Remove all the properties
|
|
|
|
yield removeProperty(elementStyle, 0, "color");
|
|
|
|
yield removeProperty(elementStyle, 0, "background-color");
|
|
|
|
yield removeProperty(elementStyle, 0, "border");
|
|
|
|
|
|
|
|
is(elementStyle.cssText, "", "Should have expected cssText");
|
|
|
|
is(elementStyle.cssText, localNode.style.cssText,
|
|
|
|
"Local node and style front match.");
|
|
|
|
|
|
|
|
runNextTest();
|
2013-07-24 02:51:58 +04:00
|
|
|
});
|
|
|
|
|
2016-04-29 10:30:02 +03:00
|
|
|
function* setProperty(rule, index, name, value) {
|
2016-05-26 18:48:00 +03:00
|
|
|
let changes = rule.startModifyingProperties(isCssPropertyKnown);
|
2016-04-29 10:30:02 +03:00
|
|
|
changes.setProperty(index, name, value);
|
|
|
|
yield changes.apply();
|
|
|
|
}
|
|
|
|
|
|
|
|
function* removeProperty(rule, index, name) {
|
2016-05-26 18:48:00 +03:00
|
|
|
let changes = rule.startModifyingProperties(isCssPropertyKnown);
|
2016-04-29 10:30:02 +03:00
|
|
|
changes.removeProperty(index, name);
|
|
|
|
yield changes.apply();
|
|
|
|
}
|
|
|
|
|
2013-07-24 02:51:58 +04:00
|
|
|
addTest(function cleanup() {
|
|
|
|
delete gStyles;
|
|
|
|
delete gWalker;
|
|
|
|
delete gClient;
|
|
|
|
runNextTest();
|
|
|
|
});
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
|
|
|
|
<a id="inspectorContent" target="_blank" href="inspector-styles-data.html">Test Document</a>
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display: none">
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<pre id="test">
|
|
|
|
</pre>
|
|
|
|
</body>
|
|
|
|
</html>
|