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.

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

mercurial