toolkit/devtools/server/tests/mochitest/test_styles-applied.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <!--
michael@0 4 https://bugzilla.mozilla.org/show_bug.cgi?id=
michael@0 5 -->
michael@0 6 <head>
michael@0 7 <meta charset="utf-8">
michael@0 8 <title>Test for Bug </title>
michael@0 9
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
michael@0 12 <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script>
michael@0 13 <script type="application/javascript;version=1.8">
michael@0 14 Components.utils.import("resource://gre/modules/devtools/Loader.jsm");
michael@0 15 const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {});
michael@0 16
michael@0 17 const inspector = devtools.require("devtools/server/actors/inspector");
michael@0 18
michael@0 19 window.onload = function() {
michael@0 20 SimpleTest.waitForExplicitFinish();
michael@0 21 runNextTest();
michael@0 22 }
michael@0 23
michael@0 24 var gWalker = null;
michael@0 25 var gStyles = null;
michael@0 26 var gClient = null;
michael@0 27
michael@0 28 addTest(function setup() {
michael@0 29 let url = document.getElementById("inspectorContent").href;
michael@0 30 attachURL(url, function(err, client, tab, doc) {
michael@0 31 let {InspectorFront} = devtools.require("devtools/server/actors/inspector");
michael@0 32 let inspector = InspectorFront(client, tab);
michael@0 33 promiseDone(inspector.getWalker().then(walker => {
michael@0 34 ok(walker, "getWalker() should return an actor.");
michael@0 35 gClient = client;
michael@0 36 gWalker = walker;
michael@0 37 return inspector.getPageStyle();
michael@0 38 }).then(styles => {
michael@0 39 gStyles = styles;
michael@0 40 }).then(runNextTest));
michael@0 41 });
michael@0 42 });
michael@0 43
michael@0 44 addTest(function inheritedUserStyles() {
michael@0 45 let node = node;
michael@0 46 promiseDone(gWalker.querySelector(gWalker.rootNode, "#test-node").then(node => {
michael@0 47 return gStyles.getApplied(node, { inherited: true, filter: "user" });
michael@0 48 }).then(applied => {
michael@0 49 ok(!applied[0].inherited, "Entry 0 should be uninherited");
michael@0 50 is(applied[0].rule.type, 100, "Entry 0 should be an element style");
michael@0 51 ok(!!applied[0].rule.href, "Element styles should have a URL");
michael@0 52 is(applied[0].rule.cssText, "", "Entry 0 should be an empty style");
michael@0 53
michael@0 54 is(applied[1].inherited.id, "uninheritable-rule-inheritable-style",
michael@0 55 "Entry 1 should be inherited from the parent");
michael@0 56 is(applied[1].rule.type, 100, "Entry 1 should be an element style");
michael@0 57 is(applied[1].rule.cssText, "color: red;", "Entry 1 should have the expected cssText");
michael@0 58
michael@0 59 is(applied[2].inherited.id, "inheritable-rule-inheritable-style",
michael@0 60 "Entry 2 should be inherited from the parent's parent");
michael@0 61 is(applied[2].rule.type, 100, "Entry 2 should be an element style");
michael@0 62 is(applied[2].rule.cssText, "color: blue;", "Entry 2 should have the expected cssText");
michael@0 63
michael@0 64 is(applied[3].inherited.id, "inheritable-rule-inheritable-style",
michael@0 65 "Entry 3 should be inherited from the parent's parent");
michael@0 66 is(applied[3].rule.type, 1, "Entry 3 should be a rule style");
michael@0 67 is(applied[3].rule.cssText, "font-size: 15px;", "Entry 3 should have the expected cssText");
michael@0 68 ok(!applied[3].matchedSelectors, "Shouldn't get matchedSelectors with this request.");
michael@0 69
michael@0 70 is(applied[4].inherited.id, "inheritable-rule-uninheritable-style",
michael@0 71 "Entry 4 should be inherited from the parent's parent");
michael@0 72 is(applied[4].rule.type, 1, "Entry 4 should be an rule style");
michael@0 73 is(applied[4].rule.cssText, "font-size: 15px;", "Entry 4 should have the expected cssText");
michael@0 74 ok(!applied[4].matchedSelectors, "Shouldn't get matchedSelectors with this request.");
michael@0 75
michael@0 76 is(applied.length, 5, "Should have 5 rules.");
michael@0 77 }).then(runNextTest));
michael@0 78 });
michael@0 79
michael@0 80 addTest(function inheritedSystemStyles() {
michael@0 81 let node = node;
michael@0 82 promiseDone(gWalker.querySelector(gWalker.rootNode, "#test-node").then(node => {
michael@0 83 return gStyles.getApplied(node, { inherited: true, filter: "ua" });
michael@0 84 }).then(applied => {
michael@0 85 // If our system stylesheets are prone to churn, this might be a fragile
michael@0 86 // test. If you're here because of that I apologize, file a bug
michael@0 87 // and we can find a different way to test.
michael@0 88
michael@0 89 ok(!applied[1].inherited, "Entry 1 should not be inherited");
michael@0 90 ok(!applied[1].rule.parentStyleSheet.system, "Entry 1 should be a system style");
michael@0 91 is(applied[1].rule.type, 1, "Entry 1 should be a rule style");
michael@0 92
michael@0 93 is(applied.length, 7, "Should have 7 rules.");
michael@0 94 }).then(runNextTest));
michael@0 95 });
michael@0 96
michael@0 97 addTest(function noInheritedStyles() {
michael@0 98 let node = node;
michael@0 99 promiseDone(gWalker.querySelector(gWalker.rootNode, "#test-node").then(node => {
michael@0 100 return gStyles.getApplied(node, { inherited: false, filter: "user" });
michael@0 101 }).then(applied => {
michael@0 102 ok(!applied[0].inherited, "Entry 0 should be uninherited");
michael@0 103 is(applied[0].rule.type, 100, "Entry 0 should be an element style");
michael@0 104 is(applied[0].rule.cssText, "", "Entry 0 should be an empty style");
michael@0 105 is(applied.length, 1, "Should have 1 rule.");
michael@0 106 }).then(runNextTest));
michael@0 107 });
michael@0 108
michael@0 109 addTest(function matchedSelectors() {
michael@0 110 promiseDone(gWalker.querySelector(gWalker.rootNode, "#test-node").then(node => {
michael@0 111 return gStyles.getApplied(node, {
michael@0 112 inherited: true, filter: "user", matchedSelectors: true
michael@0 113 });
michael@0 114 }).then(applied => {
michael@0 115 is(applied[3].matchedSelectors[0], ".inheritable-rule", "Entry 3 should have a matched selector");
michael@0 116 is(applied[4].matchedSelectors[0], ".inheritable-rule", "Entry 4 should have a matched selector");
michael@0 117 }).then(runNextTest));
michael@0 118 });
michael@0 119
michael@0 120 addTest(function testMediaQuery() {
michael@0 121 let node = node;
michael@0 122 promiseDone(gWalker.querySelector(gWalker.rootNode, "#mediaqueried").then(node => {
michael@0 123 return gStyles.getApplied(node, {
michael@0 124 inherited: false, filter: "user", matchedSelectors: true
michael@0 125 });
michael@0 126 }).then(applied => {
michael@0 127 is(applied[1].rule.type, 1, "Entry 1 is a rule style");
michael@0 128 is(applied[1].rule.parentRule.type, 4, "Entry 1's parent rule is a media rule");
michael@0 129 is(applied[1].rule.parentRule.media[0], "screen", "Entry 1's parent rule has the expected medium");
michael@0 130 }).then(runNextTest));
michael@0 131 });
michael@0 132
michael@0 133 addTest(function cleanup() {
michael@0 134 delete gStyles;
michael@0 135 delete gWalker;
michael@0 136 delete gClient;
michael@0 137 runNextTest();
michael@0 138 });
michael@0 139
michael@0 140 </script>
michael@0 141 </head>
michael@0 142 <body>
michael@0 143 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a>
michael@0 144 <a id="inspectorContent" target="_blank" href="inspector-styles-data.html">Test Document</a>
michael@0 145 <p id="display"></p>
michael@0 146 <div id="content" style="display: none">
michael@0 147
michael@0 148 </div>
michael@0 149 <pre id="test">
michael@0 150 </pre>
michael@0 151 </body>
michael@0 152 </html>

mercurial