1 // Copyright 2013 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 UI_BASE_TEST_UI_CONTROLS_H_
6 #define UI_BASE_TEST_UI_CONTROLS_H_
8 #include "base/callback_forward.h"
9 #include "build/build_config.h"
10 #include "ui/events/keycodes/keyboard_codes.h"
11 #include "ui/gfx/native_widget_types.h"
13 namespace ui_controls
{
15 // A set of utility functions to generate native events in platform
16 // independent way. Note that since the implementations depend on a window being
17 // top level, these can only be called from test suites that are not sharded.
18 // For aura tests, please look into |aura::test:EventGenerator| first. This
19 // class provides a way to emulate events in synchronous way and it is often
20 // easier to write tests with this class than using |ui_controls|.
22 // Many of the functions in this class include a variant that takes a Closure.
23 // The version that takes a Closure waits until the generated event is
24 // processed. Once the generated event is processed the Closure is Run (and
25 // deleted). Note that this is a somewhat fragile process in that any event of
26 // the correct type (key down, mouse click, etc.) will trigger the Closure to be
27 // run. Hence a usage such as
30 // SendKeyPressNotifyWhenDone(..., task);
32 // might trigger |task| early.
34 // Note: Windows does not currently do anything with the |window| argument for
35 // these functions, so passing NULL is ok.
37 // Send a key press with/without modifier keys.
39 // If you're writing a test chances are you want the variant in ui_test_utils.
40 // See it for details.
42 // Per the above comment, these methods can only be called from non-sharded test
43 // suites. This method ensures that they're not accidently called by sharded
45 void EnableUIControls();
47 bool SendKeyPress(gfx::NativeWindow window
,
53 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window
,
59 const base::Closure
& task
);
61 // Simulate a mouse move.
62 bool SendMouseMove(long screen_x
, long screen_y
);
63 bool SendMouseMoveNotifyWhenDone(long screen_x
,
65 const base::Closure
& task
);
73 // Used to indicate the state of the button when generating events.
74 enum MouseButtonState
{
79 // Sends a mouse down and/or up message. The click will be sent to wherever
80 // the cursor currently is, so be sure to move the cursor before calling this
81 // (and be sure the cursor has arrived!).
82 bool SendMouseEvents(MouseButton type
, int state
);
83 bool SendMouseEventsNotifyWhenDone(MouseButton type
,
85 const base::Closure
& task
);
87 // Same as SendMouseEvents with UP | DOWN.
88 bool SendMouseClick(MouseButton type
);
90 #if defined(TOOLKIT_VIEWS)
91 // Runs |closure| after processing all pending ui events.
92 void RunClosureAfterAllPendingUIEvents(const base::Closure
& closure
);
97 void InstallUIControlsAura(UIControlsAura
* instance
);
100 #if defined(OS_MACOSX)
101 // Returns true when tests need to use extra Tab and Shift-Tab key events
102 // to traverse to the desired item; because the application is configured to
103 // traverse more elements for accessibility reasons.
104 bool IsFullKeyboardAccessEnabled();
107 } // namespace ui_controls
109 #endif // UI_BASE_TEST_UI_CONTROLS_H_