1# Copyright 2015 The Chromium OS 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"""An adapter to remotely access the browser facade on DUT.""" 6 7 8class BrowserFacadeRemoteAdapter(object): 9 """BrowserFacadeRemoteAdapter is an adapter to remotely control DUT browser. 10 11 The Autotest host object representing the remote DUT, passed to this 12 class on initialization, can be accessed from its _client property. 13 14 """ 15 def __init__(self, remote_facade_proxy): 16 """Construct an BrowserFacadeRemoteAdapter. 17 18 @param remote_facade_proxy: RemoteFacadeProxy object. 19 20 """ 21 self._proxy = remote_facade_proxy 22 23 24 @property 25 def _browser_proxy(self): 26 """Gets the proxy to DUT browser facade. 27 28 @return XML RPC proxy to DUT browser facade. 29 30 """ 31 return self._proxy.browser 32 33 34 def start_custom_chrome(self, kwargs): 35 """Start a custom Chrome with given arguments. 36 37 @param kwargs: A dict of keyword arguments passed to Chrome. 38 @return: True on success, False otherwise. 39 40 """ 41 return self._browser_proxy.start_custom_chrome(kwargs) 42 43 44 def start_default_chrome(self, restart=False, extra_browser_args=None): 45 """Start the default Chrome. 46 47 @param restart: True to start Chrome without clearing previous state. 48 @param extra_browser_args: A list containing extra browser args passed 49 to Chrome in addition to default ones. 50 @return: True on success, False otherwise. 51 52 """ 53 return self._browser_proxy.start_default_chrome( 54 restart, extra_browser_args) 55 56 57 def new_tab(self, url): 58 """Opens a new tab and loads URL. 59 60 @param url: The URL to load. 61 @return a str, the tab descriptor of the opened tab. 62 63 """ 64 return self._browser_proxy.new_tab(url) 65 66 67 def close_tab(self, tab_descriptor): 68 """Closes a previously opened tab. 69 70 @param tab_descriptor: Indicate which tab to be closed. 71 72 """ 73 self._browser_proxy.close_tab(tab_descriptor) 74 75 76 def wait_for_javascript_expression( 77 self, tab_descriptor, expression, timeout): 78 """Waits for the given JavaScript expression to be True on the given tab 79 80 @param tab_descriptor: Indicate on which tab to wait for the expression. 81 @param expression: Indiate for what expression to wait. 82 @param timeout: Indicate the timeout of the expression. 83 """ 84 self._browser_proxy.wait_for_javascript_expression( 85 tab_descriptor, expression, timeout) 86 87 88 def execute_javascript(self, tab_descriptor, statement, timeout): 89 """Executes a JavaScript statement on the given tab. 90 91 @param tab_descriptor: Indicate on which tab to execute the statement. 92 @param statement: Indiate what statement to execute. 93 @param timeout: Indicate the timeout of the statement. 94 """ 95 self._browser_proxy.execute_javascript( 96 tab_descriptor, statement, timeout) 97 98 99 def evaluate_javascript(self, tab_descriptor, expression, timeout): 100 """Evaluates a JavaScript expression on the given tab. 101 102 @param tab_descriptor: Indicate on which tab to evaluate the expression. 103 @param expression: Indiate what expression to evaluate. 104 @param timeout: Indicate the timeout of the expression. 105 @return the JSONized result of the given expression 106 """ 107 return self._browser_proxy.evaluate_javascript( 108 tab_descriptor, expression, timeout) 109