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

Side by Side Diff: tools/telemetry/telemetry/core/browser.py

Issue 736653002: [Pywebsocket PerformanceTests 2/2] Add blink_perf.pywebsocket (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 6 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
OLDNEW
1 # Copyright 2012 The Chromium Authors. All rights reserved. 1 # Copyright 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 4
5 import os 5 import os
6 6
7 from telemetry import decorators 7 from telemetry import decorators
8 from telemetry.core import app 8 from telemetry.core import app
9 from telemetry.core import browser_credentials 9 from telemetry.core import browser_credentials
10 from telemetry.core import exceptions 10 from telemetry.core import exceptions
11 from telemetry.core import extension_dict 11 from telemetry.core import extension_dict
12 from telemetry.core import local_server 12 from telemetry.core import local_server
13 from telemetry.core import memory_cache_http_server 13 from telemetry.core import memory_cache_http_server
14 from telemetry.core import pywebsocket_server
14 from telemetry.core import tab_list 15 from telemetry.core import tab_list
15 from telemetry.core.backends import browser_backend 16 from telemetry.core.backends import browser_backend
16 17
17 18
18 class Browser(app.App): 19 class Browser(app.App):
19 """A running browser instance that can be controlled in a limited way. 20 """A running browser instance that can be controlled in a limited way.
20 21
21 To create a browser instance, use browser_finder.FindBrowser. 22 To create a browser instance, use browser_finder.FindBrowser.
22 23
23 Be sure to clean up after yourself by calling Close() when you are done with 24 Be sure to clean up after yourself by calling Close() when you are done with
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 219
219 self._local_server_controller.Close() 220 self._local_server_controller.Close()
220 self._browser_backend.Close() 221 self._browser_backend.Close()
221 self.credentials = None 222 self.credentials = None
222 223
223 @property 224 @property
224 def http_server(self): 225 def http_server(self):
225 return self._local_server_controller.GetRunningServer( 226 return self._local_server_controller.GetRunningServer(
226 memory_cache_http_server.MemoryCacheHTTPServer, None) 227 memory_cache_http_server.MemoryCacheHTTPServer, None)
227 228
229 @property
230 def pywebsocket_server(self):
231 return self._local_server_controller.GetRunningServer(
232 pywebsocket_server.PywebsocketServer, None)
233
228 def SetHTTPServerDirectories(self, paths): 234 def SetHTTPServerDirectories(self, paths):
229 """Returns True if the HTTP server was started, False otherwise.""" 235 """Returns True if the HTTP server was started, False otherwise."""
230 if isinstance(paths, basestring): 236 if isinstance(paths, basestring):
231 paths = set([paths]) 237 paths = set([paths])
232 paths = set(os.path.realpath(p) for p in paths) 238 paths = set(os.path.realpath(p) for p in paths)
233 239
234 # If any path is in a subdirectory of another, remove the subdirectory. 240 # If any path is in a subdirectory of another, remove the subdirectory.
235 duplicates = set() 241 duplicates = set()
236 for parent_path in paths: 242 for parent_path in paths:
237 for sub_path in paths: 243 for sub_path in paths:
238 if parent_path == sub_path: 244 if parent_path == sub_path:
239 continue 245 continue
240 if os.path.commonprefix((parent_path, sub_path)) == parent_path: 246 if os.path.commonprefix((parent_path, sub_path)) == parent_path:
241 duplicates.add(sub_path) 247 duplicates.add(sub_path)
242 paths -= duplicates 248 paths -= duplicates
243 249
244 if self.http_server: 250 if self.http_server:
245 if paths and self.http_server.paths == paths: 251 if paths and self.http_server.paths == paths:
246 return False 252 return False
247 253
248 self.http_server.Close() 254 self.http_server.Close()
249 255
250 if not paths: 256 if not paths:
251 return False 257 return False
252 258
253 server = memory_cache_http_server.MemoryCacheHTTPServer(paths) 259 server = memory_cache_http_server.MemoryCacheHTTPServer(paths)
254 self.StartLocalServer(server) 260 self.StartLocalServer(server)
255 return True 261 return True
256 262
263 def StartPywebsocketServer(self):
264 if self.pywebsocket_server:
265 return False
266
267 server = pywebsocket_server.PywebsocketServer()
268 self.StartLocalServer(server)
269 return True
270
257 def StartLocalServer(self, server): 271 def StartLocalServer(self, server):
258 """Starts a LocalServer and associates it with this browser. 272 """Starts a LocalServer and associates it with this browser.
259 273
260 It will be closed when the browser closes. 274 It will be closed when the browser closes.
261 """ 275 """
262 self._local_server_controller.StartServer(server) 276 self._local_server_controller.StartServer(server)
263 277
264 @property 278 @property
265 def local_servers(self): 279 def local_servers(self):
266 """Returns the currently running local servers.""" 280 """Returns the currently running local servers."""
267 return self._local_server_controller.local_servers 281 return self._local_server_controller.local_servers
268 282
269 def GetStandardOutput(self): 283 def GetStandardOutput(self):
270 return self._browser_backend.GetStandardOutput() 284 return self._browser_backend.GetStandardOutput()
271 285
272 def GetStackTrace(self): 286 def GetStackTrace(self):
273 return self._browser_backend.GetStackTrace() 287 return self._browser_backend.GetStackTrace()
274 288
275 @property 289 @property
276 def supports_system_info(self): 290 def supports_system_info(self):
277 return self._browser_backend.supports_system_info 291 return self._browser_backend.supports_system_info
278 292
279 def GetSystemInfo(self): 293 def GetSystemInfo(self):
280 """Returns low-level information about the system, if available. 294 """Returns low-level information about the system, if available.
281 295
282 See the documentation of the SystemInfo class for more details.""" 296 See the documentation of the SystemInfo class for more details."""
283 return self._browser_backend.GetSystemInfo() 297 return self._browser_backend.GetSystemInfo()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698