OLD | NEW |
(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(); |
OLD | NEW |