summaryrefslogtreecommitdiffstats
path: root/testing/mochitest/tests/Harness_sanity/test_SpecialPowersLoadPrivilegedScript.html
blob: e9b54537604f1b0c6886f693dfd62aa97395b50c (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
<!DOCTYPE HTML>
<html>
<head>
  <title>Test for SpecialPowers.loadChromeScript</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>

<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

function loadPrivilegedScriptTest() {
  var Cc = Components.classes;
  var Ci = Components.interfaces;
  function isMainProcess() {
    return Cc["@mozilla.org/xre/app-info;1"].
             getService(Ci.nsIXULRuntime).
             processType == Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
  }
  port.postMessage({'isMainProcess': isMainProcess()});
}

var contentProcessType = SpecialPowers.isMainProcess();
var port;
try {
  port = SpecialPowers.loadPrivilegedScript(loadPrivilegedScriptTest.toSource());
} catch (e) {
  ok(false, "loadPrivilegedScript shoulde not throw");
}
port.onmessage = (e) => {
  is(contentProcessType, e.data['isMainProcess'], "content and the script should be in the same process");
  SimpleTest.finish();
};
</script>