Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js |
| diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js |
| index b155d62f92a725a13da45f4fc94aeb58615e8641..80b8ad876f249271bd63eb96317f793cea51a115 100644 |
| --- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js |
| +++ b/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/windowclient-navigate-worker.js |
| @@ -1,26 +1,46 @@ |
| -var port = null; |
| +function match_query(query_string) { |
| + return self.location.search.substr(1) == query_string; |
| +} |
| -self.onmessage = function(e) { |
| - port = e.data.port; |
| - port.onmessage = on_message; |
| - port.postMessage('ready'); |
| -}; |
| +function receive_event(event_name) { |
| + return new Promise(function(resolve) { |
| + self.addEventListener(event_name, resolve, false); |
| + }); |
| +} |
| -function on_message(e) { |
| - var url = e.data; |
| - var client; |
| +function navigate_test(e) { |
| + var port = e.data.port; |
| + var url = e.data.url; |
| - self.clients.matchAll({ includeUncontrolled : true }).then(function(cs) { |
| - cs.forEach(function(c) { c.frameType == 'nested' && (client = c); }); |
| - return client.navigate(url); |
| + return clients.matchAll({ includeUncontrolled : true }) |
| + .then(function(client_list) { |
| + for (var i = 0; i < client_list.length; i++) { |
| + var client = client_list[i]; |
| + if (client.frameType == 'nested') { |
| + return client.navigate(url); |
| + } |
| + } |
| + port.postMessage('Could not found window client.'); |
| }) |
| - .then(function(c) { |
| - if (!c) |
| - port.postMessage(c); |
| + .then(function(new_client) { |
| + if (new_client === null) |
| + port.postMessage(new_client); |
| else |
| - port.postMessage(c.url); |
| + port.postMessage(new_client.url); |
| }) |
| - .catch(function(e) { |
| - port.postMessage(e.name); |
| + .catch(function(error) { |
| + port.postMessage(error.name); |
| }); |
| } |
| +if (match_query('installing')) { |
| + // If the query string is "?installing", then do test on installing worker. |
| + // This is only for in-scope-but-not-controlled test. |
| + receive_event('install').then(function(e) { |
| + console.log(self.registration.installing); |
|
nhiroki
2016/02/16 07:33:22
Can you remove this logging?
zino
2016/02/16 07:41:12
Done.
|
| + e.waitUntil(receive_event('message').then(navigate_test)); |
| + }); |
| +} else { |
| + receive_event('message').then(function(e) { |
| + e.waitUntil(navigate_test(e)); |
| + }); |
| +} |