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

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

Issue 2166523003: Add ref count to service workers for extension API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: sync@tott Created 4 years, 2 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: chrome/test/data/extensions/api_test/service_worker/api_worker_ref_count/page.js
diff --git a/chrome/test/data/extensions/api_test/service_worker/api_worker_ref_count/page.js b/chrome/test/data/extensions/api_test/service_worker/api_worker_ref_count/page.js
new file mode 100644
index 0000000000000000000000000000000000000000..0f26b96e0e51cd9a766ccb97f6582e3a1109c4fa
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/service_worker/api_worker_ref_count/page.js
@@ -0,0 +1,33 @@
+// Copyright 2016 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 worker = null;
+var FAILURE_MESSAGE = 'FAILURE';
+
+window.runServiceWorker = function() {
+ navigator.serviceWorker.register('sw.js').then(function() {
+ return navigator.serviceWorker.ready;
+ }).then(function(registration) {
+ worker = registration.active;
+ chrome.test.sendMessage('WORKER STARTED');
+ }).catch(function(err) {
+ chrome.test.sendMessage(FAILURE_MESSAGE);
+ });
+};
+
+window.testSendMessage = function() {
+ if (worker == null) {
+ chrome.test.sendMessage(FAILURE_MESSAGE);
+ return;
+ }
+ var channel = new MessageChannel();
+ channel.port1.onmessage = function(e) {
+ if (e.data == 'Worker reply: Hello world') {
+ chrome.test.sendMessage('SUCCESS');
+ } else {
+ chrome.test.sendMessage(FAILURE_MESSAGE);
+ }
+ };
+ worker.postMessage('sendMessageTest', [channel.port2]);
+};

Powered by Google App Engine
This is Rietveld 408576698