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

Unified Diff: chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js

Issue 2924213002: Draft: Dispatching extension events to stopped extension SW.
Patch Set: rebase @tott Created 3 years, 6 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/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'}
+]);

Powered by Google App Engine
This is Rietveld 408576698