Chromium Code Reviews| 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 var messagePort = null; | |
| 14 function sendMessage(msg) { messagePort.postMessage(msg); } | |
| 15 | |
| 16 function checkExpectations() { | |
| 17 if (capturedEventData.length < expectedEventData.length) { | |
| 18 return; | |
| 19 } | |
| 20 | |
| 21 var passed = JSON.stringify(expectedEventData) == | |
| 22 JSON.stringify(capturedEventData); | |
| 23 if (passed) { | |
| 24 sendMessage('chrome.tabs.onUpdated callback'); | |
| 25 } else { | |
| 26 sendMessage('FAILURE'); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 self.onmessage = function(e) { | |
| 31 var data = e.data; | |
| 32 messagePort = e.ports[0]; | |
| 33 if (data == 'addOnUpdatedListener') { | |
| 34 addOnUpdatedListener(); | |
| 35 e.ports[0].postMessage('listener-added'); | |
| 36 } | |
| 37 }; | |
| 38 | |
| 39 function addOnUpdatedListener() { | |
| 40 var getURL = chrome.extension.getURL; | |
|
Devlin
2017/06/01 04:54:49
nit: probably not worth caching this for the one u
lazyboy
2017/06/01 23:33:29
Done.
| |
| 41 chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { | |
| 42 console.log('onUpdated, tabId: ' + tabId + ', info: ' + | |
| 43 JSON.stringify(info) + ', tab: ' + JSON.stringify(tab)); | |
| 44 capturedEventData.push(info); | |
| 45 checkExpectations(); | |
| 46 }); | |
| 47 | |
| 48 var url = getURL('on_updated.html'); | |
| 49 expect([ | |
| 50 {status: 'loading', 'url': url}, | |
| 51 {status: 'complete'}, | |
| 52 {title: 'foo'}, | |
| 53 {title: 'bar'} | |
| 54 ]); | |
| 55 }; | |
| OLD | NEW |