Index: chrome/test/data/extensions/api_test/service_worker/update/v2/background.js |
diff --git a/chrome/test/data/extensions/api_test/service_worker/update/v2/background.js b/chrome/test/data/extensions/api_test/service_worker/update/v2/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8017de9da8732cb0b943c9c566c7ff9832e20300 |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/service_worker/update/v2/background.js |
@@ -0,0 +1,25 @@ |
+// 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'); |
+ }); |
+ }; |
+}); |
+ |
+controllerChangePromise.then(function(serviceWorker) { |
+ var channel = new MessageChannel(); |
+ channel.port1.onmessage = function(e) { |
+ chrome.test.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'); |
+}); |