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
|
// 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_WEBDRIVER_AUTOMATION_H_
#define CHROME_TEST_WEBDRIVER_AUTOMATION_H_
#include <map>
#include <string>
#include <vector>
#include "base/task.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
#include "chrome/common/automation_constants.h"
#include "ui/base/keycodes/keyboard_codes.h"
class DictionaryValue;
class FilePath;
class GURL;
class ProxyLauncher;
class TabProxy;
namespace gfx {
class Point;
}
namespace webdriver {
struct WebKeyEvent {
WebKeyEvent(automation::KeyEventTypes type,
ui::KeyboardCode key_code,
const std::string& unmodified_text,
const std::string& modified_text,
int modifiers);
automation::KeyEventTypes type;
ui::KeyboardCode key_code;
std::string unmodified_text;
std::string modified_text;
int modifiers;
};
// Creates and controls the Chrome instance.
// This class should be created and accessed on a single thread.
// Note: All member functions are void because they are invoked
// by posting a task from NewRunnableMethod.
class Automation {
public:
Automation();
virtual ~Automation();
// Creates a browser, using the exe found in |browser_dir|. If |browser_dir|
// is empty, it will search in all the default locations.
void Init(const FilePath& browser_dir, bool* success);
// Terminates this session and disconnects its automation proxy. After
// invoking this method, the Automation can safely be deleted.
void Terminate();
// Executes the given |script| in the specified frame of the current
// tab. |result| will be set to the JSON result. Returns true on success.
void ExecuteScript(int tab_id,
const std::string& frame_xpath,
const std::string& script,
std::string* result,
bool* success);
// Sends a key event to the current browser. Waits until the key has
// been processed by the web page.
void SendWebKeyEvent(int tab_id, const WebKeyEvent& key_event, bool* success);
void NavigateToURL(int tab_id, const std::string& url, bool* success);
void GoForward(int tab_id, bool* success);
void GoBack(int tab_id, bool* success);
void Reload(int tab_id, bool* success);
void GetURL(int tab_id, std::string* url, bool* success);
void GetGURL(int tab_id, GURL* gurl, bool* success);
void GetTabTitle(int tab_id, std::string* tab_title, bool* success);
void GetCookies(
int tab_id, const GURL& gurl, std::string* cookies, bool* success);
void GetCookieByName(int tab_id,
const GURL& gurl,
const std::string& cookie_name,
std::string* cookie,
bool* success);
void DeleteCookie(int tab_id,
const GURL& gurl,
const std::string& cookie_name,
bool* success);
void SetCookie(
int tab_id, const GURL& gurl, const std::string& cookie, bool* success);
void MouseMove(int tab_id, const gfx::Point& p, bool* success);
void MouseClick(int tab_id, const gfx::Point& p, int flag, bool* success);
void MouseDrag(int tab_id,
const gfx::Point& start,
const gfx::Point& end,
bool* success);
// Get persistent IDs for all the tabs currently open. These IDs can be used
// to identify the tab as long as the tab exists.
void GetTabIds(std::vector<int>* tab_ids, bool* success);
// Check if the given tab exists currently.
void DoesTabExist(int tab_id, bool* does_exist);
void CloseTab(int tab_id, bool* success);
// Gets the version of the runing browser.
void GetVersion(std::string* version);
private:
typedef std::map<int, scoped_refptr<TabProxy> > TabIdMap;
TabProxy* GetTabById(int tab_id);
scoped_ptr<ProxyLauncher> launcher_;
// Map from tab ID to |TabProxy|. The tab ID is simply the |AutomationHandle|
// for the proxy.
TabIdMap tab_id_map_;
bool SendJSONRequest(
int tab_id, const DictionaryValue& dict, std::string* reply);
DISALLOW_COPY_AND_ASSIGN(Automation);
};
} // namespace webdriver
DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_
|