summaryrefslogtreecommitdiff
path: root/browser/devtools/styleinspector/test/browser_bug705707_is_content_stylesheet.js
blob: 13de2a1ffe644449f974aac68f8dd6e45edf636b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* vim: set ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Tests that the correct stylesheets origins are identified in HTML & XUL
// stylesheets

let doc;

const TEST_URI = "http://example.com/browser/browser/devtools/styleinspector/" +
                 "test/browser_bug705707_is_content_stylesheet.html";
const TEST_URI2 = "http://example.com/browser/browser/devtools/styleinspector/" +
                 "test/browser_bug705707_is_content_stylesheet.xul";
const XUL_URI = Cc["@mozilla.org/network/io-service;1"]
                .getService(Ci.nsIIOService)
                .newURI(TEST_URI2, null, null);
const XUL_PRINCIPAL =  Components.classes["@mozilla.org/scriptsecuritymanager;1"]
                                 .getService(Ci.nsIScriptSecurityManager)
                                 .getNoAppCodebasePrincipal(XUL_URI);


let {CssLogic} = devtools.require("devtools/styleinspector/css-logic");

function test()
{
  waitForExplicitFinish();
  addTab(TEST_URI);
  browser.addEventListener("load", htmlLoaded, true);
}

function htmlLoaded()
{
  browser.removeEventListener("load", htmlLoaded, true);
  doc = content.document;
  testFromHTML()
}

function testFromHTML()
{
  let target = doc.querySelector("#target");

  executeSoon(function() {
    checkSheets(target);
    gBrowser.removeCurrentTab();
    openXUL();
  });
}

function openXUL()
{
  Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
    .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.ALLOW_ACTION);
  addTab(TEST_URI2);
  browser.addEventListener("load", xulLoaded, true);
}

function xulLoaded()
{
  browser.removeEventListener("load", xulLoaded, true);
  doc = content.document;
  testFromXUL()
}

function testFromXUL()
{
  let target = doc.querySelector("#target");

  executeSoon(function() {
    checkSheets(target);
    finishUp();
  });
}

function checkSheets(aTarget)
{
  let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"]
      .getService(Ci.inIDOMUtils);
  let domRules = domUtils.getCSSStyleRules(aTarget);

  for (let i = 0, n = domRules.Count(); i < n; i++) {
    let domRule = domRules.GetElementAt(i);
    let sheet = domRule.parentStyleSheet;
    let isContentSheet = CssLogic.isContentStylesheet(sheet);

    if (!sheet.href ||
        /browser_bug705707_is_content_stylesheet_/.test(sheet.href)) {
      ok(isContentSheet, sheet.href + " identified as content stylesheet");
    } else {
      ok(!isContentSheet, sheet.href + " identified as non-content stylesheet");
    }
  }
}

function finishUp()
{
  info("finishing up");
  Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
    .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.DENY_ACTION);
  doc = null;
  gBrowser.removeCurrentTab();
  finish();
}