Commit ed55940b authored by Hiroshige Hayashizaki's avatar Hiroshige Hayashizaki Committed by Commit Bot

Add tests for worker's URLs intercepted by ServiceWorker

This CL checks worker global scopes' URLs (self.location) in the
cases where worker top-level scripts are intercepted by
ServiceWorkers.

The test failure introduced in this CL will be fixed by
https://chromium-review.googlesource.com/1153598.

Bug: 861564
Change-Id: Ia92e1de697b5b9c6a61ab8e5c5abcaaf6dcee777
Reviewed-on: https://chromium-review.googlesource.com/1157220Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580041}
parent 0b64c025
...@@ -39,4 +39,6 @@ self.onconnect = async function(e) { ...@@ -39,4 +39,6 @@ self.onconnect = async function(e) {
const response = await fetch(fetch_url); const response = await fetch(fetch_url);
const text = await response.text(); const text = await response.text();
port.postMessage('fetch(): ' + text); port.postMessage('fetch(): ' + text);
port.postMessage(self.location.href);
}; };
...@@ -2,7 +2,7 @@ This is a testharness.js-based test. ...@@ -2,7 +2,7 @@ This is a testharness.js-based test.
PASS initialize global state PASS initialize global state
FAIL request to sw1 scope gets network redirect to sw2 scope assert_equals: expected "the shared worker script was served from network" but got "sw2 saw the request for the worker script" FAIL request to sw1 scope gets network redirect to sw2 scope assert_equals: expected "the shared worker script was served from network" but got "sw2 saw the request for the worker script"
FAIL request to sw1 scope gets network redirect to out-of-scope assert_equals: expected "sw1 saw importScripts from the worker" but got "importScripts: served from network" FAIL request to sw1 scope gets network redirect to out-of-scope assert_equals: expected "sw1 saw importScripts from the worker" but got "importScripts: served from network"
PASS request to sw1 scope gets service-worker redirect to sw2 scope FAIL request to sw1 scope gets service-worker redirect to sw2 scope assert_equals: location.href expected "https://web-platform.test:8444/service-workers/service-worker/resources/worker_interception_redirect_webworker.py?greeting=sw2%20saw%20the%20request%20for%20the%20worker%20script" but got "https://web-platform.test:8444/service-workers/service-worker/resources/scope2/worker_interception_redirect_webworker.py"
FAIL request to sw1 scope gets service-worker redirect to out-of-scope assert_equals: expected "sw1 saw importScripts from the worker" but got "importScripts: served from network" FAIL request to sw1 scope gets service-worker redirect to out-of-scope assert_equals: expected "sw1 saw importScripts from the worker" but got "importScripts: served from network"
PASS cleanup global state PASS cleanup global state
Harness: the test ran to completion. Harness: the test ran to completion.
......
...@@ -107,7 +107,8 @@ promise_test(async t => { ...@@ -107,7 +107,8 @@ promise_test(async t => {
}, 'cleanup global state'); }, 'cleanup global state');
}, 'initialize global state'); }, 'initialize global state');
function worker_redirect_test(worker_url, function worker_redirect_test(worker_request_url,
worker_expected_url,
expected_main_resource_message, expected_main_resource_message,
expected_import_scripts_message, expected_import_scripts_message,
expected_fetch_message, expected_fetch_message,
...@@ -119,7 +120,7 @@ function worker_redirect_test(worker_url, ...@@ -119,7 +120,7 @@ function worker_redirect_test(worker_url,
t.add_cleanup(() => { frame.remove(); }); t.add_cleanup(() => { frame.remove(); });
// Start the worker. // Start the worker.
const w = new frame.contentWindow.SharedWorker(worker_url); const w = new frame.contentWindow.SharedWorker(worker_request_url);
w.port.start(); w.port.start();
// Expect a message from the worker indicating which service worker // Expect a message from the worker indicating which service worker
...@@ -137,11 +138,19 @@ function worker_redirect_test(worker_url, ...@@ -137,11 +138,19 @@ function worker_redirect_test(worker_url,
// which service worker provided the response for the fetch(), if any. // which service worker provided the response for the fetch(), if any.
const fetch_message = await get_message_from_worker(w); const fetch_message = await get_message_from_worker(w);
assert_equals(fetch_message, expected_fetch_message); assert_equals(fetch_message, expected_fetch_message);
// Expect a message from the worker indicating |self.location|.
const worker_actual_url = await get_message_from_worker(w);
assert_equals(
worker_actual_url,
(new URL(worker_expected_url, location.href)).toString(),
'location.href');
}, description); }, description);
} }
worker_redirect_test( worker_redirect_test(
build_worker_url('network', 'scope2'), build_worker_url('network', 'scope2'),
'resources/scope2/worker_interception_redirect_webworker.py',
'the shared worker script was served from network', 'the shared worker script was served from network',
'sw1 saw importScripts from the worker', 'sw1 saw importScripts from the worker',
'fetch(): sw1 saw the fetch from the worker', 'fetch(): sw1 saw the fetch from the worker',
...@@ -149,6 +158,7 @@ worker_redirect_test( ...@@ -149,6 +158,7 @@ worker_redirect_test(
worker_redirect_test( worker_redirect_test(
build_worker_url('network', 'out-scope'), build_worker_url('network', 'out-scope'),
'resources/worker_interception_redirect_webworker.py',
'the shared worker script was served from network', 'the shared worker script was served from network',
'sw1 saw importScripts from the worker', 'sw1 saw importScripts from the worker',
'fetch(): sw1 saw the fetch from the worker', 'fetch(): sw1 saw the fetch from the worker',
...@@ -156,6 +166,7 @@ worker_redirect_test( ...@@ -156,6 +166,7 @@ worker_redirect_test(
worker_redirect_test( worker_redirect_test(
build_worker_url('serviceworker', 'scope2'), build_worker_url('serviceworker', 'scope2'),
'resources/worker_interception_redirect_webworker.py?greeting=sw2%20saw%20the%20request%20for%20the%20worker%20script',
'sw2 saw the request for the worker script', 'sw2 saw the request for the worker script',
'sw2 saw importScripts from the worker', 'sw2 saw importScripts from the worker',
'fetch(): sw2 saw the fetch from the worker', 'fetch(): sw2 saw the fetch from the worker',
...@@ -163,6 +174,7 @@ worker_redirect_test( ...@@ -163,6 +174,7 @@ worker_redirect_test(
worker_redirect_test( worker_redirect_test(
build_worker_url('serviceworker', 'out-scope'), build_worker_url('serviceworker', 'out-scope'),
'resources/worker_interception_redirect_webworker.py',
'the shared worker script was served from network', 'the shared worker script was served from network',
'sw1 saw importScripts from the worker', 'sw1 saw importScripts from the worker',
'fetch(): sw1 saw the fetch from the worker', 'fetch(): sw1 saw the fetch from the worker',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment