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

Unified Diff: chrome/test/data/extensions/api_test/service_worker/update_without_skip_waiting/v2/page.js

Issue 1510573003: Add test without skipWaiting() to demonstrate extension & service worker update. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: change private key Created 5 years 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: chrome/test/data/extensions/api_test/service_worker/update_without_skip_waiting/v2/page.js
diff --git a/chrome/test/data/extensions/api_test/service_worker/update_without_skip_waiting/v2/page.js b/chrome/test/data/extensions/api_test/service_worker/update_without_skip_waiting/v2/page.js
new file mode 100644
index 0000000000000000000000000000000000000000..ac755f70dc9e01a9b02eae14ef7a065ee3148447
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/service_worker/update_without_skip_waiting/v2/page.js
@@ -0,0 +1,41 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var controllerChangePromise = new Promise(function(resolve, reject) {
+ navigator.serviceWorker.oncontrollerchange = function(e) {
+ navigator.serviceWorker.ready.then(function(registration) {
+ resolve(registration.active);
+ }).catch(function(err) {
+ reject('oncontrollerchange failure');
+ });
+ };
+});
falken 2015/12/09 03:59:16 Remove this dead code.
lazyboy 2015/12/09 21:47:56 Done.
+
+var registerServiceWorkerPromise = new Promise(function(resolve, reject) {
+ var serviceWorkerRegistration;
+ navigator.serviceWorker.register('sw.js').then(function() {
+ return navigator.serviceWorker.ready;
+ }).then(function(registration) {
+ serviceWorkerRegistration = registration;
+ return registration.update();
+ }).then(function() {
+ resolve(serviceWorkerRegistration.active);
falken 2015/12/09 03:59:16 This is kind of tricky. The update() promise resol
lazyboy 2015/12/09 21:47:56 OK, I'm waiting for registration.onupdatefound now
+ }).catch(function(err) {
+ reject(err);
+ });
+});
+
+Promise.all([registerServiceWorkerPromise])
+ .then(function(results) {
+ var serviceWorker = results[0];
+ var channel = new MessageChannel();
+ channel.port1.onmessage = function(e) {
+ console.log('Message received from SW: ' + e.data);
+ chrome.test.sendMessage(e.data);
+ };
+ serviceWorker.postMessage('ping', [channel.port2]);
+}).catch(function(err) {
+ console.log(err);
+ chrome.test.sendMessage('FAILURE_V2');
+});

Powered by Google App Engine
This is Rietveld 408576698