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

Side by Side Diff: chrome/test/ui/ui_test.cc

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

Powered by Google App Engine
This is Rietveld 408576698