test_importscript.html (2168B)
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>Test service worker - script cache policy</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 <div id="content"></div> 14 <script src="utils.js"></script> 15 <script class="testbody" type="text/javascript"> 16 function start() { 17 return navigator.serviceWorker.register("importscript_worker.js", 18 { scope: "./sw_clients/" }) 19 .then(swr => waitForState(swr.installing, 'activated', swr)) 20 .then(swr => registration = swr); 21 } 22 23 function unregister() { 24 return fetch("importscript.sjs?clearcounter").then(function() { 25 return registration.unregister(); 26 }).then(function(result) { 27 ok(result, "Unregister should return true."); 28 }, function(e) { 29 dump("Unregistering the SW failed with " + e + "\n"); 30 }); 31 } 32 33 function testPostMessage(swr) { 34 var p = new Promise(function(res, rej) { 35 window.onmessage = function(e) { 36 if (e.data === "READY") { 37 swr.active.postMessage("do magic"); 38 return; 39 } 40 41 ok(e.data === "OK", "Worker posted the correct value: " + e.data); 42 res(); 43 } 44 }); 45 46 var content = document.getElementById("content"); 47 ok(content, "Parent exists."); 48 49 iframe = document.createElement("iframe"); 50 iframe.setAttribute('src', "sw_clients/service_worker_controlled.html"); 51 content.appendChild(iframe); 52 53 return p.then(() => content.removeChild(iframe)); 54 } 55 56 function runTest() { 57 start() 58 .then(testPostMessage) 59 .then(unregister) 60 .catch(function(e) { 61 ok(false, "Some test failed with error " + e); 62 }).then(SimpleTest.finish); 63 } 64 65 SimpleTest.waitForExplicitFinish(); 66 SpecialPowers.pushPrefEnv({"set": [ 67 ["dom.serviceWorkers.exemptFromPerDomainMax", true], 68 ["dom.serviceWorkers.enabled", true], 69 ["dom.serviceWorkers.testing.enabled", true] 70 ]}, runTest); 71 </script> 72 </pre> 73 </body> 74 </html>