1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/styleinspector/test/browser_styleinspector_csslogic-content-stylesheets.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +// Check stylesheets on HMTL and XUL document 1.11 + 1.12 +const TEST_URI_HTML = TEST_URL_ROOT + "doc_content_stylesheet.html"; 1.13 +const TEST_URI_XUL = TEST_URL_ROOT + "doc_content_stylesheet.xul"; 1.14 +const XUL_URI = Cc["@mozilla.org/network/io-service;1"] 1.15 + .getService(Ci.nsIIOService) 1.16 + .newURI(TEST_URI_XUL, null, null); 1.17 +const XUL_PRINCIPAL = Components.classes["@mozilla.org/scriptsecuritymanager;1"] 1.18 + .getService(Ci.nsIScriptSecurityManager) 1.19 + .getNoAppCodebasePrincipal(XUL_URI); 1.20 + 1.21 +let {CssLogic} = devtools.require("devtools/styleinspector/css-logic"); 1.22 + 1.23 +let test = asyncTest(function*() { 1.24 + info("Checking stylesheets on HTML document"); 1.25 + yield addTab(TEST_URI_HTML); 1.26 + let target = getNode("#target"); 1.27 + 1.28 + let {toolbox, inspector, view} = yield openRuleView(); 1.29 + yield selectNode(target, inspector); 1.30 + 1.31 + info("Checking stylesheets"); 1.32 + checkSheets(target); 1.33 + 1.34 + info("Checking stylesheets on XUL document"); 1.35 + info("Allowing XUL content"); 1.36 + allowXUL(); 1.37 + yield addTab(TEST_URI_XUL); 1.38 + 1.39 + let {toolbox, inspector, view} = yield openRuleView(); 1.40 + let target = getNode("#target"); 1.41 + yield selectNode(target, inspector); 1.42 + 1.43 + checkSheets(target); 1.44 + info("Disallowing XUL content"); 1.45 + disallowXUL(); 1.46 +}); 1.47 + 1.48 +function allowXUL() { 1.49 + Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) 1.50 + .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.ALLOW_ACTION); 1.51 +} 1.52 + 1.53 +function disallowXUL() { 1.54 + Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) 1.55 + .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.DENY_ACTION); 1.56 +} 1.57 + 1.58 +function checkSheets(target) { 1.59 + let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"] 1.60 + .getService(Ci.inIDOMUtils); 1.61 + let domRules = domUtils.getCSSStyleRules(target); 1.62 + 1.63 + for (let i = 0, n = domRules.Count(); i < n; i++) { 1.64 + let domRule = domRules.GetElementAt(i); 1.65 + let sheet = domRule.parentStyleSheet; 1.66 + let isContentSheet = CssLogic.isContentStylesheet(sheet); 1.67 + 1.68 + if (!sheet.href || 1.69 + /doc_content_stylesheet_/.test(sheet.href)) { 1.70 + ok(isContentSheet, sheet.href + " identified as content stylesheet"); 1.71 + } else { 1.72 + ok(!isContentSheet, sheet.href + " identified as non-content stylesheet"); 1.73 + } 1.74 + } 1.75 +}