| Index: chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js
|
| diff --git a/chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js b/chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..06250cc6dca90278f780cc6e6544cf1ab7fe013a
|
| --- /dev/null
|
| +++ b/chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2017 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 expectedEventData;
|
| +var capturedEventData;
|
| +
|
| +function expect(data) {
|
| + expectedEventData = data;
|
| + capturedEventData = [];
|
| +}
|
| +
|
| +function sendMessage(msg) {
|
| + clients.matchAll({}).then(function(clients) {
|
| + console.log('Num clients found: ' + clients.length);
|
| + clients.forEach(function(client) {
|
| + client.postMessage(msg);
|
| + });
|
| + });
|
| +}
|
| +
|
| +self.addEventListener('activate', function(e) {
|
| + console.log('-----------> activate');
|
| + e.waitUntil(self.clients.claim());
|
| +});
|
| +
|
| +function checkExpectations() {
|
| + console.log('capturedEventData.length: ' + capturedEventData.length);
|
| + console.log('expectedEventData.length: ' + expectedEventData.length);
|
| + if (capturedEventData.length < expectedEventData.length) {
|
| + return;
|
| + }
|
| +
|
| + var passed = JSON.stringify(expectedEventData) ==
|
| + JSON.stringify(capturedEventData);
|
| + if (passed) {
|
| + console.log('PASSED');
|
| + sendMessage('chrome.tabs.onUpdated callback');
|
| + } else {
|
| + console.log('expect: ' + JSON.stringify(expectedEventData));
|
| + console.log('actual: ' + JSON.stringify(capturedEventData));
|
| + sendMessage('FAILURE');
|
| + }
|
| +}
|
| +
|
| +var getURL = chrome.extension.getURL;
|
| +chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
|
| + console.log('onUpdated, tabId: ' + tabId + ', info: ' + JSON.stringify(info) +
|
| + ', tab: ' + JSON.stringify(tab));
|
| + capturedEventData.push(info);
|
| + checkExpectations();
|
| +});
|
| +
|
| +var url = getURL('on_updated.html');
|
| +expect([
|
| + {status: 'loading', 'url': url},
|
| + {status: 'complete'},
|
| + {title: 'foo'},
|
| + {title: 'bar'}
|
| +]);
|
|
|