| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
| 6 | 6 |
| 7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
| 8 #include <signal.h> | 8 #include <signal.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #endif | 10 #endif |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void UITestBase::SetUp() { | 112 void UITestBase::SetUp() { |
| 113 // Tests that do a session restore (e.g. SessionRestoreUITest, StartupTest) | 113 // Tests that do a session restore (e.g. SessionRestoreUITest, StartupTest) |
| 114 // call SetUp() multiple times because they restart the browser mid-test. | 114 // call SetUp() multiple times because they restart the browser mid-test. |
| 115 // We don't want to reset the ProxyLauncher's state in those cases. | 115 // We don't want to reset the ProxyLauncher's state in those cases. |
| 116 if (!launcher_.get()) | 116 if (!launcher_.get()) |
| 117 launcher_.reset(CreateProxyLauncher()); | 117 launcher_.reset(CreateProxyLauncher()); |
| 118 launcher_->AssertAppNotRunning("Please close any other instances " | 118 launcher_->AssertAppNotRunning("Please close any other instances " |
| 119 "of the app before testing."); | 119 "of the app before testing."); |
| 120 | 120 |
| 121 JavaScriptExecutionController::set_timeout( | 121 JavaScriptExecutionController::set_timeout( |
| 122 TestTimeouts::action_max_timeout_ms()); | 122 TestTimeouts::action_max_timeout()); |
| 123 test_start_time_ = Time::NowFromSystemTime(); | 123 test_start_time_ = Time::NowFromSystemTime(); |
| 124 | 124 |
| 125 SetLaunchSwitches(); | 125 SetLaunchSwitches(); |
| 126 ASSERT_TRUE(launcher_->InitializeConnection(DefaultLaunchState(), | 126 ASSERT_TRUE(launcher_->InitializeConnection(DefaultLaunchState(), |
| 127 wait_for_initial_loads_)); | 127 wait_for_initial_loads_)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 void UITestBase::TearDown() { | 130 void UITestBase::TearDown() { |
| 131 if (launcher_.get()) | 131 if (launcher_.get()) |
| 132 launcher_->TerminateConnection(); | 132 launcher_->TerminateConnection(); |
| 133 | 133 |
| 134 CheckErrorsAndCrashes(); | 134 CheckErrorsAndCrashes(); |
| 135 } | 135 } |
| 136 | 136 |
| 137 AutomationProxy* UITestBase::automation() const { | 137 AutomationProxy* UITestBase::automation() const { |
| 138 return launcher_->automation(); | 138 return launcher_->automation(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 base::TimeDelta UITestBase::action_timeout() { |
| 142 return automation()->action_timeout(); |
| 143 } |
| 144 |
| 141 int UITestBase::action_timeout_ms() { | 145 int UITestBase::action_timeout_ms() { |
| 142 return automation()->action_timeout_ms(); | 146 return action_timeout().InMilliseconds(); |
| 147 } |
| 148 |
| 149 void UITestBase::set_action_timeout(base::TimeDelta timeout) { |
| 150 automation()->set_action_timeout(timeout); |
| 151 VLOG(1) << "Automation action timeout set to " |
| 152 << timeout.InMilliseconds() << " ms"; |
| 143 } | 153 } |
| 144 | 154 |
| 145 void UITestBase::set_action_timeout_ms(int timeout) { | 155 void UITestBase::set_action_timeout_ms(int timeout) { |
| 146 automation()->set_action_timeout_ms(timeout); | 156 set_action_timeout(base::TimeDelta::FromMilliseconds(timeout)); |
| 147 VLOG(1) << "Automation action timeout set to " << timeout << " ms"; | |
| 148 } | 157 } |
| 149 | 158 |
| 150 ProxyLauncher* UITestBase::CreateProxyLauncher() { | 159 ProxyLauncher* UITestBase::CreateProxyLauncher() { |
| 151 return new AnonymousProxyLauncher(false); | 160 return new AnonymousProxyLauncher(false); |
| 152 } | 161 } |
| 153 | 162 |
| 154 ProxyLauncher::LaunchState UITestBase::DefaultLaunchState() { | 163 ProxyLauncher::LaunchState UITestBase::DefaultLaunchState() { |
| 155 FilePath browser_executable = browser_directory_.Append(GetExecutablePath()); | 164 FilePath browser_executable = browser_directory_.Append(GetExecutablePath()); |
| 156 CommandLine command(browser_executable); | 165 CommandLine command(browser_executable); |
| 157 command.AppendArguments(launch_arguments_, false); | 166 command.AppendArguments(launch_arguments_, false); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 | 416 |
| 408 bool succeeded = automation()->Send(new AutomationMsg_CloseBrowser( | 417 bool succeeded = automation()->Send(new AutomationMsg_CloseBrowser( |
| 409 browser->handle(), &result, application_closed)); | 418 browser->handle(), &result, application_closed)); |
| 410 | 419 |
| 411 if (!succeeded) | 420 if (!succeeded) |
| 412 return false; | 421 return false; |
| 413 | 422 |
| 414 if (*application_closed) { | 423 if (*application_closed) { |
| 415 int exit_code = -1; | 424 int exit_code = -1; |
| 416 EXPECT_TRUE(launcher_->WaitForBrowserProcessToQuit( | 425 EXPECT_TRUE(launcher_->WaitForBrowserProcessToQuit( |
| 417 TestTimeouts::action_max_timeout_ms(), &exit_code)); | 426 TestTimeouts::action_max_timeout(), &exit_code)); |
| 418 EXPECT_EQ(0, exit_code); // Expect a clean shutown. | 427 EXPECT_EQ(0, exit_code); // Expect a clean shutown. |
| 419 } | 428 } |
| 420 | 429 |
| 421 return result; | 430 return result; |
| 422 } | 431 } |
| 423 | 432 |
| 424 // static | 433 // static |
| 425 FilePath UITestBase::ComputeTypicalUserDataSource( | 434 FilePath UITestBase::ComputeTypicalUserDataSource( |
| 426 UITestBase::ProfileType profile_type) { | 435 UITestBase::ProfileType profile_type) { |
| 427 FilePath source_history_file; | 436 FilePath source_history_file; |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 586 PathService::Get(chrome::DIR_USER_DATA, &path); | 595 PathService::Get(chrome::DIR_USER_DATA, &path); |
| 587 path = path.AppendASCII(chrome::kInitialProfile); | 596 path = path.AppendASCII(chrome::kInitialProfile); |
| 588 return LoadDictionaryValueFromPath(path.Append(chrome::kPreferencesFilename)); | 597 return LoadDictionaryValueFromPath(path.Append(chrome::kPreferencesFilename)); |
| 589 } | 598 } |
| 590 | 599 |
| 591 void UITest::WaitForFinish(const std::string &name, | 600 void UITest::WaitForFinish(const std::string &name, |
| 592 const std::string &id, | 601 const std::string &id, |
| 593 const GURL &url, | 602 const GURL &url, |
| 594 const std::string& test_complete_cookie, | 603 const std::string& test_complete_cookie, |
| 595 const std::string& expected_cookie_value, | 604 const std::string& expected_cookie_value, |
| 596 const int wait_time) { | 605 const base::TimeDelta wait_time) { |
| 597 // The webpage being tested has javascript which sets a cookie | 606 // The webpage being tested has javascript which sets a cookie |
| 598 // which signals completion of the test. The cookie name is | 607 // which signals completion of the test. The cookie name is |
| 599 // a concatenation of the test name and the test id. This allows | 608 // a concatenation of the test name and the test id. This allows |
| 600 // us to run multiple tests within a single webpage and test | 609 // us to run multiple tests within a single webpage and test |
| 601 // that they all c | 610 // that they all c |
| 602 std::string cookie_name = name; | 611 std::string cookie_name = name; |
| 603 cookie_name.append("."); | 612 cookie_name.append("."); |
| 604 cookie_name.append(id); | 613 cookie_name.append(id); |
| 605 cookie_name.append("."); | 614 cookie_name.append("."); |
| 606 cookie_name.append(test_complete_cookie); | 615 cookie_name.append(test_complete_cookie); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 620 if (file_util::EvictFileFromSystemCache(path)) | 629 if (file_util::EvictFileFromSystemCache(path)) |
| 621 return true; | 630 return true; |
| 622 base::PlatformThread::Sleep(kDelay); | 631 base::PlatformThread::Sleep(kDelay); |
| 623 } | 632 } |
| 624 return false; | 633 return false; |
| 625 } | 634 } |
| 626 | 635 |
| 627 bool UITest::WaitUntilJavaScriptCondition(TabProxy* tab, | 636 bool UITest::WaitUntilJavaScriptCondition(TabProxy* tab, |
| 628 const std::wstring& frame_xpath, | 637 const std::wstring& frame_xpath, |
| 629 const std::wstring& jscript, | 638 const std::wstring& jscript, |
| 630 int timeout_ms) { | 639 base::TimeDelta timeout) { |
| 631 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); | 640 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); |
| 632 const int kMaxDelays = timeout_ms / kDelay.InMilliseconds(); | 641 const int kMaxDelays = timeout / kDelay; |
| 633 | 642 |
| 634 // Wait until the test signals it has completed. | 643 // Wait until the test signals it has completed. |
| 635 for (int i = 0; i < kMaxDelays; ++i) { | 644 for (int i = 0; i < kMaxDelays; ++i) { |
| 636 bool done_value = false; | 645 bool done_value = false; |
| 637 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript, | 646 bool success = tab->ExecuteAndExtractBool(frame_xpath, jscript, |
| 638 &done_value); | 647 &done_value); |
| 639 EXPECT_TRUE(success); | 648 EXPECT_TRUE(success); |
| 640 if (!success) | 649 if (!success) |
| 641 return false; | 650 return false; |
| 642 if (done_value) | 651 if (done_value) |
| 643 return true; | 652 return true; |
| 644 | 653 |
| 645 base::PlatformThread::Sleep(kDelay); | 654 base::PlatformThread::Sleep(kDelay); |
| 646 } | 655 } |
| 647 | 656 |
| 648 ADD_FAILURE() << "Timeout reached in WaitUntilJavaScriptCondition"; | 657 ADD_FAILURE() << "Timeout reached in WaitUntilJavaScriptCondition"; |
| 649 return false; | 658 return false; |
| 650 } | 659 } |
| 651 | 660 |
| 652 bool UITest::WaitUntilCookieValue(TabProxy* tab, | 661 bool UITest::WaitUntilCookieValue(TabProxy* tab, |
| 653 const GURL& url, | 662 const GURL& url, |
| 654 const char* cookie_name, | 663 const char* cookie_name, |
| 655 int timeout_ms, | 664 base::TimeDelta timeout, |
| 656 const char* expected_value) { | 665 const char* expected_value) { |
| 657 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); | 666 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); |
| 658 const int kMaxDelays = timeout_ms / kDelay.InMilliseconds(); | 667 const int kMaxDelays = timeout / kDelay; |
| 659 | 668 |
| 660 std::string cookie_value; | 669 std::string cookie_value; |
| 661 for (int i = 0; i < kMaxDelays; ++i) { | 670 for (int i = 0; i < kMaxDelays; ++i) { |
| 662 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); | 671 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); |
| 663 if (cookie_value == expected_value) | 672 if (cookie_value == expected_value) |
| 664 return true; | 673 return true; |
| 665 | 674 |
| 666 base::PlatformThread::Sleep(kDelay); | 675 base::PlatformThread::Sleep(kDelay); |
| 667 } | 676 } |
| 668 | 677 |
| 669 ADD_FAILURE() << "Timeout reached in WaitUntilCookieValue"; | 678 ADD_FAILURE() << "Timeout reached in WaitUntilCookieValue"; |
| 670 return false; | 679 return false; |
| 671 } | 680 } |
| 672 | 681 |
| 673 std::string UITest::WaitUntilCookieNonEmpty(TabProxy* tab, | 682 std::string UITest::WaitUntilCookieNonEmpty(TabProxy* tab, |
| 674 const GURL& url, | 683 const GURL& url, |
| 675 const char* cookie_name, | 684 const char* cookie_name, |
| 676 int timeout_ms) { | 685 base::TimeDelta timeout) { |
| 677 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); | 686 const TimeDelta kDelay = TimeDelta::FromMilliseconds(250); |
| 678 const int kMaxDelays = timeout_ms / kDelay.InMilliseconds(); | 687 const int kMaxDelays = timeout / kDelay; |
| 679 | 688 |
| 680 for (int i = 0; i < kMaxDelays; ++i) { | 689 for (int i = 0; i < kMaxDelays; ++i) { |
| 681 std::string cookie_value; | 690 std::string cookie_value; |
| 682 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); | 691 EXPECT_TRUE(tab->GetCookieByName(url, cookie_name, &cookie_value)); |
| 683 if (!cookie_value.empty()) | 692 if (!cookie_value.empty()) |
| 684 return cookie_value; | 693 return cookie_value; |
| 685 | 694 |
| 686 base::PlatformThread::Sleep(kDelay); | 695 base::PlatformThread::Sleep(kDelay); |
| 687 } | 696 } |
| 688 | 697 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 &session_end_completed)); | 735 &session_end_completed)); |
| 727 ASSERT_TRUE(session_end_completed); | 736 ASSERT_TRUE(session_end_completed); |
| 728 | 737 |
| 729 // Make sure session restore says we didn't crash. | 738 // Make sure session restore says we didn't crash. |
| 730 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); | 739 scoped_ptr<DictionaryValue> profile_prefs(GetDefaultProfilePreferences()); |
| 731 ASSERT_TRUE(profile_prefs.get()); | 740 ASSERT_TRUE(profile_prefs.get()); |
| 732 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, | 741 ASSERT_TRUE(profile_prefs->GetBoolean(prefs::kSessionExitedCleanly, |
| 733 &exited_cleanly)); | 742 &exited_cleanly)); |
| 734 ASSERT_TRUE(exited_cleanly); | 743 ASSERT_TRUE(exited_cleanly); |
| 735 } | 744 } |
| OLD | NEW |