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