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

Side by Side Diff: tools/telemetry/telemetry/browser_backend.py

Issue 11412238: Proof of concept for running extension API stack through dev tools. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import urllib2 4 import urllib2
5 import httplib 5 import httplib
6 import socket 6 import socket
7 import json 7 import json
8 8
9 from telemetry import browser_gone_exception 9 from telemetry import browser_gone_exception
10 from telemetry import inspector_backend 10 from telemetry import inspector_backend
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 return True 58 return True
59 try: 59 try:
60 util.WaitFor(IsBrowserUp, timeout=30) 60 util.WaitFor(IsBrowserUp, timeout=30)
61 except util.TimeoutException: 61 except util.TimeoutException:
62 raise browser_gone_exception.BrowserGoneException() 62 raise browser_gone_exception.BrowserGoneException()
63 63
64 @property 64 @property
65 def _debugger_url(self): 65 def _debugger_url(self):
66 return 'http://localhost:%i/json' % self._port 66 return 'http://localhost:%i/json' % self._port
67 67
68 def _ListExtensionPages(self, extension_id, timeout=None):
69 req = urllib2.urlopen(self._debugger_url, timeout=timeout)
70 data = req.read()
71 all_contexts = json.loads(data)
72 pages = [ctx for ctx in all_contexts
73 if ctx['url'].startswith('chrome-extension://%s' % extension_id)]
74 return pages
75
68 def _ListTabs(self, timeout=None): 76 def _ListTabs(self, timeout=None):
69 req = urllib2.urlopen(self._debugger_url, timeout=timeout) 77 req = urllib2.urlopen(self._debugger_url, timeout=timeout)
70 data = req.read() 78 data = req.read()
71 all_contexts = json.loads(data) 79 all_contexts = json.loads(data)
72 tabs = [ctx for ctx in all_contexts 80 tabs = [ctx for ctx in all_contexts
73 if not ctx['url'].startswith('chrome-extension://')] 81 if not ctx['url'].startswith('chrome-extension://')]
74 # FIXME(dtu): The remote debugger protocol returns in order of most 82 # FIXME(dtu): The remote debugger protocol returns in order of most
75 # recently created tab first. In order to convert it to the UI tab 83 # recently created tab first. In order to convert it to the UI tab
76 # order, we just reverse the list, which assumes we can't move tabs. 84 # order, we just reverse the list, which assumes we can't move tabs.
77 # We should guarantee that the remote debugger returns in the UI tab order. 85 # We should guarantee that the remote debugger returns in the UI tab order.
(...skipping 17 matching lines...) Expand all
95 103
96 util.WaitFor(lambda: self.num_tabs == target_num_tabs, timeout=5) 104 util.WaitFor(lambda: self.num_tabs == target_num_tabs, timeout=5)
97 105
98 @property 106 @property
99 def num_tabs(self): 107 def num_tabs(self):
100 return len(self._ListTabs()) 108 return len(self._ListTabs())
101 109
102 def GetNthTabUrl(self, index): 110 def GetNthTabUrl(self, index):
103 return self._ListTabs()[index]['url'] 111 return self._ListTabs()[index]['url']
104 112
113 def ConnectToExtensionPage(self, browser, extension_id):
114 ib = inspector_backend.InspectorBackend(self,
115 self._ListExtensionPages(extension_id)[0])
116 return tab.Tab(browser, ib)
nduca 2012/11/29 05:09:27 raise exception if nothing found
nduca 2012/11/29 05:09:27 this change looks totally landable. we'll want a u
zel 2012/12/04 03:12:48 I don't see browser_backend_unittest.py - what am
117
105 def ConnectToNthTab(self, browser, index): 118 def ConnectToNthTab(self, browser, index):
106 ib = inspector_backend.InspectorBackend(self, self._ListTabs()[index]) 119 ib = inspector_backend.InspectorBackend(self, self._ListTabs()[index])
107 return tab.Tab(browser, ib) 120 return tab.Tab(browser, ib)
108 121
109 def DoesDebuggerUrlExist(self, url): 122 def DoesDebuggerUrlExist(self, url):
110 matches = [t for t in self._ListTabs() 123 matches = [t for t in self._ListTabs()
111 if 'webSocketDebuggerUrl' in t and\ 124 if 'webSocketDebuggerUrl' in t and\
112 t['webSocketDebuggerUrl'] == url] 125 t['webSocketDebuggerUrl'] == url]
113 return len(matches) >= 1 126 return len(matches) >= 1
114 127
115 def CreateForwarder(self, host_port): 128 def CreateForwarder(self, host_port):
116 raise NotImplementedError() 129 raise NotImplementedError()
117 130
118 def IsBrowserRunning(self): 131 def IsBrowserRunning(self):
119 raise NotImplementedError() 132 raise NotImplementedError()
OLDNEW
« tools/telemetry/examples/telemetry_extension_test.py ('K') | « tools/telemetry/telemetry/browser.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698