diff options
author | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-17 02:27:10 +0000 |
---|---|---|
committer | nirnimesh@chromium.org <nirnimesh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-17 02:27:10 +0000 |
commit | bb6e37a6c367c3a9c7577038ebacf933920b2354 (patch) | |
tree | 73444de881e47cc87e9eba831589b232429188d0 /chrome/test/automation | |
parent | ce3f910ff3d7508f2a3a0c7ab8b268b56f25dba7 (diff) | |
download | chromium_src-bb6e37a6c367c3a9c7577038ebacf933920b2354.zip chromium_src-bb6e37a6c367c3a9c7577038ebacf933920b2354.tar.gz chromium_src-bb6e37a6c367c3a9c7577038ebacf933920b2354.tar.bz2 |
Revert 66350 - 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
TBR=nirnimesh@chromium.org
Review URL: http://codereview.chromium.org/5139001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66368 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r-- | chrome/test/automation/automation_proxy.cc | 14 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy.h | 18 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy_uitest.cc | 22 | ||||
-rw-r--r-- | chrome/test/automation/automation_proxy_uitest.h | 6 | ||||
-rw-r--r-- | chrome/test/automation/proxy_launcher.cc | 75 | ||||
-rw-r--r-- | chrome/test/automation/proxy_launcher.h | 78 |
6 files changed, 20 insertions, 193 deletions
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 3e540b9..fbdde25 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -107,8 +107,10 @@ AutomationProxy::AutomationProxy(int command_execution_timeout_ms, // least it is legal... ;-) DCHECK_GE(command_execution_timeout_ms, 0); listener_thread_id_ = PlatformThread::CurrentId(); + InitializeChannelID(); InitializeHandleTracker(); InitializeThread(); + InitializeChannel(); } AutomationProxy::~AutomationProxy() { @@ -120,7 +122,7 @@ AutomationProxy::~AutomationProxy() { tracker_.reset(); } -std::string AutomationProxy::GenerateChannelID() { +void AutomationProxy::InitializeChannelID() { // The channel counter keeps us out of trouble if we create and destroy // several AutomationProxies sequentially over the course of a test run. // (Creating the channel sometimes failed before when running a lot of @@ -131,7 +133,7 @@ std::string AutomationProxy::GenerateChannelID() { std::ostringstream buf; buf << "ChromeTestingInterface:" << base::GetCurrentProcId() << "." << ++channel_counter; - return buf.str(); + channel_id_ = buf.str(); } void AutomationProxy::InitializeThread() { @@ -144,8 +146,7 @@ void AutomationProxy::InitializeThread() { thread_.swap(thread); } -void AutomationProxy::InitializeChannel(const std::string& channel_id, - bool use_named_interface) { +void AutomationProxy::InitializeChannel() { DCHECK(shutdown_event_.get() != NULL); // TODO(iyengar) @@ -153,9 +154,8 @@ void AutomationProxy::InitializeChannel(const std::string& channel_id, // provider, where we use the shutdown event provided by the chrome browser // process. channel_.reset(new IPC::SyncChannel( - channel_id, - use_named_interface ? IPC::Channel::MODE_SERVER - : IPC::Channel::MODE_NAMED_CLIENT, + channel_id_, + IPC::Channel::MODE_SERVER, this, // we are the listener new AutomationMessageFilter(this), thread_->message_loop(), diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 7902ef0..853a6d3 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -61,17 +61,6 @@ class AutomationProxy : public IPC::Channel::Listener, AutomationProxy(int command_execution_timeout_ms, bool disconnect_on_failure); virtual ~AutomationProxy(); - // Creates a previously unused channel id. - static std::string GenerateChannelID(); - - // Initializes a channel for a connection to an AutomationProvider. - // If use_named_interface is false, it will act as a client - // and connect to the named IPC socket with channel_id as its path. - // If use_named_interface is true, it will act as a server and - // use an anonymous socketpair instead. - void InitializeChannel(const std::string& channel_id, - bool use_named_interface); - // IPC callback virtual void OnMessageReceived(const IPC::Message& msg); virtual void OnChannelError(); @@ -219,6 +208,10 @@ class AutomationProxy : public IPC::Channel::Listener, const std::string& password) WARN_UNUSED_RESULT; #endif + // Returns the ID of the automation IPC channel, so that it can be + // passed to the app as a launch parameter. + const std::string& channel_id() const { return channel_id_; } + #if defined(OS_POSIX) base::file_handle_mapping_vector fds_to_map() const; #endif @@ -270,9 +263,12 @@ class AutomationProxy : public IPC::Channel::Listener, protected: template <class T> scoped_refptr<T> ProxyObjectFromHandle(int handle); + void InitializeChannelID(); void InitializeThread(); + void InitializeChannel(); void InitializeHandleTracker(); + std::string channel_id_; scoped_ptr<base::Thread> thread_; scoped_ptr<IPC::SyncChannel> channel_; scoped_ptr<AutomationHandleTracker> tracker_; diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index 04d3fb3..28903ca 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -29,7 +29,6 @@ #include "chrome/test/automation/autocomplete_edit_proxy.h" #include "chrome/test/automation/automation_proxy_uitest.h" #include "chrome/test/automation/browser_proxy.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/ui_test_utils.h" @@ -48,22 +47,6 @@ using testing::CreateFunctor; using testing::StrEq; using testing::_; -// Replace the default automation proxy with our mock client. -class ExternalTabUITestMockLauncher : public ProxyLauncher { - public: - AutomationProxy* CreateAutomationProxy(int execution_timeout) const { - return new ExternalTabUITestMockClient(execution_timeout); - } - - void InitializeConnection(UITestBase* ui_test_base) const { - ui_test_base->LaunchBrowserAndServer(); - } - - std::string PrefixedChannelID() const { - return ""; - } -}; - class AutomationProxyTest : public UITest { protected: AutomationProxyTest() { @@ -858,8 +841,9 @@ template <typename T> T** ReceivePointer(scoped_refptr<T>& p) { // NOLINT return reinterpret_cast<T**>(&p); } -ProxyLauncher* ExternalTabUITest::CreateProxyLauncher() { - return new ExternalTabUITestMockLauncher(); +AutomationProxy* ExternalTabUITest::CreateAutomationProxy(int exec_timeout) { + mock_ = new ExternalTabUITestMockClient(exec_timeout); + return mock_; } // Create with specifying a url diff --git a/chrome/test/automation/automation_proxy_uitest.h b/chrome/test/automation/automation_proxy_uitest.h index fce950e..55da8cc 100644 --- a/chrome/test/automation/automation_proxy_uitest.h +++ b/chrome/test/automation/automation_proxy_uitest.h @@ -112,10 +112,10 @@ class ExternalTabUITestMockClient : public AutomationProxy { class ExternalTabUITest : public UITest { public: ExternalTabUITest() : UITest(MessageLoop::TYPE_UI) {} - // Override UITest's CreateProxyLauncher to provide the unit test + // Override UITest's CreateAutomationProxy to provide the unit test // with our special implementation of AutomationProxy. - // This function is called from within UITest::SetUp(). - virtual ProxyLauncher* CreateProxyLauncher(); + // This function is called from within UITest::LaunchBrowserAndServer. + virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); protected: // Filtered Inet will override automation callbacks for network resources. virtual bool ShouldFilterInet() { diff --git a/chrome/test/automation/proxy_launcher.cc b/chrome/test/automation/proxy_launcher.cc deleted file mode 100644 index be414824..0000000 --- a/chrome/test/automation/proxy_launcher.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/test/automation/proxy_launcher.h" - -#include "chrome/common/automation_constants.h" -#include "chrome/common/logging_chrome.h" -#include "chrome/test/automation/automation_proxy.h" -#include "chrome/test/ui/ui_test.h" - -// Default path of named testing interface. -static const char kInterfacePath[] = "/var/tmp/ChromeTestingInterface"; - -// NamedProxyLauncher functions - -NamedProxyLauncher::NamedProxyLauncher(bool launch_browser, - bool disconnect_on_failure) - : launch_browser_(launch_browser), - disconnect_on_failure_(disconnect_on_failure) { - channel_id_ = kInterfacePath; -} - -AutomationProxy* NamedProxyLauncher::CreateAutomationProxy( - int execution_timeout) const { - AutomationProxy* proxy = new AutomationProxy(execution_timeout, - disconnect_on_failure_); - proxy->InitializeChannel(channel_id_, false); - return proxy; -} - -void NamedProxyLauncher::InitializeConnection(UITestBase* ui_test_base) const { - if (launch_browser_) { - // Set up IPC testing interface as a client. - ui_test_base->LaunchBrowser(); - - // Wait for browser to be ready for connections. - struct stat file_info; - while (stat(kInterfacePath, &file_info)) - PlatformThread::Sleep(automation::kSleepTime); - } - - ui_test_base->ConnectToRunningBrowser(); -} - -std::string NamedProxyLauncher::PrefixedChannelID() const { - std::string channel_id; - channel_id.append(automation::kNamedInterfacePrefix).append(channel_id_); - return channel_id; -} - -// AnonymousProxyLauncher functions - -AnonymousProxyLauncher::AnonymousProxyLauncher(bool disconnect_on_failure) - : disconnect_on_failure_(disconnect_on_failure) { - channel_id_ = AutomationProxy::GenerateChannelID(); -} - -AutomationProxy* AnonymousProxyLauncher::CreateAutomationProxy( - int execution_timeout) const { - AutomationProxy* proxy = new AutomationProxy(execution_timeout, - disconnect_on_failure_); - proxy->InitializeChannel(channel_id_, true); - return proxy; -} - -void AnonymousProxyLauncher::InitializeConnection( - UITestBase* ui_test_base) const { - ui_test_base->LaunchBrowserAndServer(); -} - -std::string AnonymousProxyLauncher::PrefixedChannelID() const { - return channel_id_; -} - diff --git a/chrome/test/automation/proxy_launcher.h b/chrome/test/automation/proxy_launcher.h deleted file mode 100644 index f7f02d9..0000000 --- a/chrome/test/automation/proxy_launcher.h +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ -#define CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ - -#include <string> - -#include "base/basictypes.h" - -class AutomationProxy; -class UITestBase; - -// Subclass from this class to use a different implementation of AutomationProxy -// or to use different channel IDs inside a class that derives from UITest. -class ProxyLauncher { - public: - ProxyLauncher() {} - virtual ~ProxyLauncher() {} - - // Creates an automation proxy. - virtual AutomationProxy* CreateAutomationProxy( - int execution_timeout) const = 0; - - // Launches the browser if needed and establishes a connection - // connection with it using the specified UITestBase. - virtual void InitializeConnection(UITestBase* ui_test_base) const = 0; - - // Returns the automation proxy's channel with any prefixes prepended, - // for passing as a command line parameter over to the browser. - virtual std::string PrefixedChannelID() const = 0; - - private: - DISALLOW_COPY_AND_ASSIGN(ProxyLauncher); -}; - -// Uses an automation proxy that communicates over a named socket. -// This is used if you want to connect an AutomationProxy -// to a browser process that is already running. -// The channel id of the proxy is a constant specified by kInterfacePath. -class NamedProxyLauncher : public ProxyLauncher { - public: - // If launch_browser is true, launches Chrome with named interface enabled. - // Otherwise, there should be an existing instance the proxy can connect to. - NamedProxyLauncher(bool launch_browser, bool disconnect_on_failure); - - virtual AutomationProxy* CreateAutomationProxy(int execution_timeout) const; - virtual void InitializeConnection(UITestBase* ui_test_base) const; - virtual std::string PrefixedChannelID() const; - - protected: - std::string channel_id_; // Channel id of automation proxy. - bool launch_browser_; // True if we should launch the browser too. - bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. - - private: - DISALLOW_COPY_AND_ASSIGN(NamedProxyLauncher); -}; - -// Uses an automation proxy that communicates over an anonymous socket. -class AnonymousProxyLauncher : public ProxyLauncher { - public: - explicit AnonymousProxyLauncher(bool disconnect_on_failure); - virtual AutomationProxy* CreateAutomationProxy(int execution_timeout) const; - virtual void InitializeConnection(UITestBase* ui_test_base) const; - virtual std::string PrefixedChannelID() const; - - protected: - std::string channel_id_; // Channel id of automation proxy. - bool disconnect_on_failure_; // True if we disconnect on IPC channel failure. - - private: - DISALLOW_COPY_AND_ASSIGN(AnonymousProxyLauncher); -}; - -#endif // CHROME_TEST_AUTOMATION_PROXY_LAUNCHER_H_ - |