summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.