browser/devtools/styleinspector/test/browser_styleinspector_csslogic-content-stylesheets.js

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 /* vim: set ft=javascript ts=2 et sw=2 tw=80: */
michael@0 2 /* Any copyright is dedicated to the Public Domain.
michael@0 3 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 4
michael@0 5 "use strict";
michael@0 6
michael@0 7 // Check stylesheets on HMTL and XUL document
michael@0 8
michael@0 9 const TEST_URI_HTML = TEST_URL_ROOT + "doc_content_stylesheet.html";
michael@0 10 const TEST_URI_XUL = TEST_URL_ROOT + "doc_content_stylesheet.xul";
michael@0 11 const XUL_URI = Cc["@mozilla.org/network/io-service;1"]
michael@0 12 .getService(Ci.nsIIOService)
michael@0 13 .newURI(TEST_URI_XUL, null, null);
michael@0 14 const XUL_PRINCIPAL = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
michael@0 15 .getService(Ci.nsIScriptSecurityManager)
michael@0 16 .getNoAppCodebasePrincipal(XUL_URI);
michael@0 17
michael@0 18 let {CssLogic} = devtools.require("devtools/styleinspector/css-logic");
michael@0 19
michael@0 20 let test = asyncTest(function*() {
michael@0 21 info("Checking stylesheets on HTML document");
michael@0 22 yield addTab(TEST_URI_HTML);
michael@0 23 let target = getNode("#target");
michael@0 24
michael@0 25 let {toolbox, inspector, view} = yield openRuleView();
michael@0 26 yield selectNode(target, inspector);
michael@0 27
michael@0 28 info("Checking stylesheets");
michael@0 29 checkSheets(target);
michael@0 30
michael@0 31 info("Checking stylesheets on XUL document");
michael@0 32 info("Allowing XUL content");
michael@0 33 allowXUL();
michael@0 34 yield addTab(TEST_URI_XUL);
michael@0 35
michael@0 36 let {toolbox, inspector, view} = yield openRuleView();
michael@0 37 let target = getNode("#target");
michael@0 38 yield selectNode(target, inspector);
michael@0 39
michael@0 40 checkSheets(target);
michael@0 41 info("Disallowing XUL content");
michael@0 42 disallowXUL();
michael@0 43 });
michael@0 44
michael@0 45 function allowXUL() {
michael@0 46 Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
michael@0 47 .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.ALLOW_ACTION);
michael@0 48 }
michael@0 49
michael@0 50 function disallowXUL() {
michael@0 51 Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
michael@0 52 .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.DENY_ACTION);
michael@0 53 }
michael@0 54
michael@0 55 function checkSheets(target) {
michael@0 56 let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
michael@0 57 .getService(Ci.inIDOMUtils);
michael@0 58 let domRules = domUtils.getCSSStyleRules(target);
michael@0 59
michael@0 60 for (let i = 0, n = domRules.Count(); i < n; i++) {
michael@0 61 let domRule = domRules.GetElementAt(i);
michael@0 62 let sheet = domRule.parentStyleSheet;
michael@0 63 let isContentSheet = CssLogic.isContentStylesheet(sheet);
michael@0 64
michael@0 65 if (!sheet.href ||
michael@0 66 /doc_content_stylesheet_/.test(sheet.href)) {
michael@0 67 ok(isContentSheet, sheet.href + " identified as content stylesheet");
michael@0 68 } else {
michael@0 69 ok(!isContentSheet, sheet.href + " identified as non-content stylesheet");
michael@0 70 }
michael@0 71 }
michael@0 72 }

mercurial