blob: 48152575bde89d0020821b518a24ba228588efd5 [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]7cc2c912011-02-13 03:11:2116#include "ui/base/keycodes/keyboard_codes.h"
[email protected]2a28e0b22011-02-03 21:49:0317
[email protected]ab6bb8e2011-03-03 22:41:1618class AutomationProxy;
[email protected]358dc4e2011-02-22 22:07:5719class DictionaryValue;
20class FilePath;
[email protected]6f3b4332011-02-15 23:22:3521class GURL;
[email protected]e4857a212011-03-26 17:14:0222class ListValue;
[email protected]358dc4e2011-02-22 22:07:5723class ProxyLauncher;
[email protected]5fb586a2011-03-08 00:06:2824struct WebKeyEvent;
[email protected]6f3b4332011-02-15 23:22:3525
[email protected]81edbaf2011-02-22 19:31:4826namespace gfx {
27class Point;
28}
29
[email protected]2a28e0b22011-02-03 21:49:0330namespace webdriver {
31
[email protected]f5aae772011-03-11 22:44:0832class FramePath;
33
[email protected]2a28e0b22011-02-03 21:49:0334// Creates and controls the Chrome instance.
35// This class should be created and accessed on a single thread.
[email protected]6f3b4332011-02-15 23:22:3536// Note: All member functions are void because they are invoked
37// by posting a task from NewRunnableMethod.
[email protected]358dc4e2011-02-22 22:07:5738class Automation {
[email protected]2a28e0b22011-02-03 21:49:0339 public:
[email protected]808d1032011-02-09 20:16:5540 Automation();
41 virtual ~Automation();
[email protected]2a28e0b22011-02-03 21:49:0342
[email protected]358dc4e2011-02-22 22:07:5743 // Creates a browser, using the exe found in |browser_dir|. If |browser_dir|
44 // is empty, it will search in all the default locations.
45 void Init(const FilePath& browser_dir, bool* success);
[email protected]2a28e0b22011-02-03 21:49:0346
47 // Terminates this session and disconnects its automation proxy. After
48 // invoking this method, the Automation can safely be deleted.
49 void Terminate();
50
51 // Executes the given |script| in the specified frame of the current
52 // tab. |result| will be set to the JSON result. Returns true on success.
[email protected]496e5792011-02-17 17:02:5353 void ExecuteScript(int tab_id,
[email protected]f5aae772011-03-11 22:44:0854 const FramePath& frame_path,
[email protected]2a28e0b22011-02-03 21:49:0355 const std::string& script,
56 std::string* result,
57 bool* success);
58
[email protected]47f21f12011-03-31 15:32:4259 // Sends a webkit key event to the current browser. Waits until the key has
[email protected]7cc2c912011-02-13 03:11:2160 // been processed by the web page.
[email protected]47f21f12011-03-31 15:32:4261 void SendWebKeyEvent(int tab_id,
62 const WebKeyEvent& key_event,
63 bool* success);
64
65 // Sends an OS level key event to the current browser. Waits until the key
66 // has been processed by the browser.
67 void SendNativeKeyEvent(int tab_id,
68 ui::KeyboardCode key_code,
69 int modifiers,
70 bool* success);
[email protected]7cc2c912011-02-13 03:11:2171
[email protected]98598afb2011-03-29 19:29:3772 // Captures a snapshot of the tab to the specified path. The PNG will
73 // contain the entire page, including what is not in the current view
74 // on the screen.
75 void CaptureEntirePageAsPNG(int tab_id, const FilePath& path, bool* success);
76
[email protected]496e5792011-02-17 17:02:5377 void NavigateToURL(int tab_id, const std::string& url, bool* success);
78 void GoForward(int tab_id, bool* success);
79 void GoBack(int tab_id, bool* success);
80 void Reload(int tab_id, bool* success);
81 void GetURL(int tab_id, std::string* url, bool* success);
82 void GetGURL(int tab_id, GURL* gurl, bool* success);
83 void GetTabTitle(int tab_id, std::string* tab_title, bool* success);
[email protected]e4857a212011-03-26 17:14:0284
85 void GetCookies(const std::string& url, ListValue** cookies, bool* success);
86 void GetCookiesDeprecated(
[email protected]496e5792011-02-17 17:02:5387 int tab_id, const GURL& gurl, std::string* cookies, bool* success);
[email protected]e4857a212011-03-26 17:14:0288 void DeleteCookie(const std::string& url,
[email protected]496e5792011-02-17 17:02:5389 const std::string& cookie_name,
[email protected]6f3b4332011-02-15 23:22:3590 bool* success);
[email protected]e4857a212011-03-26 17:14:0291 void DeleteCookieDeprecated(int tab_id,
92 const GURL& gurl,
93 const std::string& cookie_name,
94 bool* success);
[email protected]496e5792011-02-17 17:02:5395 void SetCookie(
[email protected]e4857a212011-03-26 17:14:0296 const std::string& url, DictionaryValue* cookie_dict, bool* success);
97 void SetCookieDeprecated(
[email protected]496e5792011-02-17 17:02:5398 int tab_id, const GURL& gurl, const std::string& cookie, bool* success);
[email protected]e4857a212011-03-26 17:14:0299
[email protected]81edbaf2011-02-22 19:31:48100 void MouseMove(int tab_id, const gfx::Point& p, bool* success);
[email protected]5fb586a2011-03-08 00:06:28101 void MouseClick(int tab_id,
102 const gfx::Point& p,
103 automation::MouseButton button,
104 bool* success);
[email protected]81edbaf2011-02-22 19:31:48105 void MouseDrag(int tab_id,
106 const gfx::Point& start,
107 const gfx::Point& end,
108 bool* success);
[email protected]496e5792011-02-17 17:02:53109
110 // Get persistent IDs for all the tabs currently open. These IDs can be used
111 // to identify the tab as long as the tab exists.
112 void GetTabIds(std::vector<int>* tab_ids, bool* success);
113
114 // Check if the given tab exists currently.
[email protected]5fb586a2011-03-08 00:06:28115 void DoesTabExist(int tab_id, bool* does_exist, bool* success);
[email protected]496e5792011-02-17 17:02:53116
117 void CloseTab(int tab_id, bool* success);
[email protected]2a28e0b22011-02-03 21:49:03118
[email protected]026667662011-02-22 20:48:25119 // Gets the version of the runing browser.
[email protected]e4857a212011-03-26 17:14:02120 void GetBrowserVersion(std::string* version);
[email protected]026667662011-02-22 20:48:25121
[email protected]781dbd7d2011-02-25 23:23:27122 // Waits for all tabs to stop loading.
123 void WaitForAllTabsToStopLoading(bool* success);
124
[email protected]2a28e0b22011-02-03 21:49:03125 private:
[email protected]ab6bb8e2011-03-03 22:41:16126 AutomationProxy* automation() const;
[email protected]5fb586a2011-03-08 00:06:28127 bool GetIndicesForTab(int tab_id, int* browser_index, int* tab_index);
[email protected]2a28e0b22011-02-03 21:49:03128
[email protected]358dc4e2011-02-22 22:07:57129 scoped_ptr<ProxyLauncher> launcher_;
[email protected]ab6bb8e2011-03-03 22:41:16130
[email protected]2a28e0b22011-02-03 21:49:03131 DISALLOW_COPY_AND_ASSIGN(Automation);
132};
133
134} // namespace webdriver
135
136DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
137
138#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_