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

Side by Side Diff: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js

Issue 1604893002: ServiceWorker: Rewrite windowclient-navigate.html test. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/windowclient-navigate.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var port = null; 1 function match_query(query_string) {
2 return self.location.search.substr(1) == query_string;
3 }
2 4
3 self.onmessage = function(e) { 5 function receive_event(event_name) {
4 port = e.data.port; 6 return new Promise(function(resolve) {
5 port.onmessage = on_message; 7 self.addEventListener(event_name, resolve, false);
6 port.postMessage('ready');
7 };
8
9 function on_message(e) {
10 var url = e.data;
11 var client;
12
13 self.clients.matchAll({ includeUncontrolled : true }).then(function(cs) {
14 cs.forEach(function(c) { c.frameType == 'nested' && (client = c); });
15 return client.navigate(url);
16 })
17 .then(function(c) {
18 if (!c)
19 port.postMessage(c);
20 else
21 port.postMessage(c.url);
22 })
23 .catch(function(e) {
24 port.postMessage(e.name);
25 }); 8 });
26 } 9 }
10
11 function get_test_data() {
12 return receive_event('message');
13 }
14
15 function navigate_test(e) {
16 var port = e.data.port;
17 var url = e.data.url;
18
19 return clients.matchAll({ includeUncontrolled : true })
20 .then(function(client_list) {
21 for (var i = 0; i < client_list.length; i++) {
22 var client = client_list[i];
23 if (client.frameType == 'nested') {
24 return client.navigate(url);
25 }
26 }
27 port.postMessage('Could not found window client.');
28 })
29 .then(function(new_client) {
30 if (new_client === null)
31 port.postMessage(new_client);
32 else
33 port.postMessage(new_client.url);
34 })
35 .catch(function(error) {
36 port.postMessage(error.name);
37 });
38 }
39
40 receive_event('install').then(function(e) {
41 if (match_query('installing'))
42 e.waitUntil(get_test_data().then(navigate_test));
43 });
44
45 receive_event('activate').then(function(e) {
46 if (match_query('activating')) {
47 // TODO(zino): Should do test in this case.
48 }
49 get_test_data().then(navigate_test);
nhiroki 2016/02/01 07:13:55 Hmmm... there could be deadlock. e.waitUntil(get_
zino 2016/02/02 15:58:31 I have some questions. (1) Can the fetch event be
nhiroki 2016/02/08 04:37:15 No. When the worker is in installed/activating sta
50 });
51
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/windowclient-navigate.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698