summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 16:50:23 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 16:50:23 +0000
commitdedf2055a80cf9d869767bbd0c99f51e4f31260e (patch)
tree4ff02b6ef242a467d4db73c92ed1afec9a3fdabe
parent1ef1c66a37fae2707f743c3588f88e893125b82f (diff)
downloadchromium_src-dedf2055a80cf9d869767bbd0c99f51e4f31260e.zip
chromium_src-dedf2055a80cf9d869767bbd0c99f51e4f31260e.tar.gz
chromium_src-dedf2055a80cf9d869767bbd0c99f51e4f31260e.tar.bz2
Add regression test for bug 7900 and necessary infrastructure.
The test simulates following scenario: user opens a local html page with Chrome when a browser instance is already running. The new Chrome process should notify the existing process about new page and exit. Bug 7900 broke this behavior causing the new process to crash. I verified that the ui_tests infrastructure would catch this crash and cause the test to fail. BUG=7900, 8056 Review URL: http://codereview.chromium.org/39257 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11247 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/chrome_main_uitest.cc23
-rw-r--r--chrome/test/automation/automation_proxy.cc36
-rw-r--r--chrome/test/automation/automation_proxy.h4
3 files changed, 62 insertions, 1 deletions
diff --git a/chrome/app/chrome_main_uitest.cc b/chrome/app/chrome_main_uitest.cc
index 41fd782..6038c9c 100644
--- a/chrome/app/chrome_main_uitest.cc
+++ b/chrome/app/chrome_main_uitest.cc
@@ -2,9 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/common/chrome_constants.h"
#include "chrome/test/ui/ui_test.h"
+#include "base/command_line.h"
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "net/base/net_util.h"
+
typedef UITest ChromeMainTest;
// Launch the app, then close the app.
@@ -44,3 +48,20 @@ TEST_F(ChromeMainTest, DISABLED_SecondLaunch) {
ASSERT_EQ(2, window_count);
}
+TEST_F(ChromeMainTest, ReuseBrowserInstanceWhenOpeningFile) {
+ include_testing_id_ = false;
+ use_existing_browser_ = true;
+
+ std::wstring test_file = test_data_directory_;
+ file_util::AppendToPath(&test_file, L"empty.html");
+
+ CommandLine command_line(L"");
+ command_line.AppendLooseValue(test_file);
+
+ LaunchBrowser(command_line, false);
+
+ FilePath test_file_path(FilePath::FromWStringHack(test_file));
+
+ ASSERT_TRUE(automation()->WaitForURLDisplayed(
+ net::FilePathToFileURL(test_file_path), action_timeout_ms()));
+}
diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc
index 73bb91d..aec886b 100644
--- a/chrome/test/automation/automation_proxy.cc
+++ b/chrome/test/automation/automation_proxy.cc
@@ -343,6 +343,42 @@ bool AutomationProxy::WaitForAppModalDialog(int wait_timeout) {
}
#endif // defined(OS_WIN)
+bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) {
+ const TimeTicks start = TimeTicks::Now();
+ const TimeDelta timeout = TimeDelta::FromMilliseconds(wait_timeout);
+ while (TimeTicks::Now() - start < timeout) {
+ int window_count;
+ if (!GetBrowserWindowCount(&window_count))
+ return false;
+
+ for (int i = 0; i < window_count; i++) {
+ BrowserProxy* window = GetBrowserWindow(i);
+ if (!window)
+ break;
+
+ int tab_count;
+ if (!window->GetTabCount(&tab_count))
+ continue;
+
+ for (int j = 0; j < tab_count; j++) {
+ TabProxy* tab = window->GetTab(j);
+ if (!tab)
+ break;
+
+ GURL tab_url;
+ if (!tab->GetCurrentURL(&tab_url))
+ continue;
+
+ if (tab_url == url)
+ return true;
+ }
+ }
+ PlatformThread::Sleep(automation::kSleepTime);
+ }
+
+ return false;
+}
+
bool AutomationProxy::SetFilteredInet(bool enabled) {
return Send(new AutomationMsg_SetFilteredInet(0, enabled));
}
diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h
index ff74db3..fa2d33f 100644
--- a/chrome/test/automation/automation_proxy.h
+++ b/chrome/test/automation/automation_proxy.h
@@ -119,6 +119,10 @@ class AutomationProxy : public IPC::Channel::Listener,
// success.
bool WaitForAppModalDialog(int wait_timeout);
+ // Block the thread until one of the tabs in any window (including windows
+ // opened after the call) displays given url. Returns true on success.
+ bool WaitForURLDisplayed(GURL url, int wait_timeout);
+
// Returns the BrowserProxy for the browser window at the given index,
// transferring ownership of the pointer to the caller.
// On failure, returns NULL.