local-url-inherit-controller.https.html (3993B)
1 <!DOCTYPE html> 2 <title>Service Worker: local URL windows and workers inherit controller</title> 3 <meta name=timeout content=long> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/common/get-host-info.sub.js"></script> 7 <script src="resources/test-helpers.sub.js"></script> 8 <body> 9 <script> 10 11 const SCRIPT = 'resources/local-url-inherit-controller-worker.js'; 12 const SCOPE = 'resources/local-url-inherit-controller-frame.html'; 13 14 async function doAsyncTest(t, opts) { 15 let name = `${opts.scheme}-${opts.child}-${opts.check}`; 16 let scope = SCOPE + '?name=' + name; 17 let reg = await service_worker_unregister_and_register(t, SCRIPT, scope); 18 add_completion_callback(_ => reg.unregister()); 19 await wait_for_state(t, reg.installing, 'activated'); 20 21 let frame = await with_iframe(scope); 22 add_completion_callback(_ => frame.remove()); 23 assert_not_equals(frame.contentWindow.navigator.serviceWorker.controller, null, 24 'frame should be controlled'); 25 26 let result = await frame.contentWindow.checkChildController(opts); 27 result = result.data; 28 29 let expect = 'unexpected'; 30 if (opts.check === 'controller') { 31 expect = opts.expect === 'inherit' 32 ? frame.contentWindow.navigator.serviceWorker.controller.scriptURL 33 : null; 34 } else if (opts.check === 'fetch') { 35 // The service worker FetchEvent handler will provide an "intercepted" 36 // body. If the local URL ends up with an opaque origin and is not 37 // intercepted then it will get an opaque Response. In that case it 38 // should see an empty string body. 39 expect = opts.expect === 'intercept' ? 'intercepted' : ''; 40 } 41 42 assert_equals(result, expect, 43 `${opts.scheme} URL ${opts.child} should ${opts.expect} ${opts.check}`); 44 } 45 46 promise_test(function(t) { 47 return doAsyncTest(t, { 48 scheme: 'blob', 49 child: 'iframe', 50 check: 'controller', 51 expect: 'inherit', 52 }); 53 }, 'Same-origin blob URL iframe should inherit service worker controller.'); 54 55 promise_test(function(t) { 56 return doAsyncTest(t, { 57 scheme: 'blob', 58 child: 'iframe', 59 check: 'fetch', 60 expect: 'intercept', 61 }); 62 }, 'Same-origin blob URL iframe should intercept fetch().'); 63 64 promise_test(function(t) { 65 return doAsyncTest(t, { 66 scheme: 'blob', 67 child: 'worker', 68 check: 'controller', 69 expect: 'inherit', 70 }); 71 }, 'Same-origin blob URL worker should inherit service worker controller.'); 72 73 promise_test(function(t) { 74 return doAsyncTest(t, { 75 scheme: 'blob', 76 child: 'worker', 77 check: 'fetch', 78 expect: 'intercept', 79 }); 80 }, 'Same-origin blob URL worker should intercept fetch().'); 81 82 promise_test(function(t) { 83 return doAsyncTest(t, { 84 scheme: 'blob', 85 child: 'sharedworker', 86 check: 'controller', 87 expect: 'inherit', 88 }); 89 }, 'Same-origin blob URL sharedworker should inherit service worker controller.'); 90 91 promise_test(function(t) { 92 return doAsyncTest(t, { 93 scheme: 'blob', 94 child: 'sharedworker', 95 check: 'fetch', 96 expect: 'intercept', 97 }); 98 }, 'Same-origin blob URL sharedworker should intercept fetch().'); 99 100 promise_test(function(t) { 101 return doAsyncTest(t, { 102 scheme: 'data', 103 child: 'iframe', 104 check: 'fetch', 105 expect: 'not intercept', 106 }); 107 }, 'Data URL iframe should not intercept fetch().'); 108 109 promise_test(function(t) { 110 // Data URLs should result in an opaque origin and should probably not 111 // have access to a cross-origin service worker. See: 112 // 113 // https://github.com/w3c/ServiceWorker/issues/1262 114 // 115 return doAsyncTest(t, { 116 scheme: 'data', 117 child: 'worker', 118 check: 'controller', 119 expect: 'not inherit', 120 }); 121 }, 'Data URL worker should not inherit service worker controller.'); 122 123 promise_test(function(t) { 124 return doAsyncTest(t, { 125 scheme: 'data', 126 child: 'worker', 127 check: 'fetch', 128 expect: 'not intercept', 129 }); 130 }, 'Data URL worker should not intercept fetch().'); 131 132 </script> 133 </body>