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 import logging |
| 6 |
| 7 from telemetry.core.chrome import png_bitmap |
| 8 |
| 9 class WebDriverTabBackend(object): |
| 10 def __init__(self, browser_backend, window_handle): |
| 11 self._browser_backend = browser_backend |
| 12 self._window_handle = window_handle |
| 13 |
| 14 def Disconnect(self): |
| 15 pass |
| 16 |
| 17 @property |
| 18 def browser(self): |
| 19 return self._browser_backend.browser |
| 20 |
| 21 @property |
| 22 def window_handle(self): |
| 23 return self._window_handle |
| 24 |
| 25 @property |
| 26 def url(self): |
| 27 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 28 return self._browser_backend.driver.current_url |
| 29 |
| 30 def Activate(self): |
| 31 # Webdriver doesn't support tab control. |
| 32 raise NotImplementedError() |
| 33 |
| 34 def Close(self): |
| 35 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 36 self._browser_backend.driver.close() |
| 37 |
| 38 def WaitForDocumentReadyStateToBeComplete(self, timeout=None): |
| 39 # TODO(chrisgao): Double check of document state. |
| 40 pass |
| 41 |
| 42 def WaitForDocumentReadyStateToBeInteractiveOrBetter(self, timeout=None): |
| 43 # TODO(chrisgao): Double check of document state. |
| 44 pass |
| 45 |
| 46 @property |
| 47 def screenshot_supported(self): |
| 48 return True |
| 49 |
| 50 def Screenshot(self, timeout=None): # pylint: disable=W0613 |
| 51 if timeout: |
| 52 logging.warning('timeout is not supported') |
| 53 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 54 snap = self._browser_backend.driver.get_screenshot_as_base64() |
| 55 if snap: |
| 56 return png_bitmap.PngBitmap(snap) |
| 57 return None |
| 58 |
| 59 @property |
| 60 def message_output_stream(self): |
| 61 # Webdriver has no API for grabbing console messages. |
| 62 raise NotImplementedError() |
| 63 |
| 64 @message_output_stream.setter |
| 65 def message_output_stream(self, stream): |
| 66 raise NotImplementedError() |
| 67 |
| 68 def GetDOMStats(self, timeout=None): |
| 69 # Webdriver has no API for DOM status. |
| 70 raise NotImplementedError() |
| 71 |
| 72 def PerformActionAndWaitForNavigate(self, action_function, _): |
| 73 # TODO(chrisgao): Double check of navigation. |
| 74 action_function() |
| 75 |
| 76 def Navigate(self, url, script_to_evaluate_on_commit=None, timeout=None): |
| 77 if script_to_evaluate_on_commit: |
| 78 raise NotImplementedError('script_to_evaluate_on_commit is NOT supported') |
| 79 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 80 if timeout: |
| 81 self._browser_backend.driver.set_page_load_timeout(timeout * 1000) |
| 82 self._browser_backend.driver.get(url) |
| 83 |
| 84 def GetCookieByName(self, name, timeout=None): |
| 85 if timeout: |
| 86 logging.warning('timeout is not supported') |
| 87 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 88 cookie = self._browser_backend.driver.get_cookie(name) |
| 89 if cookie: |
| 90 return cookie['value'] |
| 91 return None |
| 92 |
| 93 def ExecuteJavaScript(self, expr, timeout=None): |
| 94 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 95 if timeout: |
| 96 logging.warning('timeout is not supported') |
| 97 self._browser_backend.driver.execute_script(expr) |
| 98 |
| 99 def EvaluateJavaScript(self, expr, timeout=None): |
| 100 self._browser_backend.driver.switch_to_window(self._window_handle) |
| 101 if timeout: |
| 102 logging.warning('timeout is not supported') |
| 103 return self._browser_backend.driver.execute_script( |
| 104 'return eval(\'%s\')' % expr.replace('\'', '\\\'').replace('\n', ' ')) |
| 105 |
| 106 @property |
| 107 def timeline_model(self): |
| 108 # IE/Firefox has no timeline. |
| 109 raise NotImplementedError() |
| 110 |
| 111 def StartTimelineRecording(self): |
| 112 raise NotImplementedError() |
| 113 |
| 114 def StopTimelineRecording(self): |
| 115 raise NotImplementedError() |
| 116 |
| 117 def ClearCache(self): |
| 118 # Can't find a way to clear cache of a tab in IE/Firefox. |
| 119 raise NotImplementedError() |
OLD | NEW |