tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

notification_permission_worker.js (1629B)


      1 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
      2 
      3 function info(message) {
      4  dump("INFO: " + message + "\n");
      5 }
      6 
      7 function ok(test, message) {
      8  postMessage({ type: "ok", test, message });
      9 }
     10 
     11 function is(a, b, message) {
     12  postMessage({ type: "is", test1: a, test2: b, message });
     13 }
     14 
     15 if (self.Notification) {
     16  var steps = [
     17    function (done) {
     18      info("Test notification permission");
     19      ok(typeof Notification === "function", "Notification constructor exists");
     20      ok(
     21        Notification.permission === "denied",
     22        "Notification.permission is denied."
     23      );
     24 
     25      var n = new Notification("Hello");
     26      n.onerror = () => {
     27        ok(true, "error called due to permission denied.");
     28        done();
     29      };
     30    },
     31  ];
     32 
     33  onmessage = () => {
     34    var context = {};
     35    (function executeRemainingTests(remainingTests) {
     36      if (!remainingTests.length) {
     37        postMessage({ type: "finish" });
     38        return;
     39      }
     40 
     41      var nextTest = remainingTests.shift();
     42      var finishTest = executeRemainingTests.bind(null, remainingTests);
     43      var startTest = nextTest.call.bind(nextTest, context, finishTest);
     44 
     45      try {
     46        startTest();
     47        // if no callback was defined for test function,
     48        // we must manually invoke finish to continue
     49        if (nextTest.length === 0) {
     50          finishTest();
     51        }
     52      } catch (ex) {
     53        ok(false, "Test threw exception! " + nextTest + " " + ex);
     54        finishTest();
     55      }
     56    })(steps);
     57  };
     58 } else {
     59  ok(true, "Notifications are not enabled in workers on the platform.");
     60  postMessage({ type: "finish" });
     61 }