1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/devtools/server/tests/mochitest/test_styles-matched.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id= 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug </title> 1.12 + 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> 1.15 + <script type="application/javascript;version=1.8" src="inspector-helpers.js"></script> 1.16 + <script type="application/javascript;version=1.8"> 1.17 +Components.utils.import("resource://gre/modules/devtools/Loader.jsm"); 1.18 +const {Promise: promise} = Components.utils.import("resource://gre/modules/Promise.jsm", {}); 1.19 + 1.20 +const inspector = devtools.require("devtools/server/actors/inspector"); 1.21 +const {CssLogic} = devtools.require("devtools/styleinspector/css-logic"); 1.22 + 1.23 +window.onload = function() { 1.24 + SimpleTest.waitForExplicitFinish(); 1.25 + runNextTest(); 1.26 +} 1.27 + 1.28 +var gWalker = null; 1.29 +var gStyles = null; 1.30 +var gClient = null; 1.31 + 1.32 +addTest(function setup() { 1.33 + let url = document.getElementById("inspectorContent").href; 1.34 + attachURL(url, function(err, client, tab, doc) { 1.35 + gInspectee = doc; 1.36 + let {InspectorFront} = devtools.require("devtools/server/actors/inspector"); 1.37 + let inspector = InspectorFront(client, tab); 1.38 + promiseDone(inspector.getWalker().then(walker => { 1.39 + ok(walker, "getWalker() should return an actor."); 1.40 + gClient = client; 1.41 + gWalker = walker; 1.42 + return inspector.getPageStyle(); 1.43 + }).then(styles => { 1.44 + gStyles = styles; 1.45 + }).then(runNextTest)); 1.46 + }); 1.47 +}); 1.48 + 1.49 +addTest(function testMatchedStyles() { 1.50 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#matched-test-node").then(node => { 1.51 + return gStyles.getMatchedSelectors(node, "font-size", {}); 1.52 + }).then(matched => { 1.53 + is(matched[0].sourceText, "this.style", "First match comes from the element style"); 1.54 + is(matched[0].selector, "@element.style", "Element style has a special selector"); 1.55 + is(matched[0].value, "10px", "First match has the expected value"); 1.56 + is(matched[0].status, CssLogic.STATUS.BEST, "First match is the best match") 1.57 + is(matched[0].rule.type, 100, "First match is an element style"); 1.58 + is(matched[0].rule.href, gInspectee.defaultView.location.href, "Node style comes from this document") 1.59 + 1.60 + is(matched[1].sourceText, ".inheritable-rule", "Second match comes from a rule"); 1.61 + is(matched[1].selector, ".inheritable-rule", "Second style has a selector"); 1.62 + is(matched[1].value, "15px", "Second match has the expected value"); 1.63 + is(matched[1].status, CssLogic.STATUS.PARENT_MATCH, "Second match is from the parent") 1.64 + is(matched[1].rule.parentStyleSheet.href, null, "Inline stylesheet shouldn't have an href"); 1.65 + is(matched[1].rule.parentStyleSheet.nodeHref, gInspectee.defaultView.location.href, "Inline stylesheet's nodeHref should match the current document"); 1.66 + ok(!matched[1].rule.parentStyleSheet.system, "Inline stylesheet shouldn't be a system stylesheet."); 1.67 + }).then(runNextTest)); 1.68 +}); 1.69 + 1.70 +addTest(function testSystemStyles() { 1.71 + let testNode = null; 1.72 + 1.73 + promiseDone(gWalker.querySelector(gWalker.rootNode, "#matched-test-node").then(node => { 1.74 + testNode = node; 1.75 + return gStyles.getMatchedSelectors(testNode, "display", { filter: "user" }); 1.76 + }).then(matched => { 1.77 + is(matched.length, 0, "No user selectors apply to this rule."); 1.78 + return gStyles.getMatchedSelectors(testNode, "display", { filter: "ua" }); 1.79 + }).then(matched => { 1.80 + is(matched[0].selector, "div", "Should match system div selector"); 1.81 + is(matched[0].value, "block"); 1.82 + }).then(runNextTest)); 1.83 +}); 1.84 + 1.85 +addTest(function cleanup() { 1.86 + delete gStyles; 1.87 + delete gWalker; 1.88 + delete gClient; 1.89 + runNextTest(); 1.90 +}); 1.91 + 1.92 + </script> 1.93 +</head> 1.94 +<body> 1.95 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=">Mozilla Bug </a> 1.96 +<a id="inspectorContent" target="_blank" href="inspector-styles-data.html">Test Document</a> 1.97 +<p id="display"></p> 1.98 +<div id="content" style="display: none"> 1.99 + 1.100 +</div> 1.101 +<pre id="test"> 1.102 +</pre> 1.103 +</body> 1.104 +</html>