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. 4 5#ifndef UI_BASE_TEST_UI_CONTROLS_H_ 6#define UI_BASE_TEST_UI_CONTROLS_H_ 7 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" 12 13namespace ui_controls { 14 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|. 21// 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 28// 29// SendKeyPress(...); 30// SendKeyPressNotifyWhenDone(..., task); 31// 32// might trigger |task| early. 33// 34// Note: Windows does not currently do anything with the |window| argument for 35// these functions, so passing NULL is ok. 36 37// Send a key press with/without modifier keys. 38// 39// If you're writing a test chances are you want the variant in ui_test_utils. 40// See it for details. 41 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 44// tests. 45void EnableUIControls(); 46 47bool SendKeyPress(gfx::NativeWindow window, 48 ui::KeyboardCode key, 49 bool control, 50 bool shift, 51 bool alt, 52 bool command); 53bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, 54 ui::KeyboardCode key, 55 bool control, 56 bool shift, 57 bool alt, 58 bool command, 59 const base::Closure& task); 60 61// Simulate a mouse move. 62bool SendMouseMove(long screen_x, long screen_y); 63bool SendMouseMoveNotifyWhenDone(long screen_x, 64 long screen_y, 65 const base::Closure& task); 66 67enum MouseButton { 68 LEFT = 0, 69 MIDDLE, 70 RIGHT, 71}; 72 73// Used to indicate the state of the button when generating events. 74enum MouseButtonState { 75 UP = 1, 76 DOWN = 2 77}; 78 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!). 82bool SendMouseEvents(MouseButton type, int state); 83bool SendMouseEventsNotifyWhenDone(MouseButton type, 84 int state, 85 const base::Closure& task); 86 87// Same as SendMouseEvents with UP | DOWN. 88bool SendMouseClick(MouseButton type); 89 90#if defined(TOOLKIT_VIEWS) 91// Runs |closure| after processing all pending ui events. 92void RunClosureAfterAllPendingUIEvents(const base::Closure& closure); 93#endif 94 95#if defined(USE_AURA) 96class UIControlsAura; 97void InstallUIControlsAura(UIControlsAura* instance); 98#endif 99 100} // namespace ui_controls 101 102#endif // UI_BASE_TEST_UI_CONTROLS_H_ 103