summaryrefslogtreecommitdiffstats
path: root/devtools/client/inspector/shared/test/browser_styleinspector_csslogic-content-stylesheets.js
blob: 421a2bb47f6fdf6531d72cfa0352c7fc94b7a89e (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
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Check stylesheets on HMTL and XUL document

// FIXME: this test opens the devtools for nothing, it should be changed into a
// devtools/server/tests/mochitest/test_css-logic-...something...html
// test

const TEST_URI_HTML = TEST_URL_ROOT + "doc_content_stylesheet.html";
const TEST_URI_AUTHOR = TEST_URL_ROOT + "doc_author-sheet.html";
const TEST_URI_XUL = TEST_URL_ROOT + "doc_content_stylesheet.xul";
const XUL_URI = Cc["@mozilla.org/network/io-service;1"]
                .getService(Ci.nsIIOService)
                .newURI(TEST_URI_XUL, null, null);
var ssm = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
                            .getService(Ci.nsIScriptSecurityManager);
const XUL_PRINCIPAL = ssm.createCodebasePrincipal(XUL_URI, {});

add_task(function* () {
  requestLongerTimeout(2);

  info("Checking stylesheets on HTML document");
  yield addTab(TEST_URI_HTML);

  let {inspector, testActor} = yield openInspector();
  yield selectNode("#target", inspector);

  info("Checking stylesheets");
  yield checkSheets("#target", testActor);

  info("Checking authored stylesheets");
  yield addTab(TEST_URI_AUTHOR);

  ({inspector} = yield openInspector());
  yield selectNode("#target", inspector);
  yield checkSheets("#target", testActor);

  info("Checking stylesheets on XUL document");
  info("Allowing XUL content");
  allowXUL();
  yield addTab(TEST_URI_XUL);

  ({inspector} = yield openInspector());
  yield selectNode("#target", inspector);

  yield checkSheets("#target", testActor);
  info("Disallowing XUL content");
  disallowXUL();
});

function allowXUL() {
  Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
    .addFromPrincipal(XUL_PRINCIPAL, "allowXULXBL",
      Ci.nsIPermissionManager.ALLOW_ACTION);
}

function disallowXUL() {
  Cc["@mozilla.org/permissionmanager;1"].getService(Ci.nsIPermissionManager)
    .addFromPrincipal(XUL_PRINCIPAL, "allowXULXBL",
      Ci.nsIPermissionManager.DENY_ACTION);
}

function* checkSheets(targetSelector, testActor) {
  let sheets = yield testActor.getStyleSheetsInfoForNode(targetSelector);

  for (let sheet of sheets) {
    if (!sheet.href ||
        /doc_content_stylesheet_/.test(sheet.href) ||
        // For the "authored" case.
        /^data:.*seagreen/.test(sheet.href)) {
      ok(sheet.isContentSheet,
        sheet.href + " identified as content stylesheet");
    } else {
      ok(!sheet.isContentSheet,
        sheet.href + " identified as non-content stylesheet");
    }
  }
}