summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-09 15:16:29 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-09 15:16:29 +0000
commit7807088ce89434b0e9c3e88316d0fecc257fd39e (patch)
treec487f59d86309d048f21ec62766ef4ad769c05d9 /chrome
parent700632dcd3ffd2426d543be17eb99bc50f2f2624 (diff)
downloadchromium_src-7807088ce89434b0e9c3e88316d0fecc257fd39e.zip
chromium_src-7807088ce89434b0e9c3e88316d0fecc257fd39e.tar.gz
chromium_src-7807088ce89434b0e9c3e88316d0fecc257fd39e.tar.bz2
Makes ui_test_utils::ShowAndFocusNativeWindow return false if it
fails. Changes in_process_browser_test skip main if setup fails. BUG=102297 TEST=none R=ben@chromium.org,phajdan.jr@chromium.org Review URL: http://codereview.chromium.org/8479046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@109246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_focus_uitest.cc4
-rw-r--r--chrome/test/base/in_process_browser_test.cc5
-rw-r--r--chrome/test/base/ui_test_utils.cc3
-rw-r--r--chrome/test/base/ui_test_utils.h4
-rw-r--r--chrome/test/base/ui_test_utils_gtk.cc9
-rw-r--r--chrome/test/base/ui_test_utils_mac.mm3
-rw-r--r--chrome/test/base/ui_test_utils_win.cc7
7 files changed, 21 insertions, 14 deletions
diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc
index a32cadb..cdb9431 100644
--- a/chrome/browser/browser_focus_uitest.cc
+++ b/chrome/browser/browser_focus_uitest.cc
@@ -228,14 +228,14 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FLAKY_BrowsersRememberFocus) {
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
// Now hide the window, show it again, the focus should not have changed.
ui_test_utils::HideNativeWindow(window);
- ui_test_utils::ShowAndFocusNativeWindow(window);
+ ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
ASSERT_TRUE(IsViewFocused(VIEW_ID_TAB_CONTAINER_FOCUS_VIEW));
browser()->FocusLocationBar();
ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
// Hide the window, show it again, the focus should not have changed.
ui_test_utils::HideNativeWindow(window);
- ui_test_utils::ShowAndFocusNativeWindow(window);
+ ASSERT_TRUE(ui_test_utils::ShowAndFocusNativeWindow(window));
ASSERT_TRUE(IsViewFocused(VIEW_ID_LOCATION_BAR));
// The rest of this test does not make sense on Linux because the behavior
diff --git a/chrome/test/base/in_process_browser_test.cc b/chrome/test/base/in_process_browser_test.cc
index 11df173..75871cb 100644
--- a/chrome/test/base/in_process_browser_test.cc
+++ b/chrome/test/base/in_process_browser_test.cc
@@ -288,11 +288,14 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() {
pool.Recycle();
#endif
- RunTestOnMainThread();
+ if (!HasFatalFailure())
+ RunTestOnMainThread();
#if defined(OS_MACOSX)
pool.Recycle();
#endif
+ // Invoke cleanup and quit even if there are failures. This is similar to
+ // gtest in that it invokes TearDown even if Setup fails.
CleanUpOnMainThread();
#if defined(OS_MACOSX)
pool.Recycle();
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index f5ba5cc..5097b05 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -584,8 +584,7 @@ bool BringBrowserWindowToFront(const Browser* browser) {
if (!GetNativeWindow(browser, &window))
return false;
- ui_test_utils::ShowAndFocusNativeWindow(window);
- return true;
+ return ui_test_utils::ShowAndFocusNativeWindow(window);
}
Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) {
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 2f29d6e5..517ba4b 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -519,8 +519,8 @@ bool SendKeyPressAndWaitWithDetails(
// Hide a native window.
void HideNativeWindow(gfx::NativeWindow window);
-// Show and focus a native window.
-void ShowAndFocusNativeWindow(gfx::NativeWindow window);
+// Show and focus a native window. Returns true on success.
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) WARN_UNUSED_RESULT;
// Watches for responses from the DOMAutomationController and keeps them in a
// queue. Useful for waiting for a message to be received.
diff --git a/chrome/test/base/ui_test_utils_gtk.cc b/chrome/test/base/ui_test_utils_gtk.cc
index 166f764..841f558 100644
--- a/chrome/test/base/ui_test_utils_gtk.cc
+++ b/chrome/test/base/ui_test_utils_gtk.cc
@@ -87,11 +87,10 @@ void HideNativeWindow(gfx::NativeWindow window) {
gtk_widget_hide(GTK_WIDGET(window));
}
-void ShowAndFocusNativeWindow(gfx::NativeWindow window) {
- if (gtk_window_has_toplevel_focus(GTK_WINDOW(window)))
- return;
-
- gtk_window_present(GTK_WINDOW(window));
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+ if (!gtk_window_has_toplevel_focus(GTK_WINDOW(window)))
+ gtk_window_present(GTK_WINDOW(window));
+ return true;
}
} // namespace ui_test_utils
diff --git a/chrome/test/base/ui_test_utils_mac.mm b/chrome/test/base/ui_test_utils_mac.mm
index 92beef1..cecb701 100644
--- a/chrome/test/base/ui_test_utils_mac.mm
+++ b/chrome/test/base/ui_test_utils_mac.mm
@@ -55,13 +55,14 @@ void HideNativeWindow(gfx::NativeWindow window) {
[window orderOut:nil];
}
-void ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
// Make sure an unbundled program can get the input focus.
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn,kProcessTransformToForegroundApplication);
SetFrontProcess(&psn);
[window makeKeyAndOrderFront:nil];
+ return true;
}
} // namespace ui_test_utils
diff --git a/chrome/test/base/ui_test_utils_win.cc b/chrome/test/base/ui_test_utils_win.cc
index 163542a..c585a92 100644
--- a/chrome/test/base/ui_test_utils_win.cc
+++ b/chrome/test/base/ui_test_utils_win.cc
@@ -47,10 +47,15 @@ void HideNativeWindow(gfx::NativeWindow window) {
::ShowWindow(window, SW_HIDE);
}
-void ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
// TODO(jcampan): retrieve the NativeWidgetWin and show/hide on it instead of
// using Windows API.
::ShowWindow(window, SW_SHOW);
+
+ // ShowWindow does not necessarily activate the window. In particular if a
+ // window from another app is the foreground window then the request to
+ // activate the window fails. See SetForegroundWindow for details.
+ return GetForegroundWindow() == window;
}
} // namespace ui_test_utils