Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/foreign-fetch-basics.html

Issue 1870743002: Foreign fetch should not intercept same origin or main resource requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add same origin test, and unregister service workers in tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d8b88426621cd209e4f0cbee1fea4ae0b6633dcc 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,33 +62,37 @@ 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(() => fetch(intercepted_url(scope)))
+ .then(response => response.text())
+ .then(response_text => {
+ assert_equals(response_text, 'Foreign Fetch');
+ });
+ }, 'Service Worker intercepts fetches in scope with explicit origin list.');
+
+promise_test(t => {
+ var scope = 'resources/foreign-fetch/smae-origin';
falken 2016/04/14 01:22:51 nit: same-origin
+ return service_worker_unregister_and_register(
+ t, 'resources/' + worker_for_origins(['*']), scope)
.then(r => {
add_completion_callback(() => r.unregister());
return wait_for_state(t, r.installing, 'activated');
})
.then(() => fetch(scope + '/intercept/foo'))
- .then(response => response.text())
- .then(response_text => {
- assert_equals(response_text, 'Foreign Fetch');
+ .then(response => {
+ assert_equals(response.status, 404);
});
- }, 'Service Worker intercepts fetches in scope with explicit origin list.');
+ }, 'Service Worker does not intercept same origin fetches.');
</script>
</body>

Powered by Google App Engine
This is Rietveld 408576698