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

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: nit 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 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..09b7724613d25acac74c9fdeed73b1c9be1ac87e 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,45 @@
-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) {
+ e.waitUntil(receive_event('message').then(navigate_test));
+ });
+} else {
+ receive_event('message').then(function(e) {
+ e.waitUntil(navigate_test(e));
+ });
+}
« 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