summaryrefslogtreecommitdiffstats
path: root/chrome/test/automation
diff options
context:
space:
mode:
authordtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 17:49:52 +0000
committerdtu@chromium.org <dtu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 17:49:52 +0000
commit7434850752c816283c53d402efe061270904af2b (patch)
treed2210ba1c109a522896aa1d9472e359b95d19055 /chrome/test/automation
parentf159e8dd0e5369dcd48f3abc6fdf0c6a9038827a (diff)
downloadchromium_src-7434850752c816283c53d402efe061270904af2b.zip
chromium_src-7434850752c816283c53d402efe061270904af2b.tar.gz
chromium_src-7434850752c816283c53d402efe061270904af2b.tar.bz2
Fix and refactor for ProxyLauncher browser disconnect.
In ProxyLauncher, the new TerminateConnection() function is paired with InitializeConnection(). shutdown_type_ moved from UITestBase to ProxyLauncher, since that's the only place it's used. BUG=chromium-os:8514 TEST=none Review URL: http://codereview.chromium.org/6248022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73300 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automation')
-rw-r--r--chrome/test/automation/automation_proxy_uitest.cc4
-rw-r--r--chrome/test/automation/proxy_launcher.cc33
-rw-r--r--chrome/test/automation/proxy_launcher.h40
3 files changed, 57 insertions, 20 deletions
diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc
index 5923f9f..79ef86c 100644
--- a/chrome/test/automation/automation_proxy_uitest.cc
+++ b/chrome/test/automation/automation_proxy_uitest.cc
@@ -70,6 +70,10 @@ class ExternalTabUITestMockLauncher : public ProxyLauncher {
LaunchBrowserAndServer(state, wait_for_initial_loads);
}
+ void TerminateConnection() {
+ CloseBrowserAndServer();
+ }
+
std::string PrefixedChannelID() const {
return channel_id_;
}
diff --git a/chrome/test/automation/proxy_launcher.cc b/chrome/test/automation/proxy_launcher.cc
index 0a02144..0c386fe 100644
--- a/chrome/test/automation/proxy_launcher.cc
+++ b/chrome/test/automation/proxy_launcher.cc
@@ -112,7 +112,9 @@ std::string ProxyLauncher::log_level_ = "";
ProxyLauncher::ProxyLauncher()
: process_(base::kNullProcessHandle),
- process_id_(-1) {}
+ process_id_(-1),
+ shutdown_type_(WINDOW_CLOSE) {
+}
ProxyLauncher::~ProxyLauncher() {}
@@ -144,8 +146,8 @@ void ProxyLauncher::ConnectToRunningBrowser(bool wait_for_initial_loads) {
WaitForBrowserLaunch(wait_for_initial_loads);
}
-void ProxyLauncher::CloseBrowserAndServer(ShutdownType shutdown_type) {
- QuitBrowser(shutdown_type);
+void ProxyLauncher::CloseBrowserAndServer() {
+ QuitBrowser();
CleanupAppProcesses();
// Suppress spammy failures that seem to be occurring when running
@@ -156,6 +158,10 @@ void ProxyLauncher::CloseBrowserAndServer(ShutdownType shutdown_type) {
StringPrintf(L"Unable to quit all browser processes. Original PID %d",
&process_id_));
+ DisconnectFromRunningBrowser();
+}
+
+void ProxyLauncher::DisconnectFromRunningBrowser() {
automation_proxy_.reset(); // Shut down IPC testing interface.
}
@@ -194,8 +200,8 @@ bool ProxyLauncher::LaunchAnotherBrowserBlockUntilClosed(
}
#endif
-void ProxyLauncher::QuitBrowser(ShutdownType shutdown_type) {
- if (SESSION_ENDING == shutdown_type) {
+void ProxyLauncher::QuitBrowser() {
+ if (SESSION_ENDING == shutdown_type_) {
TerminateBrowser();
return;
}
@@ -209,7 +215,7 @@ void ProxyLauncher::QuitBrowser(ShutdownType shutdown_type) {
base::TimeTicks quit_start = base::TimeTicks::Now();
EXPECT_TRUE(automation()->SetFilteredInet(false));
- if (WINDOW_CLOSE == shutdown_type) {
+ if (WINDOW_CLOSE == shutdown_type_) {
int window_count = 0;
EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count));
@@ -237,7 +243,7 @@ void ProxyLauncher::QuitBrowser(ShutdownType shutdown_type) {
EXPECT_TRUE(browser_proxy->ApplyAccelerator(IDC_CLOSE_WINDOW));
browser_proxy = NULL;
}
- } else if (USER_QUIT == shutdown_type) {
+ } else if (USER_QUIT == shutdown_type_) {
scoped_refptr<BrowserProxy> browser_proxy =
automation()->GetBrowserWindow(0);
EXPECT_TRUE(browser_proxy.get());
@@ -245,7 +251,7 @@ void ProxyLauncher::QuitBrowser(ShutdownType shutdown_type) {
EXPECT_TRUE(browser_proxy->RunCommandAsync(IDC_EXIT));
}
} else {
- NOTREACHED() << "Invalid shutdown type " << shutdown_type;
+ NOTREACHED() << "Invalid shutdown type " << shutdown_type_;
}
// Now, drop the automation IPC channel so that the automation provider in
@@ -515,6 +521,13 @@ void NamedProxyLauncher::InitializeConnection(const LaunchState& state,
ConnectToRunningBrowser(wait_for_initial_loads);
}
+void NamedProxyLauncher::TerminateConnection() {
+ if (launch_browser_)
+ CloseBrowserAndServer();
+ else
+ DisconnectFromRunningBrowser();
+}
+
std::string NamedProxyLauncher::PrefixedChannelID() const {
std::string channel_id;
channel_id.append(automation::kNamedInterfacePrefix).append(channel_id_);
@@ -541,6 +554,10 @@ void AnonymousProxyLauncher::InitializeConnection(const LaunchState& state,
LaunchBrowserAndServer(state, wait_for_initial_loads);
}
+void AnonymousProxyLauncher::TerminateConnection() {
+ CloseBrowserAndServer();
+}
+
std::string AnonymousProxyLauncher::PrefixedChannelID() const {
return channel_id_;
}
diff --git a/chrome/test/automation/proxy_launcher.h b/chrome/test/automation/proxy_launcher.h
index bdb8dc5..eca4121 100644
--- a/chrome/test/automation/proxy_launcher.h
+++ b/chrome/test/automation/proxy_launcher.h
@@ -73,17 +73,13 @@ class ProxyLauncher {
virtual ~ProxyLauncher();
- // Creates an automation proxy.
- virtual AutomationProxy* CreateAutomationProxy(
- int execution_timeout) = 0;
-
// Launches the browser if needed and establishes a connection with it.
virtual void InitializeConnection(const LaunchState& state,
bool wait_for_initial_loads) = 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;
+ // Shuts down the browser if needed and destroys any
+ // connections established by InitalizeConnection.
+ virtual void TerminateConnection() = 0;
// Launches the browser and IPC testing connection in server mode.
void LaunchBrowserAndServer(const LaunchState& state,
@@ -93,11 +89,9 @@ class ProxyLauncher {
// which then attempts to connect to a browser.
void ConnectToRunningBrowser(bool wait_for_initial_loads);
- // Only for pyauto.
- void set_command_execution_timeout_ms(int timeout);
-
+ // Paired with LaunchBrowserAndServer().
// Closes the browser and IPC testing server.
- void CloseBrowserAndServer(ShutdownType shutdown_type);
+ void CloseBrowserAndServer();
// Launches the browser with the given command line.
// TODO(phajdan.jr): Make LaunchBrowser private. Tests should use
@@ -114,7 +108,7 @@ class ProxyLauncher {
#endif
// Exits out of browser instance.
- void QuitBrowser(ShutdownType shutdown_type);
+ void QuitBrowser();
// Terminates the browser, simulates end of session.
void TerminateBrowser();
@@ -155,6 +149,11 @@ class ProxyLauncher {
// Return how long the shutdown took.
base::TimeDelta browser_quit_time() const;
+ // Sets the shutdown type, which defaults to WINDOW_CLOSE.
+ void set_shutdown_type(ShutdownType value) {
+ shutdown_type_ = value;
+ }
+
// Get/Set a flag to run the renderer in-process when running the tests.
static bool in_process_renderer() { return in_process_renderer_; }
static void set_in_process_renderer(bool value) {
@@ -218,6 +217,18 @@ class ProxyLauncher {
}
protected:
+ // Creates an automation proxy.
+ virtual AutomationProxy* CreateAutomationProxy(
+ int execution_timeout) = 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;
+
+ // Paired with ConnectToRunningBrowser().
+ // Disconnects the testing IPC from the browser.
+ void DisconnectFromRunningBrowser();
+
virtual bool ShouldFilterInet() {
return true;
}
@@ -256,6 +267,9 @@ class ProxyLauncher {
// How long the shutdown took.
base::TimeDelta browser_quit_time_;
+ // The method for shutting down the browser. Used in ShutdownTest.
+ ShutdownType shutdown_type_;
+
// True if we're in single process mode.
static bool in_process_renderer_;
@@ -306,6 +320,7 @@ class NamedProxyLauncher : public ProxyLauncher {
virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
virtual void InitializeConnection(const LaunchState& state,
bool wait_for_initial_loads);
+ virtual void TerminateConnection();
virtual std::string PrefixedChannelID() const;
protected:
@@ -324,6 +339,7 @@ class AnonymousProxyLauncher : public ProxyLauncher {
virtual AutomationProxy* CreateAutomationProxy(int execution_timeout);
virtual void InitializeConnection(const LaunchState& state,
bool wait_for_initial_loads);
+ virtual void TerminateConnection();
virtual std::string PrefixedChannelID() const;
protected: