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

Unified Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/foreign-fetch-helpers.js

Issue 2676733002: Upstream foreign fetch tests. (Closed)
Patch Set: rebase Created 3 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/external/wpt/service-workers/service-worker/resources/foreign-fetch-helpers.js
diff --git a/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/foreign-fetch-helpers.js b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/foreign-fetch-helpers.js
new file mode 100644
index 0000000000000000000000000000000000000000..e1831ed173c125027d5364e213da2f95b01fa6a9
--- /dev/null
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/foreign-fetch-helpers.js
@@ -0,0 +1,44 @@
+// Common helper functions for foreign fetch tests.
+
+// Installs a service worker on a different origin. Both |worker| and |scope|
+// are resolved relative to the /service-workers/service-worker/resources/
+// directory on a remote origin.
+function install_cross_origin_worker(
+ t, worker, scope, origin = get_host_info().HTTPS_REMOTE_ORIGIN) {
+ return with_iframe(origin + new URL('resources/install-worker-helper.html', location).pathname)
+ .then(frame => new Promise((resolve, reject) => {
+ frame.contentWindow.postMessage({worker: worker,
+ options: {scope: scope}},
+ '*');
+ window.addEventListener('message', reply => {
+ if (reply.source != frame.contentWindow) return;
+ if (reply.data == 'success') resolve();
+ else reject(reply.data);
+ });
+ }));
+}
+
+// Performs a fetch from a different origin. By default this performs a fetch
+// from a window on that origin, but if |worker_type| is 'dedicated' or 'shared'
+// the fetch is made from a worker on that origin instead.
+// This uses a window rather than an iframe because an iframe might get blocked
+// by mixed content checks.
+function fetch_from_different_origin(origin, url, worker_type) {
+ const win = open(origin + new URL('resources/foreign-fetch-helper-iframe.html', location).pathname);
+ return new Promise(resolve => {
+ self.addEventListener('message', e => {
+ if (e.source != win) return;
+ resolve();
+ });
+ })
+ .then(() => new Promise((resolve) => {
+ const channel = new MessageChannel();
+ win.postMessage({url: url,
+ worker: worker_type},
+ '*', [channel.port1]);
+ channel.port2.onmessage = reply => {
+ win.close();
+ resolve(reply.data);
+ };
+ }));
+}

Powered by Google App Engine
This is Rietveld 408576698