notification_worker_child-child.js (3031B)
1 /* eslint-disable mozilla/no-comparison-or-assignment-inside-ok */ 2 3 function ok(test, message) { 4 postMessage({ type: "ok", test, message }); 5 } 6 7 function is(a, b, message) { 8 postMessage({ type: "is", test1: a, test2: b, message }); 9 } 10 11 if (self.Notification) { 12 var steps = [ 13 function () { 14 ok(typeof Notification === "function", "Notification constructor exists"); 15 ok(Notification.permission, "Notification.permission exists"); 16 ok( 17 typeof Notification.requestPermission === "undefined", 18 "Notification.requestPermission should not exist" 19 ); 20 //ok(typeof Notification.get === "function", "Notification.get exists"); 21 }, 22 23 function (done) { 24 var options = { 25 dir: "auto", 26 lang: "", 27 body: "This is a notification body", 28 tag: "sometag", 29 icon: "icon.png", 30 }; 31 var notification = new Notification("This is a title", options); 32 33 ok(notification !== undefined, "Notification exists"); 34 is(notification.onclick, null, "onclick() should be null"); 35 is(notification.onshow, null, "onshow() should be null"); 36 is(notification.onerror, null, "onerror() should be null"); 37 is(notification.onclose, null, "onclose() should be null"); 38 is(typeof notification.close, "function", "close() should exist"); 39 40 is(notification.dir, options.dir, "auto should get set"); 41 is(notification.lang, options.lang, "lang should get set"); 42 is(notification.body, options.body, "body should get set"); 43 is(notification.tag, options.tag, "tag should get set"); 44 is( 45 notification.icon, 46 new URL(options.icon, location.href).toString(), 47 "icon should get set" 48 ); 49 50 // store notification in test context 51 this.notification = notification; 52 53 notification.onshow = function () { 54 ok(true, "onshow handler should be called"); 55 done(); 56 }; 57 }, 58 59 function (done) { 60 var notification = this.notification; 61 62 notification.onclose = function () { 63 ok(true, "onclose handler should be called"); 64 done(); 65 }; 66 67 notification.close(); 68 }, 69 ]; 70 71 onmessage = () => { 72 var context = {}; 73 (function executeRemainingTests(remainingTests) { 74 if (!remainingTests.length) { 75 postMessage({ type: "finish" }); 76 return; 77 } 78 79 var nextTest = remainingTests.shift(); 80 var finishTest = executeRemainingTests.bind(null, remainingTests); 81 var startTest = nextTest.call.bind(nextTest, context, finishTest); 82 83 try { 84 startTest(); 85 // if no callback was defined for test function, 86 // we must manually invoke finish to continue 87 if (nextTest.length === 0) { 88 finishTest(); 89 } 90 } catch (ex) { 91 ok(false, "Test threw exception! " + nextTest + " " + ex); 92 finishTest(); 93 } 94 })(steps); 95 }; 96 } else { 97 ok(true, "Notifications are not enabled in workers on the platform."); 98 postMessage({ type: "finish" }); 99 }