|
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/ */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 // Check stylesheets on HMTL and XUL document |
|
8 |
|
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); |
|
17 |
|
18 let {CssLogic} = devtools.require("devtools/styleinspector/css-logic"); |
|
19 |
|
20 let test = asyncTest(function*() { |
|
21 info("Checking stylesheets on HTML document"); |
|
22 yield addTab(TEST_URI_HTML); |
|
23 let target = getNode("#target"); |
|
24 |
|
25 let {toolbox, inspector, view} = yield openRuleView(); |
|
26 yield selectNode(target, inspector); |
|
27 |
|
28 info("Checking stylesheets"); |
|
29 checkSheets(target); |
|
30 |
|
31 info("Checking stylesheets on XUL document"); |
|
32 info("Allowing XUL content"); |
|
33 allowXUL(); |
|
34 yield addTab(TEST_URI_XUL); |
|
35 |
|
36 let {toolbox, inspector, view} = yield openRuleView(); |
|
37 let target = getNode("#target"); |
|
38 yield selectNode(target, inspector); |
|
39 |
|
40 checkSheets(target); |
|
41 info("Disallowing XUL content"); |
|
42 disallowXUL(); |
|
43 }); |
|
44 |
|
45 function allowXUL() { |
|
46 Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) |
|
47 .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.ALLOW_ACTION); |
|
48 } |
|
49 |
|
50 function disallowXUL() { |
|
51 Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager) |
|
52 .addFromPrincipal(XUL_PRINCIPAL, 'allowXULXBL', Ci.nsIPermissionManager.DENY_ACTION); |
|
53 } |
|
54 |
|
55 function checkSheets(target) { |
|
56 let domUtils = Cc["@mozilla.org/inspector/dom-utils;1"] |
|
57 .getService(Ci.inIDOMUtils); |
|
58 let domRules = domUtils.getCSSStyleRules(target); |
|
59 |
|
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); |
|
64 |
|
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 } |