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

Unified Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/foreign-fetch-cors-worker.js

Issue 1969403004: Expose and check origin of request in response for foreign fetch. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@set-request-and-credentials-mode
Patch Set: update layouttests Created 4 years, 7 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/resources/foreign-fetch-cors-worker.js
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/foreign-fetch-cors-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/foreign-fetch-cors-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..1b819ceed2a09fb046f14968a6b080f55e749a6d
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/foreign-fetch-cors-worker.js
@@ -0,0 +1,30 @@
+importScripts('../../resources/get-host-info.js');
+var host_info = get_host_info();
+
+self.addEventListener('install', function(event) {
+ event.registerForeignFetch({scopes: [registration.scope], origins: ['*']});
+ });
+
+self.addEventListener('foreignfetch', function(event) {
+ var response = JSON.parse(decodeURIComponent(location.search.substring(1)));
+ var url = new URL(event.request.url);
+ var params = JSON.parse(decodeURIComponent(url.search.substring(1)));
+ var url_to_fetch = 'fetch-access-control.php?';
+ if (params.cross_origin) {
+ url_to_fetch =
+ host_info.HTTPS_ORIGIN + '/serviceworker/resources/' + url_to_fetch;
+ }
+ if (params.with_aceheaders)
+ url_to_fetch += 'ACEHeaders=X-ServiceWorker-ServerHeader&';
+ if (params.with_acaorigin)
+ url_to_fetch += 'ACAOrigin=*';
+ fetch_params = {};
+ if (params.cross_origin && !params.with_acaorigin)
+ fetch_params.mode = 'no-cors';
+ event.respondWith(fetch(url_to_fetch, fetch_params)
+ .then(r => {
+ response.response = r;
+ return response;
+ }));
+ return;
+ });

Powered by Google App Engine
This is Rietveld 408576698