Skip to content

Commit 42bc726

Browse files
mfalkenmoz-wptsync-bot
authored andcommitted
Bug 1456024 [wpt PR 10568] - service worker: Add importScripts() to worker interception test., a=testonly
Automatic update from web-platform-testsservice worker: Add importScripts() to worker interception test. Also remove the Firefox-specific comment as they fixed the mentioned bug. Bug: 829720 Change-Id: I76727361ff9c7d61931fbf018035917ac5aa71d8 Reviewed-on: https://chromium-review.googlesource.com/1023616 Reviewed-by: Hiroki Nakagawa <[email protected]> Commit-Queue: Matt Falkenhagen <[email protected]> Cr-Commit-Position: refs/heads/master@{#552629} -- wpt-commits: d187735e321696e116dd64ff544c254d7fa361b3 wpt-pr: 10568
1 parent 52bfaef commit 42bc726

File tree

4 files changed

+43
-20
lines changed

4 files changed

+43
-20
lines changed

testing/web-platform/meta/MANIFEST.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -599497,11 +599497,11 @@
599497599497
"support"
599498599498
],
599499599499
"service-workers/service-worker/resources/worker-interception-redirect-serviceworker.js": [
599500-
"05a2f3a4ad034b9cece10b5abc7ffff71bfcb4aa",
599500+
"ebf3c26bd9a176cf535549dc42637c92e29de4f0",
599501599501
"support"
599502599502
],
599503599503
"service-workers/service-worker/resources/worker-interception-redirect-webworker.js": [
599504-
"615f6dd41ee6f9f141132a48544f976ce0403d27",
599504+
"262e33ee28cd9a7b9081d30c438ad75f59bd84c9",
599505599505
"support"
599506599506
],
599507599507
"service-workers/service-worker/resources/worker-load-interceptor.js": [
@@ -599657,7 +599657,7 @@
599657599657
"testharness"
599658599658
],
599659599659
"service-workers/service-worker/worker-interception-redirect.https.html": [
599660-
"8654d94e9797ac332bedcadeed61837ccf13b944",
599660+
"2e5bd64ed27fb4cc63aba9859565d506a829871e",
599661599661
"testharness"
599662599662
],
599663599663
"service-workers/service-worker/worker-interception.https.html": [

testing/web-platform/tests/service-workers/service-worker/resources/worker-interception-redirect-serviceworker.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,18 @@ self.addEventListener('fetch', evt => {
3131
return;
3232
}
3333

34-
// (3) The worker does a fetch() to simple.txt. Indicate that this service
34+
// (3) The worker does an importScripts() to import-scripts-echo.py. Indicate
35+
// that this service worker handled the request.
36+
if (evt.request.url.indexOf('import-scripts-echo.py') != -1) {
37+
const msg = encodeURIComponent(`${name} saw importScripts from the worker`);
38+
evt.respondWith(fetch(`import-scripts-echo.py?msg=${msg}`));
39+
return;
40+
}
41+
42+
// (4) The worker does a fetch() to simple.txt. Indicate that this service
3543
// worker handled the request.
3644
if (evt.request.url.indexOf('simple.txt') != -1) {
3745
evt.respondWith(new Response(`${name} saw the fetch from the worker`));
46+
return;
3847
}
3948
});

testing/web-platform/tests/service-workers/service-worker/resources/worker-interception-redirect-webworker.js

+12
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,23 @@ let greeting = '%GREETING_TEXT%';
1818
if (!greeting)
1919
greeting = 'the shared worker script was served from network';
2020

21+
// Call importScripts() which fills |echo_output| with a string indicating
22+
// whether a service worker intercepted the importScripts() request.
23+
let echo_output;
24+
const import_scripts_msg = encodeURIComponent(
25+
'importScripts: served from network');
26+
const import_scripts_url =
27+
new URL(`import-scripts-echo.py?msg=${import_scripts_msg}`, resources_url);
28+
importScripts(import_scripts_url);
29+
const import_scripts_greeting = echo_output;
30+
2131
self.onconnect = async function(e) {
2232
const port = e.ports[0];
2333
port.start();
2434
port.postMessage(greeting);
2535

36+
port.postMessage(import_scripts_greeting);
37+
2638
const fetch_url = new URL('simple.txt', resources_url);
2739
const response = await fetch(fetch_url);
2840
const text = await response.text();

testing/web-platform/tests/service-workers/service-worker/worker-interception-redirect.https.html

+18-16
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
// 3. The request is redirected to scope2 or out-of-scope.
3333
// 4. The worker posts message to the page describing where the final response
3434
// 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.
3737
//
3838
// Currently this only tests shared worker but dedicated worker tests should be
3939
// added in a future patch.
@@ -109,7 +109,8 @@
109109

110110
function worker_redirect_test(worker_url,
111111
expected_main_resource_message,
112-
expected_subresource_message,
112+
expected_import_scripts_message,
113+
expected_fetch_message,
113114
description) {
114115
promise_test(async t => {
115116
// Create a frame to load the worker from. This way we can remove the frame
@@ -126,43 +127,44 @@
126127
const data = await get_message_from_worker(w);
127128
assert_equals(data, expected_main_resource_message);
128129

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);
142140
}, description);
143141
}
144142

145143
worker_redirect_test(
146144
build_worker_url('network', 'scope2'),
147145
'the shared worker script was served from network',
146+
'sw1 saw importScripts from the worker',
148147
'fetch(): sw1 saw the fetch from the worker',
149148
'request to sw1 scope gets network redirect to sw2 scope');
150149

151150
worker_redirect_test(
152151
build_worker_url('network', 'out-scope'),
153152
'the shared worker script was served from network',
153+
'sw1 saw importScripts from the worker',
154154
'fetch(): sw1 saw the fetch from the worker',
155155
'request to sw1 scope gets network redirect to out-of-scope');
156156

157157
worker_redirect_test(
158158
build_worker_url('serviceworker', 'scope2'),
159159
'sw2 saw the request for the worker script',
160+
'sw2 saw importScripts from the worker',
160161
'fetch(): sw2 saw the fetch from the worker',
161162
'request to sw1 scope gets service-worker redirect to sw2 scope');
162163

163164
worker_redirect_test(
164165
build_worker_url('serviceworker', 'out-scope'),
165166
'the shared worker script was served from network',
167+
'sw1 saw importScripts from the worker',
166168
'fetch(): sw1 saw the fetch from the worker',
167169
'request to sw1 scope gets service-worker redirect to out-of-scope');
168170
</script>

0 commit comments

Comments
 (0)