OLD | NEW |
(Empty) | |
| 1 # Copyright (c) 2013 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 from telemetry.core.backends import browser_backend |
| 6 from telemetry.core.backends.webdriver import webdriver_tab_list_backend |
| 7 |
| 8 class WebDriverBrowserBackend(browser_backend.BrowserBackend): |
| 9 """The webdriver-based backend for controlling a locally-executed browser |
| 10 instance, on Linux, Mac, and Windows. |
| 11 """ |
| 12 |
| 13 def __init__(self, driver_creator, supports_extensions, options): |
| 14 super(WebDriverBrowserBackend, self).__init__( |
| 15 is_content_shell=False, |
| 16 supports_extensions=supports_extensions, |
| 17 options=options, |
| 18 tab_list_backend=webdriver_tab_list_backend.WebDriverTabListBackend) |
| 19 |
| 20 self._driver_creator = driver_creator |
| 21 self._driver = None |
| 22 self.webpagereplay_local_http_port = 80 |
| 23 self.webpagereplay_local_https_port = 443 |
| 24 self.webpagereplay_remote_http_port = self.webpagereplay_local_http_port |
| 25 self.webpagereplay_remote_https_port = self.webpagereplay_local_https_port |
| 26 |
| 27 def Start(self): |
| 28 assert not self._driver |
| 29 self._driver = self._driver_creator() |
| 30 |
| 31 @property |
| 32 def driver(self): |
| 33 assert self._driver |
| 34 return self._driver |
| 35 |
| 36 @property |
| 37 def supports_tab_control(self): |
| 38 # Based on webdriver protocol API, only closing a tab is supported while |
| 39 # activating or creating a tab is not. Thus, tab control is not supported. |
| 40 return False |
| 41 |
| 42 @property |
| 43 def supports_tracing(self): |
| 44 # Tracing is not available in IE/Firefox yet and not supported through |
| 45 # webdriver API. |
| 46 return False |
| 47 |
| 48 def GetProcessName(self, _): |
| 49 # Leave implementation details to subclass as process name depends on the |
| 50 # type of browser. |
| 51 raise NotImplementedError() |
| 52 |
| 53 def Close(self): |
| 54 self._driver.quit() |
| 55 self._driver = None |
| 56 |
| 57 def CreateForwarder(self, *port_pairs): |
| 58 return browser_backend.DoNothingForwarder(*port_pairs) |
| 59 |
| 60 def IsBrowserRunning(self): |
| 61 # Assume the browser is running if not explicitly closed. |
| 62 return self._driver is not None |
| 63 |
| 64 def GetStandardOutput(self): |
| 65 # TODO(chrisgao): check if python client can get stdout of browsers. |
| 66 return '' |
| 67 |
| 68 def __del__(self): |
| 69 self.Close() |
OLD | NEW |