1 // Copyright (c) 2012 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.
5 #ifndef CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_
6 #define CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/common/content_settings.h"
14 #include "chrome/test/automation/automation_handle_tracker.h"
25 // This class presents the interface to actions that can be performed on
26 // a given browser window. Note that this object can be invalidated at any
27 // time if the corresponding browser window in the app is closed. In that case,
28 // any subsequent calls will return false immediately.
29 class BrowserProxy
: public AutomationResourceProxy
{
31 BrowserProxy(AutomationMessageSender
* sender
,
32 AutomationHandleTracker
* tracker
,
34 : AutomationResourceProxy(tracker
, sender
, handle
) {}
36 // Activates the tab corresponding to (zero-based) tab_index. Returns true if
38 bool ActivateTab(int tab_index
) WARN_UNUSED_RESULT
;
40 // Bring the browser window to the front, activating it. Returns true on
42 bool BringToFront() WARN_UNUSED_RESULT
;
44 // Append a new tab to the TabStrip. The new tab is selected.
45 // The new tab navigates to the given tab_url.
46 // Returns true if successful.
47 bool AppendTab(const GURL
& tab_url
) WARN_UNUSED_RESULT
;
49 // Gets the (zero-based) index of the currently active tab. Returns true if
51 bool GetActiveTabIndex(int* active_tab_index
) const WARN_UNUSED_RESULT
;
53 // Returns the number of tabs in the given window. Returns true if
54 // the call was successful.
55 bool GetTabCount(int* num_tabs
) const WARN_UNUSED_RESULT
;
57 // Returns the type of the given window. Returns true if the call was
59 bool GetType(Browser::Type
* type
) const WARN_UNUSED_RESULT
;
61 // Returns the TabProxy for the tab at the given index, transferring
62 // ownership of the pointer to the caller. On failure, returns NULL.
64 // Use GetTabCount to see how many windows you can ask for. Tab numbers
66 scoped_refptr
<TabProxy
> GetTab(int tab_index
) const;
68 // Returns the TabProxy for the currently active tab, transferring
69 // ownership of the pointer to the caller. On failure, returns NULL.
70 scoped_refptr
<TabProxy
> GetActiveTab() const;
72 // Returns the WindowProxy for this browser's window. It can be used to
73 // retreive view bounds, simulate clicks and key press events. The caller
74 // owns the returned WindowProxy.
75 // On failure, returns NULL.
76 scoped_refptr
<WindowProxy
> GetWindow() const;
78 // Apply the accelerator with given id (IDC_BACK, IDC_NEWTAB ...)
79 // The list can be found at chrome/app/chrome_command_ids.h
80 // Returns true if the call was successful.
82 // The alternate way to test the accelerators is to use the Windows messaging
83 // system to send the actual keyboard events (ui_controls.h) A precondition
84 // to using this system is that the target window should have the keyboard
85 // focus. This leads to a flaky test behavior in circumstances when the
86 // desktop screen is locked or the test is being executed over a remote
88 bool ApplyAccelerator(int id
) WARN_UNUSED_RESULT
;
90 // Block the thread until the tab count is |count|.
91 // Returns true on success.
92 bool WaitForTabCountToBecome(int count
) WARN_UNUSED_RESULT
;
94 // Block the thread until the specified tab is the active tab.
95 // |wait_timeout| is the timeout, in milliseconds, for waiting.
96 // Returns false if the tab does not become active.
97 bool WaitForTabToBecomeActive(
99 base::TimeDelta wait_timeout
) WARN_UNUSED_RESULT
;
101 // Returns whether the Find window is fully visible If animating, |is_visible|
102 // will be false. Returns false on failure.
103 bool IsFindWindowFullyVisible(bool* is_visible
) WARN_UNUSED_RESULT
;
105 // Run the specified command in the browser
106 // (see Browser::ExecuteCommandWithDisposition() for the list of supported
107 // commands). Returns true if the command was successfully dispatched,
109 bool RunCommandAsync(int browser_command
) const WARN_UNUSED_RESULT
;
111 // Run the specified command in the browser
112 // (see Browser::ExecuteCommandWithDisposition() for the list of supported
113 // commands). Returns true if the command was successfully dispatched and
114 // executed, false otherwise.
115 bool RunCommand(int browser_command
) const WARN_UNUSED_RESULT
;
117 // Simulates a termination the browser session (as if the user logged off the
119 bool TerminateSession() WARN_UNUSED_RESULT
;
121 // Generic pattern for sending automation requests.
122 bool SendJSONRequest(const std::string
& request
,
124 std::string
* response
) WARN_UNUSED_RESULT
;
126 // Gets the load times for all tabs started from the command line.
127 // Puts the time of the first tab to start loading into |min_start_time|,
128 // the time when loading stopped into |max_stop_time| (should be similar to
129 // the delay that WaitForInitialLoads waits for), and a list of all
130 // finished timestamps into |stop_times|. Returns true on success.
131 bool GetInitialLoadTimes(
132 base::TimeDelta timeout
,
133 float* min_start_time
,
134 float* max_stop_time
,
135 std::vector
<float>* stop_times
);
139 virtual ~BrowserProxy() {}
141 DISALLOW_COPY_AND_ASSIGN(BrowserProxy
);
144 #endif // CHROME_TEST_AUTOMATION_BROWSER_PROXY_H_