test_match_all_client_id.html (2593B)
1 <!-- 2 Any copyright is dedicated to the Public Domain. 3 http://creativecommons.org/publicdomain/zero/1.0/ 4 --> 5 <!DOCTYPE HTML> 6 <html> 7 <head> 8 <title>Bug 1058311 - Test matchAll client id </title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 </head> 12 <body> 13 <p id="display"></p> 14 <div id="content" style="display: none"></div> 15 <pre id="test"></pre> 16 <script src="utils.js"></script> 17 <script class="testbody" type="text/javascript"> 18 var registration; 19 var clientURL = "match_all_client/match_all_client_id.html"; 20 function start() { 21 return navigator.serviceWorker.register("match_all_client_id_worker.js", 22 { scope: "./match_all_client/" }) 23 .then((swr) => { 24 registration = swr; 25 return waitForState(swr.installing, 'activated', swr); 26 }); 27 } 28 29 function unregister() { 30 return registration.unregister().then(function(result) { 31 ok(result, "Unregister should return true."); 32 }, function(e) { 33 dump("Unregistering the SW failed with " + e + "\n"); 34 }); 35 } 36 37 function getMessageListener() { 38 return new Promise(function(res, rej) { 39 window.onmessage = function(e) { 40 ok(e.data, "Same client id for multiple calls."); 41 is(e.origin, "http://mochi.test:8888", "Event should have the correct origin"); 42 43 if (!e.data) { 44 rej(); 45 return; 46 } 47 48 info("DONE from: " + e.source); 49 res(); 50 } 51 }); 52 } 53 54 function testNestedWindow() { 55 var p = getMessageListener(); 56 57 var content = document.getElementById("content"); 58 ok(content, "Parent exists."); 59 60 iframe = document.createElement("iframe"); 61 62 content.appendChild(iframe); 63 iframe.setAttribute('src', clientURL); 64 65 return p.then(() => content.removeChild(iframe)); 66 } 67 68 function testAuxiliaryWindow() { 69 var p = getMessageListener(); 70 var w = window.open(clientURL); 71 72 return p.then(() => w.close()); 73 } 74 75 function runTest() { 76 info(window.opener == undefined); 77 start() 78 .then(testAuxiliaryWindow) 79 .then(testNestedWindow) 80 .then(unregister) 81 .catch(function(e) { 82 ok(false, "Some test failed with error " + e); 83 }).then(SimpleTest.finish); 84 } 85 86 SimpleTest.waitForExplicitFinish(); 87 SpecialPowers.pushPrefEnv({"set": [ 88 ["dom.serviceWorkers.exemptFromPerDomainMax", true], 89 ["dom.serviceWorkers.enabled", true], 90 ["dom.serviceWorkers.testing.enabled", true] 91 ]}, runTest); 92 </script> 93 </pre> 94 </body> 95 </html>