blob: 6b70f631a88369d016a1abf21614a0caa62406e0 [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]3b63f8f42011-03-28 01:54:1512#include "base/memory/ref_counted.h"
13#include "base/memory/scoped_ptr.h"
[email protected]2a28e0b22011-02-03 21:49:0314#include "base/task.h"
[email protected]7cc2c912011-02-13 03:11:2115#include "chrome/common/automation_constants.h"
[email protected]75895ca2011-04-07 18:12:5716#include "chrome/test/webdriver/error_codes.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]f5aae772011-03-11 22:44:0834class FramePath;
35
[email protected]2a28e0b22011-02-03 21:49:0336// Creates and controls the Chrome instance.
37// This class should be created and accessed on a single thread.
[email protected]6f3b4332011-02-15 23:22:3538// Note: All member functions are void because they are invoked
39// by posting a task from NewRunnableMethod.
[email protected]358dc4e2011-02-22 22:07:5740class Automation {
[email protected]2a28e0b22011-02-03 21:49:0341 public:
[email protected]808d1032011-02-09 20:16:5542 Automation();
43 virtual ~Automation();
[email protected]2a28e0b22011-02-03 21:49:0344
[email protected]c4bdfe652011-05-17 20:14:2045 // Creates a browser, using the specified |browser_exe|.
46 void InitWithBrowserPath(const FilePath& browser_exe,
47 const CommandLine& options,
48 ErrorCode* code);
49
50 // Start the system's default Chrome binary.
51 void Init(const CommandLine& options,
[email protected]f6a9d2622011-05-13 17:33:5552 ErrorCode* code);
[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,
64 bool* success);
65
[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,
70 bool* success);
71
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,
77 bool* success);
[email protected]7cc2c912011-02-13 03:11:2178
[email protected]98598afb2011-03-29 19:29:3779 // Captures a snapshot of the tab to the specified path. The PNG will
80 // contain the entire page, including what is not in the current view
81 // on the screen.
82 void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, bool* success);
83
[email protected]496e5792011-02-17 17:02:5384 void NavigateToURL(int tab_id, const std::string& url, bool* success);
85 void GoForward(int tab_id, bool* success);
86 void GoBack(int tab_id, bool* success);
87 void Reload(int tab_id, bool* success);
[email protected]e4857a212011-03-26 17:14:0288
89 void GetCookies(const std::string& url, ListValue** cookies, bool* success);
90 void GetCookiesDeprecated(
[email protected]496e5792011-02-17 17:02:5391 int tab_id, const GURL& gurl, std::string* cookies, bool* success);
[email protected]e4857a212011-03-26 17:14:0292 void DeleteCookie(const std::string& url,
[email protected]496e5792011-02-17 17:02:5393 const std::string& cookie_name,
[email protected]6f3b4332011-02-15 23:22:3594 bool* success);
[email protected]e4857a212011-03-26 17:14:0295 void DeleteCookieDeprecated(int tab_id,
96 const GURL& gurl,
97 const std::string& cookie_name,
98 bool* success);
[email protected]496e5792011-02-17 17:02:5399 void SetCookie(
[email protected]e4857a212011-03-26 17:14:02100 const std::string& url, DictionaryValue* cookie_dict, bool* success);
101 void SetCookieDeprecated(
[email protected]496e5792011-02-17 17:02:53102 int tab_id, const GURL& gurl, const std::string& cookie, bool* success);
[email protected]e4857a212011-03-26 17:14:02103
[email protected]81edbaf2011-02-22 19:31:48104 void MouseMove(int tab_id, const gfx::Point& p, bool* success);
[email protected]5fb586a2011-03-08 00:06:28105 void MouseClick(int tab_id,
106 const gfx::Point& p,
107 automation::MouseButton button,
108 bool* success);
[email protected]81edbaf2011-02-22 19:31:48109 void MouseDrag(int tab_id,
110 const gfx::Point& start,
111 const gfx::Point& end,
112 bool* success);
[email protected]a1b38b3c2011-04-27 15:49:16113 void MouseButtonDown(int tab_id, const gfx::Point& p, bool* success);
114 void MouseButtonUp(int tab_id, const gfx::Point& p, bool* success);
115 void MouseDoubleClick(int tab_id, const gfx::Point& p, bool* success);
[email protected]496e5792011-02-17 17:02:53116
117 // Get persistent IDs for all the tabs currently open. These IDs can be used
118 // to identify the tab as long as the tab exists.
119 void GetTabIds(std::vector<int>* tab_ids, bool* success);
120
121 // Check if the given tab exists currently.
[email protected]5fb586a2011-03-08 00:06:28122 void DoesTabExist(int tab_id, bool* does_exist, bool* success);
[email protected]496e5792011-02-17 17:02:53123
124 void CloseTab(int tab_id, bool* success);
[email protected]2a28e0b22011-02-03 21:49:03125
[email protected]16623742011-05-16 20:04:26126 // Gets the active JavaScript modal dialog's message.
127 void GetAppModalDialogMessage(std::string* message, bool* success);
128
129 // Accepts or dismisses the active JavaScript modal dialog.
130 void AcceptOrDismissAppModalDialog(bool accept, bool* success);
131
132 // Accepts an active prompt JavaScript modal dialog, using the given
133 // prompt text as the result of the prompt.
134 void AcceptPromptAppModalDialog(const std::string& prompt_text,
135 bool* success);
136
[email protected]026667662011-02-22 20:48:25137 // Gets the version of the runing browser.
[email protected]e4857a212011-03-26 17:14:02138 void GetBrowserVersion(std::string* version);
[email protected]026667662011-02-22 20:48:25139
[email protected]75895ca2011-04-07 18:12:57140 // Gets the ChromeDriver automation version supported by the automation
141 // server.
142 void GetChromeDriverAutomationVersion(int* version, bool* success);
143
[email protected]781dbd7d2011-02-25 23:23:27144 // Waits for all tabs to stop loading.
145 void WaitForAllTabsToStopLoading(bool* success);
146
[email protected]2a28e0b22011-02-03 21:49:03147 private:
[email protected]ab6bb8e2011-03-03 22:41:16148 AutomationProxy* automation() const;
[email protected]5fb586a2011-03-08 00:06:28149 bool GetIndicesForTab(int tab_id, int* browser_index, int* tab_index);
[email protected]2a28e0b22011-02-03 21:49:03150
[email protected]358dc4e2011-02-22 22:07:57151 scoped_ptr<ProxyLauncher> launcher_;
[email protected]ab6bb8e2011-03-03 22:41:16152
[email protected]2a28e0b22011-02-03 21:49:03153 DISALLOW_COPY_AND_ASSIGN(Automation);
154};
155
156} // namespace webdriver
157
158DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
159
160#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_