Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: chrome/test/webdriver/automation.cc

Issue 7522024: Refactor chromedriver's script execution to reduce amount of custom Value parsing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/automation.h" 5 #include "chrome/test/webdriver/automation.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 13 matching lines...) Expand all
24 #include "base/utf_string_conversions.h" 24 #include "base/utf_string_conversions.h"
25 #include "base/values.h" 25 #include "base/values.h"
26 #include "chrome/common/automation_constants.h" 26 #include "chrome/common/automation_constants.h"
27 #include "chrome/common/chrome_constants.h" 27 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/url_constants.h" 29 #include "chrome/common/url_constants.h"
30 #include "chrome/test/automation/automation_json_requests.h" 30 #include "chrome/test/automation/automation_json_requests.h"
31 #include "chrome/test/automation/automation_proxy.h" 31 #include "chrome/test/automation/automation_proxy.h"
32 #include "chrome/test/automation/proxy_launcher.h" 32 #include "chrome/test/automation/proxy_launcher.h"
33 #include "chrome/test/webdriver/frame_path.h" 33 #include "chrome/test/webdriver/frame_path.h"
34 #include "chrome/test/webdriver/webdriver_basic_types.h"
34 #include "chrome/test/webdriver/webdriver_error.h" 35 #include "chrome/test/webdriver/webdriver_error.h"
35 #include "ui/gfx/point.h"
36 36
37 #if defined(OS_WIN) 37 #if defined(OS_WIN)
38 #include "base/win/registry.h" 38 #include "base/win/registry.h"
39 #include "base/win/windows_version.h" 39 #include "base/win/windows_version.h"
40 #endif 40 #endif
41 41
42 namespace { 42 namespace {
43 43
44 // Gets the path to the default Chrome executable. Returns true on success. 44 // Gets the path to the default Chrome executable. Returns true on success.
45 bool GetDefaultChromeExe(FilePath* browser_exe) { 45 bool GetDefaultChromeExe(FilePath* browser_exe) {
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 &unscoped_value, &error_msg)) { 235 &unscoped_value, &error_msg)) {
236 *error = new Error(kUnknownError, error_msg); 236 *error = new Error(kUnknownError, error_msg);
237 return; 237 return;
238 } 238 }
239 scoped_ptr<Value> value(unscoped_value); 239 scoped_ptr<Value> value(unscoped_value);
240 if (!value->GetAsString(result)) 240 if (!value->GetAsString(result))
241 *error = new Error(kUnknownError, "Execute script did not return string"); 241 *error = new Error(kUnknownError, "Execute script did not return string");
242 } 242 }
243 243
244 void Automation::MouseMove(int tab_id, 244 void Automation::MouseMove(int tab_id,
245 const gfx::Point& p, 245 const Point& p,
246 Error** error) { 246 Error** error) {
247 int windex = 0, tab_index = 0; 247 int windex = 0, tab_index = 0;
248 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 248 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
249 if (*error) 249 if (*error)
250 return; 250 return;
251 251
252 std::string error_msg; 252 std::string error_msg;
253 if (!SendMouseMoveJSONRequest( 253 if (!SendMouseMoveJSONRequest(
254 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 254 automation(), windex, tab_index,
255 static_cast<int>(p.x()), static_cast<int>(p.y()), &error_msg)) {
255 *error = new Error(kUnknownError, error_msg); 256 *error = new Error(kUnknownError, error_msg);
256 } 257 }
257 } 258 }
258 259
259 void Automation::MouseClick(int tab_id, 260 void Automation::MouseClick(int tab_id,
260 const gfx::Point& p, 261 const Point& p,
261 automation::MouseButton button, 262 automation::MouseButton button,
262 Error** error) { 263 Error** error) {
263 int windex = 0, tab_index = 0; 264 int windex = 0, tab_index = 0;
264 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 265 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
265 if (*error) 266 if (*error)
266 return; 267 return;
267 268
268 std::string error_msg; 269 std::string error_msg;
269 if (!SendMouseClickJSONRequest( 270 if (!SendMouseClickJSONRequest(
270 automation(), windex, tab_index, button, p.x(), p.y(), &error_msg)) { 271 automation(), windex, tab_index, button, p.x(), p.y(), &error_msg)) {
271 *error = new Error(kUnknownError, error_msg); 272 *error = new Error(kUnknownError, error_msg);
272 } 273 }
273 } 274 }
274 275
275 void Automation::MouseDrag(int tab_id, 276 void Automation::MouseDrag(int tab_id,
276 const gfx::Point& start, 277 const Point& start,
277 const gfx::Point& end, 278 const Point& end,
278 Error** error) { 279 Error** error) {
279 int windex = 0, tab_index = 0; 280 int windex = 0, tab_index = 0;
280 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 281 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
281 if (*error) 282 if (*error)
282 return; 283 return;
283 284
284 std::string error_msg; 285 std::string error_msg;
285 if (!SendMouseDragJSONRequest(automation(), windex, tab_index, start.x(), 286 if (!SendMouseDragJSONRequest(
286 start.y(), end.x(), end.y(), &error_msg)) { 287 automation(), windex, tab_index, static_cast<int>(start.x()),
288 static_cast<int>(start.y()), static_cast<int>(end.x()),
Paweł Hajdan Jr. 2011/08/02 20:04:47 Why do we need those static_casts all over the pla
kkania 2011/08/03 17:07:56 Done.
289 static_cast<int>(end.y()), &error_msg)) {
287 *error = new Error(kUnknownError, error_msg); 290 *error = new Error(kUnknownError, error_msg);
288 } 291 }
289 } 292 }
290 293
291 void Automation::MouseButtonUp(int tab_id, 294 void Automation::MouseButtonUp(int tab_id,
292 const gfx::Point& p, 295 const Point& p,
293 Error** error) { 296 Error** error) {
294 *error = CheckAdvancedInteractionsSupported(); 297 *error = CheckAdvancedInteractionsSupported();
295 if (*error) 298 if (*error)
296 return; 299 return;
297 300
298 int windex = 0, tab_index = 0; 301 int windex = 0, tab_index = 0;
299 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 302 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
300 if (*error) 303 if (*error)
301 return; 304 return;
302 305
303 std::string error_msg; 306 std::string error_msg;
304 if (!SendMouseButtonUpJSONRequest( 307 if (!SendMouseButtonUpJSONRequest(
305 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 308 automation(), windex, tab_index, static_cast<int>(p.x()),
309 static_cast<int>(p.y()), &error_msg)) {
306 *error = new Error(kUnknownError, error_msg); 310 *error = new Error(kUnknownError, error_msg);
307 } 311 }
308 } 312 }
309 313
310 void Automation::MouseButtonDown(int tab_id, 314 void Automation::MouseButtonDown(int tab_id,
311 const gfx::Point& p, 315 const Point& p,
312 Error** error) { 316 Error** error) {
313 *error = CheckAdvancedInteractionsSupported(); 317 *error = CheckAdvancedInteractionsSupported();
314 if (*error) 318 if (*error)
315 return; 319 return;
316 320
317 int windex = 0, tab_index = 0; 321 int windex = 0, tab_index = 0;
318 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 322 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
319 if (*error) 323 if (*error)
320 return; 324 return;
321 325
322 std::string error_msg; 326 std::string error_msg;
323 if (!SendMouseButtonDownJSONRequest( 327 if (!SendMouseButtonDownJSONRequest(
324 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 328 automation(), windex, tab_index, static_cast<int>(p.x()),
329 static_cast<int>(p.y()), &error_msg)) {
325 *error = new Error(kUnknownError, error_msg); 330 *error = new Error(kUnknownError, error_msg);
326 } 331 }
327 } 332 }
328 333
329 void Automation::MouseDoubleClick(int tab_id, 334 void Automation::MouseDoubleClick(int tab_id,
330 const gfx::Point& p, 335 const Point& p,
331 Error** error) { 336 Error** error) {
332 *error = CheckAdvancedInteractionsSupported(); 337 *error = CheckAdvancedInteractionsSupported();
333 if (*error) 338 if (*error)
334 return; 339 return;
335 340
336 int windex = 0, tab_index = 0; 341 int windex = 0, tab_index = 0;
337 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 342 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
338 if (*error) 343 if (*error)
339 return; 344 return;
340 345
341 std::string error_msg; 346 std::string error_msg;
342 if (!SendMouseDoubleClickJSONRequest( 347 if (!SendMouseDoubleClickJSONRequest(
343 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 348 automation(), windex, tab_index, static_cast<int>(p.x()),
349 static_cast<int>(p.y()), &error_msg)) {
344 *error = new Error(kUnknownError, error_msg); 350 *error = new Error(kUnknownError, error_msg);
345 } 351 }
346 } 352 }
347 353
348 void Automation::DragAndDropFilePaths( 354 void Automation::DragAndDropFilePaths(
349 int tab_id, const gfx::Point& location, 355 int tab_id, const Point& location,
350 const std::vector<FilePath::StringType>& paths, Error** error) { 356 const std::vector<FilePath::StringType>& paths, Error** error) {
351 int windex = 0, tab_index = 0; 357 int windex = 0, tab_index = 0;
352 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 358 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
353 if (*error) { 359 if (*error) {
354 return; 360 return;
355 } 361 }
356 362
357 std::string error_msg; 363 std::string error_msg;
358 if (!SendDragAndDropFilePathsJSONRequest( 364 if (!SendDragAndDropFilePathsJSONRequest(
359 automation(), windex, tab_index, location.x(), location.y(), paths, 365 automation(), windex, tab_index, static_cast<int>(location.x()),
366 static_cast<int>(location.y()), paths,
360 &error_msg)) { 367 &error_msg)) {
361 *error = new Error(kUnknownError, error_msg); 368 *error = new Error(kUnknownError, error_msg);
362 } 369 }
363 } 370 }
364 371
365 void Automation::SendWebKeyEvent(int tab_id, 372 void Automation::SendWebKeyEvent(int tab_id,
366 const WebKeyEvent& key_event, 373 const WebKeyEvent& key_event,
367 Error** error) { 374 Error** error) {
368 int windex = 0, tab_index = 0; 375 int windex = 0, tab_index = 0;
369 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 376 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 768, 0, "Alerts are not supported for this version of Chrome"); 633 768, 0, "Alerts are not supported for this version of Chrome");
627 } 634 }
628 635
629 Error* Automation::CheckAdvancedInteractionsSupported() { 636 Error* Automation::CheckAdvancedInteractionsSupported() {
630 const char* message = 637 const char* message =
631 "Advanced user interactions are not supported for this version of Chrome"; 638 "Advanced user interactions are not supported for this version of Chrome";
632 return CheckVersion(750, 0, message); 639 return CheckVersion(750, 0, message);
633 } 640 }
634 641
635 } // namespace webdriver 642 } // namespace webdriver
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698