no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / workers / test / notification_permission_worker.js
blob0551247d078b4f0b4d20184a0b98dfa812b5d381
1 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */
3 function info(message) {
4   dump("INFO: " + message + "\n");
7 function ok(test, message) {
8   postMessage({ type: "ok", test, message });
11 function is(a, b, message) {
12   postMessage({ type: "is", test1: a, test2: b, message });
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       );
25       var n = new Notification("Hello");
26       n.onerror = function (e) {
27         ok(true, "error called due to permission denied.");
28         done();
29       };
30     },
31   ];
33   onmessage = function (e) {
34     var context = {};
35     (function executeRemainingTests(remainingTests) {
36       if (!remainingTests.length) {
37         postMessage({ type: "finish" });
38         return;
39       }
41       var nextTest = remainingTests.shift();
42       var finishTest = executeRemainingTests.bind(null, remainingTests);
43       var startTest = nextTest.call.bind(nextTest, context, finishTest);
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" });