| 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]);
|
| +};
|
|
|