test_match_all_client_properties.html (2693B)
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 clients properties </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_clients/match_all_controlled.html"; 20 function start() { 21 return navigator.serviceWorker.register("match_all_properties_worker.js", 22 { scope: "./match_all_clients/" }) 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 if (e.data.message === undefined) { 41 info("rejecting promise"); 42 rej(); 43 return; 44 } 45 46 ok(e.data.result, e.data.message); 47 48 if (!e.data.result) { 49 rej(); 50 } 51 if (e.data.message == "DONE") { 52 info("DONE from: " + e.source); 53 res(); 54 } 55 } 56 }); 57 } 58 59 function testNestedWindow() { 60 var p = getMessageListener(); 61 62 var content = document.getElementById("content"); 63 ok(content, "Parent exists."); 64 65 iframe = document.createElement("iframe"); 66 67 content.appendChild(iframe); 68 iframe.setAttribute('src', clientURL); 69 70 return p.then(() => content.removeChild(iframe)); 71 } 72 73 function testAuxiliaryWindow() { 74 var p = getMessageListener(); 75 var w = window.open(clientURL); 76 77 return p.then(() => w.close()); 78 } 79 80 function runTest() { 81 info("catalin"); 82 info(window.opener == undefined); 83 start() 84 .then(testAuxiliaryWindow) 85 .then(testNestedWindow) 86 .then(unregister) 87 .catch(function(e) { 88 ok(false, "Some test failed with error " + e); 89 }).then(SimpleTest.finish); 90 } 91 92 SimpleTest.waitForExplicitFinish(); 93 SpecialPowers.pushPrefEnv({"set": [ 94 ["dom.serviceWorkers.exemptFromPerDomainMax", true], 95 ["dom.serviceWorkers.enabled", true], 96 ["dom.serviceWorkers.testing.enabled", true] 97 ]}, runTest); 98 </script> 99 </pre> 100 </body> 101 </html>