Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / tools / telemetry / telemetry / core / backends / webdriver / webdriver_browser_backend.py
1 # Copyright 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 import util
6 from telemetry.core.backends import browser_backend
7 from telemetry.core.backends.webdriver import webdriver_tab_list_backend
8
9 class WebDriverBrowserBackend(browser_backend.BrowserBackend):
10   """The webdriver-based backend for controlling a locally-executed browser
11   instance, on Linux, Mac, and Windows.
12   """
13
14   def __init__(self, driver_creator, supports_extensions, browser_options):
15     super(WebDriverBrowserBackend, self).__init__(
16         is_content_shell=False,
17         supports_extensions=supports_extensions,
18         browser_options=browser_options,
19         tab_list_backend=webdriver_tab_list_backend.WebDriverTabListBackend)
20
21     self._driver_creator = driver_creator
22     self._driver = None
23     self.wpr_http_port_pair = util.PortPair(80, 80)
24     self.wpr_https_port_pair = util.PortPair(443, 443)
25
26   def Start(self):
27     assert not self._driver
28     self._driver = self._driver_creator()
29
30   @property
31   def driver(self):
32     assert self._driver
33     return self._driver
34
35   @property
36   def supports_tab_control(self):
37     # Based on webdriver protocol API, only closing a tab is supported while
38     # activating or creating a tab is not. Thus, tab control is not supported.
39     return False
40
41   @property
42   def supports_tracing(self):
43     # Tracing is not available in IE/Firefox yet and not supported through
44     # webdriver API.
45     return False
46
47   def GetProcessName(self, cmd_line):
48     # Leave implementation details to subclass as process name depends on the
49     # type of browser.
50     raise NotImplementedError()
51
52   def Close(self):
53     if self._driver:
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 __del__(self):
65     self.Close()