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