OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/webdriver/commands/mouse_commands.h" | 5 #include "chrome/test/webdriver/commands/mouse_commands.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/common/automation_constants.h" | 8 #include "chrome/common/automation_constants.h" |
9 #include "chrome/test/automation/value_conversion_util.h" | 9 #include "chrome/test/automation/value_conversion_util.h" |
10 #include "chrome/test/webdriver/commands/response.h" | 10 #include "chrome/test/webdriver/commands/response.h" |
11 #include "chrome/test/webdriver/webdriver_basic_types.h" | 11 #include "chrome/test/webdriver/webdriver_basic_types.h" |
12 #include "chrome/test/webdriver/webdriver_element_id.h" | 12 #include "chrome/test/webdriver/webdriver_element_id.h" |
13 #include "chrome/test/webdriver/webdriver_error.h" | 13 #include "chrome/test/webdriver/webdriver_error.h" |
14 #include "chrome/test/webdriver/webdriver_session.h" | 14 #include "chrome/test/webdriver/webdriver_session.h" |
15 #include "chrome/test/webdriver/webdriver_util.h" | 15 #include "chrome/test/webdriver/webdriver_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 const int kLeftButton = 0; | 19 const int kLeftButton = 0; |
20 const int kMiddleButton = 1; | 20 const int kMiddleButton = 1; |
21 const int kRightButton = 2; | 21 const int kRightButton = 2; |
22 | 22 |
23 } // namespace | 23 } // namespace |
24 | 24 |
25 namespace webdriver { | 25 namespace webdriver { |
26 | 26 |
27 MoveAndClickCommand::MoveAndClickCommand( | 27 MoveAndClickCommand::MoveAndClickCommand( |
28 const std::vector<std::string>& path_segments, | 28 const std::vector<std::string>& path_segments, |
29 const DictionaryValue* const parameters) | 29 DictionaryValue* const parameters) |
30 : WebElementCommand(path_segments, parameters) {} | 30 : WebElementCommand(path_segments, parameters) {} |
31 | 31 |
32 MoveAndClickCommand::~MoveAndClickCommand() {} | 32 MoveAndClickCommand::~MoveAndClickCommand() {} |
33 | 33 |
34 bool MoveAndClickCommand::DoesPost() { | 34 bool MoveAndClickCommand::DoesPost() { |
35 return true; | 35 return true; |
36 } | 36 } |
37 | 37 |
38 void MoveAndClickCommand::ExecutePost(Response* response) { | 38 void MoveAndClickCommand::ExecutePost(Response* response) { |
39 std::string tag_name; | 39 std::string tag_name; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 if (!error) | 81 if (!error) |
82 error = session_->MouseMoveAndClick(location, automation::kLeftButton); | 82 error = session_->MouseMoveAndClick(location, automation::kLeftButton); |
83 } | 83 } |
84 if (error) { | 84 if (error) { |
85 response->SetError(error); | 85 response->SetError(error); |
86 return; | 86 return; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments, | 90 HoverCommand::HoverCommand(const std::vector<std::string>& path_segments, |
91 const DictionaryValue* const parameters) | 91 DictionaryValue* const parameters) |
92 : WebElementCommand(path_segments, parameters) {} | 92 : WebElementCommand(path_segments, parameters) {} |
93 | 93 |
94 HoverCommand::~HoverCommand() {} | 94 HoverCommand::~HoverCommand() {} |
95 | 95 |
96 bool HoverCommand::DoesPost() { | 96 bool HoverCommand::DoesPost() { |
97 return true; | 97 return true; |
98 } | 98 } |
99 | 99 |
100 void HoverCommand::ExecutePost(Response* response) { | 100 void HoverCommand::ExecutePost(Response* response) { |
101 Error* error = NULL; | 101 Error* error = NULL; |
102 Point location; | 102 Point location; |
103 error = session_->GetClickableLocation(element, &location); | 103 error = session_->GetClickableLocation(element, &location); |
104 if (!error) | 104 if (!error) |
105 error = session_->MouseMove(location); | 105 error = session_->MouseMove(location); |
106 if (error) { | 106 if (error) { |
107 response->SetError(error); | 107 response->SetError(error); |
108 return; | 108 return; |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 DragCommand::DragCommand(const std::vector<std::string>& path_segments, | 112 DragCommand::DragCommand(const std::vector<std::string>& path_segments, |
113 const DictionaryValue* const parameters) | 113 DictionaryValue* const parameters) |
114 : WebElementCommand(path_segments, parameters) {} | 114 : WebElementCommand(path_segments, parameters) {} |
115 | 115 |
116 DragCommand::~DragCommand() {} | 116 DragCommand::~DragCommand() {} |
117 | 117 |
118 bool DragCommand::Init(Response* const response) { | 118 bool DragCommand::Init(Response* const response) { |
119 if (!WebElementCommand::Init(response)) | 119 if (!WebElementCommand::Init(response)) |
120 return false; | 120 return false; |
121 | 121 |
122 if (!GetIntegerParameter("x", &drag_x_) || | 122 if (!GetIntegerParameter("x", &drag_x_) || |
123 !GetIntegerParameter("y", &drag_y_)) { | 123 !GetIntegerParameter("y", &drag_y_)) { |
(...skipping 25 matching lines...) Expand all Loading... |
149 error = session_->MouseDrag(drag_from, drag_to); | 149 error = session_->MouseDrag(drag_from, drag_to); |
150 | 150 |
151 if (error) { | 151 if (error) { |
152 response->SetError(error); | 152 response->SetError(error); |
153 return; | 153 return; |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 AdvancedMouseCommand::AdvancedMouseCommand( | 157 AdvancedMouseCommand::AdvancedMouseCommand( |
158 const std::vector<std::string>& path_segments, | 158 const std::vector<std::string>& path_segments, |
159 const DictionaryValue* const parameters) | 159 DictionaryValue* const parameters) |
160 : WebDriverCommand(path_segments, parameters) {} | 160 : WebDriverCommand(path_segments, parameters) {} |
161 | 161 |
162 AdvancedMouseCommand::~AdvancedMouseCommand() {} | 162 AdvancedMouseCommand::~AdvancedMouseCommand() {} |
163 | 163 |
164 bool AdvancedMouseCommand::DoesPost() { | 164 bool AdvancedMouseCommand::DoesPost() { |
165 return true; | 165 return true; |
166 } | 166 } |
167 | 167 |
168 MoveToCommand::MoveToCommand( | 168 MoveToCommand::MoveToCommand( |
169 const std::vector<std::string>& path_segments, | 169 const std::vector<std::string>& path_segments, |
170 const DictionaryValue* const parameters) | 170 DictionaryValue* const parameters) |
171 : AdvancedMouseCommand(path_segments, parameters), has_element_(false), | 171 : AdvancedMouseCommand(path_segments, parameters), has_element_(false), |
172 has_offset_(false), x_offset_(0), y_offset_(0) {} | 172 has_offset_(false), x_offset_(0), y_offset_(0) {} |
173 | 173 |
174 MoveToCommand::~MoveToCommand() {} | 174 MoveToCommand::~MoveToCommand() {} |
175 | 175 |
176 bool MoveToCommand::Init(Response* const response) { | 176 bool MoveToCommand::Init(Response* const response) { |
177 if (!AdvancedMouseCommand::Init(response)) | 177 if (!AdvancedMouseCommand::Init(response)) |
178 return false; | 178 return false; |
179 | 179 |
180 std::string element_name; | 180 std::string element_name; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 231 } |
232 | 232 |
233 error = session_->MouseMove(location); | 233 error = session_->MouseMove(location); |
234 if (error) { | 234 if (error) { |
235 response->SetError(error); | 235 response->SetError(error); |
236 return; | 236 return; |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 ClickCommand::ClickCommand(const std::vector<std::string>& path_segments, | 240 ClickCommand::ClickCommand(const std::vector<std::string>& path_segments, |
241 const DictionaryValue* const parameters) | 241 DictionaryValue* const parameters) |
242 : AdvancedMouseCommand(path_segments, parameters) {} | 242 : AdvancedMouseCommand(path_segments, parameters) {} |
243 | 243 |
244 ClickCommand::~ClickCommand() {} | 244 ClickCommand::~ClickCommand() {} |
245 | 245 |
246 bool ClickCommand::Init(Response* const response) { | 246 bool ClickCommand::Init(Response* const response) { |
247 if (!AdvancedMouseCommand::Init(response)) | 247 if (!AdvancedMouseCommand::Init(response)) |
248 return false; | 248 return false; |
249 | 249 |
250 if (!GetIntegerParameter("button", &button_)) { | 250 if (!GetIntegerParameter("button", &button_)) { |
251 response->SetError(new Error(kBadRequest, "Missing mouse button argument")); | 251 response->SetError(new Error(kBadRequest, "Missing mouse button argument")); |
(...skipping 19 matching lines...) Expand all Loading... |
271 | 271 |
272 Error* error = session_->MouseClick(button); | 272 Error* error = session_->MouseClick(button); |
273 if (error) { | 273 if (error) { |
274 response->SetError(error); | 274 response->SetError(error); |
275 return; | 275 return; |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 ButtonDownCommand::ButtonDownCommand( | 279 ButtonDownCommand::ButtonDownCommand( |
280 const std::vector<std::string>& path_segments, | 280 const std::vector<std::string>& path_segments, |
281 const DictionaryValue* const parameters) | 281 DictionaryValue* const parameters) |
282 : AdvancedMouseCommand(path_segments, parameters) {} | 282 : AdvancedMouseCommand(path_segments, parameters) {} |
283 | 283 |
284 ButtonDownCommand::~ButtonDownCommand() {} | 284 ButtonDownCommand::~ButtonDownCommand() {} |
285 | 285 |
286 void ButtonDownCommand::ExecutePost(Response* const response) { | 286 void ButtonDownCommand::ExecutePost(Response* const response) { |
287 session_->MouseButtonDown(); | 287 session_->MouseButtonDown(); |
288 } | 288 } |
289 | 289 |
290 ButtonUpCommand::ButtonUpCommand(const std::vector<std::string>& path_segments, | 290 ButtonUpCommand::ButtonUpCommand(const std::vector<std::string>& path_segments, |
291 const DictionaryValue* const parameters) | 291 DictionaryValue* const parameters) |
292 : AdvancedMouseCommand(path_segments, parameters) {} | 292 : AdvancedMouseCommand(path_segments, parameters) {} |
293 | 293 |
294 ButtonUpCommand::~ButtonUpCommand() {} | 294 ButtonUpCommand::~ButtonUpCommand() {} |
295 | 295 |
296 void ButtonUpCommand::ExecutePost(Response* const response) { | 296 void ButtonUpCommand::ExecutePost(Response* const response) { |
297 session_->MouseButtonUp(); | 297 session_->MouseButtonUp(); |
298 } | 298 } |
299 | 299 |
300 DoubleClickCommand::DoubleClickCommand( | 300 DoubleClickCommand::DoubleClickCommand( |
301 const std::vector<std::string>& path_segments, | 301 const std::vector<std::string>& path_segments, |
302 const DictionaryValue* const parameters) | 302 DictionaryValue* const parameters) |
303 : AdvancedMouseCommand(path_segments, parameters) {} | 303 : AdvancedMouseCommand(path_segments, parameters) {} |
304 | 304 |
305 DoubleClickCommand::~DoubleClickCommand() {} | 305 DoubleClickCommand::~DoubleClickCommand() {} |
306 | 306 |
307 void DoubleClickCommand::ExecutePost(Response* const response) { | 307 void DoubleClickCommand::ExecutePost(Response* const response) { |
308 Error* error = session_->MouseDoubleClick(); | 308 Error* error = session_->MouseDoubleClick(); |
309 if (error) { | 309 if (error) { |
310 response->SetError(error); | 310 response->SetError(error); |
311 return; | 311 return; |
312 } | 312 } |
313 } | 313 } |
314 | 314 |
315 } // namespace webdriver | 315 } // namespace webdriver |
OLD | NEW |