Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html |
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html |
index 4ad709756001efe51581ac860ee851e53ad7f623..a62891f380a37c6f0eea790f59ffb2b69165a0c1 100644 |
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html |
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html |
@@ -1,27 +1,49 @@ |
<!DOCTYPE html> |
<script src="../resources/testharness.js"></script> |
<script src="../resources/testharnessreport.js"></script> |
+<script src="../resources/get-host-info.js"></script> |
<script src="resources/test-helpers.js"></script> |
<body> |
<script> |
+var host_info = get_host_info(); |
+ |
function worker_for_origins(origins) { |
- var worker = 'resources/foreign-fetch-worker.js?'; |
+ var worker = 'foreign-fetch-worker.js?'; |
return worker + encodeURIComponent(JSON.stringify(origins)); |
} |
+function install_cross_origin_worker(t, worker, scope) { |
+ return with_iframe(host_info.HTTPS_REMOTE_ORIGIN + |
+ '/serviceworker/resources/install-worker-helper.html') |
+ .then(frame => new Promise((resolve, reject) => { |
+ var channel = new MessageChannel(); |
+ frame.contentWindow.postMessage({worker: worker, |
+ options: {scope: scope}, |
+ port: channel.port1}, |
+ '*', [channel.port1]); |
+ channel.port2.onmessage = reply => { |
+ if (reply.data == 'success') resolve(); |
+ else reject(reply.data); |
+ }; |
+ })); |
+} |
+ |
+function intercepted_url(scope) { |
+ return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + |
+ scope + '/intercept/foo'; |
+} |
+ |
+function non_intercepted_url(scope) { |
+ return host_info.HTTPS_REMOTE_ORIGIN + '/serviceworker/resources/' + |
+ scope + '/foo'; |
+} |
+ |
promise_test(t => { |
- var scope = 'resources/foreign-fetch/scope'; |
- return service_worker_unregister_and_register( |
- t, worker_for_origins(['*']), scope) |
- .then(r => { |
- add_completion_callback(() => r.unregister()); |
- return wait_for_state(t, r.installing, 'activated'); |
- }) |
- .then(() => fetch(scope + '/foo')) |
- .then(response => { |
- assert_equals(response.status, 404); |
- return fetch(scope + '/intercept/foo'); |
- }) |
+ var scope = 'foreign-fetch/scope/wildcard'; |
+ return install_cross_origin_worker(t, worker_for_origins(['*']), scope) |
+ .then(() => promise_rejects(t, new TypeError(), |
+ fetch(non_intercepted_url(scope)))) |
+ .then(() => fetch(intercepted_url(scope))) |
.then(response => response.text()) |
.then(response_text => { |
assert_equals(response_text, 'Foreign Fetch'); |
@@ -29,14 +51,10 @@ promise_test(t => { |
}, 'Service Worker intercepts fetches in scope with wildcard origin.'); |
promise_test(t => { |
- var scope = 'resources/foreign-fetch/scope/match-origin'; |
- return service_worker_unregister_and_register( |
+ var scope = 'foreign-fetch/scope/match-origin'; |
+ return install_cross_origin_worker( |
t, worker_for_origins([location.origin]), scope) |
- .then(r => { |
- add_completion_callback(() => r.unregister()); |
- return wait_for_state(t, r.installing, 'activated'); |
- }) |
- .then(() => fetch(scope + '/intercept/foo')) |
+ .then(() => fetch(intercepted_url(scope))) |
.then(response => response.text()) |
.then(response_text => { |
assert_equals(response_text, 'Foreign Fetch'); |
@@ -44,28 +62,18 @@ promise_test(t => { |
}, 'Service Worker intercepts fetches in scope with explicit origin.'); |
promise_test(t => { |
- var scope = 'resources/foreign-fetch/scope/nomatch-origin'; |
- return service_worker_unregister_and_register( |
+ var scope = 'foreign-fetch/scope/nomatch-origin'; |
+ return install_cross_origin_worker( |
t, worker_for_origins(['https://example.com']), scope) |
- .then(r => { |
- add_completion_callback(() => r.unregister()); |
- return wait_for_state(t, r.installing, 'activated'); |
- }) |
- .then(() => fetch(scope + '/intercept/foo')) |
- .then(response => { |
- assert_equals(response.status, 404); |
- }); |
+ .then(() => promise_rejects(t, new TypeError(), |
+ fetch(non_intercepted_url(scope)))); |
}, 'Service Worker doesn\'t intercept fetches with non matching origin.'); |
promise_test(t => { |
- var scope = 'resources/foreign-fetch/scope/origin-list'; |
- return service_worker_unregister_and_register( |
+ var scope = 'foreign-fetch/scope/origin-list'; |
+ return install_cross_origin_worker( |
t, worker_for_origins([location.origin, 'https://example.com']), scope) |
- .then(r => { |
- add_completion_callback(() => r.unregister()); |
- return wait_for_state(t, r.installing, 'activated'); |
- }) |
- .then(() => fetch(scope + '/intercept/foo')) |
+ .then(() => fetch(intercepted_url(scope))) |
.then(response => response.text()) |
.then(response_text => { |
assert_equals(response_text, 'Foreign Fetch'); |