test_sanitize_domain.html (2985B)
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 1080109 - Clear ServiceWorker registrations for specific domains</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 class="testbody" type="text/javascript"> 17 18 function start() { 19 const Cc = SpecialPowers.Cc; 20 const Ci = SpecialPowers.Ci; 21 22 function checkDomainRegistration(domain, exists) { 23 return testFrame("http://" + domain + "/tests/dom/serviceworkers/test/sanitize/example_check_and_unregister.html").then(function(body) { 24 if (body === "FAIL") { 25 ok(false, "Error acquiring registration or unregistering for " + domain); 26 } else { 27 if (exists) { 28 ok(body === true, "Expected " + domain + " to still have a registration."); 29 } else { 30 ok(body === false, "Expected " + domain + " to have no registration."); 31 } 32 } 33 }); 34 } 35 36 registerSW().then(function() { 37 return testFrame("http://example.com/tests/dom/serviceworkers/test/sanitize/frame.html").then(function(body) { 38 is(body, "intercepted", "Expected serviceworker to intercept request"); 39 }); 40 }).then(function() { 41 return SpecialPowers.removeServiceWorkerDataForExampleDomain(); 42 }).then(function() { 43 return checkDomainRegistration("prefixexample.com", true /* exists */) 44 .then(function(e) { 45 return checkDomainRegistration("example.com", false /* exists */); 46 }).then(function(e) { 47 SimpleTest.finish(); 48 }); 49 }) 50 } 51 52 function testFrame(src) { 53 return new Promise(function(resolve, reject) { 54 var iframe = document.createElement("iframe"); 55 iframe.src = src; 56 window.onmessage = function(message) { 57 window.onmessage = null; 58 iframe.src = "about:blank"; 59 document.body.removeChild(iframe); 60 iframe = null; 61 SpecialPowers.exactGC(function() { 62 resolve(message.data); 63 }); 64 }; 65 document.body.appendChild(iframe); 66 }); 67 } 68 69 function registerSW() { 70 return testFrame("http://example.com/tests/dom/serviceworkers/test/sanitize/register.html") 71 .then(function(e) { 72 // Register for prefixexample.com and then ensure it does not get unregistered. 73 return testFrame("http://prefixexample.com/tests/dom/serviceworkers/test/sanitize/register.html"); 74 }); 75 } 76 77 SimpleTest.waitForExplicitFinish(); 78 79 SpecialPowers.pushPrefEnv({"set": [ 80 ["dom.serviceWorkers.exemptFromPerDomainMax", true], 81 ["dom.serviceWorkers.enabled", true], 82 ["dom.serviceWorkers.testing.enabled", true], 83 ]}, function() { 84 start(); 85 }); 86 </script> 87 </pre> 88 </body> 89 </html>