OLD | NEW |
1 <script> | 1 <!-- |
2 | 2 * Copyright (c) 2011 The Chromium Authors. All rights reserved. Use of this |
3 var receivedEvents = []; | 3 * source code is governed by a BSD-style license that can be found in the |
4 var devtoolsTabEvents = undefined; | 4 * LICENSE file. |
5 | 5 --> |
6 function pageEventListener() { | 6 <script src="background.js"></script> |
7 receivedEvents.push("onPageEvent"); | |
8 } | |
9 | |
10 function tabCloseListener() { | |
11 receivedEvents.push("onTabClose"); | |
12 } | |
13 | |
14 function setListenersOnTab(tabId) { | |
15 try { | |
16 devtoolsTabEvents = chrome.devtools.getTabEvents(tabId); | |
17 devtoolsTabEvents.onPageEvent.addListener(pageEventListener); | |
18 devtoolsTabEvents.onTabClose.addListener(tabCloseListener); | |
19 window.domAutomationController.send(true); | |
20 } catch(e) { | |
21 window.domAutomationController.send(false); | |
22 } | |
23 } | |
24 | |
25 function testReceivePageEvent() { | |
26 if (receivedEvents.length == 1) { | |
27 var eventName = receivedEvents.pop(); | |
28 window.domAutomationController.send(eventName === "onPageEvent"); | |
29 } else { | |
30 receivedEvents = []; | |
31 window.domAutomationController.send(false); | |
32 } | |
33 } | |
34 | |
35 function testReceiveTabCloseEvent() { | |
36 if (receivedEvents.length == 1) { | |
37 var eventName = receivedEvents.pop(); | |
38 window.domAutomationController.send(eventName === "onTabClose"); | |
39 } else { | |
40 receivedEvents = []; | |
41 window.domAutomationController.send(false); | |
42 } | |
43 } | |
44 | |
45 function unregisterListeners() { | |
46 devtoolsTabEvents.onPageEvent.removeListener(pageEventListener); | |
47 devtoolsTabEvents.onTabClose.removeListener(tabCloseListener); | |
48 window.domAutomationController.send(true); | |
49 } | |
50 | |
51 </script> | |
OLD | NEW |