| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 <fstream> | 5 #include <fstream> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // The vector will contain mostly IDC values for encoding commands plus a few | 411 // The vector will contain mostly IDC values for encoding commands plus a few |
| 412 // menu separators (0 values). If we hit a separator we just retry. | 412 // menu separators (0 values). If we hit a separator we just retry. |
| 413 int index = base::RandInt(0, len); | 413 int index = base::RandInt(0, len); |
| 414 while ((*encodings)[index].encoding_id == 0) { | 414 while ((*encodings)[index].encoding_id == 0) { |
| 415 index = base::RandInt(0, len); | 415 index = base::RandInt(0, len); |
| 416 } | 416 } |
| 417 | 417 |
| 418 return RunCommandAsync((*encodings)[index].encoding_id); | 418 return RunCommandAsync((*encodings)[index].encoding_id); |
| 419 } | 419 } |
| 420 | 420 |
| 421 bool AutomatedUITest::CloseActiveTab() { | |
| 422 bool return_value = false; | |
| 423 BrowserProxy* browser = active_browser(); | |
| 424 if (browser == NULL) { | |
| 425 AddErrorAttribute("browser_window_not_found"); | |
| 426 return false; | |
| 427 } | |
| 428 int browser_windows_count; | |
| 429 int tab_count; | |
| 430 bool is_timeout; | |
| 431 browser->GetTabCountWithTimeout(&tab_count, | |
| 432 action_max_timeout_ms(), | |
| 433 &is_timeout); | |
| 434 automation()->GetBrowserWindowCount(&browser_windows_count); | |
| 435 // Avoid quitting the application by not closing the last window. | |
| 436 if (tab_count > 1) { | |
| 437 return_value = browser->RunCommandAsync(IDC_CLOSE_TAB); | |
| 438 // Wait for the tab to close before we continue. | |
| 439 if (!browser->WaitForTabCountToBecome(tab_count - 1, | |
| 440 action_max_timeout_ms())) { | |
| 441 AddWarningAttribute("tab_count_failed_to_change"); | |
| 442 return false; | |
| 443 } | |
| 444 } else if (tab_count == 1 && browser_windows_count > 1) { | |
| 445 return_value = browser->RunCommandAsync(IDC_CLOSE_TAB); | |
| 446 // Wait for the window to close before we continue. | |
| 447 if (!automation()->WaitForWindowCountToBecome(browser_windows_count - 1, | |
| 448 action_max_timeout_ms())) { | |
| 449 AddWarningAttribute("window_count_failed_to_change"); | |
| 450 return false; | |
| 451 } | |
| 452 } else { | |
| 453 AddInfoAttribute("would_have_exited_application"); | |
| 454 return false; | |
| 455 } | |
| 456 return return_value; | |
| 457 } | |
| 458 | |
| 459 bool AutomatedUITest::FindInPage() { | 421 bool AutomatedUITest::FindInPage() { |
| 460 return RunCommandAsync(IDC_FIND); | 422 return RunCommandAsync(IDC_FIND); |
| 461 } | 423 } |
| 462 | 424 |
| 463 bool AutomatedUITest::ForwardButton() { | 425 bool AutomatedUITest::ForwardButton() { |
| 464 return RunCommandAsync(IDC_FORWARD); | 426 return RunCommandAsync(IDC_FORWARD); |
| 465 } | 427 } |
| 466 | 428 |
| 467 bool AutomatedUITest::GoOffTheRecord() { | 429 bool AutomatedUITest::GoOffTheRecord() { |
| 468 return RunCommandAsync(IDC_NEW_INCOGNITO_WINDOW); | 430 return RunCommandAsync(IDC_NEW_INCOGNITO_WINDOW); |
| 469 } | 431 } |
| 470 | 432 |
| 471 bool AutomatedUITest::Home() { | 433 bool AutomatedUITest::Home() { |
| 472 return RunCommandAsync(IDC_HOME); | 434 return RunCommandAsync(IDC_HOME); |
| 473 } | 435 } |
| 474 | 436 |
| 475 bool AutomatedUITest::JavaScriptConsole() { | 437 bool AutomatedUITest::JavaScriptConsole() { |
| 476 return RunCommandAsync(IDC_JS_CONSOLE); | 438 return RunCommandAsync(IDC_JS_CONSOLE); |
| 477 } | 439 } |
| 478 | 440 |
| 479 bool AutomatedUITest::JavaScriptDebugger() { | 441 bool AutomatedUITest::JavaScriptDebugger() { |
| 480 return RunCommandAsync(IDC_DEBUGGER); | 442 return RunCommandAsync(IDC_DEBUGGER); |
| 481 } | 443 } |
| 482 | 444 |
| 483 bool AutomatedUITest::Navigate() { | 445 bool AutomatedUITest::Navigate() { |
| 484 BrowserProxy* browser = active_browser(); | 446 scoped_ptr<TabProxy> tab(GetActiveTab()); |
| 485 if (browser == NULL) { | |
| 486 AddErrorAttribute("browser_window_not_found"); | |
| 487 return false; | |
| 488 } | |
| 489 bool did_timeout; | |
| 490 scoped_ptr<TabProxy> tab( | |
| 491 browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout)); | |
| 492 // TODO(devint): This might be masking a bug. I can't think of many | |
| 493 // valid cases where we would get a browser window, but not be able | |
| 494 // to return an active tab. Yet this has happened and has triggered crashes. | |
| 495 // Investigate this. | |
| 496 if (tab.get() == NULL) { | 447 if (tab.get() == NULL) { |
| 497 AddErrorAttribute("active_tab_not_found"); | 448 AddErrorAttribute("active_tab_not_found"); |
| 498 return false; | 449 return false; |
| 499 } | 450 } |
| 500 std::string url = "about:blank"; | 451 std::string url = "about:blank"; |
| 501 if (init_reader_.NodeAttribute("url", &url)) { | 452 if (init_reader_.NodeAttribute("url", &url)) { |
| 502 xml_writer_.AddAttribute("url", url); | 453 xml_writer_.AddAttribute("url", url); |
| 503 } | 454 } |
| 504 GURL test_url(url); | 455 GURL test_url(url); |
| 505 did_timeout = false; | 456 bool did_timeout = false; |
| 506 tab->NavigateToURLWithTimeout(test_url, | 457 tab->NavigateToURLWithTimeout(test_url, |
| 507 command_execution_timeout_ms(), | 458 command_execution_timeout_ms(), |
| 508 &did_timeout); | 459 &did_timeout); |
| 509 | 460 |
| 510 if (did_timeout) { | 461 if (did_timeout) { |
| 511 AddWarningAttribute("timeout"); | 462 AddWarningAttribute("timeout"); |
| 512 return false; | 463 return false; |
| 513 } | 464 } |
| 514 return true; | 465 return true; |
| 515 } | 466 } |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 - 1); | 623 - 1); |
| 673 return_value = return_value && | 624 return_value = return_value && |
| 674 DoAction(kTestDialogPossibleActions[action_index]); | 625 DoAction(kTestDialogPossibleActions[action_index]); |
| 675 if (DidCrash(false)) | 626 if (DidCrash(false)) |
| 676 break; | 627 break; |
| 677 } | 628 } |
| 678 return DoAction("PressEscapeKey") && return_value; | 629 return DoAction("PressEscapeKey") && return_value; |
| 679 } | 630 } |
| 680 | 631 |
| 681 bool AutomatedUITest::ForceCrash() { | 632 bool AutomatedUITest::ForceCrash() { |
| 682 BrowserProxy* browser = active_browser(); | 633 scoped_ptr<TabProxy> tab(GetActiveTab()); |
| 683 if (browser == NULL) { | |
| 684 AddErrorAttribute("browser_window_not_found"); | |
| 685 return false; | |
| 686 } | |
| 687 scoped_ptr<TabProxy> tab(browser->GetActiveTab()); | |
| 688 GURL test_url("about:crash"); | 634 GURL test_url("about:crash"); |
| 689 bool did_timeout; | 635 bool did_timeout; |
| 690 tab->NavigateToURLWithTimeout(test_url, kDebuggingTimeoutMsec, &did_timeout); | 636 tab->NavigateToURLWithTimeout(test_url, kDebuggingTimeoutMsec, &did_timeout); |
| 691 if (!did_timeout) { | 637 if (!did_timeout) { |
| 692 AddInfoAttribute("expected_crash"); | 638 AddInfoAttribute("expected_crash"); |
| 693 return false; | 639 return false; |
| 694 } | 640 } |
| 695 return true; | 641 return true; |
| 696 } | 642 } |
| 697 | 643 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 } | 905 } |
| 960 } | 906 } |
| 961 | 907 |
| 962 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { | 908 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { |
| 963 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); | 909 const CommandLine& parsed_command_line = *CommandLine::ForCurrentProcess(); |
| 964 if (parsed_command_line.HasSwitch(kReproSwitch)) | 910 if (parsed_command_line.HasSwitch(kReproSwitch)) |
| 965 RunReproduction(); | 911 RunReproduction(); |
| 966 else | 912 else |
| 967 RunAutomatedUITest(); | 913 RunAutomatedUITest(); |
| 968 } | 914 } |
| OLD | NEW |