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

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

Issue 8806030: Add commands to Chrome WebDriver for installing and manipulating extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years 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/webdriver_automation.h ('k') | chrome/test/webdriver/webdriver_server.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/webdriver_automation.h" 5 #include "chrome/test/webdriver/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 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 return; 299 return;
300 } 300 }
301 } 301 }
302 302
303 void Automation::Terminate() { 303 void Automation::Terminate() {
304 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { 304 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) {
305 launcher_->QuitBrowser(); 305 launcher_->QuitBrowser();
306 } 306 }
307 } 307 }
308 308
309 void Automation::ExecuteScript(int tab_id, 309 void Automation::ExecuteScript(const WebViewId& view_id,
310 const FramePath& frame_path, 310 const FramePath& frame_path,
311 const std::string& script, 311 const std::string& script,
312 std::string* result, 312 std::string* result,
313 Error** error) { 313 Error** error) {
314 int windex = 0, tab_index = 0; 314 WebViewLocator view_locator;
315 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 315 *error = ConvertViewIdToLocator(view_id, &view_locator);
316 if (*error) 316 if (*error)
317 return; 317 return;
318 318
319 Value* unscoped_value; 319 Value* unscoped_value;
320 std::string error_msg; 320 std::string error_msg;
321 if (!SendExecuteJavascriptJSONRequest(automation(), windex, tab_index, 321 if (!SendExecuteJavascriptJSONRequest(automation(), view_locator,
322 frame_path.value(), script, 322 frame_path.value(), script,
323 &unscoped_value, &error_msg)) { 323 &unscoped_value, &error_msg)) {
324 *error = new Error(kUnknownError, error_msg); 324 *error = new Error(kUnknownError, error_msg);
325 return; 325 return;
326 } 326 }
327 scoped_ptr<Value> value(unscoped_value); 327 scoped_ptr<Value> value(unscoped_value);
328 if (!value->GetAsString(result)) 328 if (!value->GetAsString(result))
329 *error = new Error(kUnknownError, "Execute script did not return string"); 329 *error = new Error(kUnknownError, "Execute script did not return string");
330 } 330 }
331 331
332 void Automation::MouseMove(int tab_id, 332 void Automation::MouseMove(const WebViewId& view_id,
333 const Point& p, 333 const Point& p,
334 Error** error) { 334 Error** error) {
335 int windex = 0, tab_index = 0; 335 WebViewLocator view_locator;
336 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 336 *error = ConvertViewIdToLocator(view_id, &view_locator);
337 if (*error) 337 if (*error)
338 return; 338 return;
339 339
340 std::string error_msg; 340 std::string error_msg;
341 if (!SendMouseMoveJSONRequest( 341 if (!SendMouseMoveJSONRequest(
342 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), 342 automation(), view_locator, p.rounded_x(), p.rounded_y(),
343 &error_msg)) { 343 &error_msg)) {
344 *error = new Error(kUnknownError, error_msg); 344 *error = new Error(kUnknownError, error_msg);
345 } 345 }
346 } 346 }
347 347
348 void Automation::MouseClick(int tab_id, 348 void Automation::MouseClick(const WebViewId& view_id,
349 const Point& p, 349 const Point& p,
350 automation::MouseButton button, 350 automation::MouseButton button,
351 Error** error) { 351 Error** error) {
352 int windex = 0, tab_index = 0; 352 WebViewLocator view_locator;
353 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 353 *error = ConvertViewIdToLocator(view_id, &view_locator);
354 if (*error) 354 if (*error)
355 return; 355 return;
356 356
357 std::string error_msg; 357 std::string error_msg;
358 if (!SendMouseClickJSONRequest( 358 if (!SendMouseClickJSONRequest(
359 automation(), windex, tab_index, button, p.rounded_x(), 359 automation(), view_locator, button, p.rounded_x(),
360 p.rounded_y(), &error_msg)) { 360 p.rounded_y(), &error_msg)) {
361 *error = new Error(kUnknownError, error_msg); 361 *error = new Error(kUnknownError, error_msg);
362 } 362 }
363 } 363 }
364 364
365 void Automation::MouseDrag(int tab_id, 365 void Automation::MouseDrag(const WebViewId& view_id,
366 const Point& start, 366 const Point& start,
367 const Point& end, 367 const Point& end,
368 Error** error) { 368 Error** error) {
369 int windex = 0, tab_index = 0; 369 WebViewLocator view_locator;
370 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 370 *error = ConvertViewIdToLocator(view_id, &view_locator);
371 if (*error) 371 if (*error)
372 return; 372 return;
373 373
374 std::string error_msg; 374 std::string error_msg;
375 if (!SendMouseDragJSONRequest( 375 if (!SendMouseDragJSONRequest(
376 automation(), windex, tab_index, start.rounded_x(), start.rounded_y(), 376 automation(), view_locator, start.rounded_x(), start.rounded_y(),
377 end.rounded_x(), end.rounded_y(), &error_msg)) { 377 end.rounded_x(), end.rounded_y(), &error_msg)) {
378 *error = new Error(kUnknownError, error_msg); 378 *error = new Error(kUnknownError, error_msg);
379 } 379 }
380 } 380 }
381 381
382 void Automation::MouseButtonUp(int tab_id, 382 void Automation::MouseButtonUp(const WebViewId& view_id,
383 const Point& p, 383 const Point& p,
384 Error** error) { 384 Error** error) {
385 *error = CheckAdvancedInteractionsSupported(); 385 *error = CheckAdvancedInteractionsSupported();
386 if (*error) 386 if (*error)
387 return; 387 return;
388 388
389 int windex = 0, tab_index = 0; 389 WebViewLocator view_locator;
390 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 390 *error = ConvertViewIdToLocator(view_id, &view_locator);
391 if (*error) 391 if (*error)
392 return; 392 return;
393 393
394 std::string error_msg; 394 std::string error_msg;
395 if (!SendMouseButtonUpJSONRequest( 395 if (!SendMouseButtonUpJSONRequest(
396 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), 396 automation(), view_locator, p.rounded_x(), p.rounded_y(),
397 &error_msg)) { 397 &error_msg)) {
398 *error = new Error(kUnknownError, error_msg); 398 *error = new Error(kUnknownError, error_msg);
399 } 399 }
400 } 400 }
401 401
402 void Automation::MouseButtonDown(int tab_id, 402 void Automation::MouseButtonDown(const WebViewId& view_id,
403 const Point& p, 403 const Point& p,
404 Error** error) { 404 Error** error) {
405 *error = CheckAdvancedInteractionsSupported(); 405 *error = CheckAdvancedInteractionsSupported();
406 if (*error) 406 if (*error)
407 return; 407 return;
408 408
409 int windex = 0, tab_index = 0; 409 WebViewLocator view_locator;
410 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 410 *error = ConvertViewIdToLocator(view_id, &view_locator);
411 if (*error) 411 if (*error)
412 return; 412 return;
413 413
414 std::string error_msg; 414 std::string error_msg;
415 if (!SendMouseButtonDownJSONRequest( 415 if (!SendMouseButtonDownJSONRequest(
416 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), 416 automation(), view_locator, p.rounded_x(), p.rounded_y(),
417 &error_msg)) { 417 &error_msg)) {
418 *error = new Error(kUnknownError, error_msg); 418 *error = new Error(kUnknownError, error_msg);
419 } 419 }
420 } 420 }
421 421
422 void Automation::MouseDoubleClick(int tab_id, 422 void Automation::MouseDoubleClick(const WebViewId& view_id,
423 const Point& p, 423 const Point& p,
424 Error** error) { 424 Error** error) {
425 *error = CheckAdvancedInteractionsSupported(); 425 *error = CheckAdvancedInteractionsSupported();
426 if (*error) 426 if (*error)
427 return; 427 return;
428 428
429 int windex = 0, tab_index = 0; 429 WebViewLocator view_locator;
430 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 430 *error = ConvertViewIdToLocator(view_id, &view_locator);
431 if (*error) 431 if (*error)
432 return; 432 return;
433 433
434 std::string error_msg; 434 std::string error_msg;
435 if (!SendMouseDoubleClickJSONRequest( 435 if (!SendMouseDoubleClickJSONRequest(
436 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), 436 automation(), view_locator, p.rounded_x(), p.rounded_y(),
437 &error_msg)) { 437 &error_msg)) {
438 *error = new Error(kUnknownError, error_msg); 438 *error = new Error(kUnknownError, error_msg);
439 } 439 }
440 } 440 }
441 441
442 void Automation::DragAndDropFilePaths( 442 void Automation::DragAndDropFilePaths(
443 int tab_id, const Point& location, 443 const WebViewId& view_id, const Point& location,
444 const std::vector<FilePath::StringType>& paths, Error** error) { 444 const std::vector<FilePath::StringType>& paths, Error** error) {
445 int windex = 0, tab_index = 0; 445 WebViewLocator view_locator;
446 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 446 *error = ConvertViewIdToLocator(view_id, &view_locator);
447 if (*error) { 447 if (*error) {
448 return; 448 return;
449 } 449 }
450 450
451 std::string error_msg; 451 std::string error_msg;
452 if (!SendDragAndDropFilePathsJSONRequest( 452 if (!SendDragAndDropFilePathsJSONRequest(
453 automation(), windex, tab_index, location.rounded_x(), 453 automation(), view_locator, location.rounded_x(),
454 location.rounded_y(), paths, &error_msg)) { 454 location.rounded_y(), paths, &error_msg)) {
455 *error = new Error(kUnknownError, error_msg); 455 *error = new Error(kUnknownError, error_msg);
456 } 456 }
457 } 457 }
458 458
459 void Automation::SendWebKeyEvent(int tab_id, 459 void Automation::SendWebKeyEvent(const WebViewId& view_id,
460 const WebKeyEvent& key_event, 460 const WebKeyEvent& key_event,
461 Error** error) { 461 Error** error) {
462 int windex = 0, tab_index = 0; 462 WebViewLocator view_locator;
463 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 463 *error = ConvertViewIdToLocator(view_id, &view_locator);
464 if (*error) 464 if (*error)
465 return; 465 return;
466 466
467 std::string error_msg; 467 std::string error_msg;
468 if (!SendWebKeyEventJSONRequest( 468 if (!SendWebKeyEventJSONRequest(
469 automation(), windex, tab_index, key_event, &error_msg)) { 469 automation(), view_locator, key_event, &error_msg)) {
470 *error = new Error(kUnknownError, error_msg); 470 *error = new Error(kUnknownError, error_msg);
471 } 471 }
472 } 472 }
473 473
474 void Automation::SendNativeKeyEvent(int tab_id, 474 void Automation::SendNativeKeyEvent(const WebViewId& view_id,
475 ui::KeyboardCode key_code, 475 ui::KeyboardCode key_code,
476 int modifiers, 476 int modifiers,
477 Error** error) { 477 Error** error) {
478 int windex = 0, tab_index = 0; 478 WebViewLocator view_locator;
479 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 479 *error = ConvertViewIdToLocator(view_id, &view_locator);
480 if (*error) 480 if (*error)
481 return; 481 return;
482 482
483 std::string error_msg; 483 std::string error_msg;
484 if (!SendNativeKeyEventJSONRequest( 484 if (!SendNativeKeyEventJSONRequest(
485 automation(), windex, tab_index, key_code, modifiers, &error_msg)) { 485 automation(), view_locator, key_code, modifiers, &error_msg)) {
486 *error = new Error(kUnknownError, error_msg); 486 *error = new Error(kUnknownError, error_msg);
487 } 487 }
488 } 488 }
489 489
490 void Automation::CaptureEntirePageAsPNG(int tab_id, 490 void Automation::CaptureEntirePageAsPNG(const WebViewId& view_id,
491 const FilePath& path, 491 const FilePath& path,
492 Error** error) { 492 Error** error) {
493 int windex = 0, tab_index = 0; 493 WebViewLocator view_locator;
494 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 494 *error = ConvertViewIdToLocator(view_id, &view_locator);
495 if (*error) 495 if (*error)
496 return; 496 return;
497 497
498 std::string error_msg; 498 std::string error_msg;
499 if (!SendCaptureEntirePageJSONRequest( 499 if (!SendCaptureEntirePageJSONRequest(
500 automation(), windex, tab_index, path, &error_msg)) { 500 automation(), view_locator, path, &error_msg)) {
501 *error = new Error(kUnknownError, error_msg); 501 *error = new Error(kUnknownError, error_msg);
502 } 502 }
503 } 503 }
504 504
505 void Automation::NavigateToURL(int tab_id, 505 void Automation::NavigateToURL(const WebViewId& view_id,
506 const std::string& url, 506 const std::string& url,
507 Error** error) { 507 Error** error) {
508 int windex = 0, tab_index = 0; 508 WebViewLocator view_locator;
509 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 509 *error = ConvertViewIdToLocator(view_id, &view_locator);
510 if (*error) 510 if (*error)
511 return; 511 return;
512 512
513 AutomationMsg_NavigationResponseValues navigate_response; 513 AutomationMsg_NavigationResponseValues navigate_response;
514 std::string error_msg; 514 std::string error_msg;
515 if (!SendNavigateToURLJSONRequest(automation(), windex, tab_index, 515 if (!SendNavigateToURLJSONRequest(automation(), view_locator,
516 url, 1, &navigate_response, 516 url, 1, &navigate_response,
517 &error_msg)) { 517 &error_msg)) {
518 *error = new Error(kUnknownError, error_msg); 518 *error = new Error(kUnknownError, error_msg);
519 return; 519 return;
520 } 520 }
521 // TODO(kkania): Do not rely on this enum. 521 // TODO(kkania): Do not rely on this enum.
522 if (navigate_response == AUTOMATION_MSG_NAVIGATION_ERROR) 522 if (navigate_response == AUTOMATION_MSG_NAVIGATION_ERROR)
523 *error = new Error(kUnknownError, "Navigation error occurred"); 523 *error = new Error(kUnknownError, "Navigation error occurred");
524 } 524 }
525 525
526 void Automation::NavigateToURLAsync(int tab_id, 526 void Automation::NavigateToURLAsync(const WebViewId& view_id,
527 const std::string& url, 527 const std::string& url,
528 Error** error) { 528 Error** error) {
529 int windex = 0, tab_index = 0; 529 WebViewLocator view_locator;
530 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 530 *error = ConvertViewIdToLocator(view_id, &view_locator);
531 if (*error) 531 if (*error)
532 return; 532 return;
533 533
534 scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(windex); 534 std::string error_msg;
535 if (!browser) { 535 if (!view_id.old_style()) {
536 *error = new Error(kUnknownError, "Couldn't obtain browser proxy"); 536 AutomationMsg_NavigationResponseValues navigate_response;
537 return; 537 if (!SendNavigateToURLJSONRequest(automation(), view_locator, url,
538 } 538 0, &navigate_response, &error_msg)) {
539 scoped_refptr<TabProxy> tab = browser->GetTab(tab_index); 539 *error = new Error(kUnknownError, error_msg);
540 if (!tab) { 540 return;
541 *error = new Error(kUnknownError, "Couldn't obtain tab proxy"); 541 }
542 return; 542 } else {
543 } 543 scoped_refptr<BrowserProxy> browser =
544 if (!tab->NavigateToURLAsync(GURL(url))) { 544 automation()->GetBrowserWindow(view_locator.browser_index());
545 *error = new Error(kUnknownError, "Unable to navigate to url"); 545 if (!browser) {
546 return; 546 *error = new Error(kUnknownError, "Couldn't obtain browser proxy");
547 return;
548 }
549 scoped_refptr<TabProxy> tab = browser->GetTab(view_locator.tab_index());
550 if (!tab) {
551 *error = new Error(kUnknownError, "Couldn't obtain tab proxy");
552 return;
553 }
554 if (!tab->NavigateToURLAsync(GURL(url))) {
555 *error = new Error(kUnknownError, "Unable to navigate to url");
556 return;
557 }
547 } 558 }
548 } 559 }
549 560
550 void Automation::GoForward(int tab_id, Error** error) { 561 void Automation::GoForward(const WebViewId& view_id, Error** error) {
551 int windex = 0, tab_index = 0; 562 WebViewLocator view_locator;
552 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 563 *error = ConvertViewIdToLocator(view_id, &view_locator);
553 if (*error) 564 if (*error)
554 return; 565 return;
555 566
556 std::string error_msg; 567 std::string error_msg;
557 if (!SendGoForwardJSONRequest( 568 if (!SendGoForwardJSONRequest(
558 automation(), windex, tab_index, &error_msg)) { 569 automation(), view_locator, &error_msg)) {
559 *error = new Error(kUnknownError, error_msg); 570 *error = new Error(kUnknownError, error_msg);
560 } 571 }
561 } 572 }
562 573
563 void Automation::GoBack(int tab_id, Error** error) { 574 void Automation::GoBack(const WebViewId& view_id, Error** error) {
564 int windex = 0, tab_index = 0; 575 WebViewLocator view_locator;
565 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 576 *error = ConvertViewIdToLocator(view_id, &view_locator);
566 if (*error) 577 if (*error)
567 return; 578 return;
568 579
569 std::string error_msg; 580 std::string error_msg;
570 if (!SendGoBackJSONRequest(automation(), windex, tab_index, &error_msg)) 581 if (!SendGoBackJSONRequest(automation(), view_locator, &error_msg))
571 *error = new Error(kUnknownError, error_msg); 582 *error = new Error(kUnknownError, error_msg);
572 } 583 }
573 584
574 void Automation::Reload(int tab_id, Error** error) { 585 void Automation::Reload(const WebViewId& view_id, Error** error) {
575 int windex = 0, tab_index = 0; 586 WebViewLocator view_locator;
576 *error = GetIndicesForTab(tab_id, &windex, &tab_index); 587 *error = ConvertViewIdToLocator(view_id, &view_locator);
577 if (*error) 588 if (*error)
578 return; 589 return;
579 590
580 std::string error_msg; 591 std::string error_msg;
581 if (!SendReloadJSONRequest(automation(), windex, tab_index, &error_msg)) 592 if (!SendReloadJSONRequest(automation(), view_locator, &error_msg))
582 *error = new Error(kUnknownError, error_msg); 593 *error = new Error(kUnknownError, error_msg);
583 } 594 }
584 595
585 void Automation::GetCookies(const std::string& url, 596 void Automation::GetCookies(const std::string& url,
586 ListValue** cookies, 597 ListValue** cookies,
587 Error** error) { 598 Error** error) {
588 std::string error_msg; 599 std::string error_msg;
589 if (!SendGetCookiesJSONRequest(automation(), url, cookies, &error_msg)) 600 if (!SendGetCookiesJSONRequest(automation(), url, cookies, &error_msg))
590 *error = new Error(kUnknownError, error_msg); 601 *error = new Error(kUnknownError, error_msg);
591 } 602 }
592 603
593 void Automation::DeleteCookie(const std::string& url, 604 void Automation::DeleteCookie(const std::string& url,
594 const std::string& cookie_name, 605 const std::string& cookie_name,
595 Error** error) { 606 Error** error) {
596 std::string error_msg; 607 std::string error_msg;
597 if (!SendDeleteCookieJSONRequest( 608 if (!SendDeleteCookieJSONRequest(
598 automation(), url, cookie_name, &error_msg)) { 609 automation(), url, cookie_name, &error_msg)) {
599 *error = new Error(kUnknownError, error_msg); 610 *error = new Error(kUnknownError, error_msg);
600 } 611 }
601 } 612 }
602 613
603 void Automation::SetCookie(const std::string& url, 614 void Automation::SetCookie(const std::string& url,
604 DictionaryValue* cookie_dict, 615 DictionaryValue* cookie_dict,
605 Error** error) { 616 Error** error) {
606 std::string error_msg; 617 std::string error_msg;
607 if (!SendSetCookieJSONRequest(automation(), url, cookie_dict, &error_msg)) 618 if (!SendSetCookieJSONRequest(automation(), url, cookie_dict, &error_msg))
608 *error = new Error(kUnknownError, error_msg); 619 *error = new Error(kUnknownError, error_msg);
609 } 620 }
610 621
611 void Automation::GetTabIds(std::vector<int>* tab_ids, 622 void Automation::GetViews(std::vector<WebViewInfo>* views,
612 Error** error) { 623 Error** error) {
613 std::string error_msg; 624 bool has_views = false;
614 if (!SendGetTabIdsJSONRequest(automation(), tab_ids, &error_msg)) 625 *error = CompareVersion(963, 0, &has_views);
615 *error = new Error(kUnknownError, error_msg);
616 }
617
618 void Automation::DoesTabExist(int tab_id, bool* does_exist, Error** error) {
619 std::string error_msg;
620 if (!SendIsTabIdValidJSONRequest(
621 automation(), tab_id, does_exist, &error_msg)) {
622 *error = new Error(kUnknownError, error_msg);
623 }
624 }
625
626 void Automation::CloseTab(int tab_id, Error** error) {
627 int windex = 0, tab_index = 0;
628 *error = GetIndicesForTab(tab_id, &windex, &tab_index);
629 if (*error) 626 if (*error)
630 return; 627 return;
631 628
632 std::string error_msg; 629 std::string error_msg;
633 if (!SendCloseTabJSONRequest(automation(), windex, tab_index, &error_msg)) 630 if (has_views) {
631 if (!SendGetWebViewsJSONRequest(automation(), views, &error_msg))
632 *error = new Error(kUnknownError, error_msg);
633 } else {
634 if (!SendGetTabIdsJSONRequest(automation(), views, &error_msg))
635 *error = new Error(kUnknownError, error_msg);
636 }
637 }
638
639 void Automation::DoesViewExist(
640 const WebViewId& view_id, bool* does_exist, Error** error) {
641 std::string error_msg;
642 if (view_id.old_style()) {
643 if (!SendIsTabIdValidJSONRequest(
644 automation(), view_id, does_exist, &error_msg))
645 *error = new Error(kUnknownError, error_msg);
646 } else {
647 if (!SendDoesAutomationObjectExistJSONRequest(
648 automation(), view_id, does_exist, &error_msg))
649 *error = new Error(kUnknownError, error_msg);
650 }
651 }
652
653 void Automation::CloseView(const WebViewId& view_id, Error** error) {
654 WebViewLocator view_locator;
655 *error = ConvertViewIdToLocator(view_id, &view_locator);
656 if (*error)
657 return;
658
659 std::string error_msg;
660 if (!SendCloseViewJSONRequest(automation(), view_locator, &error_msg))
634 *error = new Error(kUnknownError, error_msg); 661 *error = new Error(kUnknownError, error_msg);
635 } 662 }
636 663
637 void Automation::GetAppModalDialogMessage(std::string* message, Error** error) { 664 void Automation::GetAppModalDialogMessage(std::string* message, Error** error) {
638 *error = CheckAlertsSupported(); 665 *error = CheckAlertsSupported();
639 if (*error) 666 if (*error)
640 return; 667 return;
641 668
642 std::string error_msg; 669 std::string error_msg;
643 if (!SendGetAppModalDialogMessageJSONRequest( 670 if (!SendGetAppModalDialogMessageJSONRequest(
(...skipping 30 matching lines...) Expand all
674 void Automation::GetBrowserVersion(std::string* version) { 701 void Automation::GetBrowserVersion(std::string* version) {
675 *version = automation()->server_version(); 702 *version = automation()->server_version();
676 } 703 }
677 704
678 void Automation::GetChromeDriverAutomationVersion(int* version, Error** error) { 705 void Automation::GetChromeDriverAutomationVersion(int* version, Error** error) {
679 std::string error_msg; 706 std::string error_msg;
680 if (!SendGetChromeDriverAutomationVersion(automation(), version, &error_msg)) 707 if (!SendGetChromeDriverAutomationVersion(automation(), version, &error_msg))
681 *error = new Error(kUnknownError, error_msg); 708 *error = new Error(kUnknownError, error_msg);
682 } 709 }
683 710
684 void Automation::WaitForAllTabsToStopLoading(Error** error) { 711 void Automation::WaitForAllViewsToStopLoading(Error** error) {
685 std::string error_msg; 712 std::string error_msg;
686 if (!SendWaitForAllTabsToStopLoadingJSONRequest(automation(), &error_msg)) 713 if (!SendWaitForAllViewsToStopLoadingJSONRequest(automation(), &error_msg))
687 *error = new Error(kUnknownError, error_msg); 714 *error = new Error(kUnknownError, error_msg);
688 } 715 }
689 716
690 void Automation::InstallExtensionDeprecated( 717 void Automation::InstallExtensionDeprecated(
691 const FilePath& path, Error** error) { 718 const FilePath& path, Error** error) {
692 if (!launcher_->automation()->InstallExtension(path, false).get()) 719 if (!launcher_->automation()->InstallExtension(path, false).get())
693 *error = new Error(kUnknownError, "Failed to install extension"); 720 *error = new Error(kUnknownError, "Failed to install extension");
694 } 721 }
695 722
696 void Automation::GetInstalledExtensions(
697 std::vector<std::string>* extension_ids, Error** error) {
698 *error = CheckNewExtensionInterfaceSupported();
699 if (*error)
700 return;
701
702 std::string error_msg;
703 base::ListValue extensions_list;
704 if (!SendGetExtensionsInfoJSONRequest(
705 automation(), &extensions_list, &error_msg)) {
706 *error = new Error(kUnknownError, error_msg);
707 return;
708 }
709
710 for (size_t i = 0; i < extensions_list.GetSize(); i++) {
711 DictionaryValue* extension_dict;
712 if (!extensions_list.GetDictionary(i, &extension_dict)) {
713 *error = new Error(kUnknownError, "Invalid extension dictionary");
714 return;
715 }
716 bool is_component;
717 if (!extension_dict->GetBoolean("is_component", &is_component)) {
718 *error = new Error(kUnknownError,
719 "Missing or invalid 'is_component_extension'");
720 return;
721 }
722 if (is_component)
723 continue;
724
725 std::string extension_id;
726 if (!extension_dict->GetString("id", &extension_id)) {
727 *error = new Error(kUnknownError, "Missing or invalid 'id'");
728 return;
729 }
730 extension_ids->push_back(extension_id);
731 }
732 }
733
734 void Automation::InstallExtension( 723 void Automation::InstallExtension(
735 const FilePath& path, std::string* extension_id, Error** error) { 724 const FilePath& path, std::string* extension_id, Error** error) {
736 *error = CheckNewExtensionInterfaceSupported(); 725 *error = CheckNewExtensionInterfaceSupported();
737 if (*error) 726 if (*error)
738 return; 727 return;
739 728
740 std::string error_msg; 729 std::string error_msg;
741 if (!SendInstallExtensionJSONRequest( 730 if (!SendInstallExtensionJSONRequest(
742 automation(), path, false /* with_ui */, extension_id, &error_msg)) 731 automation(), path, false /* with_ui */, extension_id,
732 &error_msg))
743 *error = new Error(kUnknownError, error_msg); 733 *error = new Error(kUnknownError, error_msg);
744 } 734 }
745 735
736 void Automation::GetExtensionsInfo(
737 base::ListValue* extensions_list, Error** error) {
738 *error = CheckNewExtensionInterfaceSupported();
739 if (*error)
740 return;
741
742 std::string error_msg;
743 if (!SendGetExtensionsInfoJSONRequest(
744 automation(), extensions_list, &error_msg))
745 *error = new Error(kUnknownError, error_msg);
746 }
747
748 void Automation::IsPageActionVisible(
749 const WebViewId& tab_id,
750 const std::string& extension_id,
751 bool* is_visible,
752 Error** error) {
753 *error = CheckNewExtensionInterfaceSupported();
754 if (*error)
755 return;
756
757 std::string error_msg;
758 if (!SendIsPageActionVisibleJSONRequest(
759 automation(), tab_id, extension_id, is_visible, &error_msg))
760 *error = new Error(kUnknownError, error_msg);
761 }
762
763 void Automation::SetExtensionState(
764 const std::string& extension_id,
765 bool enable,
766 Error** error) {
767 *error = CheckNewExtensionInterfaceSupported();
768 if (*error)
769 return;
770
771 std::string error_msg;
772 if (!SendSetExtensionStateJSONRequest(
773 automation(), extension_id, enable /* enable */,
774 false /* allow_in_incognito */, &error_msg))
775 *error = new Error(kUnknownError, error_msg);
776 }
777
778 void Automation::ClickExtensionButton(
779 const std::string& extension_id,
780 bool browser_action,
781 Error** error) {
782 std::string error_msg;
783 if (!SendClickExtensionButtonJSONRequest(
784 automation(), extension_id, browser_action, &error_msg))
785 *error = new Error(kUnknownError, error_msg);
786 }
787
788 void Automation::UninstallExtension(
789 const std::string& extension_id, Error** error) {
790 *error = CheckNewExtensionInterfaceSupported();
791 if (*error)
792 return;
793
794 std::string error_msg;
795 if (!SendUninstallExtensionJSONRequest(
796 automation(), extension_id, &error_msg))
797 *error = new Error(kUnknownError, error_msg);
798 }
799
746 AutomationProxy* Automation::automation() const { 800 AutomationProxy* Automation::automation() const {
747 return launcher_->automation(); 801 return launcher_->automation();
748 } 802 }
749 803
750 Error* Automation::GetIndicesForTab( 804 Error* Automation::ConvertViewIdToLocator(
751 int tab_id, int* browser_index, int* tab_index) { 805 const WebViewId& view_id, WebViewLocator* view_locator) {
752 std::string error_msg; 806 if (view_id.old_style()) {
753 if (!SendGetIndicesFromTabIdJSONRequest( 807 int browser_index, tab_index;
754 automation(), tab_id, browser_index, tab_index, &error_msg)) { 808 std::string error_msg;
755 return new Error(kUnknownError, error_msg); 809 if (!SendGetIndicesFromTabIdJSONRequest(
810 automation(), view_id.tab_id(), &browser_index, &tab_index,
811 &error_msg))
812 return new Error(kUnknownError, error_msg);
813 *view_locator = WebViewLocator::ForIndexPair(browser_index, tab_index);
814 } else {
815 *view_locator = WebViewLocator::ForViewId(view_id.GetId());
756 } 816 }
757 return NULL; 817 return NULL;
758 } 818 }
759 819
760 Error* Automation::CompareVersion(int client_build_no, 820 Error* Automation::CompareVersion(int client_build_no,
761 int client_patch_no, 821 int client_patch_no,
762 bool* is_newer_or_equal) { 822 bool* is_newer_or_equal) {
763 std::string version = automation()->server_version(); 823 std::string version = automation()->server_version();
764 std::vector<std::string> split_version; 824 std::vector<std::string> split_version;
765 base::SplitString(version, '.', &split_version); 825 base::SplitString(version, '.', &split_version);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 return CheckVersion(750, 0, message); 866 return CheckVersion(750, 0, message);
807 } 867 }
808 868
809 Error* Automation::CheckNewExtensionInterfaceSupported() { 869 Error* Automation::CheckNewExtensionInterfaceSupported() {
810 const char* message = 870 const char* message =
811 "Extension interface is not supported for this version of Chrome"; 871 "Extension interface is not supported for this version of Chrome";
812 return CheckVersion(947, 0, message); 872 return CheckVersion(947, 0, message);
813 } 873 }
814 874
815 } // namespace webdriver 875 } // namespace webdriver
OLDNEW
« no previous file with comments | « chrome/test/webdriver/webdriver_automation.h ('k') | chrome/test/webdriver/webdriver_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698