|
3 | 3 | <head>
|
4 | 4 | <script src="/resources/testharness.js"></script>
|
5 | 5 | <script src="/resources/testharnessreport.js"></script>
|
| 6 | + <script src="../service-workers/service-worker/resources/test-helpers.sub.js"></script> |
6 | 7 | <script src="support/test_utils.sub.js"></script>
|
7 | 8 | </head>
|
8 | 9 |
|
|
13 | 14 | return datatype.name == "storage";
|
14 | 15 | })[0];
|
15 | 16 |
|
| 17 | + var serviceWorkerTestPageIFrame; |
| 18 | + function fetchFromIFrame() { |
| 19 | + return serviceWorkerTestPageIFrame.contentWindow |
| 20 | + .fetch('support/controlled-endpoint.py') |
| 21 | + .then((result) => { |
| 22 | + return result.text(); |
| 23 | + }); |
| 24 | + } |
| 25 | + |
16 | 26 | // The tests are set up asynchronously.
|
17 | 27 | setup({"explicit_done": true});
|
18 | 28 |
|
|
22 | 32 | test(function() {}, "Populate backends.");
|
23 | 33 |
|
24 | 34 | TestUtils.populateStorage()
|
| 35 | + .then(() => { |
| 36 | + return new Promise(function(resolve, reject) { |
| 37 | + promise_test(function(t) { |
| 38 | + return navigator.serviceWorker.getRegistration("support/").then(function(reg) { |
| 39 | + return wait_for_state(t, reg.installing || reg.waiting || reg.active, 'activated'); |
| 40 | + }).then(resolve, reject); |
| 41 | + }); |
| 42 | + }); |
| 43 | + }) |
| 44 | + .then(() => { |
| 45 | + return new Promise(function (resolve) { |
| 46 | + // Create iFrame in the service worker's scope. This page will make a request |
| 47 | + // for another page that is only served by the service worker |
| 48 | + serviceWorkerTestPageIFrame = document.createElement("iframe"); |
| 49 | + serviceWorkerTestPageIFrame.src = "support/page_using_service_worker.html"; |
| 50 | + serviceWorkerTestPageIFrame.onload = function() { resolve(); }; |
| 51 | + document.body.appendChild(serviceWorkerTestPageIFrame); |
| 52 | + }); |
| 53 | + }) |
| 54 | + .then(() => { |
| 55 | + const serviceWorkerResponseBody = fetchFromIFrame(); |
| 56 | + |
| 57 | + promise_test(function() { |
| 58 | + return serviceWorkerResponseBody.then(function(body) { |
| 59 | + assert_equals(body, "FROM_SERVICE_WORKER", "Response should be from service worker"); |
| 60 | + }); |
| 61 | + }, "Baseline: Service worker responds to request"); |
| 62 | + |
| 63 | + return serviceWorkerResponseBody; |
| 64 | + }) |
25 | 65 | .then(function() {
|
| 66 | + const waitForControllerChange = new Promise(function(resolve) { |
| 67 | + serviceWorkerTestPageIFrame.contentWindow |
| 68 | + .navigator.serviceWorker.addEventListener("controllerchange", resolve); |
| 69 | + }); |
26 | 70 | // Navigate to a resource with a Clear-Site-Data header in
|
27 | 71 | // an iframe, then verify that all backends of the "storage"
|
28 | 72 | // datatype have been deleted.
|
|
45 | 89 | }, test_name);
|
46 | 90 | });
|
47 | 91 |
|
| 92 | + promise_test(function() { |
| 93 | + return fetchFromIFrame().then(function(body) { |
| 94 | + assert_equals(body, "FROM_NETWORK", "Response should be from network and not from the service worker"); |
| 95 | + }); |
| 96 | + }, "Service worker no longer responds to requests"); |
| 97 | + |
| 98 | + promise_test(function() { |
| 99 | + return waitForControllerChange.then(function() { |
| 100 | + assert_false(!!serviceWorkerTestPageIFrame.contentWindow.navigator.serviceWorker.controller, |
| 101 | + "Client should not have a controller"); |
| 102 | + }); |
| 103 | + }, "controllerchange event fires and client no longer has controller"); |
| 104 | + |
48 | 105 | done();
|
49 | 106 | });
|
50 | 107 | });
|
|
0 commit comments