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

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

Issue 1656933003: Add origins argument to registerForeignFetchScopes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add url::Origin::operator== to make tests simpler Created 4 years, 10 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 0332746d1f80aa14dba0dafa0de10a739951547f..e51fd6bf26971a3fce3344dfa9eb751e50153b93 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
@@ -4,11 +4,15 @@
<script src="resources/test-helpers.js"></script>
<body>
<script>
-var worker = 'resources/foreign-fetch-worker.js';
+function worker_for_origins(origins) {
+ var worker = 'resources/foreign-fetch-worker.js?';
+ return worker + encodeURIComponent(JSON.stringify(origins));
+}
promise_test(t => {
var scope = 'resources/foreign-fetch/scope';
- return service_worker_unregister_and_register(t, worker, 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');
@@ -22,6 +26,51 @@ promise_test(t => {
.then(response_text => {
assert_equals(response_text, 'Foreign Fetch');
});
- }, 'Service Worker intercepts fetches in scope.');
+ }, '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(
+ 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(response => response.text())
+ .then(response_text => {
+ assert_equals(response_text, 'Foreign Fetch');
+ });
+ }, '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(
+ 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);
+ });
+ }, '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(
+ 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(response => response.text())
+ .then(response_text => {
+ assert_equals(response_text, 'Foreign Fetch');
+ });
+ }, 'Service Worker intercepts fetches in scope with explicit origin list.');
+
</script>
</body>

Powered by Google App Engine
This is Rietveld 408576698