Extensions: Store disable reasons in Sync
[chromium-blink-merge.git] / chrome / test / base / interactive_test_utils.h
blobe8c7a224b16fb61f8d4c12931634602e3f5f5573
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"
12 namespace gfx {
13 class Point;
16 #if defined(TOOLKIT_VIEWS)
17 namespace views {
18 class View;
20 #endif
22 namespace ui_test_utils {
24 // Brings the native window for |browser| to the foreground. Returns true on
25 // success.
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,
51 ui::KeyboardCode key,
52 bool control,
53 bool shift,
54 bool alt,
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,
61 ui::KeyboardCode key,
62 bool control,
63 bool shift,
64 bool alt,
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,
72 ui::KeyboardCode key,
73 bool control,
74 bool shift,
75 bool alt,
76 bool command,
77 int type,
78 const content::NotificationSource& source)
79 WARN_UNUSED_RESULT;
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>.
90 template <class U>
91 bool SendKeyPressAndWaitWithDetails(
92 const Browser* browser,
93 ui::KeyboardCode key,
94 bool control,
95 bool shift,
96 bool alt,
97 bool command,
98 int type,
99 const content::NotificationSource& source,
100 const content::Details<U>& details) WARN_UNUSED_RESULT;
102 template <class U>
103 bool SendKeyPressAndWaitWithDetails(
104 const Browser* browser,
105 ui::KeyboardCode key,
106 bool control,
107 bool shift,
108 bool alt,
109 bool command,
110 int type,
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))
116 return false;
118 observer.Wait();
120 U my_details;
121 if (!observer.GetDetailsFor(source.map_key(), &my_details))
122 return false;
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,
133 int state,
134 const base::Closure& task);
135 #endif
137 namespace internal {
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,
142 int state,
143 const base::Closure& followup);
145 } // namespace internal
147 } // namespace ui_test_utils
149 #endif // CHROME_TEST_BASE_INTERACTIVE_TEST_UTILS_H_