blob: 3886c948f32bb32ec1d42c0d649c9045131355cd [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]16b14292011-08-15 17:03:4512#include "base/command_line.h"
[email protected]fcad49452011-06-28 17:11:5713#include "base/file_path.h"
[email protected]3b63f8f42011-03-28 01:54:1514#include "base/memory/ref_counted.h"
15#include "base/memory/scoped_ptr.h"
[email protected]2a28e0b22011-02-03 21:49:0316#include "base/task.h"
[email protected]7cc2c912011-02-13 03:11:2117#include "chrome/common/automation_constants.h"
[email protected]7cc2c912011-02-13 03:11:2118#include "ui/base/keycodes/keyboard_codes.h"
[email protected]2a28e0b22011-02-03 21:49:0319
[email protected]ab6bb8e2011-03-03 22:41:1620class AutomationProxy;
[email protected]358dc4e2011-02-22 22:07:5721class ProxyLauncher;
[email protected]5fb586a2011-03-08 00:06:2822struct WebKeyEvent;
[email protected]6f3b4332011-02-15 23:22:3523
[email protected]f3a1c642011-07-12 19:15:0324namespace base {
25class DictionaryValue;
26class ListValue;
27}
28
[email protected]2a28e0b22011-02-03 21:49:0329namespace webdriver {
30
[email protected]2937a8c2011-05-20 15:02:3331class Error;
[email protected]f5aae772011-03-11 22:44:0832class FramePath;
[email protected]3e981b22011-08-16 15:20:0133class Point;
[email protected]f5aae772011-03-11 22:44:0834
[email protected]2a28e0b22011-02-03 21:49:0335// Creates and controls the Chrome instance.
36// This class should be created and accessed on a single thread.
[email protected]6f3b4332011-02-15 23:22:3537// Note: All member functions are void because they are invoked
38// by posting a task from NewRunnableMethod.
[email protected]358dc4e2011-02-22 22:07:5739class Automation {
[email protected]2a28e0b22011-02-03 21:49:0340 public:
[email protected]16b14292011-08-15 17:03:4541 struct BrowserOptions {
42 BrowserOptions();
43 ~BrowserOptions();
44
45 CommandLine command;
46 FilePath user_data_dir;
47 std::string channel_id;
48 };
49
[email protected]808d1032011-02-09 20:16:5550 Automation();
51 virtual ~Automation();
[email protected]2a28e0b22011-02-03 21:49:0352
[email protected]c4bdfe652011-05-17 20:14:2053 // Start the system's default Chrome binary.
[email protected]16b14292011-08-15 17:03:4554 void Init(const BrowserOptions& options, Error** error);
[email protected]2a28e0b22011-02-03 21:49:0355
56 // Terminates this session and disconnects its automation proxy. After
57 // invoking this method, the Automation can safely be deleted.
58 void Terminate();
59
60 // Executes the given |script| in the specified frame of the current
61 // tab. |result| will be set to the JSON result. Returns true on success.
[email protected]496e5792011-02-17 17:02:5362 void ExecuteScript(int tab_id,
[email protected]f5aae772011-03-11 22:44:0863 const FramePath& frame_path,
[email protected]2a28e0b22011-02-03 21:49:0364 const std::string& script,
65 std::string* result,
[email protected]2937a8c2011-05-20 15:02:3366 Error** error);
[email protected]2a28e0b22011-02-03 21:49:0367
[email protected]47f21f12011-03-31 15:32:4268 // Sends a webkit key event to the current browser. Waits until the key has
[email protected]7cc2c912011-02-13 03:11:2169 // been processed by the web page.
[email protected]47f21f12011-03-31 15:32:4270 void SendWebKeyEvent(int tab_id,
71 const WebKeyEvent& key_event,
[email protected]2937a8c2011-05-20 15:02:3372 Error** error);
[email protected]47f21f12011-03-31 15:32:4273
74 // Sends an OS level key event to the current browser. Waits until the key
75 // has been processed by the browser.
76 void SendNativeKeyEvent(int tab_id,
77 ui::KeyboardCode key_code,
78 int modifiers,
[email protected]2937a8c2011-05-20 15:02:3379 Error** error);
[email protected]7cc2c912011-02-13 03:11:2180
[email protected]fcad49452011-06-28 17:11:5781 // Drag and drop the file paths to the given location.
82 void DragAndDropFilePaths(int tab_id,
[email protected]3e981b22011-08-16 15:20:0183 const Point& location,
[email protected]fcad49452011-06-28 17:11:5784 const std::vector<FilePath::StringType>& paths,
85 Error** error);
86
[email protected]98598afb2011-03-29 19:29:3787 // Captures a snapshot of the tab to the specified path. The PNG will
88 // contain the entire page, including what is not in the current view
89 // on the screen.
[email protected]2937a8c2011-05-20 15:02:3390 void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, Error** error);
[email protected]98598afb2011-03-29 19:29:3791
[email protected]2937a8c2011-05-20 15:02:3392 void NavigateToURL(int tab_id, const std::string& url, Error** error);
[email protected]33ef9382011-08-11 00:04:5593 void NavigateToURLAsync(int tab_id, const std::string& url, Error** error);
[email protected]2937a8c2011-05-20 15:02:3394 void GoForward(int tab_id, Error** error);
95 void GoBack(int tab_id, Error** error);
96 void Reload(int tab_id, Error** error);
[email protected]e4857a212011-03-26 17:14:0297
[email protected]f3a1c642011-07-12 19:15:0398 void GetCookies(const std::string& url,
99 base::ListValue** cookies,
100 Error** error);
[email protected]e4857a212011-03-26 17:14:02101 void DeleteCookie(const std::string& url,
[email protected]496e5792011-02-17 17:02:53102 const std::string& cookie_name,
[email protected]2937a8c2011-05-20 15:02:33103 Error** error);
[email protected]f3a1c642011-07-12 19:15:03104 void SetCookie(const std::string& url,
105 base::DictionaryValue* cookie_dict,
106 Error** error);
[email protected]e4857a212011-03-26 17:14:02107
[email protected]3e981b22011-08-16 15:20:01108 void MouseMove(int tab_id, const Point& p, Error** error);
[email protected]5fb586a2011-03-08 00:06:28109 void MouseClick(int tab_id,
[email protected]3e981b22011-08-16 15:20:01110 const Point& p,
[email protected]5fb586a2011-03-08 00:06:28111 automation::MouseButton button,
[email protected]2937a8c2011-05-20 15:02:33112 Error** error);
[email protected]81edbaf2011-02-22 19:31:48113 void MouseDrag(int tab_id,
[email protected]3e981b22011-08-16 15:20:01114 const Point& start,
115 const Point& end,
[email protected]2937a8c2011-05-20 15:02:33116 Error** error);
[email protected]3e981b22011-08-16 15:20:01117 void MouseButtonDown(int tab_id, const Point& p, Error** error);
118 void MouseButtonUp(int tab_id, const Point& p, Error** error);
119 void MouseDoubleClick(int tab_id, const Point& p, Error** error);
[email protected]496e5792011-02-17 17:02:53120
121 // Get persistent IDs for all the tabs currently open. These IDs can be used
122 // to identify the tab as long as the tab exists.
[email protected]2937a8c2011-05-20 15:02:33123 void GetTabIds(std::vector<int>* tab_ids, Error** error);
[email protected]496e5792011-02-17 17:02:53124
125 // Check if the given tab exists currently.
[email protected]2937a8c2011-05-20 15:02:33126 void DoesTabExist(int tab_id, bool* does_exist, Error** error);
[email protected]496e5792011-02-17 17:02:53127
[email protected]2937a8c2011-05-20 15:02:33128 void CloseTab(int tab_id, Error** error);
[email protected]2a28e0b22011-02-03 21:49:03129
[email protected]16623742011-05-16 20:04:26130 // Gets the active JavaScript modal dialog's message.
[email protected]2937a8c2011-05-20 15:02:33131 void GetAppModalDialogMessage(std::string* message, Error** error);
[email protected]16623742011-05-16 20:04:26132
133 // Accepts or dismisses the active JavaScript modal dialog.
[email protected]2937a8c2011-05-20 15:02:33134 void AcceptOrDismissAppModalDialog(bool accept, Error** error);
[email protected]16623742011-05-16 20:04:26135
136 // Accepts an active prompt JavaScript modal dialog, using the given
137 // prompt text as the result of the prompt.
138 void AcceptPromptAppModalDialog(const std::string& prompt_text,
[email protected]2937a8c2011-05-20 15:02:33139 Error** error);
[email protected]16623742011-05-16 20:04:26140
[email protected]026667662011-02-22 20:48:25141 // Gets the version of the runing browser.
[email protected]e4857a212011-03-26 17:14:02142 void GetBrowserVersion(std::string* version);
[email protected]026667662011-02-22 20:48:25143
[email protected]75895ca2011-04-07 18:12:57144 // Gets the ChromeDriver automation version supported by the automation
145 // server.
[email protected]2937a8c2011-05-20 15:02:33146 void GetChromeDriverAutomationVersion(int* version, Error** error);
[email protected]75895ca2011-04-07 18:12:57147
[email protected]781dbd7d2011-02-25 23:23:27148 // Waits for all tabs to stop loading.
[email protected]2937a8c2011-05-20 15:02:33149 void WaitForAllTabsToStopLoading(Error** error);
[email protected]781dbd7d2011-02-25 23:23:27150
[email protected]f5fe3612011-08-01 17:44:23151 // Install packed extension.
152 void InstallExtension(const FilePath& path, Error** error);
153
[email protected]2a28e0b22011-02-03 21:49:03154 private:
[email protected]ab6bb8e2011-03-03 22:41:16155 AutomationProxy* automation() const;
[email protected]2937a8c2011-05-20 15:02:33156 Error* GetIndicesForTab(int tab_id, int* browser_index, int* tab_index);
[email protected]28c580f2011-05-24 03:41:16157 Error* CompareVersion(int client_build_no,
158 int client_patch_no,
159 bool* is_newer_or_equal);
160 Error* CheckVersion(int client_build_no,
161 int client_patch_no,
162 const std::string& error_msg);
163 Error* CheckAlertsSupported();
164 Error* CheckAdvancedInteractionsSupported();
[email protected]2a28e0b22011-02-03 21:49:03165
[email protected]358dc4e2011-02-22 22:07:57166 scoped_ptr<ProxyLauncher> launcher_;
[email protected]ab6bb8e2011-03-03 22:41:16167
[email protected]2a28e0b22011-02-03 21:49:03168 DISALLOW_COPY_AND_ASSIGN(Automation);
169};
170
171} // namespace webdriver
172
173DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
174
175#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_