michael@0: /* vim: set ft=javascript ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: "use strict"; michael@0: michael@0: // Check stylesheets on HMTL and XUL document michael@0: michael@0: const TEST_URI_HTML = TEST_URL_ROOT + "doc_content_stylesheet.html"; michael@0: const TEST_URI_XUL = TEST_URL_ROOT + "doc_content_stylesheet.xul"; michael@0: const XUL_URI = Cc["@mozilla.org/network/io-service;1"] michael@0: .getService(Ci.nsIIOService) michael@0: .newURI(TEST_URI_XUL, null, null); michael@0: const XUL_PRINCIPAL = Components.classes["@mozilla.org/scriptsecuritymanager;1"] michael@0: .getService(Ci.nsIScriptSecurityManager) michael@0: .getNoAppCodebasePrincipal(XUL_URI); michael@0: michael@0: let {CssLogic} = devtools.require("devtools/styleinspector/css-logic"); michael@0: michael@0: let test = asyncTest(function*() { michael@0: info("Checking stylesheets on HTML document"); michael@0: yield addTab(TEST_URI_HTML); michael@0: let target = getNode("#target"); michael@0: michael@0: let {toolbox, inspector, view} = yield openRuleView(); michael@0: yield selectNode(target, inspector); michael@0: michael@0: info("Checking stylesheets"); michael@0: checkSheets(target); michael@0: michael@0: info("Checking stylesheets on XUL document"); michael@0: info("Allowing XUL content"); michael@0: allowXUL(); michael@0: yield addTab(TEST_URI_XUL); michael@0: michael@0: let {toolbox, inspector, view} = yield openRuleView(); michael@0: let target = getNode("#target"); michael@0: yield selectNode(target, inspector); michael@0: michael@0: checkSheets(target); michael@0: info("Disallowing XUL content"); michael@0: disallowXUL(); michael@0: }); michael@0: michael@0: function allowXUL() { michael@0: Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) michael@0: .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.ALLOW_ACTION); michael@0: } michael@0: michael@0: function disallowXUL() { michael@0: Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) michael@0: .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.DENY_ACTION); michael@0: } michael@0: michael@0: function checkSheets(target) { michael@0: let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"] michael@0: .getService(Ci.inIDOMUtils); michael@0: let domRules = domUtils.getCSSStyleRules(target); michael@0: michael@0: for (let i = 0, n = domRules.Count(); i < n; i++) { michael@0: let domRule = domRules.GetElementAt(i); michael@0: let sheet = domRule.parentStyleSheet; michael@0: let isContentSheet = CssLogic.isContentStylesheet(sheet); michael@0: michael@0: if (!sheet.href || michael@0: /doc_content_stylesheet_/.test(sheet.href)) { michael@0: ok(isContentSheet, sheet.href + " identified as content stylesheet"); michael@0: } else { michael@0: ok(!isContentSheet, sheet.href + " identified as non-content stylesheet"); michael@0: } michael@0: } michael@0: }