Skip to content

Commit b96ddb2

Browse files
committed
Clean up Touch commands
1 parent 93180d5 commit b96ddb2

File tree

5 files changed

+45
-96
lines changed

5 files changed

+45
-96
lines changed

src/chrome/test/webdriver/commands/touch_commands.cc

Lines changed: 35 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,20 @@ TouchClickCommand::TouchClickCommand(const std::vector<std::string>& path_segmen
2323

2424
TouchClickCommand::~TouchClickCommand() {}
2525

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-
4526
void TouchClickCommand::ExecutePost(Response* const response) {
4627
Point location;
4728
Error* error;
48-
printf("Execute Touch Click Comman post\n");
29+
std::string element_name;
30+
31+
if (!GetStringParameter("element", &element_name))
32+
{
33+
response->SetError(new Error(
34+
kBadRequest, "Invalid command arguments"));
35+
}
36+
37+
ElementId element = ElementId(element_name);
4938

50-
error = session_->GetElementLocationInView(element_, &location);
39+
error = session_->GetElementLocationInView(element, &location);
5140
if (error) {
5241
response->SetError(error);
5342
return;
@@ -67,32 +56,22 @@ TouchDoubleClickCommand::TouchDoubleClickCommand(const std::vector<std::string>&
6756

6857
TouchDoubleClickCommand::~TouchDoubleClickCommand() {}
6958

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-
}
8859

8960
void TouchDoubleClickCommand::ExecutePost(Response *const response)
9061
{
9162
Point location;
9263
Error* error;
93-
printf("Execute Touch Double Click Comman post\n");
64+
std::string element_name;
65+
66+
if (!GetStringParameter("element", &element_name))
67+
{
68+
response->SetError(new Error(
69+
kBadRequest, "Invalid command arguments"));
70+
}
71+
72+
ElementId element = ElementId(element_name);
9473

95-
error = session_->GetElementLocationInView(element_, &location);
74+
error = session_->GetElementLocationInView(element, &location);
9675
if (error) {
9776
response->SetError(error);
9877
return;
@@ -115,9 +94,8 @@ TouchDownCommand::~TouchDownCommand() {}
11594
void TouchDownCommand::ExecutePost(Response *const response)
11695
{
11796
Error* error;
118-
printf("Execute Touch Down Comman post\n");
119-
12097
int x, y;
98+
12199
if (!GetIntegerParameter("x", &x) ||
122100
!GetIntegerParameter("y", &y)) {
123101
response->SetError(new Error(
@@ -146,9 +124,8 @@ TouchUpCommand::~TouchUpCommand() {}
146124
void TouchUpCommand::ExecutePost(Response *const response)
147125
{
148126
Error* error;
149-
printf("Execute Touch Up Comman post\n");
150-
151127
int x, y;
128+
152129
if (!GetIntegerParameter("x", &x) ||
153130
!GetIntegerParameter("y", &y)) {
154131
response->SetError(new Error(
@@ -177,9 +154,8 @@ TouchMoveCommand::~TouchMoveCommand() {}
177154
void TouchMoveCommand::ExecutePost(Response *const response)
178155
{
179156
Error* error;
180-
printf("Execute Touch Move Comman post\n");
181-
182157
int x, y;
158+
183159
if (!GetIntegerParameter("x", &x) ||
184160
!GetIntegerParameter("y", &y)) {
185161
response->SetError(new Error(
@@ -208,9 +184,8 @@ TouchScrollCommand::~TouchScrollCommand() {}
208184
void TouchScrollCommand::ExecutePost(Response *const response)
209185
{
210186
Error* error;
211-
printf("Execute Scroll Comman post\n");
212-
213187
int x, y;
188+
214189
if (!GetIntegerParameter("xoffset", &x) ||
215190
!GetIntegerParameter("yoffset", &y)) {
216191
response->SetError(new Error(
@@ -254,33 +229,21 @@ TouchLongClickCommand::TouchLongClickCommand(const std::vector<std::string>& pat
254229

255230
TouchLongClickCommand::~TouchLongClickCommand() {}
256231

257-
bool TouchLongClickCommand::Init(Response* const response) {
258-
if (!TouchCommand::Init(response))
259-
return false;
260-
261-
std::string element_name;
262-
has_element_ = GetStringParameter("element", &element_name);
263-
264-
if (has_element_) {
265-
element_ = ElementId(element_name);
266-
}
267-
268-
if (!has_element_ ) {
269-
response->SetError(new Error(
270-
kBadRequest, "Invalid command arguments"));
271-
}
272-
273-
return true;
274-
}
275-
276232
void TouchLongClickCommand::ExecutePost(Response *const response)
277233
{
278234
Error* error;
279-
printf("Execute Touch LongClick post\n");
280-
281235
Point location;
236+
std::string element_name;
237+
238+
if (!GetStringParameter("element", &element_name))
239+
{
240+
response->SetError(new Error(
241+
kBadRequest, "Invalid command arguments"));
242+
}
282243

283-
error = session_->GetElementLocationInView(element_, &location);
244+
ElementId element = ElementId(element_name);
245+
246+
error = session_->GetElementLocationInView(element, &location);
284247
if (error) {
285248
response->SetError(error);
286249
return;
@@ -304,11 +267,10 @@ TouchFlickCommand::~TouchFlickCommand() {}
304267
void TouchFlickCommand::ExecutePost(Response *const response)
305268
{
306269
Error* error;
307-
printf("Execute Touch Flick post\n");
308-
309270
int xSpeed, ySpeed;
310271
int xoffset, yoffset, speed;
311272
std::string element_name;
273+
312274
if (GetIntegerParameter("xspeed", &xSpeed) &&
313275
GetIntegerParameter("yspeed", &ySpeed))
314276
{
@@ -323,8 +285,6 @@ void TouchFlickCommand::ExecutePost(Response *const response)
323285
}
324286
else
325287
{
326-
if (GetStringParameter("element", &element_name))
327-
printf("ElementName\n");
328288
response->SetError(new Error(
329289
kBadRequest,
330290
"Missing or invalid parameters"));

src/chrome/test/webdriver/commands/touch_commands.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,19 @@ class TouchCommand : public WebDriverCommand {
2727
DISALLOW_COPY_AND_ASSIGN(TouchCommand);
2828
};
2929

30+
//Single tap on the touch enabled device.
3031
class TouchClickCommand : public TouchCommand {
3132
public:
3233
TouchClickCommand(const std::vector<std::string>& path_segments,
3334
const base::DictionaryValue* const parameters);
3435
virtual ~TouchClickCommand();
3536

36-
virtual bool Init(Response* const response) OVERRIDE;
3737
virtual void ExecutePost(Response* const response) OVERRIDE;
3838

39-
private:
40-
bool has_element_;
41-
ElementId element_;
42-
4339
DISALLOW_COPY_AND_ASSIGN(TouchClickCommand);
4440
};
4541

42+
//Finger down on the screen.
4643
class TouchDownCommand : public TouchCommand {
4744
public:
4845
TouchDownCommand(const std::vector<std::string>& path_segments,
@@ -55,6 +52,8 @@ class TouchDownCommand : public TouchCommand {
5552
DISALLOW_COPY_AND_ASSIGN(TouchDownCommand);
5653
};
5754

55+
56+
//Finger up on the screen.
5857
class TouchUpCommand : public TouchCommand {
5958
public:
6059
TouchUpCommand(const std::vector<std::string>& path_segments,
@@ -67,22 +66,19 @@ class TouchUpCommand : public TouchCommand {
6766
DISALLOW_COPY_AND_ASSIGN(TouchUpCommand);
6867
};
6968

69+
//Double tap on the touch screen using finger motion events.
7070
class TouchDoubleClickCommand : public TouchCommand {
7171
public:
7272
TouchDoubleClickCommand(const std::vector<std::string>& ps,
7373
const base::DictionaryValue* const parameters);
7474
virtual ~TouchDoubleClickCommand();
7575

76-
virtual bool Init(Response* const response) OVERRIDE;
7776
virtual void ExecutePost(Response* const response) OVERRIDE;
7877

79-
private:
80-
bool has_element_;
81-
ElementId element_;
82-
8378
DISALLOW_COPY_AND_ASSIGN(TouchDoubleClickCommand);
8479
};
8580

81+
//Finger move on the screen.
8682
class TouchMoveCommand : public TouchCommand {
8783
public:
8884
TouchMoveCommand(const std::vector<std::string>& path_segments,
@@ -95,6 +91,7 @@ class TouchMoveCommand : public TouchCommand {
9591
DISALLOW_COPY_AND_ASSIGN(TouchMoveCommand);
9692
};
9793

94+
//Scroll on the touch screen using finger based motion events.
9895
class TouchScrollCommand : public TouchCommand {
9996
public:
10097
TouchScrollCommand(const std::vector<std::string>& path_segments,
@@ -107,21 +104,18 @@ class TouchScrollCommand : public TouchCommand {
107104
DISALLOW_COPY_AND_ASSIGN(TouchScrollCommand);
108105
};
109106

107+
//Long press on the touch screen using finger motion events.
110108
class TouchLongClickCommand : public TouchCommand {
111109
public:
112110
TouchLongClickCommand(const std::vector<std::string>& path_segments,
113111
const base::DictionaryValue* const parameters);
114112
virtual ~TouchLongClickCommand();
115-
virtual bool Init(Response* const response) OVERRIDE;
116113
virtual void ExecutePost(Response* const response) OVERRIDE;
117114

118-
private:
119-
bool has_element_;
120-
ElementId element_;
121-
122115
DISALLOW_COPY_AND_ASSIGN(TouchLongClickCommand);
123116
};
124117

118+
//Flick on the touch screen using finger motion events.
125119
class TouchFlickCommand : public TouchCommand {
126120
public:
127121
TouchFlickCommand(const std::vector<std::string>& path_segments,

src/chrome/test/webdriver/webdriver_automation.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,6 @@ void Automation::TouchFlick(const WebViewId &view_id, const int &xSpeed, const i
22662266
QWidget *view = view_id.GetView();
22672267

22682268
QWebView *webView = qobject_cast<QWebView*>(view);
2269-
std::cout<<"Speed x= "<<xSpeed*3<<" y="<<ySpeed*3<<std::endl;
22702269
webView->page()->mainFrame()->scroll(xSpeed*3, ySpeed*3);
22712270
}
22722271

@@ -2280,7 +2279,6 @@ void Automation::TouchFlickElement(const WebViewId &view_id, const ElementId &el
22802279
}
22812280

22822281
QWidget *view = view_id.GetView();
2283-
std::cout<<"Offset x= "<<-offset.x()*(speed+1)<<" y="<<-offset.y()*(speed+1)<<std::endl;
22842282
QWebView *webView = qobject_cast<QWebView*>(view);
22852283
webView->page()->mainFrame()->scroll(-offset.x()*(speed+1), -offset.y()*(speed+1));
22862284
}

src/chrome/test/webdriver/webdriver_session.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,8 +2668,6 @@ Error* Session::TouchScroll(Point location)
26682668
current_target_.view_id,
26692669
location,
26702670
&error));
2671-
if (!error)
2672-
mouse_position_ = location;
26732671
return error;
26742672
}
26752673

@@ -2683,8 +2681,6 @@ Error* Session::TouchScroll(ElementId element, Point location)
26832681
element,
26842682
location,
26852683
&error));
2686-
if (!error)
2687-
mouse_position_ = location;
26882684
return error;
26892685
}
26902686

src/chrome/test/webdriver/webdriver_session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class Session {
406406
// Overrides the current geolocation.
407407
Error* OverrideGeolocation(const base::DictionaryValue* geolocation);
408408

409+
//touch command
409410
Error* TouchClick(Point location);
410411

411412
Error* TouchDoubleClick(Point location);

0 commit comments

Comments
 (0)