Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / base / interactive_test_utils.h
blobafe3e581e891fbf774419da7364287fd2b5577d0
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
6 #define CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_
8 #include "chrome/browser/ui/view_ids.h"
9 #include "chrome/test/base/ui_test_utils.h"
10 #include "ui/ui_controls/ui_controls.h"
12 #if defined(TOOLKIT_VIEWS)
13 #include "ui/views/view.h"
14 #endif
16 namespace gfx {
17 class Point;
20 namespace ui_test_utils {
22 // Brings the native window for |browser| to the foreground. Returns true on
23 // success.
24 bool BringBrowserWindowToFront(const Browser* browser) WARN_UNUSED_RESULT;
26 // Returns true if the View is focused.
27 bool IsViewFocused(const Browser* browser, ViewID vid);
29 // Simulates a mouse click on a View in the browser.
30 void ClickOnView(const Browser* browser, ViewID vid);
32 // A collection of utilities that are used from interactive_ui_tests. These are
33 // separated from ui_test_utils.h to ensure that browser_tests don't use them,
34 // since they depend on focus which isn't possible for sharded test.
36 // Hide a native window.
37 void HideNativeWindow(gfx::NativeWindow window);
39 // Show and focus a native window. Returns true on success.
40 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) WARN_UNUSED_RESULT;
42 // Sends a key press, blocking until the key press is received or the test times
43 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true
44 // if the event was successfully sent and received.
45 bool SendKeyPressSync(const Browser* browser,
46 ui::KeyboardCode key,
47 bool control,
48 bool shift,
49 bool alt,
50 bool command) WARN_UNUSED_RESULT;
52 // Sends a key press, blocking until both the key press and a notification from
53 // |source| of type |type| are received, or until the test times out. This uses
54 // ui_controls::SendKeyPress, see it for details. Returns true if the event was
55 // successfully sent and both the event and notification were received.
56 bool SendKeyPressAndWait(const Browser* browser,
57 ui::KeyboardCode key,
58 bool control,
59 bool shift,
60 bool alt,
61 bool command,
62 int type,
63 const content::NotificationSource& source)
64 WARN_UNUSED_RESULT;
66 // Sends a move event blocking until received. Returns true if the event was
67 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone,
68 // see it for details.
69 bool SendMouseMoveSync(const gfx::Point& location) WARN_UNUSED_RESULT;
70 bool SendMouseEventsSync(ui_controls::MouseButton type,
71 int state) WARN_UNUSED_RESULT;
73 // See SendKeyPressAndWait. This function additionally performs a check on the
74 // NotificationDetails using the provided Details<U>.
75 template <class U>
76 bool SendKeyPressAndWaitWithDetails(
77 const Browser* browser,
78 ui::KeyboardCode key,
79 bool control,
80 bool shift,
81 bool alt,
82 bool command,
83 int type,
84 const content::NotificationSource& source,
85 const content::Details<U>& details) WARN_UNUSED_RESULT;
87 template <class U>
88 bool SendKeyPressAndWaitWithDetails(
89 const Browser* browser,
90 ui::KeyboardCode key,
91 bool control,
92 bool shift,
93 bool alt,
94 bool command,
95 int type,
96 const content::NotificationSource& source,
97 const content::Details<U>& details) {
98 WindowedNotificationObserverWithDetails<U> observer(type, source);
100 if (!SendKeyPressSync(browser, key, control, shift, alt, command))
101 return false;
103 observer.Wait();
105 U my_details;
106 if (!observer.GetDetailsFor(source.map_key(), &my_details))
107 return false;
109 return *details.ptr() == my_details && !testing::Test::HasFatalFailure();
112 // A combination of SendMouseMove to the middle of the view followed by
113 // SendMouseEvents.
114 void MoveMouseToCenterAndPress(
115 #if defined(TOOLKIT_VIEWS)
116 views::View* view,
117 #elif defined(TOOLKIT_GTK)
118 GtkWidget* widget,
119 #elif defined(OS_IOS)
120 UIView* view,
121 #elif defined(OS_MACOSX)
122 NSView* view,
123 #endif
124 ui_controls::MouseButton button,
125 int state,
126 const base::Closure& task);
128 namespace internal {
130 // A utility function to send a mouse click event in a closure. It's shared by
131 // ui_controls_linux.cc and ui_controls_mac.cc
132 void ClickTask(ui_controls::MouseButton button,
133 int state,
134 const base::Closure& followup);
136 } // namespace internal
138 } // namespace ui_test_utils
140 #endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_