• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 set_http_server_directories(self, directories):
58        """Starts an HTTP server.
59
60        @param directories: Directories to start serving.
61
62        @return True on success. False otherwise.
63
64        """
65        return self._browser_proxy.set_http_server_directories(directories)
66
67
68    def http_server_url_of(self, fullpath):
69        """Converts a path to a URL.
70
71        @param fullpath: String containing the full path to the content.
72
73        @return the URL for the provided path.
74
75        """
76        return self._browser_proxy.http_server_url_of(fullpath)
77
78
79    def new_tab(self, url):
80        """Opens a new tab and loads URL.
81
82        @param url: The URL to load.
83        @return a str, the tab descriptor of the opened tab.
84
85        """
86        return self._browser_proxy.new_tab(url)
87
88
89    def close_tab(self, tab_descriptor):
90        """Closes a previously opened tab.
91
92        @param tab_descriptor: Indicate which tab to be closed.
93
94        """
95        self._browser_proxy.close_tab(tab_descriptor)
96
97
98    def wait_for_javascript_expression(
99            self, tab_descriptor, expression, timeout):
100        """Waits for the given JavaScript expression to be True on the given tab
101
102        @param tab_descriptor: Indicate on which tab to wait for the expression.
103        @param expression: Indiate for what expression to wait.
104        @param timeout: Indicate the timeout of the expression.
105        """
106        self._browser_proxy.wait_for_javascript_expression(
107                tab_descriptor, expression, timeout)
108
109
110    def execute_javascript(self, tab_descriptor, statement, timeout):
111        """Executes a JavaScript statement on the given tab.
112
113        @param tab_descriptor: Indicate on which tab to execute the statement.
114        @param statement: Indiate what statement to execute.
115        @param timeout: Indicate the timeout of the statement.
116        """
117        self._browser_proxy.execute_javascript(
118                tab_descriptor, statement, timeout)
119
120
121    def evaluate_javascript(self, tab_descriptor, expression, timeout):
122        """Evaluates a JavaScript expression on the given tab.
123
124        @param tab_descriptor: Indicate on which tab to evaluate the expression.
125        @param expression: Indiate what expression to evaluate.
126        @param timeout: Indicate the timeout of the expression.
127        @return the JSONized result of the given expression
128        """
129        return self._browser_proxy.evaluate_javascript(
130                tab_descriptor, expression, timeout)
131