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

Unified Diff: LayoutTests/http/tests/serviceworker/resources/end-to-end-worker.js

Issue 238993003: ServiceWorker: "minimal" end-to-end sample as a W3C test (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Clarify registration promise chain Created 6 years, 8 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
Index: LayoutTests/http/tests/serviceworker/resources/end-to-end-worker.js
diff --git a/LayoutTests/http/tests/serviceworker/resources/end-to-end-worker.js b/LayoutTests/http/tests/serviceworker/resources/end-to-end-worker.js
new file mode 100644
index 0000000000000000000000000000000000000000..4ac2e2e2893084945d36672632014f6dee05ef61
--- /dev/null
+++ b/LayoutTests/http/tests/serviceworker/resources/end-to-end-worker.js
@@ -0,0 +1,33 @@
+var port;
+var resolve;
+
+oninstall = function(e) {
+ e.waitUntil(new Promise(function(r) { resolve = r; }));
+};
+
+onactivate = function(e) {
+ port.postMessage('ping');
+ e.waitUntil(new Promise(function(r) { resolve = r; }));
+};
+
+onmessage = function(e) {
+ var message = e.data;
+ if (Object(message) === message) {
+ if ('port' in message) {
+ if (message.from === 'registering doc')
+ port = message.port;
+ var response = 'Ack for: ' + message.from;
+ try {
+ message.port.postMessage(response);
+ } catch(e) {}
+ try {
+ message.source.postMessage(response, '*');
kinuko 2014/04/16 03:28:38 Let's remove this from our first end-to-end test f
jsbell 2014/04/16 17:04:19 Done.
+ } catch (e) {}
+ }
+ }
+
+ if (resolve) {
+ resolve();
+ resolve = null;
+ }
+};

Powered by Google App Engine
This is Rietveld 408576698