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

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

Issue 2943583002: [extension SW] Support lazy events from extension service workers. (Closed)
Patch Set: sync @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..f6a7374ca2116497489442daca0dc9d352de21a4
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/service_worker/events_to_stopped_worker/sw.js
@@ -0,0 +1,55 @@
+// 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 = [];
+}
+
+// Claim clients to send postMessage reply to them.
+self.addEventListener('activate', function(e) {
+ e.waitUntil(self.clients.claim());
+});
+
+function sendMessage(msg) {
+ clients.matchAll({}).then(function(clients) {
+ clients.forEach(function(client) {
+ client.postMessage(msg);
+ });
+ });
+}
+
+function checkExpectations() {
+ if (capturedEventData.length < expectedEventData.length) {
+ return;
+ }
+
+ var passed = JSON.stringify(expectedEventData) ==
+ JSON.stringify(capturedEventData);
+ if (passed) {
+ sendMessage('chrome.tabs.onUpdated callback');
+ } else {
+ sendMessage('FAILURE');
+ }
+}
+
+function addOnUpdatedListener() {
+ chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
+ capturedEventData.push(info);
+ checkExpectations();
+ });
+
+ var url = chrome.extension.getURL('on_updated.html');
+ expect([
+ {status: 'loading', 'url': url},
+ {status: 'complete'},
+ {title: 'foo'},
+ {title: 'bar'}
+ ]);
+};
+
+addOnUpdatedListener();

Powered by Google App Engine
This is Rietveld 408576698