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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Common helper functions for foreign fetch tests.
2
3 // Installs a service worker on a different origin. Both |worker| and |scope|
4 // are resolved relative to the /service-workers/service-worker/resources/
5 // directory on a remote origin.
6 function install_cross_origin_worker(
7 t, worker, scope, origin = get_host_info().HTTPS_REMOTE_ORIGIN) {
8 return with_iframe(origin + new URL('resources/install-worker-helper.html', lo cation).pathname)
9 .then(frame => new Promise((resolve, reject) => {
10 frame.contentWindow.postMessage({worker: worker,
11 options: {scope: scope}},
12 '*');
13 window.addEventListener('message', reply => {
14 if (reply.source != frame.contentWindow) return;
15 if (reply.data == 'success') resolve();
16 else reject(reply.data);
17 });
18 }));
19 }
20
21 // Performs a fetch from a different origin. By default this performs a fetch
22 // from a window on that origin, but if |worker_type| is 'dedicated' or 'shared'
23 // the fetch is made from a worker on that origin instead.
24 // This uses a window rather than an iframe because an iframe might get blocked
25 // by mixed content checks.
26 function fetch_from_different_origin(origin, url, worker_type) {
27 const win = open(origin + new URL('resources/foreign-fetch-helper-iframe.html' , location).pathname);
28 return new Promise(resolve => {
29 self.addEventListener('message', e => {
30 if (e.source != win) return;
31 resolve();
32 });
33 })
34 .then(() => new Promise((resolve) => {
35 const channel = new MessageChannel();
36 win.postMessage({url: url,
37 worker: worker_type},
38 '*', [channel.port1]);
39 channel.port2.onmessage = reply => {
40 win.close();
41 resolve(reply.data);
42 };
43 }));
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698