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

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: rebase 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
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/mouse_commands.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 17 matching lines...) Expand all
28 #include "chrome/common/chrome_constants.h" 28 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
31 #include "chrome/test/automation/automation_json_requests.h" 31 #include "chrome/test/automation/automation_json_requests.h"
32 #include "chrome/test/automation/automation_proxy.h" 32 #include "chrome/test/automation/automation_proxy.h"
33 #include "chrome/test/automation/browser_proxy.h" 33 #include "chrome/test/automation/browser_proxy.h"
34 #include "chrome/test/automation/extension_proxy.h" 34 #include "chrome/test/automation/extension_proxy.h"
35 #include "chrome/test/automation/proxy_launcher.h" 35 #include "chrome/test/automation/proxy_launcher.h"
36 #include "chrome/test/automation/tab_proxy.h" 36 #include "chrome/test/automation/tab_proxy.h"
37 #include "chrome/test/webdriver/frame_path.h" 37 #include "chrome/test/webdriver/frame_path.h"
38 #include "chrome/test/webdriver/utility_functions.h" 38 #include "chrome/test/webdriver/webdriver_basic_types.h"
39 #include "chrome/test/webdriver/webdriver_error.h" 39 #include "chrome/test/webdriver/webdriver_error.h"
40 #include "ui/gfx/point.h" 40 #include "chrome/test/webdriver/webdriver_util.h"
41 41
42 #if defined(OS_WIN) 42 #if defined(OS_WIN)
43 #include "base/win/registry.h" 43 #include "base/win/registry.h"
44 #include "base/win/windows_version.h" 44 #include "base/win/windows_version.h"
45 #endif 45 #endif
46 46
47 namespace { 47 namespace {
48 48
49 // Iterates through each browser executable path, and checks if the path exists 49 // Iterates through each browser executable path, and checks if the path exists
50 // in any of the given locations. If found, returns true and sets |browser_exe|. 50 // in any of the given locations. If found, returns true and sets |browser_exe|.
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 &unscoped_value, &error_msg)) { 295 &unscoped_value, &error_msg)) {
296 *error = new Error(kUnknownError, error_msg); 296 *error = new Error(kUnknownError, error_msg);
297 return; 297 return;
298 } 298 }
299 scoped_ptr<Value> value(unscoped_value); 299 scoped_ptr<Value> value(unscoped_value);
300 if (!value->GetAsString(result)) 300 if (!value->GetAsString(result))
301 *error = new Error(kUnknownError, "Execute script did not return string"); 301 *error = new Error(kUnknownError, "Execute script did not return string");
302 } 302 }
303 303
304 void Automation::MouseMove(int tab_id, 304 void Automation::MouseMove(int tab_id,
305 const gfx::Point& p, 305 const Point& p,
306 Error** error) { 306 Error** error) {
307 int windex = 0, tab_index = 0; 307 int windex = 0, tab_index = 0;
308 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 308 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
309 if (*error) 309 if (*error)
310 return; 310 return;
311 311
312 std::string error_msg; 312 std::string error_msg;
313 if (!SendMouseMoveJSONRequest( 313 if (!SendMouseMoveJSONRequest(
314 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 314 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(),
315 &error_msg)) {
315 *error = new Error(kUnknownError, error_msg); 316 *error = new Error(kUnknownError, error_msg);
316 } 317 }
317 } 318 }
318 319
319 void Automation::MouseClick(int tab_id, 320 void Automation::MouseClick(int tab_id,
320 const gfx::Point& p, 321 const Point& p,
321 automation::MouseButton button, 322 automation::MouseButton button,
322 Error** error) { 323 Error** error) {
323 int windex = 0, tab_index = 0; 324 int windex = 0, tab_index = 0;
324 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 325 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
325 if (*error) 326 if (*error)
326 return; 327 return;
327 328
328 std::string error_msg; 329 std::string error_msg;
329 if (!SendMouseClickJSONRequest( 330 if (!SendMouseClickJSONRequest(
330 automation(), windex, tab_index, button, p.x(), p.y(), &error_msg)) { 331 automation(), windex, tab_index, button, p.rounded_x(),
332 p.rounded_y(), &error_msg)) {
331 *error = new Error(kUnknownError, error_msg); 333 *error = new Error(kUnknownError, error_msg);
332 } 334 }
333 } 335 }
334 336
335 void Automation::MouseDrag(int tab_id, 337 void Automation::MouseDrag(int tab_id,
336 const gfx::Point& start, 338 const Point& start,
337 const gfx::Point& end, 339 const Point& end,
338 Error** error) { 340 Error** error) {
339 int windex = 0, tab_index = 0; 341 int windex = 0, tab_index = 0;
340 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 342 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
341 if (*error) 343 if (*error)
342 return; 344 return;
343 345
344 std::string error_msg; 346 std::string error_msg;
345 if (!SendMouseDragJSONRequest(automation(), windex, tab_index, start.x(), 347 if (!SendMouseDragJSONRequest(
346 start.y(), end.x(), end.y(), &error_msg)) { 348 automation(), windex, tab_index, start.rounded_x(), start.rounded_y(),
349 end.rounded_x(), end.rounded_y(), &error_msg)) {
347 *error = new Error(kUnknownError, error_msg); 350 *error = new Error(kUnknownError, error_msg);
348 } 351 }
349 } 352 }
350 353
351 void Automation::MouseButtonUp(int tab_id, 354 void Automation::MouseButtonUp(int tab_id,
352 const gfx::Point& p, 355 const Point& p,
353 Error** error) { 356 Error** error) {
354 *error = CheckAdvancedInteractionsSupported(); 357 *error = CheckAdvancedInteractionsSupported();
355 if (*error) 358 if (*error)
356 return; 359 return;
357 360
358 int windex = 0, tab_index = 0; 361 int windex = 0, tab_index = 0;
359 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 362 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
360 if (*error) 363 if (*error)
361 return; 364 return;
362 365
363 std::string error_msg; 366 std::string error_msg;
364 if (!SendMouseButtonUpJSONRequest( 367 if (!SendMouseButtonUpJSONRequest(
365 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 368 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(),
369 &error_msg)) {
366 *error = new Error(kUnknownError, error_msg); 370 *error = new Error(kUnknownError, error_msg);
367 } 371 }
368 } 372 }
369 373
370 void Automation::MouseButtonDown(int tab_id, 374 void Automation::MouseButtonDown(int tab_id,
371 const gfx::Point& p, 375 const Point& p,
372 Error** error) { 376 Error** error) {
373 *error = CheckAdvancedInteractionsSupported(); 377 *error = CheckAdvancedInteractionsSupported();
374 if (*error) 378 if (*error)
375 return; 379 return;
376 380
377 int windex = 0, tab_index = 0; 381 int windex = 0, tab_index = 0;
378 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 382 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
379 if (*error) 383 if (*error)
380 return; 384 return;
381 385
382 std::string error_msg; 386 std::string error_msg;
383 if (!SendMouseButtonDownJSONRequest( 387 if (!SendMouseButtonDownJSONRequest(
384 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 388 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(),
389 &error_msg)) {
385 *error = new Error(kUnknownError, error_msg); 390 *error = new Error(kUnknownError, error_msg);
386 } 391 }
387 } 392 }
388 393
389 void Automation::MouseDoubleClick(int tab_id, 394 void Automation::MouseDoubleClick(int tab_id,
390 const gfx::Point& p, 395 const Point& p,
391 Error** error) { 396 Error** error) {
392 *error = CheckAdvancedInteractionsSupported(); 397 *error = CheckAdvancedInteractionsSupported();
393 if (*error) 398 if (*error)
394 return; 399 return;
395 400
396 int windex = 0, tab_index = 0; 401 int windex = 0, tab_index = 0;
397 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 402 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
398 if (*error) 403 if (*error)
399 return; 404 return;
400 405
401 std::string error_msg; 406 std::string error_msg;
402 if (!SendMouseDoubleClickJSONRequest( 407 if (!SendMouseDoubleClickJSONRequest(
403 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { 408 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(),
409 &error_msg)) {
404 *error = new Error(kUnknownError, error_msg); 410 *error = new Error(kUnknownError, error_msg);
405 } 411 }
406 } 412 }
407 413
408 void Automation::DragAndDropFilePaths( 414 void Automation::DragAndDropFilePaths(
409 int tab_id, const gfx::Point& location, 415 int tab_id, const Point& location,
410 const std::vector<FilePath::StringType>& paths, Error** error) { 416 const std::vector<FilePath::StringType>& paths, Error** error) {
411 int windex = 0, tab_index = 0; 417 int windex = 0, tab_index = 0;
412 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 418 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
413 if (*error) { 419 if (*error) {
414 return; 420 return;
415 } 421 }
416 422
417 std::string error_msg; 423 std::string error_msg;
418 if (!SendDragAndDropFilePathsJSONRequest( 424 if (!SendDragAndDropFilePathsJSONRequest(
419 automation(), windex, tab_index, location.x(), location.y(), paths, 425 automation(), windex, tab_index, location.rounded_x(),
420 &error_msg)) { 426 location.rounded_y(), paths, &error_msg)) {
421 *error = new Error(kUnknownError, error_msg); 427 *error = new Error(kUnknownError, error_msg);
422 } 428 }
423 } 429 }
424 430
425 void Automation::SendWebKeyEvent(int tab_id, 431 void Automation::SendWebKeyEvent(int tab_id,
426 const WebKeyEvent& key_event, 432 const WebKeyEvent& key_event,
427 Error** error) { 433 Error** error) {
428 int windex = 0, tab_index = 0; 434 int windex = 0, tab_index = 0;
429 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 435 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
430 if (*error) 436 if (*error)
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 768, 0, "Alerts are not supported for this version of Chrome"); 721 768, 0, "Alerts are not supported for this version of Chrome");
716 } 722 }
717 723
718 Error* Automation::CheckAdvancedInteractionsSupported() { 724 Error* Automation::CheckAdvancedInteractionsSupported() {
719 const char* message = 725 const char* message =
720 "Advanced user interactions are not supported for this version of Chrome"; 726 "Advanced user interactions are not supported for this version of Chrome";
721 return CheckVersion(750, 0, message); 727 return CheckVersion(750, 0, message);
722 } 728 }
723 729
724 } // namespace webdriver 730 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/automation.h ('k') | chrome/test/webdriver/commands/mouse_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698