summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authorjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 18:45:44 +0000
committerjam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-29 18:45:44 +0000
commit895a8472bdc74bcaa0c32609f68c6570dedba03e (patch)
tree36b36b3e13d0c1e475a4357874f89f41c9d0a23e /chrome/test
parent57b531b405a961a7af36a54b9956c5514212ac53 (diff)
downloadchromium_src-895a8472bdc74bcaa0c32609f68c6570dedba03e.zip
chromium_src-895a8472bdc74bcaa0c32609f68c6570dedba03e.tar.gz
chromium_src-895a8472bdc74bcaa0c32609f68c6570dedba03e.tar.bz2
Move the test functions that deal with focus to interactive_ui_tets_utils.h and into the interactive_ui_tests target. That way they can't be misused from browser_tests.
Review URL: https://codereview.chromium.org/11414223 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170224 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/base/interactive_test_utils.cc105
-rw-r--r--chrome/test/base/interactive_test_utils.h140
-rw-r--r--chrome/test/base/interactive_test_utils_aura.cc31
-rw-r--r--chrome/test/base/interactive_test_utils_aura.h21
-rw-r--r--chrome/test/base/interactive_test_utils_gtk.cc85
-rw-r--r--chrome/test/base/interactive_test_utils_mac.mm93
-rw-r--r--chrome/test/base/interactive_test_utils_views.cc54
-rw-r--r--chrome/test/base/interactive_test_utils_win.cc64
-rw-r--r--chrome/test/base/ui_test_utils.cc154
-rw-r--r--chrome/test/base/ui_test_utils.h119
-rw-r--r--chrome/test/gpu/gpu_mapsgl_endurance_browsertest.cc2
-rw-r--r--chrome/test/gpu/gpu_pixel_browsertest.cc2
12 files changed, 661 insertions, 209 deletions
diff --git a/chrome/test/base/interactive_test_utils.cc b/chrome/test/base/interactive_test_utils.cc
new file mode 100644
index 0000000..8029ab6
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils.cc
@@ -0,0 +1,105 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils.h"
+
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+
+namespace ui_test_utils {
+
+namespace {
+
+bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
+ BrowserWindow* window = browser->window();
+ if (!window)
+ return false;
+
+ *native_window = window->GetNativeWindow();
+ return *native_window;
+}
+
+} // namespace
+
+bool BringBrowserWindowToFront(const Browser* browser) {
+ gfx::NativeWindow window = NULL;
+ if (!GetNativeWindow(browser, &window))
+ return false;
+
+ return ui_test_utils::ShowAndFocusNativeWindow(window);
+}
+
+bool SendKeyPressSync(const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command) {
+ gfx::NativeWindow window = NULL;
+ if (!GetNativeWindow(browser, &window))
+ return false;
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ bool result;
+ result = ui_controls::SendKeyPressNotifyWhenDone(
+ window, key, control, shift, alt, command, runner->QuitClosure());
+#if defined(OS_WIN)
+ if (!result && BringBrowserWindowToFront(browser)) {
+ result = ui_controls::SendKeyPressNotifyWhenDone(
+ window, key, control, shift, alt, command, runner->QuitClosure());
+ }
+#endif
+ if (!result) {
+ LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed";
+ return false;
+ }
+
+ // Run the message loop. It'll stop running when either the key was received
+ // or the test timed out (in which case testing::Test::HasFatalFailure should
+ // be set).
+ runner->Run();
+ return !testing::Test::HasFatalFailure();
+}
+
+bool SendKeyPressAndWait(const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command,
+ int type,
+ const content::NotificationSource& source) {
+ content::WindowedNotificationObserver observer(type, source);
+
+ if (!SendKeyPressSync(browser, key, control, shift, alt, command))
+ return false;
+
+ observer.Wait();
+ return !testing::Test::HasFatalFailure();
+}
+
+bool SendMouseMoveSync(const gfx::Point& location) {
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ if (!ui_controls::SendMouseMoveNotifyWhenDone(
+ location.x(), location.y(), runner->QuitClosure())) {
+ return false;
+ }
+ runner->Run();
+ return !testing::Test::HasFatalFailure();
+}
+
+bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
+ scoped_refptr<content::MessageLoopRunner> runner =
+ new content::MessageLoopRunner;
+ if (!ui_controls::SendMouseEventsNotifyWhenDone(
+ type, state, runner->QuitClosure())) {
+ return false;
+ }
+ runner->Run();
+ return !testing::Test::HasFatalFailure();
+}
+
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/interactive_test_utils.h b/chrome/test/base/interactive_test_utils.h
new file mode 100644
index 0000000..afe3e58
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils.h
@@ -0,0 +1,140 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
+#define CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
+
+#include "chrome/browser/ui/view_ids.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "ui/ui_controls/ui_controls.h"
+
+#if defined(TOOLKIT_VIEWS)
+#include "ui/views/view.h"
+#endif
+
+namespace gfx {
+class Point;
+}
+
+namespace ui_test_utils {
+
+// Brings the native window for |browser| to the foreground. Returns true on
+// success.
+bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT;
+
+// Returns true if the View is focused.
+bool IsViewFocused(const Browser* browser, ViewID vid);
+
+// Simulates a mouse click on a View in the browser.
+void ClickOnView(const Browser* browser, ViewID vid);
+
+// A collection of utilities that are used from interactive_ui_tests. These are
+// separated from ui_test_utils.h to ensure that browser_tests don't use them,
+// since they depend on focus which isn't possible for sharded test.
+
+// Hide a native window.
+void HideNativeWindow(gfx::NativeWindow window);
+
+// Show and focus a native window. Returns true on success.
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) WARN_UNUSED_RESULT;
+
+// Sends a key press, blocking until the key press is received or the test times
+// out. This uses ui_controls::SendKeyPress, see it for details. Returns true
+// if the event was successfully sent and received.
+bool SendKeyPressSync(const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command) WARN_UNUSED_RESULT;
+
+// Sends a key press, blocking until both the key press and a notification from
+// |source| of type |type| are received, or until the test times out. This uses
+// ui_controls::SendKeyPress, see it for details. Returns true if the event was
+// successfully sent and both the event and notification were received.
+bool SendKeyPressAndWait(const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command,
+ int type,
+ const content::NotificationSource& source)
+ WARN_UNUSED_RESULT;
+
+// Sends a move event blocking until received. Returns true if the event was
+// successfully received. This uses ui_controls::SendMouse***NotifyWhenDone,
+// see it for details.
+bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
+bool SendMouseEventsSync(ui_controls::MouseButton type,
+ int state) WARN_UNUSED_RESULT;
+
+// See SendKeyPressAndWait. This function additionally performs a check on the
+// NotificationDetails using the provided Details<U>.
+template <class U>
+bool SendKeyPressAndWaitWithDetails(
+ const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command,
+ int type,
+ const content::NotificationSource& source,
+ const content::Details<U>& details) WARN_UNUSED_RESULT;
+
+template <class U>
+bool SendKeyPressAndWaitWithDetails(
+ const Browser* browser,
+ ui::KeyboardCode key,
+ bool control,
+ bool shift,
+ bool alt,
+ bool command,
+ int type,
+ const content::NotificationSource& source,
+ const content::Details<U>& details) {
+ WindowedNotificationObserverWithDetails<U> observer(type, source);
+
+ if (!SendKeyPressSync(browser, key, control, shift, alt, command))
+ return false;
+
+ observer.Wait();
+
+ U my_details;
+ if (!observer.GetDetailsFor(source.map_key(), &my_details))
+ return false;
+
+ return *details.ptr() == my_details && !testing::Test::HasFatalFailure();
+}
+
+// A combination of SendMouseMove to the middle of the view followed by
+// SendMouseEvents.
+void MoveMouseToCenterAndPress(
+#if defined(TOOLKIT_VIEWS)
+ views::View* view,
+#elif defined(TOOLKIT_GTK)
+ GtkWidget* widget,
+#elif defined(OS_IOS)
+ UIView* view,
+#elif defined(OS_MACOSX)
+ NSView* view,
+#endif
+ ui_controls::MouseButton button,
+ int state,
+ const base::Closure& task);
+
+namespace internal {
+
+// A utility function to send a mouse click event in a closure. It's shared by
+// ui_controls_linux.cc and ui_controls_mac.cc
+void ClickTask(ui_controls::MouseButton button,
+ int state,
+ const base::Closure& followup);
+
+} // namespace internal
+
+} // namespace ui_test_utils
+
+#endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
diff --git a/chrome/test/base/interactive_test_utils_aura.cc b/chrome/test/base/interactive_test_utils_aura.cc
new file mode 100644
index 0000000..b780b83
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_aura.cc
@@ -0,0 +1,31 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils_aura.h"
+
+#include "chrome/test/base/interactive_test_utils.h"
+#include "ui/aura/window.h"
+
+namespace ui_test_utils {
+
+#if !defined(OS_WIN)
+void HideNativeWindow(gfx::NativeWindow window) {
+ HideNativeWindowAura(window);
+}
+
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+ return ShowAndFocusNativeWindowAura(window);
+}
+#endif
+
+void HideNativeWindowAura(gfx::NativeWindow window) {
+ window->Hide();
+}
+
+bool ShowAndFocusNativeWindowAura(gfx::NativeWindow window) {
+ window->Show();
+ return true;
+}
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/interactive_test_utils_aura.h b/chrome/test/base/interactive_test_utils_aura.h
new file mode 100644
index 0000000..e157a56
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_aura.h
@@ -0,0 +1,21 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_AURA_H_
+#define CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_AURA_H_
+
+#include "chrome/test/base/ui_test_utils.h"
+
+#include "ui/aura/window.h"
+
+namespace ui_test_utils {
+
+// Aura variants of ui_test_utils method. Don't use these directly, they are
+// used to share code between win-aura and non-win-aura.
+void HideNativeWindowAura(gfx::NativeWindow window);
+bool ShowAndFocusNativeWindowAura(gfx::NativeWindow window);
+
+} // namespace ui_test_utils
+
+#endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_AURA_H_
diff --git a/chrome/test/base/interactive_test_utils_gtk.cc b/chrome/test/base/interactive_test_utils_gtk.cc
new file mode 100644
index 0000000..0bda39c
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_gtk.cc
@@ -0,0 +1,85 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils.h"
+
+#include <gtk/gtk.h>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/gtk/view_id_util.h"
+#include "ui/base/gtk/gtk_screen_util.h"
+#include "ui/ui_controls/ui_controls.h"
+
+namespace ui_test_utils {
+
+namespace {
+// Check if the focused widget for |root| is |target| or a child of |target|.
+static bool IsWidgetInFocusChain(GtkWidget* root, GtkWidget* target) {
+ GtkWidget* iter = root;
+
+ while (iter) {
+ if (iter == target)
+ return true;
+
+ if (!GTK_IS_CONTAINER(iter))
+ return false;
+
+ iter = GTK_CONTAINER(iter)->focus_child;
+ }
+
+ return false;
+}
+} // namespace
+
+bool IsViewFocused(const Browser* browser, ViewID vid) {
+ BrowserWindow* browser_window = browser->window();
+ DCHECK(browser_window);
+ gfx::NativeWindow window = browser_window->GetNativeWindow();
+ DCHECK(window);
+ GtkWidget* widget = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
+ DCHECK(widget);
+ return IsWidgetInFocusChain(GTK_WIDGET(window), widget);
+}
+
+void ClickOnView(const Browser* browser, ViewID vid) {
+ BrowserWindow* browser_window = browser->window();
+ DCHECK(browser_window);
+ gfx::NativeWindow window = browser_window->GetNativeWindow();
+ DCHECK(window);
+ GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
+ DCHECK(view);
+ MoveMouseToCenterAndPress(
+ view,
+ ui_controls::LEFT,
+ ui_controls::DOWN | ui_controls::UP,
+ MessageLoop::QuitClosure());
+ content::RunMessageLoop();
+}
+
+void HideNativeWindow(gfx::NativeWindow window) {
+ gtk_widget_hide(GTK_WIDGET(window));
+}
+
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+ if (!gtk_window_has_toplevel_focus(GTK_WINDOW(window)))
+ gtk_window_present(GTK_WINDOW(window));
+ return true;
+}
+
+void MoveMouseToCenterAndPress(GtkWidget* widget,
+ ui_controls::MouseButton button,
+ int state,
+ const base::Closure& task) {
+ gfx::Rect bounds = ui::GetWidgetScreenBounds(widget);
+ ui_controls::SendMouseMoveNotifyWhenDone(
+ bounds.x() + bounds.width() / 2,
+ bounds.y() + bounds.height() / 2,
+ base::Bind(&internal::ClickTask, button, state, task));
+}
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/interactive_test_utils_mac.mm b/chrome/test/base/interactive_test_utils_mac.mm
new file mode 100644
index 0000000..ee2a930
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_mac.mm
@@ -0,0 +1,93 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils.h"
+
+#include <Carbon/Carbon.h>
+#import <Cocoa/Cocoa.h>
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "ui/ui_controls/ui_controls.h"
+#import "chrome/browser/ui/cocoa/view_id_util.h"
+
+namespace ui_test_utils {
+
+bool IsViewFocused(const Browser* browser, ViewID vid) {
+ NSWindow* window = browser->window()->GetNativeWindow();
+ DCHECK(window);
+ NSView* view = view_id_util::GetView(window, vid);
+ if (!view)
+ return false;
+
+ NSResponder* firstResponder = [window firstResponder];
+ if (firstResponder == static_cast<NSResponder*>(view))
+ return true;
+
+ // Handle the special case of focusing a TextField.
+ if ([firstResponder isKindOfClass:[NSTextView class]]) {
+ NSView* delegate = static_cast<NSView*>([(NSTextView*)firstResponder
+ delegate]);
+ if (delegate == view)
+ return true;
+ }
+
+ return false;
+}
+
+void ClickOnView(const Browser* browser, ViewID vid) {
+ NSWindow* window = browser->window()->GetNativeWindow();
+ DCHECK(window);
+ NSView* view = view_id_util::GetView(window, vid);
+ DCHECK(view);
+ MoveMouseToCenterAndPress(
+ view,
+ ui_controls::LEFT,
+ ui_controls::DOWN | ui_controls::UP,
+ MessageLoop::QuitClosure());
+ content::RunMessageLoop();
+}
+
+void HideNativeWindow(gfx::NativeWindow window) {
+ [window orderOut:nil];
+}
+
+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;
+}
+
+void MoveMouseToCenterAndPress(
+ NSView* view,
+ ui_controls::MouseButton button,
+ int state,
+ const base::Closure& task) {
+ DCHECK(view);
+ NSWindow* window = [view window];
+ DCHECK(window);
+ NSScreen* screen = [window screen];
+ DCHECK(screen);
+
+ // Converts the center position of the view into the coordinates accepted
+ // by SendMouseMoveNotifyWhenDone() method.
+ NSRect bounds = [view bounds];
+ NSPoint center = NSMakePoint(NSMidX(bounds), NSMidY(bounds));
+ center = [view convertPoint:center toView:nil];
+ center = [window convertBaseToScreen:center];
+ center = NSMakePoint(center.x, [screen frame].size.height - center.y);
+
+ ui_controls::SendMouseMoveNotifyWhenDone(
+ center.x, center.y,
+ base::Bind(&internal::ClickTask, button, state, task));
+}
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/interactive_test_utils_views.cc b/chrome/test/base/interactive_test_utils_views.cc
new file mode 100644
index 0000000..6f41223
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_views.cc
@@ -0,0 +1,54 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils.h"
+
+#include "base/logging.h"
+#include "base/message_loop.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/views/frame/browser_view.h"
+#include "ui/ui_controls/ui_controls.h"
+#include "ui/views/focus/focus_manager.h"
+
+namespace ui_test_utils {
+
+bool IsViewFocused(const Browser* browser, ViewID vid) {
+ BrowserWindow* browser_window = browser->window();
+ DCHECK(browser_window);
+ gfx::NativeWindow window = browser_window->GetNativeWindow();
+ DCHECK(window);
+ const views::Widget* widget =
+ views::Widget::GetTopLevelWidgetForNativeView(window);
+ DCHECK(widget);
+ const views::FocusManager* focus_manager = widget->GetFocusManager();
+ DCHECK(focus_manager);
+ DCHECK(focus_manager->GetFocusedView());
+ return focus_manager->GetFocusedView()->id() == vid;
+}
+
+void ClickOnView(const Browser* browser, ViewID vid) {
+ views::View* view =
+ BrowserView::GetBrowserViewForBrowser(browser)->GetViewByID(vid);
+ DCHECK(view);
+ MoveMouseToCenterAndPress(
+ view,
+ ui_controls::LEFT,
+ ui_controls::DOWN | ui_controls::UP,
+ MessageLoop::QuitClosure());
+ content::RunMessageLoop();
+}
+
+void MoveMouseToCenterAndPress(views::View* view,
+ ui_controls::MouseButton button,
+ int state,
+ const base::Closure& closure) {
+ DCHECK(view);
+ DCHECK(view->GetWidget());
+ gfx::Point view_center(view->width() / 2, view->height() / 2);
+ views::View::ConvertPointToScreen(view, &view_center);
+ ui_controls::SendMouseMove(view_center.x(), view_center.y());
+ ui_controls::SendMouseEventsNotifyWhenDone(button, state, closure);
+}
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/interactive_test_utils_win.cc b/chrome/test/base/interactive_test_utils_win.cc
new file mode 100644
index 0000000..8215864
--- /dev/null
+++ b/chrome/test/base/interactive_test_utils_win.cc
@@ -0,0 +1,64 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/test/base/interactive_test_utils.h"
+
+#include "base/file_path.h"
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/stringprintf.h"
+#include "base/time.h"
+#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
+#include "ui/base/win/foreground_helper.h"
+#include "ui/ui_controls/ui_controls.h"
+#include "ui/views/focus/focus_manager.h"
+
+#if defined(USE_AURA)
+#include "chrome/browser/ui/host_desktop.h"
+#include "chrome/test/base/interactive_test_utils_aura.h"
+#include "ui/aura/root_window.h"
+#endif
+
+namespace ui_test_utils {
+
+void HideNativeWindow(gfx::NativeWindow window) {
+#if defined(USE_AURA)
+ if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
+ chrome::HOST_DESKTOP_TYPE_ASH) {
+ HideNativeWindowAura(window);
+ return;
+ }
+ HWND hwnd = window->GetRootWindow()->GetAcceleratedWidget();
+#else
+ HWND hwnd = window;
+#endif
+ ::ShowWindow(hwnd, SW_HIDE);
+}
+
+bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
+#if defined(USE_AURA)
+ if (chrome::GetHostDesktopTypeForNativeWindow(window) ==
+ chrome::HOST_DESKTOP_TYPE_ASH)
+ ShowAndFocusNativeWindowAura(window);
+ // Always make sure the window hosting ash is visible and focused.
+ HWND hwnd = window->GetRootWindow()->GetAcceleratedWidget();
+#else
+ HWND hwnd = window;
+#endif
+
+ ::ShowWindow(hwnd, SW_SHOW);
+
+ if (GetForegroundWindow() != hwnd) {
+ VLOG(1) << "Forcefully refocusing front window";
+ ui::ForegroundHelper::SetForeground(hwnd);
+ }
+
+ // 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() == hwnd;
+}
+
+} // namespace ui_test_utils
diff --git a/chrome/test/base/ui_test_utils.cc b/chrome/test/base/ui_test_utils.cc
index 2d9abdb..d2d6d530 100644
--- a/chrome/test/base/ui_test_utils.cc
+++ b/chrome/test/base/ui_test_utils.cc
@@ -45,6 +45,7 @@
#include "chrome/browser/ui/host_desktop.h"
#include "chrome/browser/ui/omnibox/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
+#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
@@ -150,6 +151,31 @@ class FindInPageNotificationObserver : public content::NotificationObserver {
DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
};
+const char kSnapshotBaseName[] = "ChromiumSnapshot";
+const char kSnapshotExtension[] = ".png";
+
+FilePath GetSnapshotFileName(const FilePath& snapshot_directory) {
+ base::Time::Exploded the_time;
+
+ base::Time::Now().LocalExplode(&the_time);
+ std::string filename(StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
+ kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
+ the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
+
+ FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
+ if (file_util::PathExists(snapshot_file)) {
+ int index = 0;
+ std::string suffix;
+ FilePath trial_file;
+ do {
+ suffix = StringPrintf(" (%d)", ++index);
+ trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
+ } while (file_util::PathExists(trial_file));
+ snapshot_file = trial_file;
+ }
+ return snapshot_file;
+}
+
} // namespace
bool GetCurrentTabTitle(const Browser* browser, string16* title) {
@@ -453,23 +479,6 @@ void SendToOmniboxAndSubmit(LocationBar* location_bar,
}
}
-bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
- BrowserWindow* window = browser->window();
- if (!window)
- return false;
-
- *native_window = window->GetNativeWindow();
- return *native_window;
-}
-
-bool BringBrowserWindowToFront(const Browser* browser) {
- gfx::NativeWindow window = NULL;
- if (!GetNativeWindow(browser, &window))
- return false;
-
- return ui_test_utils::ShowAndFocusNativeWindow(window);
-}
-
Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) {
for (BrowserList::const_iterator iter = BrowserList::begin();
iter != BrowserList::end();
@@ -481,77 +490,6 @@ Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers) {
return NULL;
}
-bool SendKeyPressSync(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command) {
- gfx::NativeWindow window = NULL;
- if (!GetNativeWindow(browser, &window))
- return false;
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- bool result;
- result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, runner->QuitClosure());
-#if defined(OS_WIN)
- if (!result && BringBrowserWindowToFront(browser)) {
- result = ui_controls::SendKeyPressNotifyWhenDone(
- window, key, control, shift, alt, command, runner->QuitClosure());
- }
-#endif
- if (!result) {
- LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed";
- return false;
- }
-
- // Run the message loop. It'll stop running when either the key was received
- // or the test timed out (in which case testing::Test::HasFatalFailure should
- // be set).
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendKeyPressAndWait(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command,
- int type,
- const content::NotificationSource& source) {
- content::WindowedNotificationObserver observer(type, source);
-
- if (!SendKeyPressSync(browser, key, control, shift, alt, command))
- return false;
-
- observer.Wait();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendMouseMoveSync(const gfx::Point& location) {
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- if (!ui_controls::SendMouseMoveNotifyWhenDone(
- location.x(), location.y(), runner->QuitClosure())) {
- return false;
- }
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
-bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- if (!ui_controls::SendMouseEventsNotifyWhenDone(
- type, state, runner->QuitClosure())) {
- return false;
- }
- runner->Run();
- return !testing::Test::HasFatalFailure();
-}
-
WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver(
const content::NotificationSource& source)
: WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source),
@@ -680,6 +618,46 @@ bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
return taker.TakeEntirePageSnapshot(rvh, bitmap);
}
+#if defined(OS_WIN)
+
+bool SaveScreenSnapshotToDirectory(const FilePath& directory,
+ FilePath* screenshot_path) {
+ bool succeeded = false;
+ FilePath out_path(GetSnapshotFileName(directory));
+
+ MONITORINFO monitor_info = {};
+ monitor_info.cbSize = sizeof(monitor_info);
+ HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
+ if (GetMonitorInfo(main_monitor, &monitor_info)) {
+ RECT& rect = monitor_info.rcMonitor;
+
+ std::vector<unsigned char> png_data;
+ gfx::Rect bounds(
+ gfx::Size(rect.right - rect.left, rect.bottom - rect.top));
+ if (chrome::internal::GrabWindowSnapshot(NULL, &png_data, bounds) &&
+ png_data.size() <= INT_MAX) {
+ int bytes = static_cast<int>(png_data.size());
+ int written = file_util::WriteFile(
+ out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
+ succeeded = (written == bytes);
+ }
+ }
+
+ if (succeeded && screenshot_path != NULL)
+ *screenshot_path = out_path;
+
+ return succeeded;
+}
+
+bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path) {
+ FilePath desktop;
+
+ return PathService::Get(base::DIR_USER_DESKTOP, &desktop) &&
+ SaveScreenSnapshotToDirectory(desktop, screenshot_path);
+}
+
+#endif // defined(OS_WIN)
+
void OverrideGeolocation(double latitude, double longitude) {
content::Geoposition position;
position.latitude = latitude;
diff --git a/chrome/test/base/ui_test_utils.h b/chrome/test/base/ui_test_utils.h
index 5a98a39..e08ed7d 100644
--- a/chrome/test/base/ui_test_utils.h
+++ b/chrome/test/base/ui_test_utils.h
@@ -15,7 +15,6 @@
#include "base/memory/ref_counted.h"
#include "base/string16.h"
#include "chrome/browser/history/history.h"
-#include "chrome/browser/ui/view_ids.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
@@ -25,13 +24,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/gfx/native_widget_types.h"
-#include "ui/ui_controls/ui_controls.h"
#include "webkit/glue/window_open_disposition.h"
-#if defined(TOOLKIT_VIEWS)
-#include "ui/views/view.h"
-#endif
-
class AppModalDialog;
class BookmarkModel;
class Browser;
@@ -53,7 +47,6 @@ class WebContents;
}
namespace gfx {
-class Point;
class Rect;
class Size;
}
@@ -144,12 +137,6 @@ int FindInPage(content::WebContents* tab,
int* ordinal,
gfx::Rect* selection_rect);
-// Returns true if the View is focused.
-bool IsViewFocused(const Browser* browser, ViewID vid);
-
-// Simulates a mouse click on a View in the browser.
-void ClickOnView(const Browser* browser, ViewID vid);
-
// Register |observer| for the given |type| and |source| and run
// the message loop until the observer posts a quit task.
void RegisterAndWait(content::NotificationObserver* observer,
@@ -172,44 +159,9 @@ void DownloadURL(Browser* browser, const GURL& download_url);
void SendToOmniboxAndSubmit(LocationBar* location_bar,
const std::string& input);
-// Brings the native window for |browser| to the foreground. Returns true on
-// success.
-bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT;
-
// Gets the first browser that is not in the specified set.
Browser* GetBrowserNotInSet(std::set<Browser*> excluded_browsers);
-// Sends a key press, blocking until the key press is received or the test times
-// out. This uses ui_controls::SendKeyPress, see it for details. Returns true
-// if the event was successfully sent and received.
-bool SendKeyPressSync(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command) WARN_UNUSED_RESULT;
-
-// Sends a key press, blocking until both the key press and a notification from
-// |source| of type |type| are received, or until the test times out. This uses
-// ui_controls::SendKeyPress, see it for details. Returns true if the event was
-// successfully sent and both the event and notification were received.
-bool SendKeyPressAndWait(const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command,
- int type,
- const content::NotificationSource& source)
- WARN_UNUSED_RESULT;
-
-// Sends a move event blocking until received. Returns true if the event was
-// successfully received. This uses ui_controls::SendMouse***NotifyWhenDone,
-// see it for details.
-bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
-bool SendMouseEventsSync(ui_controls::MouseButton type,
- int state) WARN_UNUSED_RESULT;
-
// A WindowedNotificationObserver hard-wired to observe
// chrome::NOTIFICATION_TAB_ADDED.
class WindowedTabAddedNotificationObserver
@@ -311,51 +263,6 @@ class BrowserAddedObserver {
DISALLOW_COPY_AND_ASSIGN(BrowserAddedObserver);
};
-// See SendKeyPressAndWait. This function additionally performs a check on the
-// NotificationDetails using the provided Details<U>.
-template <class U>
-bool SendKeyPressAndWaitWithDetails(
- const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command,
- int type,
- const content::NotificationSource& source,
- const content::Details<U>& details) WARN_UNUSED_RESULT;
-
-template <class U>
-bool SendKeyPressAndWaitWithDetails(
- const Browser* browser,
- ui::KeyboardCode key,
- bool control,
- bool shift,
- bool alt,
- bool command,
- int type,
- const content::NotificationSource& source,
- const content::Details<U>& details) {
- WindowedNotificationObserverWithDetails<U> observer(type, source);
-
- if (!SendKeyPressSync(browser, key, control, shift, alt, command))
- return false;
-
- observer.Wait();
-
- U my_details;
- if (!observer.GetDetailsFor(source.map_key(), &my_details))
- return false;
-
- return *details.ptr() == my_details && !testing::Test::HasFatalFailure();
-}
-
-// Hide a native window.
-void HideNativeWindow(gfx::NativeWindow window);
-
-// Show and focus a native window. Returns true on success.
-bool ShowAndFocusNativeWindow(gfx::NativeWindow window) WARN_UNUSED_RESULT;
-
// Takes a snapshot of the given render widget, rendered at |page_size|. The
// snapshot is set to |bitmap|. Returns true on success.
bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh,
@@ -368,22 +275,6 @@ bool TakeRenderWidgetSnapshot(content::RenderWidgetHost* rwh,
bool TakeEntirePageSnapshot(content::RenderViewHost* rvh,
SkBitmap* bitmap) WARN_UNUSED_RESULT;
-// A combination of SendMouseMove to the middle of the view followed by
-// SendMouseEvents.
-void MoveMouseToCenterAndPress(
-#if defined(TOOLKIT_VIEWS)
- views::View* view,
-#elif defined(TOOLKIT_GTK)
- GtkWidget* widget,
-#elif defined(OS_IOS)
- UIView* view,
-#elif defined(OS_MACOSX)
- NSView* view,
-#endif
- ui_controls::MouseButton button,
- int state,
- const base::Closure& task);
-
#if defined(OS_WIN)
// Saves a snapshot of the entire screen to a file named
// ChromiumSnapshotYYYYMMDDHHMMSS.png to |directory|, returning true on success.
@@ -399,16 +290,6 @@ bool SaveScreenSnapshotToDesktop(FilePath* screenshot_path);
// Configures the geolocation provider to always return the given position.
void OverrideGeolocation(double latitude, double longitude);
-namespace internal {
-
-// A utility function to send a mouse click event in a closure. It's shared by
-// ui_controls_linux.cc and ui_controls_mac.cc
-void ClickTask(ui_controls::MouseButton button,
- int state,
- const base::Closure& followup);
-
-} // namespace internal
-
// Enumerates all history contents on the backend thread. Returns them in
// descending order by time.
class HistoryEnumerator {
diff --git a/chrome/test/gpu/gpu_mapsgl_endurance_browsertest.cc b/chrome/test/gpu/gpu_mapsgl_endurance_browsertest.cc
index 10b4f5d..61dec5b 100644
--- a/chrome/test/gpu/gpu_mapsgl_endurance_browsertest.cc
+++ b/chrome/test/gpu/gpu_mapsgl_endurance_browsertest.cc
@@ -80,7 +80,7 @@ class MapsGLEnduranceTest : public InProcessBrowserTest {
ASSERT_TRUE(tracing::BeginTracing("-test_*"));
#endif
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ browser()->window()->Activate();
gfx::Rect new_bounds = GetNewTabContainerBounds(tab_container_size);
browser()->window()->SetBounds(new_bounds);
diff --git a/chrome/test/gpu/gpu_pixel_browsertest.cc b/chrome/test/gpu/gpu_pixel_browsertest.cc
index 8121b38..559eb5e 100644
--- a/chrome/test/gpu/gpu_pixel_browsertest.cc
+++ b/chrome/test/gpu/gpu_pixel_browsertest.cc
@@ -167,7 +167,7 @@ class GpuPixelBrowserTest : public InProcessBrowserTest {
ASSERT_TRUE(tracing::BeginTracing("-test_*"));
#endif
- ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ browser()->window()->Activate();
content::DOMMessageQueue message_queue;
ui_test_utils::NavigateToURL(browser(), net::FilePathToFileURL(url));