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

Unified 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, 11 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/http/tests/serviceworker/windowclient-navigate.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..ea614e96d7216cb0f07b2ff9a96831e8ec3c7f43 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,51 @@
-var port = null;
+function match_query(query_string) {
+ return self.location.search.substr(1) == query_string;
+}
+
+function receive_event(event_name) {
+ return new Promise(function(resolve) {
+ self.addEventListener(event_name, resolve, false);
+ });
+}
-self.onmessage = function(e) {
- port = e.data.port;
- port.onmessage = on_message;
- port.postMessage('ready');
-};
+function get_test_data() {
+ return receive_event('message');
+}
-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);
});
}
+
+receive_event('install').then(function(e) {
+ if (match_query('installing'))
+ e.waitUntil(get_test_data().then(navigate_test));
+});
+
+receive_event('activate').then(function(e) {
+ if (match_query('activating')) {
+ // TODO(zino): Should do test in this case.
+ }
+ 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
+});
+
« 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