summaryrefslogtreecommitdiffstats
path: root/chrome
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
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')
-rw-r--r--chrome/browser/sessions/session_restore_uitest.cc2
-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
-rw-r--r--chrome/test/startup/startup_test.cc2
-rw-r--r--chrome/test/ui/ui_test.cc12
-rw-r--r--chrome/test/ui/ui_test.h5
7 files changed, 65 insertions, 33 deletions
diff --git a/chrome/browser/sessions/session_restore_uitest.cc b/chrome/browser/sessions/session_restore_uitest.cc
index f4cdd4f..c14b3c7 100644
--- a/chrome/browser/sessions/session_restore_uitest.cc
+++ b/chrome/browser/sessions/session_restore_uitest.cc
@@ -33,7 +33,7 @@ class SessionRestoreUITest : public UITest {
virtual void QuitBrowserAndRestore(int expected_tab_count) {
#if defined(OS_MACOSX)
- shutdown_type_ = ProxyLauncher::USER_QUIT;
+ set_shutdown_type(ProxyLauncher::USER_QUIT);
#endif
UITest::TearDown();
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:
diff --git a/chrome/test/startup/startup_test.cc b/chrome/test/startup/startup_test.cc
index 437a844..8e0e826 100644
--- a/chrome/test/startup/startup_test.cc
+++ b/chrome/test/startup/startup_test.cc
@@ -275,7 +275,7 @@ void StartupTest::RunPerfTestWithManyTabs(const char* graph, const char* trace,
UITest::SetUp();
// Set flags to ensure profile is saved and can be restored.
#if defined(OS_MACOSX)
- shutdown_type_ = ProxyLauncher::USER_QUIT;
+ set_shutdown_type(ProxyLauncher::USER_QUIT);
#endif
clear_profile_ = false;
// Quit and set flags to restore session.
diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc
index 1ebb523..0b66bd3 100644
--- a/chrome/test/ui/ui_test.cc
+++ b/chrome/test/ui/ui_test.cc
@@ -89,8 +89,7 @@ UITestBase::UITestBase()
clear_profile_(true),
include_testing_id_(true),
enable_file_cookies_(true),
- profile_type_(ProxyLauncher::DEFAULT_THEME),
- shutdown_type_(ProxyLauncher::WINDOW_CLOSE) {
+ profile_type_(ProxyLauncher::DEFAULT_THEME) {
PathService::Get(chrome::DIR_APP, &browser_directory_);
PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_);
}
@@ -105,8 +104,7 @@ UITestBase::UITestBase(MessageLoop::Type msg_loop_type)
clear_profile_(true),
include_testing_id_(true),
enable_file_cookies_(true),
- profile_type_(ProxyLauncher::DEFAULT_THEME),
- shutdown_type_(ProxyLauncher::WINDOW_CLOSE) {
+ profile_type_(ProxyLauncher::DEFAULT_THEME) {
PathService::Get(chrome::DIR_APP, &browser_directory_);
PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_);
}
@@ -131,7 +129,7 @@ void UITestBase::SetUp() {
}
void UITestBase::TearDown() {
- CloseBrowserAndServer();
+ launcher_->TerminateConnection();
// Make sure that we didn't encounter any assertion failures
logging::AssertionList assertions;
@@ -197,7 +195,7 @@ void UITestBase::ConnectToRunningBrowser() {
void UITestBase::CloseBrowserAndServer() {
if (launcher_.get())
- launcher_->CloseBrowserAndServer(shutdown_type_);
+ launcher_->CloseBrowserAndServer();
}
void UITestBase::LaunchBrowser(const CommandLine& arguments,
@@ -217,7 +215,7 @@ bool UITestBase::LaunchAnotherBrowserBlockUntilClosed(
#endif
void UITestBase::QuitBrowser() {
- launcher_->QuitBrowser(shutdown_type_);
+ launcher_->QuitBrowser();
}
void UITestBase::CleanupAppProcesses() {
diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h
index 234dc85..989f760 100644
--- a/chrome/test/ui/ui_test.h
+++ b/chrome/test/ui/ui_test.h
@@ -246,7 +246,7 @@ class UITestBase {
// Sets the shutdown type, which defaults to WINDOW_CLOSE.
void set_shutdown_type(ProxyLauncher::ShutdownType value) {
- shutdown_type_ = value;
+ launcher_->set_shutdown_type(value);
}
// Get the number of crash dumps we've logged since the test started.
@@ -361,9 +361,6 @@ class UITestBase {
// PID file for websocket server.
FilePath websocket_pid_file_;
- // The method for shutting down the browser. Used in ShutdownTest.
- ProxyLauncher::ShutdownType shutdown_type_;
-
private:
// Time the test was started (so we can check for new crash dumps)
base::Time test_start_time_;