summaryrefslogtreecommitdiffstats
path: root/chrome/test/reliability/automated_ui_test_base.h
blob: 8fbf13849914ad3396590ef1b831f2290d5bba61 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_RELIABILITY_AUTOMATED_UI_TEST_BASE_H_
#define CHROME_TEST_RELIABILITY_AUTOMATED_UI_TEST_BASE_H_

#include <string>

#include "chrome/test/ui/ui_test.h"

class WindowProxy;

class AutomatedUITestBase : public UITest {
 protected:
  AutomatedUITestBase();
  virtual ~AutomatedUITestBase();

  virtual void SetUp() OVERRIDE;

  virtual void LogErrorMessage(const std::string &error);
  virtual void LogWarningMessage(const std::string &warning);
  virtual void LogInfoMessage(const std::string &info);

  // Actions

  // NOTE: This list is sorted alphabetically.
  // All functions are synchronous unless specified with Async.

  // Go back in active tab.
  // Returns true if successful, false otherwise.
  bool BackButton();

  // Close the selected tab in the current browser window. The function will
  // not try close the tab if it is the only tab of the last normal window, so
  // the application is not got closed.
  // Returns true if the tab is closed, false otherwise.
  bool CloseActiveTab();

  // Close the current browser window if it is not the only window left.
  // (Closing the last window will get application closed.)
  // Returns true if the window is closed, false otherwise.
  bool CloseActiveWindow();

  // Duplicates the current tab.
  // Returns true if a duplicated tab is added.
  bool DuplicateTab();

  // Drags the active tab. The tab is dragged vertically to remove it from the
  // tabstrip. Returns true if the tab is dragged, false otherwise.
  // Note: returning true doesn't necessarily create a new window as the tab
  // could be dragged in to another window.
  bool DragTabOut();

  // Drags the active tab.
  // If |drag_right| is true, if there is a tab to the right of the active tab,
  // the active tab is dragged to that tabs position. If |drag_right| is false,
  // if there is a tab to the left of the active tab, the active tab is dragged
  // to that tabs position. Returns true if the tab is dragged. If it returns
  // false, the tab is not dragged, probably because no other tab exists to
  // drag the active tab over.
  bool DragActiveTab(bool drag_right);

  // Activates "find in page" on the current page. Returns true on success.
  bool FindInPage();

  // Go forward in active tab.
  // Returns true if successful, false otherwise.
  bool ForwardButton();

  // Opens an OffTheRecord browser window.
  bool GoOffTheRecord();

  // Navigates to the Home page.
  // Returns true if call to activate the accelerator is successful.
  bool Home();

  // Navigates the activate tab to given url.
  bool Navigate(const GURL& url);

  // Opens a new tab in the active window using an accelerator.
  // Returns true if a new tab is successfully opened.
  bool NewTab();

  // Opens a new browser window by calling automation()->OpenNewBrowserWindow.
  // Then activates the tab opened in the new window.
  // Returns true if window is successfully created.
  // If optional parameter previous_browser is passed in, it is set to be the
  // previous browser window when new window is successfully created, and the
  // caller owns previous_browser.
  bool OpenAndActivateNewBrowserWindow(
      scoped_refptr<BrowserProxy>* previous_browser);

  // Reload the active tab.
  // Returns true if successful, false otherwise.
  bool ReloadPage();

  // Restores a previously closed tab.
  // Returns true if the tab is successfully restored.
  bool RestoreTab();

  // Activates the next tab on the active browser window.
  // Returns true on success.
  bool SelectNextTab();

  // Activates the previous tab on the active browser window.
  // Returns true on success.
  bool SelectPreviousTab();

  // Opens the Downloads page in the current active browser window.
  // Returns true on success.
  bool ShowDownloads();

  // Opens the History page in the current active browser window.
  // Returns true on success.
  bool ShowHistory();

  // Runs the specified browser command in the current active browser.
  // See Browser::ExecuteCommandWithDisposition() for the list of commands.
  // Returns true if the call is successfully dispatched.
  // Possible failures include the active window is not a browser window or
  // the message to apply the accelerator fails.
  bool RunCommandAsync(int browser_command);

  // Runs the specified browser command in the current active browser, wait
  // and return until the command has finished executing.
  // See Browser::ExecuteCommandWithDisposition() for the list of commands.
  // Returns true if the call is successfully dispatched and executed.
  // Possible failures include the active window is not a browser window, or
  // the message to apply the accelerator fails, or the command execution
  // fails.
  bool RunCommand(int browser_command);

  void set_active_browser(BrowserProxy* browser) {
    active_browser_ = browser;
  }
  BrowserProxy* active_browser() const { return active_browser_.get(); }

  // Get the selected tab within the current active browser window, then
  // create a corresponding TabProxy and transfer the ownership to caller.
  // If success return the pointer to the newly created TabProxy and the
  // caller owns the TabProxy. Return NULL otherwise.
  scoped_refptr<TabProxy> GetActiveTab();

  // Returns the WindowProxy associated with the given BrowserProxy
  // (transferring ownership of the pointer to the caller) and brings that
  // window to the top.
  scoped_refptr<WindowProxy> GetAndActivateWindowForBrowser(
      BrowserProxy* browser);

 private:
  scoped_refptr<BrowserProxy> active_browser_;

  DISALLOW_COPY_AND_ASSIGN(AutomatedUITestBase);
};

#endif  // CHROME_TEST_RELIABILITY_AUTOMATED_UI_TEST_BASE_H_