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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/windowclient-navigate-worker.js

Issue 2906963002: Upstream service wrkr "window client" test to WPT (Closed)
Patch Set: Created 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 function match_query(query_string) {
2 return self.location.search.substr(1) == query_string;
3 }
4
5 function navigate_test(e) {
6 var port = e.data.port;
7 var url = e.data.url;
8
9 return clients.matchAll({ includeUncontrolled : true })
10 .then(function(client_list) {
11 for (var i = 0; i < client_list.length; i++) {
12 var client = client_list[i];
13 if (client.frameType == 'nested') {
14 return client.navigate(url);
15 }
16 }
17 port.postMessage('Could not locate window client.');
18 })
19 .then(function(new_client) {
20 if (new_client === null)
21 port.postMessage(new_client);
22 else
23 port.postMessage(new_client.url);
24 })
25 .catch(function(error) {
26 port.postMessage(error.name);
27 });
28 }
29
30 function getTestClient() {
31 return clients.matchAll({ includeUncontrolled: true })
32 .then(function(client_list) {
33 var client, idx;
falken 2017/05/29 04:54:08 nit: idx -> i for consistency with above
mike3 2017/05/29 17:00:49 Done.
34
35 for (idx = 0; idx < client_list.length; ++idx) {
falken 2017/05/29 04:54:08 nit: ++idx -> i++ for consistency with above
mike3 2017/05/29 17:00:50 Done.
36 client = client_list[idx];
37
38 if (/windowclient-navigate\.https\.html/.test(client.url)) {
39 return client;
40 }
41 }
42
43 throw new Error('Service worker was unable to locate test client.');
44 });
45 }
46
47 function waitForMessage(client) {
48 var channel = new MessageChannel();
49 client.postMessage({ port: channel.port2 }, [channel.port2]);
50
51 return new Promise(function(resolve) {
52 channel.port1.onmessage = resolve;
53 });
54 }
55
56 // The worker must remain in the "installing" state for the duration of some
57 // sub-tests. In order to achieve this coordination without relying on global
58 // state, the worker must create a message channel with the client from within
59 // the "install" event handler.
60 if (match_query('installing')) {
61 self.addEventListener('install', function(e) {
62 e.waitUntil(getTestClient().then(waitForMessage));
63 });
64 }
65
66 self.addEventListener('message', function(e) {
67 e.waitUntil(navigate_test(e));
68 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698