|
32 | 32 | // 3. The request is redirected to scope2 or out-of-scope.
|
33 | 33 | // 4. The worker posts message to the page describing where the final response
|
34 | 34 | // was served from (service worker or network).
|
35 |
| -// 5. The worker does a fetch(), and posts back the response, which describes |
36 |
| -// where the fetch response was served from. |
| 35 | +// 5. The worker does an importScripts() and fetch(), and posts back the |
| 36 | +// responses, which describe where the responses where served from. |
37 | 37 | //
|
38 | 38 | // Currently this only tests shared worker but dedicated worker tests should be
|
39 | 39 | // added in a future patch.
|
|
109 | 109 |
|
110 | 110 | function worker_redirect_test(worker_url,
|
111 | 111 | expected_main_resource_message,
|
112 |
| - expected_subresource_message, |
| 112 | + expected_import_scripts_message, |
| 113 | + expected_fetch_message, |
113 | 114 | description) {
|
114 | 115 | promise_test(async t => {
|
115 | 116 | // Create a frame to load the worker from. This way we can remove the frame
|
|
126 | 127 | const data = await get_message_from_worker(w);
|
127 | 128 | assert_equals(data, expected_main_resource_message);
|
128 | 129 |
|
129 |
| - // The worker does a fetch() after it starts up. Expect a message from the |
130 |
| - // worker indicating which service worker provided the response for the |
131 |
| - // fetch(), if any. |
132 |
| - // |
133 |
| - // Note: for some reason, Firefox would pass all these tests if a |
134 |
| - // postMessage ping/pong step is added before the fetch(). I.e., if the |
135 |
| - // page does postMessage() and the worker does fetch() in response to the |
136 |
| - // ping, the fetch() is properly intercepted. See |
137 |
| - // https://bugzilla.mozilla.org/show_bug.cgi?id=1452528. (Chrome can't pass |
138 |
| - // the tests either way.) |
139 |
| - const message = get_message_from_worker(w); |
140 |
| - const data2 = await message; |
141 |
| - assert_equals(data2, expected_subresource_message); |
| 130 | + // The worker does an importScripts(). Expect a message from the worker |
| 131 | + // indicating which service worker provided the response for the |
| 132 | + // importScripts(), if any. |
| 133 | + const import_scripts_message = await get_message_from_worker(w); |
| 134 | + assert_equals(import_scripts_message, expected_import_scripts_message); |
| 135 | + |
| 136 | + // The worker does a fetch(). Expect a message from the worker indicating |
| 137 | + // which service worker provided the response for the fetch(), if any. |
| 138 | + const fetch_message = await get_message_from_worker(w); |
| 139 | + assert_equals(fetch_message, expected_fetch_message); |
142 | 140 | }, description);
|
143 | 141 | }
|
144 | 142 |
|
145 | 143 | worker_redirect_test(
|
146 | 144 | build_worker_url('network', 'scope2'),
|
147 | 145 | 'the shared worker script was served from network',
|
| 146 | + 'sw1 saw importScripts from the worker', |
148 | 147 | 'fetch(): sw1 saw the fetch from the worker',
|
149 | 148 | 'request to sw1 scope gets network redirect to sw2 scope');
|
150 | 149 |
|
151 | 150 | worker_redirect_test(
|
152 | 151 | build_worker_url('network', 'out-scope'),
|
153 | 152 | 'the shared worker script was served from network',
|
| 153 | + 'sw1 saw importScripts from the worker', |
154 | 154 | 'fetch(): sw1 saw the fetch from the worker',
|
155 | 155 | 'request to sw1 scope gets network redirect to out-of-scope');
|
156 | 156 |
|
157 | 157 | worker_redirect_test(
|
158 | 158 | build_worker_url('serviceworker', 'scope2'),
|
159 | 159 | 'sw2 saw the request for the worker script',
|
| 160 | + 'sw2 saw importScripts from the worker', |
160 | 161 | 'fetch(): sw2 saw the fetch from the worker',
|
161 | 162 | 'request to sw1 scope gets service-worker redirect to sw2 scope');
|
162 | 163 |
|
163 | 164 | worker_redirect_test(
|
164 | 165 | build_worker_url('serviceworker', 'out-scope'),
|
165 | 166 | 'the shared worker script was served from network',
|
| 167 | + 'sw1 saw importScripts from the worker', |
166 | 168 | 'fetch(): sw1 saw the fetch from the worker',
|
167 | 169 | 'request to sw1 scope gets service-worker redirect to out-of-scope');
|
168 | 170 | </script>
|
|
0 commit comments