test_controller.html (2389B)
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 1002570 - test controller instance.</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 19 var content; 20 var iframe; 21 var registration; 22 23 function simpleRegister() { 24 // We use the control scope for the less specific registration. The window will register a worker on controller/ 25 return navigator.serviceWorker.register("worker.js", { scope: "./control" }) 26 .then(swr => waitForState(swr.installing, 'activated', swr)) 27 .then(swr => registration = swr); 28 } 29 30 function unregister() { 31 return registration.unregister().then(function(result) { 32 ok(result, "Unregister should return true."); 33 }, function(e) { 34 dump("Unregistering the SW failed: " + e + "\n"); 35 }); 36 } 37 38 function testController() { 39 var p = new Promise(function(resolve, reject) { 40 window.onmessage = function(e) { 41 if (e.data.status == "ok") { 42 ok(e.data.result, e.data.message); 43 } else if (e.data.status == "done") { 44 window.onmessage = null; 45 content.removeChild(iframe); 46 resolve(); 47 } 48 } 49 }); 50 51 content = document.getElementById("content"); 52 ok(content, "Parent exists."); 53 54 iframe = document.createElement("iframe"); 55 iframe.setAttribute('src', "controller/index.html"); 56 content.appendChild(iframe); 57 58 return p; 59 } 60 61 // This document just flips the prefs and opens the iframe for the actual test. 62 function runTest() { 63 simpleRegister() 64 .then(testController) 65 .then(unregister) 66 .then(function() { 67 SimpleTest.finish(); 68 }).catch(function(e) { 69 ok(false, "Some test failed with error " + e); 70 SimpleTest.finish(); 71 }); 72 } 73 74 SimpleTest.waitForExplicitFinish(); 75 SpecialPowers.pushPrefEnv({"set": [ 76 ["dom.serviceWorkers.exemptFromPerDomainMax", true], 77 ["dom.serviceWorkers.enabled", true], 78 ["dom.serviceWorkers.testing.enabled", true] 79 ]}, runTest); 80 </script> 81 </pre> 82 </body> 83 </html>