summaryrefslogtreecommitdiffstats
path: root/security/sandbox/test/browser_sandbox_test.js
blob: 2c4af40ca84e29268e234793e2ccd179294b8ce6 (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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */

"use strict";

function test() {
  waitForExplicitFinish();
  const { Services } = ChromeUtils.import(
    "resource://gre/modules/Services.jsm"
  );

  // Types of processes to test, taken from GeckoProcessTypes.h
  var processTypes = ["tab", "gpu"];

  // A callback called after each test-result.
  Services.obs.addObserver(function result(subject, topic, data) {
    let { testid, shouldPermit, wasPermitted, message } = JSON.parse(data);
    ok(
      shouldPermit == wasPermitted,
      "Test " +
        testid +
        " was " +
        (wasPermitted ? "" : "not ") +
        "permitted.  | " +
        message
    );
  }, "sandbox-test-result");

  // A callback that is notified when a child process is done running tests.
  var remainingTests = processTypes.length;
  Services.obs.addObserver(_ => {
    remainingTests = remainingTests - 1;
    if (remainingTests == 0) {
      // Notify SandboxTest component that it should terminate the connection
      // with the child processes.
      comp.finishTests();
      // Notify mochitest that all process tests are complete.
      finish();
    }
  }, "sandbox-test-done");

  var comp = Cc["@mozilla.org/sandbox/sandbox-test;1"].getService(
    Ci.mozISandboxTest
  );

  comp.startTests(processTypes);
}