Skip to content

Commit b4b50e8

Browse files
committed
Added TouchClick, TouchDown, TouchUp, TouchDoubleClick commands
1 parent 9081f30 commit b4b50e8

File tree

8 files changed

+703
-25
lines changed

8 files changed

+703
-25
lines changed
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
#include "touch_commands.h"
2+
#include "chrome/test/webdriver/commands/response.h"
3+
#include "chrome/test/webdriver/webdriver_session.h"
4+
5+
namespace webdriver {
6+
7+
8+
TouchCommand::TouchCommand(
9+
const std::vector<std::string>& path_segments,
10+
const DictionaryValue* const parameters)
11+
: WebDriverCommand(path_segments, parameters) {}
12+
13+
TouchCommand::~TouchCommand() {}
14+
15+
bool TouchCommand::DoesPost() {
16+
return true;
17+
}
18+
19+
TouchClickCommand::TouchClickCommand(const std::vector<std::string>& path_segments,
20+
const DictionaryValue* const parameters)
21+
: TouchCommand(path_segments, parameters) {
22+
}
23+
24+
TouchClickCommand::~TouchClickCommand() {}
25+
26+
bool TouchClickCommand::Init(Response* const response) {
27+
if (!TouchCommand::Init(response))
28+
return false;
29+
30+
std::string element_name;
31+
has_element_ = GetStringParameter("element", &element_name);
32+
33+
if (has_element_) {
34+
element_ = ElementId(element_name);
35+
}
36+
37+
if (!has_element_ ) {
38+
response->SetError(new Error(
39+
kBadRequest, "Invalid command arguments"));
40+
}
41+
42+
return true;
43+
}
44+
45+
void TouchClickCommand::ExecutePost(Response* const response) {
46+
Point location;
47+
Error* error;
48+
printf("Execute Touch Click Comman post\n");
49+
50+
error = session_->GetElementLocationInView(element_, &location);
51+
if (error) {
52+
response->SetError(error);
53+
return;
54+
}
55+
56+
error = session_->TouchClick(location);
57+
if (error) {
58+
response->SetError(error);
59+
return;
60+
}
61+
}
62+
63+
TouchDoubleClickCommand::TouchDoubleClickCommand(const std::vector<std::string>& path_segments,
64+
const DictionaryValue* const parameters)
65+
: TouchCommand(path_segments, parameters) {
66+
}
67+
68+
TouchDoubleClickCommand::~TouchDoubleClickCommand() {}
69+
70+
bool TouchDoubleClickCommand::Init(Response* const response) {
71+
if (!TouchCommand::Init(response))
72+
return false;
73+
74+
std::string element_name;
75+
has_element_ = GetStringParameter("element", &element_name);
76+
77+
if (has_element_) {
78+
element_ = ElementId(element_name);
79+
}
80+
81+
if (!has_element_ ) {
82+
response->SetError(new Error(
83+
kBadRequest, "Invalid command arguments"));
84+
}
85+
86+
return true;
87+
}
88+
89+
void TouchDoubleClickCommand::ExecutePost(Response *const response)
90+
{
91+
Point location;
92+
Error* error;
93+
printf("Execute Touch Double Click Comman post\n");
94+
95+
error = session_->GetElementLocationInView(element_, &location);
96+
if (error) {
97+
response->SetError(error);
98+
return;
99+
}
100+
101+
error = session_->TouchDoubleClick(location);
102+
if (error) {
103+
response->SetError(error);
104+
return;
105+
}
106+
}
107+
108+
TouchDownCommand::TouchDownCommand(const std::vector<std::string>& path_segments,
109+
const DictionaryValue* const parameters)
110+
: TouchCommand(path_segments, parameters) {
111+
}
112+
113+
TouchDownCommand::~TouchDownCommand() {}
114+
115+
void TouchDownCommand::ExecutePost(Response *const response)
116+
{
117+
Error* error;
118+
printf("Execute Touch Down Comman post\n");
119+
120+
int x, y;
121+
if (!GetIntegerParameter("x", &x) ||
122+
!GetIntegerParameter("y", &y)) {
123+
response->SetError(new Error(
124+
kBadRequest,
125+
"Missing or invalid 'x' or 'y' parameters"));
126+
return;
127+
}
128+
129+
Point location(x, y);
130+
131+
132+
error = session_->TouchDown(location);
133+
if (error) {
134+
response->SetError(error);
135+
return;
136+
}
137+
}
138+
139+
TouchUpCommand::TouchUpCommand(const std::vector<std::string>& path_segments,
140+
const DictionaryValue* const parameters)
141+
: TouchCommand(path_segments, parameters) {
142+
}
143+
144+
TouchUpCommand::~TouchUpCommand() {}
145+
146+
void TouchUpCommand::ExecutePost(Response *const response)
147+
{
148+
Error* error;
149+
printf("Execute Touch Up Comman post\n");
150+
151+
int x, y;
152+
if (!GetIntegerParameter("x", &x) ||
153+
!GetIntegerParameter("y", &y)) {
154+
response->SetError(new Error(
155+
kBadRequest,
156+
"Missing or invalid 'x' or 'y' parameters"));
157+
return;
158+
}
159+
160+
Point location(x, y);
161+
162+
163+
error = session_->TouchUp(location);
164+
if (error) {
165+
response->SetError(error);
166+
return;
167+
}
168+
}
169+
170+
TouchMoveCommand::TouchMoveCommand(const std::vector<std::string>& path_segments,
171+
const DictionaryValue* const parameters)
172+
: TouchCommand(path_segments, parameters) {
173+
}
174+
175+
TouchMoveCommand::~TouchMoveCommand() {}
176+
177+
void TouchMoveCommand::ExecutePost(Response *const response)
178+
{
179+
Error* error;
180+
printf("Execute Touch Move Comman post\n");
181+
182+
int x, y;
183+
if (!GetIntegerParameter("x", &x) ||
184+
!GetIntegerParameter("y", &y)) {
185+
response->SetError(new Error(
186+
kBadRequest,
187+
"Missing or invalid 'x' or 'y' parameters"));
188+
return;
189+
}
190+
191+
Point location(x, y);
192+
193+
194+
error = session_->TouchDown(location);
195+
if (error) {
196+
response->SetError(error);
197+
return;
198+
}
199+
}
200+
201+
TouchScrollCommand::TouchScrollCommand(const std::vector<std::string>& path_segments,
202+
const DictionaryValue* const parameters)
203+
: TouchCommand(path_segments, parameters) {
204+
}
205+
206+
TouchScrollCommand::~TouchScrollCommand() {}
207+
208+
void TouchScrollCommand::ExecutePost(Response *const response)
209+
{
210+
Error* error;
211+
printf("Execute Touch Scroll Comman post\n");
212+
213+
}
214+
215+
TouchLongClickCommand::TouchLongClickCommand(const std::vector<std::string>& path_segments,
216+
const DictionaryValue* const parameters)
217+
: TouchCommand(path_segments, parameters) {
218+
}
219+
220+
TouchLongClickCommand::~TouchLongClickCommand() {}
221+
222+
void TouchLongClickCommand::ExecutePost(Response *const response)
223+
{
224+
Error* error;
225+
printf("Execute Touch LongClick post\n");
226+
227+
}
228+
229+
TouchFlickCommand::TouchFlickCommand(const std::vector<std::string>& path_segments,
230+
const DictionaryValue* const parameters)
231+
: TouchCommand(path_segments, parameters) {
232+
}
233+
234+
TouchFlickCommand::~TouchFlickCommand() {}
235+
236+
void TouchFlickCommand::ExecutePost(Response *const response)
237+
{
238+
Error* error;
239+
printf("Execute Touch Flick post\n");
240+
241+
}
242+
243+
244+
}
245+
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
#ifndef TOUCH_COMMANDS_H
2+
#define TOUCH_COMMANDS_H
3+
4+
#include <string>
5+
#include <vector>
6+
7+
#include "chrome/test/webdriver/commands/webelement_commands.h"
8+
#include "chrome/test/webdriver/webdriver_element_id.h"
9+
10+
namespace base {
11+
class DictionaryValue;
12+
}
13+
14+
namespace webdriver {
15+
16+
class Response;
17+
18+
class TouchCommand : public WebDriverCommand {
19+
public:
20+
TouchCommand(const std::vector<std::string>& path_segments,
21+
const base::DictionaryValue* const parameters);
22+
virtual ~TouchCommand();
23+
24+
virtual bool DoesPost() OVERRIDE;
25+
26+
private:
27+
DISALLOW_COPY_AND_ASSIGN(TouchCommand);
28+
};
29+
30+
class TouchClickCommand : public TouchCommand {
31+
public:
32+
TouchClickCommand(const std::vector<std::string>& path_segments,
33+
const base::DictionaryValue* const parameters);
34+
virtual ~TouchClickCommand();
35+
36+
virtual bool Init(Response* const response) OVERRIDE;
37+
virtual void ExecutePost(Response* const response) OVERRIDE;
38+
39+
private:
40+
bool has_element_;
41+
ElementId element_;
42+
43+
DISALLOW_COPY_AND_ASSIGN(TouchClickCommand);
44+
};
45+
46+
class TouchDownCommand : public TouchCommand {
47+
public:
48+
TouchDownCommand(const std::vector<std::string>& path_segments,
49+
const base::DictionaryValue* const parameters);
50+
virtual ~TouchDownCommand();
51+
52+
virtual void ExecutePost(Response* const response) OVERRIDE;
53+
54+
private:
55+
DISALLOW_COPY_AND_ASSIGN(TouchDownCommand);
56+
};
57+
58+
class TouchUpCommand : public TouchCommand {
59+
public:
60+
TouchUpCommand(const std::vector<std::string>& path_segments,
61+
const base::DictionaryValue* const parameters);
62+
virtual ~TouchUpCommand();
63+
64+
virtual void ExecutePost(Response* const response) OVERRIDE;
65+
66+
private:
67+
DISALLOW_COPY_AND_ASSIGN(TouchUpCommand);
68+
};
69+
70+
class TouchDoubleClickCommand : public TouchCommand {
71+
public:
72+
TouchDoubleClickCommand(const std::vector<std::string>& ps,
73+
const base::DictionaryValue* const parameters);
74+
virtual ~TouchDoubleClickCommand();
75+
76+
virtual bool Init(Response* const response) OVERRIDE;
77+
virtual void ExecutePost(Response* const response) OVERRIDE;
78+
79+
private:
80+
bool has_element_;
81+
ElementId element_;
82+
83+
DISALLOW_COPY_AND_ASSIGN(TouchDoubleClickCommand);
84+
};
85+
86+
class TouchMoveCommand : public TouchCommand {
87+
public:
88+
TouchMoveCommand(const std::vector<std::string>& path_segments,
89+
const base::DictionaryValue* const parameters);
90+
virtual ~TouchMoveCommand();
91+
92+
virtual void ExecutePost(Response* const response) OVERRIDE;
93+
94+
private:
95+
DISALLOW_COPY_AND_ASSIGN(TouchMoveCommand);
96+
};
97+
98+
class TouchScrollCommand : public TouchCommand {
99+
public:
100+
TouchScrollCommand(const std::vector<std::string>& path_segments,
101+
const base::DictionaryValue* const parameters);
102+
virtual ~TouchScrollCommand();
103+
104+
virtual void ExecutePost(Response* const response) OVERRIDE;
105+
106+
private:
107+
DISALLOW_COPY_AND_ASSIGN(TouchScrollCommand);
108+
};
109+
110+
class TouchLongClickCommand : public TouchCommand {
111+
public:
112+
TouchLongClickCommand(const std::vector<std::string>& path_segments,
113+
const base::DictionaryValue* const parameters);
114+
virtual ~TouchLongClickCommand();
115+
116+
virtual void ExecutePost(Response* const response) OVERRIDE;
117+
118+
private:
119+
DISALLOW_COPY_AND_ASSIGN(TouchLongClickCommand);
120+
};
121+
122+
class TouchFlickCommand : public TouchCommand {
123+
public:
124+
TouchFlickCommand(const std::vector<std::string>& path_segments,
125+
const base::DictionaryValue* const parameters);
126+
virtual ~TouchFlickCommand();
127+
128+
virtual void ExecutePost(Response* const response) OVERRIDE;
129+
130+
private:
131+
DISALLOW_COPY_AND_ASSIGN(TouchFlickCommand);
132+
};
133+
134+
} // namespace webdriver
135+
136+
#endif // TOUCH_COMMANDS_H

0 commit comments

Comments
 (0)