blob: 6d3ffc028ece0ea20d3695bfb5a1e4cf1d452a8f [file] [log] [blame]
[email protected]2a28e0b22011-02-03 21:49:031// Copyright (c) 2011 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#ifndef CHROME_TEST_WEBDRIVER_AUTOMATION_H_
6#define CHROME_TEST_WEBDRIVER_AUTOMATION_H_
7
[email protected]496e5792011-02-17 17:02:538#include <map>
[email protected]2a28e0b22011-02-03 21:49:039#include <string>
[email protected]496e5792011-02-17 17:02:5310#include <vector>
[email protected]2a28e0b22011-02-03 21:49:0311
[email protected]fcad49452011-06-28 17:11:5712#include "base/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1513#include "base/memory/ref_counted.h"
14#include "base/memory/scoped_ptr.h"
[email protected]2a28e0b22011-02-03 21:49:0315#include "base/task.h"
[email protected]7cc2c912011-02-13 03:11:2116#include "chrome/common/automation_constants.h"
[email protected]7cc2c912011-02-13 03:11:2117#include "ui/base/keycodes/keyboard_codes.h"
[email protected]2a28e0b22011-02-03 21:49:0318
[email protected]ab6bb8e2011-03-03 22:41:1619class AutomationProxy;
[email protected]f6a9d2622011-05-13 17:33:5520class CommandLine;
[email protected]358dc4e2011-02-22 22:07:5721class DictionaryValue;
22class FilePath;
[email protected]6f3b4332011-02-15 23:22:3523class GURL;
[email protected]e4857a212011-03-26 17:14:0224class ListValue;
[email protected]358dc4e2011-02-22 22:07:5725class ProxyLauncher;
[email protected]5fb586a2011-03-08 00:06:2826struct WebKeyEvent;
[email protected]6f3b4332011-02-15 23:22:3527
[email protected]81edbaf2011-02-22 19:31:4828namespace gfx {
29class Point;
30}
31
[email protected]2a28e0b22011-02-03 21:49:0332namespace webdriver {
33
[email protected]2937a8c2011-05-20 15:02:3334class Error;
[email protected]f5aae772011-03-11 22:44:0835class FramePath;
36
[email protected]2a28e0b22011-02-03 21:49:0337// Creates and controls the Chrome instance.
38// This class should be created and accessed on a single thread.
[email protected]6f3b4332011-02-15 23:22:3539// Note: All member functions are void because they are invoked
40// by posting a task from NewRunnableMethod.
[email protected]358dc4e2011-02-22 22:07:5741class Automation {
[email protected]2a28e0b22011-02-03 21:49:0342 public:
[email protected]808d1032011-02-09 20:16:5543 Automation();
44 virtual ~Automation();
[email protected]2a28e0b22011-02-03 21:49:0345
[email protected]c4bdfe652011-05-17 20:14:2046 // Creates a browser, using the specified |browser_exe|.
47 void InitWithBrowserPath(const FilePath& browser_exe,
48 const CommandLine& options,
[email protected]2937a8c2011-05-20 15:02:3349 Error** error);
[email protected]c4bdfe652011-05-17 20:14:2050
51 // Start the system's default Chrome binary.
[email protected]2937a8c2011-05-20 15:02:3352 void Init(const CommandLine& options, Error** error);
[email protected]2a28e0b22011-02-03 21:49:0353
54 // Terminates this session and disconnects its automation proxy. After
55 // invoking this method, the Automation can safely be deleted.
56 void Terminate();
57
58 // Executes the given |script| in the specified frame of the current
59 // tab. |result| will be set to the JSON result. Returns true on success.
[email protected]496e5792011-02-17 17:02:5360 void ExecuteScript(int tab_id,
[email protected]f5aae772011-03-11 22:44:0861 const FramePath& frame_path,
[email protected]2a28e0b22011-02-03 21:49:0362 const std::string& script,
63 std::string* result,
[email protected]2937a8c2011-05-20 15:02:3364 Error** error);
[email protected]2a28e0b22011-02-03 21:49:0365
[email protected]47f21f12011-03-31 15:32:4266 // Sends a webkit key event to the current browser. Waits until the key has
[email protected]7cc2c912011-02-13 03:11:2167 // been processed by the web page.
[email protected]47f21f12011-03-31 15:32:4268 void SendWebKeyEvent(int tab_id,
69 const WebKeyEvent& key_event,
[email protected]2937a8c2011-05-20 15:02:3370 Error** error);
[email protected]47f21f12011-03-31 15:32:4271
72 // Sends an OS level key event to the current browser. Waits until the key
73 // has been processed by the browser.
74 void SendNativeKeyEvent(int tab_id,
75 ui::KeyboardCode key_code,
76 int modifiers,
[email protected]2937a8c2011-05-20 15:02:3377 Error** error);
[email protected]7cc2c912011-02-13 03:11:2178
[email protected]fcad49452011-06-28 17:11:5779 // Drag and drop the file paths to the given location.
80 void DragAndDropFilePaths(int tab_id,
81 const gfx::Point& location,
82 const std::vector<FilePath::StringType>& paths,
83 Error** error);
84
[email protected]98598afb2011-03-29 19:29:3785 // Captures a snapshot of the tab to the specified path. The PNG will
86 // contain the entire page, including what is not in the current view
87 // on the screen.
[email protected]2937a8c2011-05-20 15:02:3388 void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, Error** error);
[email protected]98598afb2011-03-29 19:29:3789
[email protected]2937a8c2011-05-20 15:02:3390 void NavigateToURL(int tab_id, const std::string& url, Error** error);
91 void GoForward(int tab_id, Error** error);
92 void GoBack(int tab_id, Error** error);
93 void Reload(int tab_id, Error** error);
[email protected]e4857a212011-03-26 17:14:0294
[email protected]2937a8c2011-05-20 15:02:3395 void GetCookies(const std::string& url, ListValue** cookies, Error** error);
[email protected]e4857a212011-03-26 17:14:0296 void GetCookiesDeprecated(
[email protected]496e5792011-02-17 17:02:5397 int tab_id, const GURL& gurl, std::string* cookies, bool* success);
[email protected]e4857a212011-03-26 17:14:0298 void DeleteCookie(const std::string& url,
[email protected]496e5792011-02-17 17:02:5399 const std::string& cookie_name,
[email protected]2937a8c2011-05-20 15:02:33100 Error** error);
[email protected]e4857a212011-03-26 17:14:02101 void DeleteCookieDeprecated(int tab_id,
102 const GURL& gurl,
103 const std::string& cookie_name,
104 bool* success);
[email protected]496e5792011-02-17 17:02:53105 void SetCookie(
[email protected]2937a8c2011-05-20 15:02:33106 const std::string& url, DictionaryValue* cookie_dict, Error** error);
[email protected]e4857a212011-03-26 17:14:02107 void SetCookieDeprecated(
[email protected]496e5792011-02-17 17:02:53108 int tab_id, const GURL& gurl, const std::string& cookie, bool* success);
[email protected]e4857a212011-03-26 17:14:02109
[email protected]2937a8c2011-05-20 15:02:33110 void MouseMove(int tab_id, const gfx::Point& p, Error** error);
[email protected]5fb586a2011-03-08 00:06:28111 void MouseClick(int tab_id,
112 const gfx::Point& p,
113 automation::MouseButton button,
[email protected]2937a8c2011-05-20 15:02:33114 Error** error);
[email protected]81edbaf2011-02-22 19:31:48115 void MouseDrag(int tab_id,
116 const gfx::Point& start,
117 const gfx::Point& end,
[email protected]2937a8c2011-05-20 15:02:33118 Error** error);
119 void MouseButtonDown(int tab_id, const gfx::Point& p, Error** error);
120 void MouseButtonUp(int tab_id, const gfx::Point& p, Error** error);
121 void MouseDoubleClick(int tab_id, const gfx::Point& p, Error** error);
[email protected]496e5792011-02-17 17:02:53122
123 // Get persistent IDs for all the tabs currently open. These IDs can be used
124 // to identify the tab as long as the tab exists.
[email protected]2937a8c2011-05-20 15:02:33125 void GetTabIds(std::vector<int>* tab_ids, Error** error);
[email protected]496e5792011-02-17 17:02:53126
127 // Check if the given tab exists currently.
[email protected]2937a8c2011-05-20 15:02:33128 void DoesTabExist(int tab_id, bool* does_exist, Error** error);
[email protected]496e5792011-02-17 17:02:53129
[email protected]2937a8c2011-05-20 15:02:33130 void CloseTab(int tab_id, Error** error);
[email protected]2a28e0b22011-02-03 21:49:03131
[email protected]16623742011-05-16 20:04:26132 // Gets the active JavaScript modal dialog's message.
[email protected]2937a8c2011-05-20 15:02:33133 void GetAppModalDialogMessage(std::string* message, Error** error);
[email protected]16623742011-05-16 20:04:26134
135 // Accepts or dismisses the active JavaScript modal dialog.
[email protected]2937a8c2011-05-20 15:02:33136 void AcceptOrDismissAppModalDialog(bool accept, Error** error);
[email protected]16623742011-05-16 20:04:26137
138 // Accepts an active prompt JavaScript modal dialog, using the given
139 // prompt text as the result of the prompt.
140 void AcceptPromptAppModalDialog(const std::string& prompt_text,
[email protected]2937a8c2011-05-20 15:02:33141 Error** error);
[email protected]16623742011-05-16 20:04:26142
[email protected]026667662011-02-22 20:48:25143 // Gets the version of the runing browser.
[email protected]e4857a212011-03-26 17:14:02144 void GetBrowserVersion(std::string* version);
[email protected]026667662011-02-22 20:48:25145
[email protected]75895ca2011-04-07 18:12:57146 // Gets the ChromeDriver automation version supported by the automation
147 // server.
[email protected]2937a8c2011-05-20 15:02:33148 void GetChromeDriverAutomationVersion(int* version, Error** error);
[email protected]75895ca2011-04-07 18:12:57149
[email protected]781dbd7d2011-02-25 23:23:27150 // Waits for all tabs to stop loading.
[email protected]2937a8c2011-05-20 15:02:33151 void WaitForAllTabsToStopLoading(Error** error);
[email protected]781dbd7d2011-02-25 23:23:27152
[email protected]2a28e0b22011-02-03 21:49:03153 private:
[email protected]ab6bb8e2011-03-03 22:41:16154 AutomationProxy* automation() const;
[email protected]2937a8c2011-05-20 15:02:33155 Error* GetIndicesForTab(int tab_id, int* browser_index, int* tab_index);
[email protected]28c580f2011-05-24 03:41:16156 Error* CompareVersion(int client_build_no,
157 int client_patch_no,
158 bool* is_newer_or_equal);
159 Error* CheckVersion(int client_build_no,
160 int client_patch_no,
161 const std::string& error_msg);
162 Error* CheckAlertsSupported();
163 Error* CheckAdvancedInteractionsSupported();
[email protected]2a28e0b22011-02-03 21:49:03164
[email protected]358dc4e2011-02-22 22:07:57165 scoped_ptr<ProxyLauncher> launcher_;
[email protected]ab6bb8e2011-03-03 22:41:16166
[email protected]2a28e0b22011-02-03 21:49:03167 DISALLOW_COPY_AND_ASSIGN(Automation);
168};
169
170} // namespace webdriver
171
172DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
173
174#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_