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/base/test/ui_controls.h"
16 #if defined(TOOLKIT_VIEWS)
22 namespace ui_test_utils
{
24 // Brings the native window for |browser| to the foreground. Returns true on
26 bool BringBrowserWindowToFront(const Browser
* browser
) WARN_UNUSED_RESULT
;
28 // Returns true if the View is focused.
29 bool IsViewFocused(const Browser
* browser
, ViewID vid
);
31 // Simulates a mouse click on a View in the browser.
32 void ClickOnView(const Browser
* browser
, ViewID vid
);
34 // Makes focus shift to the given View without clicking it.
35 void FocusView(const Browser
* browser
, ViewID vid
);
37 // A collection of utilities that are used from interactive_ui_tests. These are
38 // separated from ui_test_utils.h to ensure that browser_tests don't use them,
39 // since they depend on focus which isn't possible for sharded test.
41 // Hide a native window.
42 void HideNativeWindow(gfx::NativeWindow window
);
44 // Show and focus a native window. Returns true on success.
45 bool ShowAndFocusNativeWindow(gfx::NativeWindow window
) WARN_UNUSED_RESULT
;
47 // Sends a key press, blocking until the key press is received or the test times
48 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true
49 // if the event was successfully sent and received.
50 bool SendKeyPressSync(const Browser
* browser
,
55 bool command
) WARN_UNUSED_RESULT
;
57 // Sends a key press, blocking until the key press is received or the test times
58 // out. This uses ui_controls::SendKeyPress, see it for details. Returns true
59 // if the event was successfully sent and received.
60 bool SendKeyPressToWindowSync(const gfx::NativeWindow window
,
65 bool command
) WARN_UNUSED_RESULT
;
67 // Sends a key press, blocking until both the key press and a notification from
68 // |source| of type |type| are received, or until the test times out. This uses
69 // ui_controls::SendKeyPress, see it for details. Returns true if the event was
70 // successfully sent and both the event and notification were received.
71 bool SendKeyPressAndWait(const Browser
* browser
,
78 const content::NotificationSource
& source
)
81 // Sends a move event blocking until received. Returns true if the event was
82 // successfully received. This uses ui_controls::SendMouse***NotifyWhenDone,
83 // see it for details.
84 bool SendMouseMoveSync(const gfx::Point
& location
) WARN_UNUSED_RESULT
;
85 bool SendMouseEventsSync(ui_controls::MouseButton type
,
86 int state
) WARN_UNUSED_RESULT
;
88 // See SendKeyPressAndWait. This function additionally performs a check on the
89 // NotificationDetails using the provided Details<U>.
91 bool SendKeyPressAndWaitWithDetails(
92 const Browser
* browser
,
99 const content::NotificationSource
& source
,
100 const content::Details
<U
>& details
) WARN_UNUSED_RESULT
;
103 bool SendKeyPressAndWaitWithDetails(
104 const Browser
* browser
,
105 ui::KeyboardCode key
,
111 const content::NotificationSource
& source
,
112 const content::Details
<U
>& details
) {
113 WindowedNotificationObserverWithDetails
<U
> observer(type
, source
);
115 if (!SendKeyPressSync(browser
, key
, control
, shift
, alt
, command
))
121 if (!observer
.GetDetailsFor(source
.map_key(), &my_details
))
124 return *details
.ptr() == my_details
&& !testing::Test::HasFatalFailure();
127 // A combination of SendMouseMove to the middle of the view followed by
128 // SendMouseEvents. Only exposed for toolkit-views.
129 // Alternatives: ClickOnView() and ui::test::EventGenerator.
130 #if defined(TOOLKIT_VIEWS)
131 void MoveMouseToCenterAndPress(views::View
* view
,
132 ui_controls::MouseButton button
,
134 const base::Closure
& task
);
139 // A utility function to send a mouse click event in a closure. It's shared by
140 // ui_controls_linux.cc and ui_controls_mac.cc
141 void ClickTask(ui_controls::MouseButton button
,
143 const base::Closure
& followup
);
145 } // namespace internal
147 } // namespace ui_test_utils
149 #endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_