| 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 12 matching lines...) Expand all Loading... |
| 23 #include "base/process_util.h" | 23 #include "base/process_util.h" |
| 24 #include "base/scoped_ptr.h" | 24 #include "base/scoped_ptr.h" |
| 25 #include "base/scoped_temp_dir.h" | 25 #include "base/scoped_temp_dir.h" |
| 26 #include "base/string_number_conversions.h" | 26 #include "base/string_number_conversions.h" |
| 27 #include "base/string_split.h" | 27 #include "base/string_split.h" |
| 28 #include "base/test/test_file_util.h" | 28 #include "base/test/test_file_util.h" |
| 29 #include "base/time.h" | 29 #include "base/time.h" |
| 30 #include "base/utf_string_conversions.h" | 30 #include "base/utf_string_conversions.h" |
| 31 #include "chrome/app/chrome_command_ids.h" | 31 #include "chrome/app/chrome_command_ids.h" |
| 32 #include "chrome/browser/net/url_fixer_upper.h" | 32 #include "chrome/browser/net/url_fixer_upper.h" |
| 33 #include "chrome/common/automation_constants.h" |
| 33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 35 #include "chrome/common/chrome_switches.h" | 36 #include "chrome/common/chrome_switches.h" |
| 36 #include "chrome/common/debug_flags.h" | 37 #include "chrome/common/debug_flags.h" |
| 37 #include "chrome/common/logging_chrome.h" | 38 #include "chrome/common/logging_chrome.h" |
| 38 #include "chrome/common/json_value_serializer.h" | 39 #include "chrome/common/json_value_serializer.h" |
| 39 #include "chrome/common/url_constants.h" | 40 #include "chrome/common/url_constants.h" |
| 40 #include "chrome/test/automation/automation_messages.h" | 41 #include "chrome/test/automation/automation_messages.h" |
| 41 #include "chrome/test/automation/automation_proxy.h" | 42 #include "chrome/test/automation/automation_proxy.h" |
| 42 #include "chrome/test/automation/browser_proxy.h" | 43 #include "chrome/test/automation/browser_proxy.h" |
| 43 #include "chrome/test/automation/javascript_execution_controller.h" | 44 #include "chrome/test/automation/javascript_execution_controller.h" |
| 45 #include "chrome/test/automation/proxy_launcher.h" |
| 44 #include "chrome/test/automation/tab_proxy.h" | 46 #include "chrome/test/automation/tab_proxy.h" |
| 45 #include "chrome/test/automation/window_proxy.h" | 47 #include "chrome/test/automation/window_proxy.h" |
| 46 #include "chrome/test/chrome_process_util.h" | 48 #include "chrome/test/chrome_process_util.h" |
| 47 #include "chrome/test/test_launcher_utils.h" | 49 #include "chrome/test/test_launcher_utils.h" |
| 48 #include "chrome/test/test_switches.h" | 50 #include "chrome/test/test_switches.h" |
| 49 #include "googleurl/src/gurl.h" | 51 #include "googleurl/src/gurl.h" |
| 50 #include "net/base/net_util.h" | 52 #include "net/base/net_util.h" |
| 51 | 53 |
| 52 #if defined(OS_WIN) | 54 #if defined(OS_WIN) |
| 53 #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... |
| 131 UITestBase::~UITestBase() { | 133 UITestBase::~UITestBase() { |
| 132 } | 134 } |
| 133 | 135 |
| 134 void UITestBase::SetUp() { | 136 void UITestBase::SetUp() { |
| 135 AssertAppNotRunning(L"Please close any other instances " | 137 AssertAppNotRunning(L"Please close any other instances " |
| 136 L"of the app before testing."); | 138 L"of the app before testing."); |
| 137 | 139 |
| 138 JavaScriptExecutionController::set_timeout( | 140 JavaScriptExecutionController::set_timeout( |
| 139 TestTimeouts::action_max_timeout_ms()); | 141 TestTimeouts::action_max_timeout_ms()); |
| 140 test_start_time_ = Time::NowFromSystemTime(); | 142 test_start_time_ = Time::NowFromSystemTime(); |
| 141 LaunchBrowserAndServer(); | 143 |
| 144 launcher_.reset(CreateProxyLauncher()); |
| 145 launcher_->InitializeConnection(this); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void UITestBase::TearDown() { | 148 void UITestBase::TearDown() { |
| 145 CloseBrowserAndServer(); | 149 CloseBrowserAndServer(); |
| 146 | 150 |
| 147 // Make sure that we didn't encounter any assertion failures | 151 // Make sure that we didn't encounter any assertion failures |
| 148 logging::AssertionList assertions; | 152 logging::AssertionList assertions; |
| 149 logging::GetFatalAssertions(&assertions); | 153 logging::GetFatalAssertions(&assertions); |
| 150 | 154 |
| 151 // If there were errors, get all the error strings for display. | 155 // If there were errors, get all the error strings for display. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 166 L"Encountered an unexpected crash in the program during this test."; | 170 L"Encountered an unexpected crash in the program during this test."; |
| 167 if (expected_crashes_ > 0 && actual_crashes == 0) { | 171 if (expected_crashes_ > 0 && actual_crashes == 0) { |
| 168 error_msg += L" "; | 172 error_msg += L" "; |
| 169 error_msg += kFailedNoCrashService; | 173 error_msg += kFailedNoCrashService; |
| 170 } | 174 } |
| 171 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg; | 175 EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg; |
| 172 } | 176 } |
| 173 | 177 |
| 174 // TODO(phajdan.jr): get rid of set_command_execution_timeout_ms. | 178 // TODO(phajdan.jr): get rid of set_command_execution_timeout_ms. |
| 175 void UITestBase::set_command_execution_timeout_ms(int timeout) { | 179 void UITestBase::set_command_execution_timeout_ms(int timeout) { |
| 176 server_->set_command_execution_timeout_ms(timeout); | 180 automation_proxy_->set_command_execution_timeout_ms(timeout); |
| 177 VLOG(1) << "Automation command execution timeout set to " << timeout << " ms"; | 181 VLOG(1) << "Automation command execution timeout set to " << timeout << " ms"; |
| 178 } | 182 } |
| 179 | 183 |
| 180 AutomationProxy* UITestBase::CreateAutomationProxy(int execution_timeout) { | 184 ProxyLauncher* UITestBase::CreateProxyLauncher() { |
| 181 return new AutomationProxy(execution_timeout, false); | 185 return new AnonymousProxyLauncher(false); |
| 182 } | 186 } |
| 183 | 187 |
| 184 void UITestBase::LaunchBrowserAndServer() { | 188 void UITestBase::LaunchBrowserAndServer() { |
| 185 // Set up IPC testing interface server. | 189 // Set up IPC testing interface as a server. |
| 186 server_.reset(CreateAutomationProxy( | 190 automation_proxy_.reset(launcher_->CreateAutomationProxy( |
| 187 TestTimeouts::command_execution_timeout_ms())); | 191 TestTimeouts::command_execution_timeout_ms())); |
| 188 | 192 |
| 189 LaunchBrowser(launch_arguments_, clear_profile_); | 193 LaunchBrowser(launch_arguments_, clear_profile_); |
| 190 ASSERT_EQ(AUTOMATION_SUCCESS, server_->WaitForAppLaunch()) | 194 WaitForBrowserLaunch(); |
| 195 } |
| 196 |
| 197 void UITestBase::ConnectToRunningBrowser() { |
| 198 // Set up IPC testing interface as a client. |
| 199 automation_proxy_.reset(launcher_->CreateAutomationProxy( |
| 200 TestTimeouts::command_execution_timeout_ms())); |
| 201 WaitForBrowserLaunch(); |
| 202 } |
| 203 |
| 204 void UITestBase::WaitForBrowserLaunch() { |
| 205 ASSERT_EQ(AUTOMATION_SUCCESS, automation_proxy_->WaitForAppLaunch()) |
| 191 << "Error while awaiting automation ping from browser process"; | 206 << "Error while awaiting automation ping from browser process"; |
| 192 if (wait_for_initial_loads_) | 207 if (wait_for_initial_loads_) |
| 193 ASSERT_TRUE(server_->WaitForInitialLoads()); | 208 ASSERT_TRUE(automation_proxy_->WaitForInitialLoads()); |
| 194 else | 209 else |
| 195 PlatformThread::Sleep(sleep_timeout_ms()); | 210 PlatformThread::Sleep(sleep_timeout_ms()); |
| 196 | 211 |
| 197 EXPECT_TRUE(automation()->SetFilteredInet(ShouldFilterInet())); | 212 EXPECT_TRUE(automation()->SetFilteredInet(ShouldFilterInet())); |
| 198 } | 213 } |
| 199 | 214 |
| 200 void UITestBase::CloseBrowserAndServer() { | 215 void UITestBase::CloseBrowserAndServer() { |
| 201 QuitBrowser(); | 216 QuitBrowser(); |
| 202 CleanupAppProcesses(); | 217 CleanupAppProcesses(); |
| 203 | 218 |
| 204 // Suppress spammy failures that seem to be occurring when running | 219 // Suppress spammy failures that seem to be occurring when running |
| 205 // the UI tests in single-process mode. | 220 // the UI tests in single-process mode. |
| 206 // TODO(jhughes): figure out why this is necessary at all, and fix it | 221 // TODO(jhughes): figure out why this is necessary at all, and fix it |
| 207 if (!in_process_renderer_) | 222 if (!in_process_renderer_) |
| 208 AssertAppNotRunning(StringPrintf( | 223 AssertAppNotRunning(StringPrintf( |
| 209 L"Unable to quit all browser processes. Original PID %d", process_id_)); | 224 L"Unable to quit all browser processes. Original PID %d", process_id_)); |
| 210 | 225 |
| 211 server_.reset(); // Shut down IPC testing interface. | 226 automation_proxy_.reset(); // Shut down IPC testing interface. |
| 212 } | 227 } |
| 213 | 228 |
| 214 void UITestBase::LaunchBrowser(const CommandLine& arguments, | 229 void UITestBase::LaunchBrowser(const CommandLine& arguments, |
| 215 bool clear_profile) { | 230 bool clear_profile) { |
| 216 if (clear_profile || !temp_profile_dir_->IsValid()) { | 231 if (clear_profile || !temp_profile_dir_->IsValid()) { |
| 217 temp_profile_dir_.reset(new ScopedTempDir()); | 232 temp_profile_dir_.reset(new ScopedTempDir()); |
| 218 ASSERT_TRUE(temp_profile_dir_->CreateUniqueTempDir()); | 233 ASSERT_TRUE(temp_profile_dir_->CreateUniqueTempDir()); |
| 219 | 234 |
| 220 ASSERT_TRUE( | 235 ASSERT_TRUE( |
| 221 test_launcher_utils::OverrideUserDataDir(temp_profile_dir_->path())); | 236 test_launcher_utils::OverrideUserDataDir(temp_profile_dir_->path())); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 EXPECT_TRUE(tab_proxy.get()); | 573 EXPECT_TRUE(tab_proxy.get()); |
| 559 if (!tab_proxy.get()) | 574 if (!tab_proxy.get()) |
| 560 return FilePath(); | 575 return FilePath(); |
| 561 | 576 |
| 562 FilePath download_directory; | 577 FilePath download_directory; |
| 563 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); | 578 EXPECT_TRUE(tab_proxy->GetDownloadDirectory(&download_directory)); |
| 564 return download_directory; | 579 return download_directory; |
| 565 } | 580 } |
| 566 | 581 |
| 567 void UITestBase::CloseBrowserAsync(BrowserProxy* browser) const { | 582 void UITestBase::CloseBrowserAsync(BrowserProxy* browser) const { |
| 568 ASSERT_TRUE(server_->Send( | 583 ASSERT_TRUE(automation_proxy_->Send( |
| 569 new AutomationMsg_CloseBrowserRequestAsync(0, browser->handle()))); | 584 new AutomationMsg_CloseBrowserRequestAsync(0, browser->handle()))); |
| 570 } | 585 } |
| 571 | 586 |
| 572 bool UITestBase::CloseBrowser(BrowserProxy* browser, | 587 bool UITestBase::CloseBrowser(BrowserProxy* browser, |
| 573 bool* application_closed) const { | 588 bool* application_closed) const { |
| 574 DCHECK(application_closed); | 589 DCHECK(application_closed); |
| 575 if (!browser->is_valid() || !browser->handle()) | 590 if (!browser->is_valid() || !browser->handle()) |
| 576 return false; | 591 return false; |
| 577 | 592 |
| 578 bool result = true; | 593 bool result = true; |
| 579 | 594 |
| 580 bool succeeded = server_->Send(new AutomationMsg_CloseBrowser( | 595 bool succeeded = automation_proxy_->Send(new AutomationMsg_CloseBrowser( |
| 581 0, browser->handle(), &result, application_closed)); | 596 0, browser->handle(), &result, application_closed)); |
| 582 | 597 |
| 583 if (!succeeded) | 598 if (!succeeded) |
| 584 return false; | 599 return false; |
| 585 | 600 |
| 586 if (*application_closed) { | 601 if (*application_closed) { |
| 587 // Let's wait until the process dies (if it is not gone already). | 602 // Let's wait until the process dies (if it is not gone already). |
| 588 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout); | 603 bool success = base::WaitForSingleProcess(process_, base::kNoTimeout); |
| 589 EXPECT_TRUE(success); | 604 EXPECT_TRUE(success); |
| 590 } | 605 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 688 // Tell the browser to use a temporary directory just for this test. | 703 // Tell the browser to use a temporary directory just for this test. |
| 689 command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir()); | 704 command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir()); |
| 690 | 705 |
| 691 // We need cookies on file:// for things like the page cycler. | 706 // We need cookies on file:// for things like the page cycler. |
| 692 if (enable_file_cookies_) | 707 if (enable_file_cookies_) |
| 693 command_line.AppendSwitch(switches::kEnableFileCookies); | 708 command_line.AppendSwitch(switches::kEnableFileCookies); |
| 694 | 709 |
| 695 if (dom_automation_enabled_) | 710 if (dom_automation_enabled_) |
| 696 command_line.AppendSwitch(switches::kDomAutomationController); | 711 command_line.AppendSwitch(switches::kDomAutomationController); |
| 697 | 712 |
| 698 if (include_testing_id_) { | 713 if (include_testing_id_) |
| 699 command_line.AppendSwitchASCII(switches::kTestingChannelID, | 714 command_line.AppendSwitchASCII(switches::kTestingChannelID, |
| 700 server_->channel_id()); | 715 launcher_->PrefixedChannelID()); |
| 701 } | |
| 702 | 716 |
| 703 if (!show_error_dialogs_ && | 717 if (!show_error_dialogs_ && |
| 704 !CommandLine::ForCurrentProcess()->HasSwitch( | 718 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 705 switches::kEnableErrorDialogs)) { | 719 switches::kEnableErrorDialogs)) { |
| 706 command_line.AppendSwitch(switches::kNoErrorDialogs); | 720 command_line.AppendSwitch(switches::kNoErrorDialogs); |
| 707 } | 721 } |
| 708 if (in_process_renderer_) | 722 if (in_process_renderer_) |
| 709 command_line.AppendSwitch(switches::kSingleProcess); | 723 command_line.AppendSwitch(switches::kSingleProcess); |
| 710 if (no_sandbox_) | 724 if (no_sandbox_) |
| 711 command_line.AppendSwitch(switches::kNoSandbox); | 725 command_line.AppendSwitch(switches::kNoSandbox); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 // (e.g. valgrind) without also running the test harness (e.g. python) | 782 // (e.g. valgrind) without also running the test harness (e.g. python) |
| 769 // under the special environment. Provide a way to wrap the browser | 783 // under the special environment. Provide a way to wrap the browser |
| 770 // commandline with a special prefix to invoke the special environment. | 784 // commandline with a special prefix to invoke the special environment. |
| 771 const char* browser_wrapper = getenv("BROWSER_WRAPPER"); | 785 const char* browser_wrapper = getenv("BROWSER_WRAPPER"); |
| 772 if (browser_wrapper) { | 786 if (browser_wrapper) { |
| 773 command_line.PrependWrapper(browser_wrapper); | 787 command_line.PrependWrapper(browser_wrapper); |
| 774 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with " | 788 VLOG(1) << "BROWSER_WRAPPER was set, prefixing command_line with " |
| 775 << browser_wrapper; | 789 << browser_wrapper; |
| 776 } | 790 } |
| 777 | 791 |
| 778 bool started = base::LaunchApp(command_line.argv(), | 792 base::file_handle_mapping_vector fds; |
| 779 server_->fds_to_map(), | 793 if (automation_proxy_.get()) |
| 780 wait, | 794 fds = automation_proxy_->fds_to_map(); |
| 781 process); | 795 |
| 796 bool started = base::LaunchApp(command_line.argv(), fds, wait, process); |
| 782 #endif | 797 #endif |
| 783 | 798 |
| 784 return started; | 799 return started; |
| 785 } | 800 } |
| 786 | 801 |
| 787 void UITestBase::UpdateHistoryDates() { | 802 void UITestBase::UpdateHistoryDates() { |
| 788 // Migrate the times in the segment_usage table to yesterday so we get | 803 // Migrate the times in the segment_usage table to yesterday so we get |
| 789 // actual thumbnails on the NTP. | 804 // actual thumbnails on the NTP. |
| 790 sql::Connection db; | 805 sql::Connection db; |
| 791 FilePath history = | 806 FilePath history = |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 } | 853 } |
| 839 UITestBase::SetUp(); | 854 UITestBase::SetUp(); |
| 840 PlatformTest::SetUp(); | 855 PlatformTest::SetUp(); |
| 841 } | 856 } |
| 842 | 857 |
| 843 void UITest::TearDown() { | 858 void UITest::TearDown() { |
| 844 UITestBase::TearDown(); | 859 UITestBase::TearDown(); |
| 845 PlatformTest::TearDown(); | 860 PlatformTest::TearDown(); |
| 846 } | 861 } |
| 847 | 862 |
| 848 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { | 863 ProxyLauncher* UITest::CreateProxyLauncher() { |
| 849 // Make the AutomationProxy disconnect the channel on the first error, | 864 // Make the AutomationProxy disconnect the channel on the first error, |
| 850 // so that we avoid spending a lot of time in timeouts. The browser is likely | 865 // so that we avoid spending a lot of time in timeouts. The browser is likely |
| 851 // hosed if we hit those errors. | 866 // hosed if we hit those errors. |
| 852 return new AutomationProxy(execution_timeout, true); | 867 return new AnonymousProxyLauncher(true); |
| 853 } | 868 } |
| 854 | 869 |
| 855 static CommandLine* CreatePythonCommandLine() { | 870 static CommandLine* CreatePythonCommandLine() { |
| 856 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); | 871 return new CommandLine(FilePath(FILE_PATH_LITERAL("python"))); |
| 857 } | 872 } |
| 858 | 873 |
| 859 static CommandLine* CreateHttpServerCommandLine() { | 874 static CommandLine* CreateHttpServerCommandLine() { |
| 860 FilePath src_path; | 875 FilePath src_path; |
| 861 // Get to 'src' dir. | 876 // Get to 'src' dir. |
| 862 PathService::Get(base::DIR_SOURCE_ROOT, &src_path); | 877 PathService::Get(base::DIR_SOURCE_ROOT, &src_path); |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 incorrect_state_count++; | 1183 incorrect_state_count++; |
| 1169 } | 1184 } |
| 1170 | 1185 |
| 1171 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() | 1186 LOG(INFO) << "Elapsed time: " << (base::Time::Now() - start).InSecondsF() |
| 1172 << " seconds" | 1187 << " seconds" |
| 1173 << " call failed " << fail_count << " times" | 1188 << " call failed " << fail_count << " times" |
| 1174 << " state was incorrect " << incorrect_state_count << " times"; | 1189 << " state was incorrect " << incorrect_state_count << " times"; |
| 1175 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; | 1190 ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; |
| 1176 return false; | 1191 return false; |
| 1177 } | 1192 } |
| 1178 | |
| OLD | NEW |