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

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

Issue 6012006: Revert 68944 - Revert "Add named testing interface." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 12 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/ui/ui_test.h ('k') | chrome_frame/chrome_frame.gyp » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 25 matching lines...) Expand all
36 #include "chrome/common/chrome_constants.h" 36 #include "chrome/common/chrome_constants.h"
37 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
38 #include "chrome/common/chrome_switches.h" 38 #include "chrome/common/chrome_switches.h"
39 #include "chrome/common/debug_flags.h" 39 #include "chrome/common/debug_flags.h"
40 #include "chrome/common/logging_chrome.h" 40 #include "chrome/common/logging_chrome.h"
41 #include "chrome/common/json_value_serializer.h" 41 #include "chrome/common/json_value_serializer.h"
42 #include "chrome/common/url_constants.h" 42 #include "chrome/common/url_constants.h"
43 #include "chrome/test/automation/automation_proxy.h" 43 #include "chrome/test/automation/automation_proxy.h"
44 #include "chrome/test/automation/browser_proxy.h" 44 #include "chrome/test/automation/browser_proxy.h"
45 #include "chrome/test/automation/javascript_execution_controller.h" 45 #include "chrome/test/automation/javascript_execution_controller.h"
46 #include "chrome/test/automation/proxy_launcher.h"
46 #include "chrome/test/automation/tab_proxy.h" 47 #include "chrome/test/automation/tab_proxy.h"
47 #include "chrome/test/automation/window_proxy.h" 48 #include "chrome/test/automation/window_proxy.h"
48 #include "chrome/test/chrome_process_util.h" 49 #include "chrome/test/chrome_process_util.h"
49 #include "chrome/test/test_launcher_utils.h" 50 #include "chrome/test/test_launcher_utils.h"
50 #include "chrome/test/test_switches.h" 51 #include "chrome/test/test_switches.h"
51 #include "googleurl/src/gurl.h" 52 #include "googleurl/src/gurl.h"
52 #include "net/base/net_util.h" 53 #include "net/base/net_util.h"
53 54
54 #if defined(OS_WIN) 55 #if defined(OS_WIN)
55 #include "base/win/windows_version.h" 56 #include "base/win/windows_version.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 UITestBase::~UITestBase() { 134 UITestBase::~UITestBase() {
134 } 135 }
135 136
136 void UITestBase::SetUp() { 137 void UITestBase::SetUp() {
137 AssertAppNotRunning(L"Please close any other instances " 138 AssertAppNotRunning(L"Please close any other instances "
138 L"of the app before testing."); 139 L"of the app before testing.");
139 140
140 JavaScriptExecutionController::set_timeout( 141 JavaScriptExecutionController::set_timeout(
141 TestTimeouts::action_max_timeout_ms()); 142 TestTimeouts::action_max_timeout_ms());
142 test_start_time_ = Time::NowFromSystemTime(); 143 test_start_time_ = Time::NowFromSystemTime();
143 LaunchBrowserAndServer(); 144
145 launcher_.reset(CreateProxyLauncher());
146 launcher_->InitializeConnection(this);
144 } 147 }
145 148
146 void UITestBase::TearDown() { 149 void UITestBase::TearDown() {
147 CloseBrowserAndServer(); 150 CloseBrowserAndServer();
148 151
149 // Make sure that we didn't encounter any assertion failures 152 // Make sure that we didn't encounter any assertion failures
150 logging::AssertionList assertions; 153 logging::AssertionList assertions;
151 logging::GetFatalAssertions(&assertions); 154 logging::GetFatalAssertions(&assertions);
152 155
153 // If there were errors, get all the error strings for display. 156 // If there were errors, get all the error strings for display.
(...skipping 14 matching lines...) Expand all
168 L"Encountered an unexpected crash in the program during this test."; 171 L"Encountered an unexpected crash in the program during this test.";
169 if (expected_crashes_ > 0 && actual_crashes == 0) { 172 if (expected_crashes_ > 0 && actual_crashes == 0) {
170 error_msg += L" "; 173 error_msg += L" ";
171 error_msg += kFailedNoCrashService; 174 error_msg += kFailedNoCrashService;
172 } 175 }
173 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg; 176 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg;
174 } 177 }
175 178
176 // TODO(phajdan.jr): get rid of set_command_execution_timeout_ms. 179 // TODO(phajdan.jr): get rid of set_command_execution_timeout_ms.
177 void UITestBase::set_command_execution_timeout_ms(int timeout) { 180 void UITestBase::set_command_execution_timeout_ms(int timeout) {
178 server_->set_command_execution_timeout_ms(timeout); 181 automation_proxy_->set_command_execution_timeout_ms(timeout);
179 VLOG(1) << "Automation command execution timeout set to " << timeout << " ms"; 182 VLOG(1) << "Automation command execution timeout set to " << timeout << " ms";
180 } 183 }
181 184
182 AutomationProxy* UITestBase::CreateAutomationProxy(int execution_timeout) { 185 ProxyLauncher* UITestBase::CreateProxyLauncher() {
183 return new AutomationProxy(execution_timeout, false); 186 return new AnonymousProxyLauncher(false);
187 }
188
189 void UITestBase::LaunchBrowser() {
190 LaunchBrowser(launch_arguments_, clear_profile_);
184 } 191 }
185 192
186 void UITestBase::LaunchBrowserAndServer() { 193 void UITestBase::LaunchBrowserAndServer() {
187 // Set up IPC testing interface server. 194 // Set up IPC testing interface as a server.
188 server_.reset(CreateAutomationProxy( 195 automation_proxy_.reset(launcher_->CreateAutomationProxy(
189 TestTimeouts::command_execution_timeout_ms())); 196 TestTimeouts::command_execution_timeout_ms()));
190 197
191 LaunchBrowser(launch_arguments_, clear_profile_); 198 LaunchBrowser(launch_arguments_, clear_profile_);
192 ASSERT_EQ(AUTOMATION_SUCCESS, server_->WaitForAppLaunch()) 199 WaitForBrowserLaunch();
200 }
201
202 void UITestBase::ConnectToRunningBrowser() {
203 // Set up IPC testing interface as a client.
204 automation_proxy_.reset(launcher_->CreateAutomationProxy(
205 TestTimeouts::command_execution_timeout_ms()));
206 WaitForBrowserLaunch();
207 }
208
209 void UITestBase::WaitForBrowserLaunch() {
210 ASSERT_EQ(AUTOMATION_SUCCESS, automation_proxy_->WaitForAppLaunch())
193 << "Error while awaiting automation ping from browser process"; 211 << "Error while awaiting automation ping from browser process";
194 if (wait_for_initial_loads_) 212 if (wait_for_initial_loads_)
195 ASSERT_TRUE(server_->WaitForInitialLoads()); 213 ASSERT_TRUE(automation_proxy_->WaitForInitialLoads());
196 else 214 else
197 PlatformThread::Sleep(sleep_timeout_ms()); 215 PlatformThread::Sleep(sleep_timeout_ms());
198 216
199 EXPECT_TRUE(automation()->SetFilteredInet(ShouldFilterInet())); 217 EXPECT_TRUE(automation()->SetFilteredInet(ShouldFilterInet()));
200 } 218 }
201 219
202 void UITestBase::CloseBrowserAndServer() { 220 void UITestBase::CloseBrowserAndServer() {
203 QuitBrowser(); 221 QuitBrowser();
204 CleanupAppProcesses(); 222 CleanupAppProcesses();
205 223
206 // Suppress spammy failures that seem to be occurring when running 224 // Suppress spammy failures that seem to be occurring when running
207 // the UI tests in single-process mode. 225 // the UI tests in single-process mode.
208 // TODO(jhughes): figure out why this is necessary at all, and fix it 226 // TODO(jhughes): figure out why this is necessary at all, and fix it
209 if (!in_process_renderer_) 227 if (!in_process_renderer_)
210 AssertAppNotRunning(StringPrintf( 228 AssertAppNotRunning(StringPrintf(
211 L"Unable to quit all browser processes. Original PID %d", process_id_)); 229 L"Unable to quit all browser processes. Original PID %d", process_id_));
212 230
213 server_.reset(); // Shut down IPC testing interface. 231 automation_proxy_.reset(); // Shut down IPC testing interface.
214 } 232 }
215 233
216 void UITestBase::LaunchBrowser(const CommandLine& arguments, 234 void UITestBase::LaunchBrowser(const CommandLine& arguments,
217 bool clear_profile) { 235 bool clear_profile) {
218 if (clear_profile || !temp_profile_dir_->IsValid()) { 236 if (clear_profile || !temp_profile_dir_->IsValid()) {
219 temp_profile_dir_.reset(new ScopedTempDir()); 237 temp_profile_dir_.reset(new ScopedTempDir());
220 ASSERT_TRUE(temp_profile_dir_->CreateUniqueTempDir()); 238 ASSERT_TRUE(temp_profile_dir_->CreateUniqueTempDir());
221 239
222 ASSERT_TRUE( 240 ASSERT_TRUE(
223 test_launcher_utils::OverrideUserDataDir(temp_profile_dir_->path())); 241 test_launcher_utils::OverrideUserDataDir(temp_profile_dir_->path()));
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 EXPECT_TRUE(tab_proxy.get()); 578 EXPECT_TRUE(tab_proxy.get());
561 if (!tab_proxy.get()) 579 if (!tab_proxy.get())
562 return FilePath(); 580 return FilePath();
563 581
564 FilePath download_directory; 582 FilePath download_directory;
565 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); 583 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory));
566 return download_directory; 584 return download_directory;
567 } 585 }
568 586
569 void UITestBase::CloseBrowserAsync(BrowserProxy* browser) const { 587 void UITestBase::CloseBrowserAsync(BrowserProxy* browser) const {
570 ASSERT_TRUE(server_->Send( 588 ASSERT_TRUE(automation_proxy_->Send(
571 new AutomationMsg_CloseBrowserRequestAsync(0, browser->handle()))); 589 new AutomationMsg_CloseBrowserRequestAsync(0, browser->handle())));
572 } 590 }
573 591
574 bool UITestBase::CloseBrowser(BrowserProxy* browser, 592 bool UITestBase::CloseBrowser(BrowserProxy* browser,
575 bool* application_closed) const { 593 bool* application_closed) const {
576 DCHECK(application_closed); 594 DCHECK(application_closed);
577 if (!browser->is_valid() || !browser->handle()) 595 if (!browser->is_valid() || !browser->handle())
578 return false; 596 return false;
579 597
580 bool result = true; 598 bool result = true;
581 599
582 bool succeeded = server_->Send(new AutomationMsg_CloseBrowser( 600 bool succeeded = automation_proxy_->Send(new AutomationMsg_CloseBrowser(
583 0, browser->handle(), &result, application_closed)); 601 0, browser->handle(), &result, application_closed));
584 602
585 if (!succeeded) 603 if (!succeeded)
586 return false; 604 return false;
587 605
588 if (*application_closed) { 606 if (*application_closed) {
589 // Let's wait until the process dies (if it is not gone already). 607 // Let's wait until the process dies (if it is not gone already).
590 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout); 608 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout);
591 EXPECT_TRUE(success); 609 EXPECT_TRUE(success);
592 } 610 }
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 // Tell the browser to use a temporary directory just for this test. 705 // Tell the browser to use a temporary directory just for this test.
688 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir()); 706 command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir());
689 707
690 // We need cookies on file:// for things like the page cycler. 708 // We need cookies on file:// for things like the page cycler.
691 if (enable_file_cookies_) 709 if (enable_file_cookies_)
692 command_line->AppendSwitch(switches::kEnableFileCookies); 710 command_line->AppendSwitch(switches::kEnableFileCookies);
693 711
694 if (dom_automation_enabled_) 712 if (dom_automation_enabled_)
695 command_line->AppendSwitch(switches::kDomAutomationController); 713 command_line->AppendSwitch(switches::kDomAutomationController);
696 714
697 if (include_testing_id_) { 715 if (include_testing_id_)
698 command_line->AppendSwitchASCII(switches::kTestingChannelID, 716 command_line->AppendSwitchASCII(switches::kTestingChannelID,
699 server_->channel_id()); 717 launcher_->PrefixedChannelID());
700 }
701 718
702 if (!show_error_dialogs_ && 719 if (!show_error_dialogs_ &&
703 !CommandLine::ForCurrentProcess()->HasSwitch( 720 !CommandLine::ForCurrentProcess()->HasSwitch(
704 switches::kEnableErrorDialogs)) { 721 switches::kEnableErrorDialogs)) {
705 command_line->AppendSwitch(switches::kNoErrorDialogs); 722 command_line->AppendSwitch(switches::kNoErrorDialogs);
706 } 723 }
707 if (in_process_renderer_) 724 if (in_process_renderer_)
708 command_line->AppendSwitch(switches::kSingleProcess); 725 command_line->AppendSwitch(switches::kSingleProcess);
709 if (no_sandbox_) 726 if (no_sandbox_)
710 command_line->AppendSwitch(switches::kNoSandbox); 727 command_line->AppendSwitch(switches::kNoSandbox);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // (e.g. valgrind) without also running the test harness (e.g. python) 796 // (e.g. valgrind) without also running the test harness (e.g. python)
780 // under the special environment. Provide a way to wrap the browser 797 // under the special environment. Provide a way to wrap the browser
781 // commandline with a special prefix to invoke the special environment. 798 // commandline with a special prefix to invoke the special environment.
782 const char* browser_wrapper = getenv("BROWSER_WRAPPER"); 799 const char* browser_wrapper = getenv("BROWSER_WRAPPER");
783 if (browser_wrapper) { 800 if (browser_wrapper) {
784 command_line.PrependWrapper(browser_wrapper); 801 command_line.PrependWrapper(browser_wrapper);
785 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with " 802 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with "
786 << browser_wrapper; 803 << browser_wrapper;
787 } 804 }
788 805
789 bool started = base::LaunchApp(command_line.argv(), 806 base::file_handle_mapping_vector fds;
790 server_->fds_to_map(), 807 if (automation_proxy_.get())
791 wait, 808 fds = automation_proxy_->fds_to_map();
792 process); 809
810 bool started = base::LaunchApp(command_line.argv(), fds, wait, process);
793 #endif 811 #endif
794 812
795 return started; 813 return started;
796 } 814 }
797 815
798 void UITestBase::UpdateHistoryDates() { 816 void UITestBase::UpdateHistoryDates() {
799 // Migrate the times in the segment_usage table to yesterday so we get 817 // Migrate the times in the segment_usage table to yesterday so we get
800 // actual thumbnails on the NTP. 818 // actual thumbnails on the NTP.
801 sql::Connection db; 819 sql::Connection db;
802 FilePath history = 820 FilePath history =
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 878
861 UITestBase::SetUp(); 879 UITestBase::SetUp();
862 PlatformTest::SetUp(); 880 PlatformTest::SetUp();
863 } 881 }
864 882
865 void UITest::TearDown() { 883 void UITest::TearDown() {
866 UITestBase::TearDown(); 884 UITestBase::TearDown();
867 PlatformTest::TearDown(); 885 PlatformTest::TearDown();
868 } 886 }
869 887
870 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { 888 ProxyLauncher* UITest::CreateProxyLauncher() {
871 // Make the AutomationProxy disconnect the channel on the first error, 889 // Make the AutomationProxy disconnect the channel on the first error,
872 // so that we avoid spending a lot of time in timeouts. The browser is likely 890 // so that we avoid spending a lot of time in timeouts. The browser is likely
873 // hosed if we hit those errors. 891 // hosed if we hit those errors.
874 return new AutomationProxy(execution_timeout, true); 892 return new AnonymousProxyLauncher(true);
875 } 893 }
876 894
877 static CommandLine* CreatePythonCommandLine() { 895 static CommandLine* CreatePythonCommandLine() {
878 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); 896 return new CommandLine(FilePath(FILE_PATH_LITERAL("python")));
879 } 897 }
880 898
881 static CommandLine* CreateHttpServerCommandLine() { 899 static CommandLine* CreateHttpServerCommandLine() {
882 FilePath src_path; 900 FilePath src_path;
883 // Get to 'src' dir. 901 // Get to 'src' dir.
884 PathService::Get(base::DIR_SOURCE_ROOT, &src_path); 902 PathService::Get(base::DIR_SOURCE_ROOT, &src_path);
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
1190 incorrect_state_count++; 1208 incorrect_state_count++;
1191 } 1209 }
1192 1210
1193 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() 1211 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF()
1194 << " seconds" 1212 << " seconds"
1195 << " call failed " << fail_count << " times" 1213 << " call failed " << fail_count << " times"
1196 << " state was incorrect " << incorrect_state_count << " times"; 1214 << " state was incorrect " << incorrect_state_count << " times";
1197 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; 1215 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__;
1198 return false; 1216 return false;
1199 } 1217 }
OLDNEW
« no previous file with comments | « chrome/test/ui/ui_test.h ('k') | chrome_frame/chrome_frame.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698