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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 var expectedEventData;
6 var capturedEventData;
7
8 function expect(data) {
9 expectedEventData = data;
10 capturedEventData = [];
11 }
12
13 // Claim clients to send postMessage reply to them.
14 self.addEventListener('activate', function(e) {
15 e.waitUntil(self.clients.claim());
16 });
17
18 function sendMessage(msg) {
19 clients.matchAll({}).then(function(clients) {
20 clients.forEach(function(client) {
21 client.postMessage(msg);
22 });
23 });
24 }
25
26 function checkExpectations() {
27 if (capturedEventData.length < expectedEventData.length) {
28 return;
29 }
30
31 var passed = JSON.stringify(expectedEventData) ==
32 JSON.stringify(capturedEventData);
33 if (passed) {
34 sendMessage('chrome.tabs.onUpdated callback');
35 } else {
36 sendMessage('FAILURE');
37 }
38 }
39
40 function addOnUpdatedListener() {
41 chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
42 capturedEventData.push(info);
43 checkExpectations();
44 });
45
46 var url = chrome.extension.getURL('on_updated.html');
47 expect([
48 {status: 'loading', 'url': url},
49 {status: 'complete'},
50 {title: 'foo'},
51 {title: 'bar'}
52 ]);
53 };
54
55 addOnUpdatedListener();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698