OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 receivedEvents = []; |
| 6 var devtoolsTabEvents = undefined; |
| 7 |
| 8 function pageEventListener() { |
| 9 receivedEvents.push("onPageEvent"); |
| 10 } |
| 11 |
| 12 function tabCloseListener() { |
| 13 receivedEvents.push("onTabClose"); |
| 14 } |
| 15 |
| 16 function setListenersOnTab(tabId) { |
| 17 try { |
| 18 devtoolsTabEvents = chrome.devtools.getTabEvents(tabId); |
| 19 devtoolsTabEvents.onPageEvent.addListener(pageEventListener); |
| 20 devtoolsTabEvents.onTabClose.addListener(tabCloseListener); |
| 21 window.domAutomationController.send(true); |
| 22 } catch(e) { |
| 23 window.domAutomationController.send(false); |
| 24 } |
| 25 } |
| 26 |
| 27 function testReceivePageEvent() { |
| 28 if (receivedEvents.length == 1) { |
| 29 var eventName = receivedEvents.pop(); |
| 30 window.domAutomationController.send(eventName === "onPageEvent"); |
| 31 } else { |
| 32 receivedEvents = []; |
| 33 window.domAutomationController.send(false); |
| 34 } |
| 35 } |
| 36 |
| 37 function testReceiveTabCloseEvent() { |
| 38 if (receivedEvents.length == 1) { |
| 39 var eventName = receivedEvents.pop(); |
| 40 window.domAutomationController.send(eventName === "onTabClose"); |
| 41 } else { |
| 42 receivedEvents = []; |
| 43 window.domAutomationController.send(false); |
| 44 } |
| 45 } |
| 46 |
| 47 function unregisterListeners() { |
| 48 devtoolsTabEvents.onPageEvent.removeListener(pageEventListener); |
| 49 devtoolsTabEvents.onTabClose.removeListener(tabCloseListener); |
| 50 window.domAutomationController.send(true); |
| 51 } |
OLD | NEW |