diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 20:13:22 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-24 20:13:22 +0000 |
commit | b45d80311bc50f2d6251f2fd38feaa53f5c25276 (patch) | |
tree | aa3c70780ad6d7750a2eb7ce27f1c9f18de9b8bc /chrome/test/ui/ui_test.cc | |
parent | 52a2432b71c9bcf344954b8487f00c1e2c403226 (diff) | |
download | chromium_src-b45d80311bc50f2d6251f2fd38feaa53f5c25276.zip chromium_src-b45d80311bc50f2d6251f2fd38feaa53f5c25276.tar.gz chromium_src-b45d80311bc50f2d6251f2fd38feaa53f5c25276.tar.bz2 |
Add named testing interface. This allows you to connect to a pre-existing Chrome process and run tests on it. This is an addition to the low level interface underlying testing frameworks like PyAuto and WebDriver.
Normally, test frameworks communicate with Chrome over an unnamed socket pair on POSIX. The test creates the socket pair and then launches the browser as a child process, passing an open file descriptor for one end of the socket to the browser. This change adds a command line switch that, when passed to the browser, causes it to listen on a named socket instead, eliminating this parent/child process requirement. Therefore, you can potentially connect any number of tests to a preexisting browser process.
For ChromeOS, this allows you to run tests on the instance of Chrome that is launched on startup, which controls things like the login and lock screens, the battery meter, the wireless UI, etc. Currently there is no way to run tests on a pre-existing Chrome instance. Eventually this will also allow you to connect both PyAuto and WebDriver to the same Chrome instance and run both in the same test.
If you pass the browser the following command line switch:
./chrome --testing-channel=NamedTestingInterface:/path/to/file
This causes the browser to listen for incoming connections. An AutomationProxy can connect to the browser by connecting a Unix domain socket to the specified path and control the browser over the socket.
This is currently only for POSIX. Windows support will come in a future change. Also, this initial change only allows one connection; multiple connection support will come in a future change.
BUG=chromium-os:8512
TEST=Run Chrome with --testing-interface=/var/tmp/NamedTestingInterface, then run NamedInterfaceTest.BasicNamedInterface under ui_tests.
Review URL: http://codereview.chromium.org/4202004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@67300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/ui/ui_test.cc')
-rw-r--r-- | chrome/test/ui/ui_test.cc | 60 |
1 files changed, 39 insertions, 21 deletions
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 9fbb857..e6aff60 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -43,6 +43,7 @@ #include "chrome/test/automation/automation_proxy.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/javascript_execution_controller.h" +#include "chrome/test/automation/proxy_launcher.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" #include "chrome/test/chrome_process_util.h" @@ -140,7 +141,9 @@ void UITestBase::SetUp() { JavaScriptExecutionController::set_timeout( TestTimeouts::action_max_timeout_ms()); test_start_time_ = Time::NowFromSystemTime(); - LaunchBrowserAndServer(); + + launcher_.reset(CreateProxyLauncher()); + launcher_->InitializeConnection(this); } void UITestBase::TearDown() { @@ -175,24 +178,39 @@ void UITestBase::TearDown() { // TODO(phajdan.jr): get rid of set_command_execution_timeout_ms. void UITestBase::set_command_execution_timeout_ms(int timeout) { - server_->set_command_execution_timeout_ms(timeout); + automation_proxy_->set_command_execution_timeout_ms(timeout); VLOG(1) << "Automation command execution timeout set to " << timeout << " ms"; } -AutomationProxy* UITestBase::CreateAutomationProxy(int execution_timeout) { - return new AutomationProxy(execution_timeout, false); +ProxyLauncher* UITestBase::CreateProxyLauncher() { + return new AnonymousProxyLauncher(false); +} + +void UITestBase::LaunchBrowser() { + LaunchBrowser(launch_arguments_, clear_profile_); } void UITestBase::LaunchBrowserAndServer() { - // Set up IPC testing interface server. - server_.reset(CreateAutomationProxy( - TestTimeouts::command_execution_timeout_ms())); + // Set up IPC testing interface as a server. + automation_proxy_.reset(launcher_->CreateAutomationProxy( + TestTimeouts::command_execution_timeout_ms())); LaunchBrowser(launch_arguments_, clear_profile_); - ASSERT_EQ(AUTOMATION_SUCCESS, server_->WaitForAppLaunch()) + WaitForBrowserLaunch(); +} + +void UITestBase::ConnectToRunningBrowser() { + // Set up IPC testing interface as a client. + automation_proxy_.reset(launcher_->CreateAutomationProxy( + TestTimeouts::command_execution_timeout_ms())); + WaitForBrowserLaunch(); +} + +void UITestBase::WaitForBrowserLaunch() { + ASSERT_EQ(AUTOMATION_SUCCESS, automation_proxy_->WaitForAppLaunch()) << "Error while awaiting automation ping from browser process"; if (wait_for_initial_loads_) - ASSERT_TRUE(server_->WaitForInitialLoads()); + ASSERT_TRUE(automation_proxy_->WaitForInitialLoads()); else PlatformThread::Sleep(sleep_timeout_ms()); @@ -210,7 +228,7 @@ void UITestBase::CloseBrowserAndServer() { AssertAppNotRunning(StringPrintf( L"Unable to quit all browser processes. Original PID %d", process_id_)); - server_.reset(); // Shut down IPC testing interface. + automation_proxy_.reset(); // Shut down IPC testing interface. } void UITestBase::LaunchBrowser(const CommandLine& arguments, @@ -567,7 +585,7 @@ FilePath UITestBase::GetDownloadDirectory() { } void UITestBase::CloseBrowserAsync(BrowserProxy* browser) const { - ASSERT_TRUE(server_->Send( + ASSERT_TRUE(automation_proxy_->Send( new AutomationMsg_CloseBrowserRequestAsync(0, browser->handle()))); } @@ -579,7 +597,7 @@ bool UITestBase::CloseBrowser(BrowserProxy* browser, bool result = true; - bool succeeded = server_->Send(new AutomationMsg_CloseBrowser( + bool succeeded = automation_proxy_->Send(new AutomationMsg_CloseBrowser( 0, browser->handle(), &result, application_closed)); if (!succeeded) @@ -694,10 +712,9 @@ void UITestBase::PrepareTestCommandline(CommandLine* command_line) { if (dom_automation_enabled_) command_line->AppendSwitch(switches::kDomAutomationController); - if (include_testing_id_) { + if (include_testing_id_) command_line->AppendSwitchASCII(switches::kTestingChannelID, - server_->channel_id()); - } + launcher_->PrefixedChannelID()); if (!show_error_dialogs_ && !CommandLine::ForCurrentProcess()->HasSwitch( @@ -786,10 +803,11 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, << browser_wrapper; } - bool started = base::LaunchApp(command_line.argv(), - server_->fds_to_map(), - wait, - process); + base::file_handle_mapping_vector fds; + if (automation_proxy_.get()) + fds = automation_proxy_->fds_to_map(); + + bool started = base::LaunchApp(command_line.argv(), fds, wait, process); #endif return started; @@ -867,11 +885,11 @@ void UITest::TearDown() { PlatformTest::TearDown(); } -AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { +ProxyLauncher* UITest::CreateProxyLauncher() { // Make the AutomationProxy disconnect the channel on the first error, // so that we avoid spending a lot of time in timeouts. The browser is likely // hosed if we hit those errors. - return new AutomationProxy(execution_timeout, true); + return new AnonymousProxyLauncher(true); } static CommandLine* CreatePythonCommandLine() { |