Add ICU message format support
[chromium-blink-merge.git] / ui / views / test / widget_test.h
blobfc7d0b5aacb6b80d6e3ee78ac8e2d72366d7cab8
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_VIEWS_TEST_WIDGET_TEST_H_
6 #define UI_VIEWS_TEST_WIDGET_TEST_H_
8 #include "ui/gfx/native_widget_types.h"
9 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget_delegate.h"
12 #if defined(USE_AURA)
13 #include "ui/views/widget/native_widget_aura.h"
14 #if !defined(OS_CHROMEOS)
15 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
16 #endif
17 #elif defined(OS_MACOSX)
18 #include "ui/views/widget/native_widget_mac.h"
19 #endif
21 namespace ui {
22 namespace internal {
23 class InputMethodDelegate;
25 class EventProcessor;
28 namespace views {
30 class NativeWidget;
31 class Widget;
33 #if defined(USE_AURA)
34 typedef NativeWidgetAura PlatformNativeWidget;
35 #if !defined(OS_CHROMEOS)
36 typedef DesktopNativeWidgetAura PlatformDesktopNativeWidget;
37 #endif
38 #elif defined(OS_MACOSX)
39 typedef NativeWidgetMac PlatformNativeWidget;
40 typedef NativeWidgetMac PlatformDesktopNativeWidget;
41 #endif
43 namespace internal {
45 class RootView;
47 } // namespace internal
49 namespace test {
51 // A widget that assumes mouse capture always works. It won't on Aura in
52 // testing, so we mock it.
53 class NativeWidgetCapture : public PlatformNativeWidget {
54 public:
55 explicit NativeWidgetCapture(internal::NativeWidgetDelegate* delegate);
56 ~NativeWidgetCapture() override;
58 void SetCapture() override;
59 void ReleaseCapture() override;
60 bool HasCapture() const override;
62 private:
63 bool mouse_capture_;
65 DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture);
68 class WidgetTest : public ViewsTestBase {
69 public:
70 // Scoped handle that fakes all widgets into claiming they are active. This
71 // allows a test to assume active status does not get stolen by a test that
72 // may be running in parallel. It shouldn't be used in tests that create
73 // multiple widgets.
74 class FakeActivation {
75 public:
76 virtual ~FakeActivation() {}
78 protected:
79 FakeActivation() {}
81 private:
82 DISALLOW_COPY_AND_ASSIGN(FakeActivation);
85 WidgetTest();
86 ~WidgetTest() override;
88 // Create Widgets with |native_widget| in InitParams set to an instance of
89 // test::NativeWidgetCapture.
90 Widget* CreateTopLevelPlatformWidget();
91 Widget* CreateTopLevelFramelessPlatformWidget();
92 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view);
94 // Create Widgets initialized without a |native_widget| set in InitParams.
95 // Depending on the test environment, ViewsDelegate::OnBeforeWidgetInit() may
96 // still provide one.
97 Widget* CreateTopLevelNativeWidget();
98 Widget* CreateChildNativeWidgetWithParent(Widget* parent);
99 Widget* CreateChildNativeWidget();
101 // Create a top-level Widget with |native_widget| in InitParams set to an
102 // instance of the "native desktop" type. This is a PlatformNativeWidget on
103 // ChromeOS, and a PlatformDesktopNativeWidget everywhere else.
104 Widget* CreateNativeDesktopWidget();
106 View* GetMousePressedHandler(internal::RootView* root_view);
108 View* GetMouseMoveHandler(internal::RootView* root_view);
110 View* GetGestureHandler(internal::RootView* root_view);
112 // Simulate an OS-level destruction of the native window held by |widget|.
113 static void SimulateNativeDestroy(Widget* widget);
115 // Simulate an activation of the native window held by |widget|, as if it was
116 // clicked by the user. This is a synchronous method for use in
117 // non-interactive tests that do not spin a RunLoop in the test body (since
118 // that may cause real focus changes to flakily manifest).
119 static void SimulateNativeActivate(Widget* widget);
121 // Return true if |window| is visible according to the native platform.
122 static bool IsNativeWindowVisible(gfx::NativeWindow window);
124 // Return true if |above| is higher than |below| in the native window Z-order.
125 // Both windows must be visible.
126 static bool IsWindowStackedAbove(Widget* above, Widget* below);
128 // Query the native window system for the minimum size configured for user
129 // initiated window resizes.
130 static gfx::Size GetNativeWidgetMinimumContentSize(Widget* widget);
132 // Return the event processor for |widget|. On aura platforms, this is an
133 // aura::WindowEventDispatcher. Otherwise, it is a bridge to the OS event
134 // processor.
135 static ui::EventProcessor* GetEventProcessor(Widget* widget);
137 // Get the InputMethodDelegate, for setting on a Mock InputMethod in tests.
138 static ui::internal::InputMethodDelegate* GetInputMethodDelegateForWidget(
139 Widget* widget);
141 #if defined(OS_MACOSX)
142 static scoped_ptr<FakeActivation> FakeWidgetIsActiveAlways();
143 #endif
145 private:
146 DISALLOW_COPY_AND_ASSIGN(WidgetTest);
149 // A helper WidgetDelegate for tests that require hooks into WidgetDelegate
150 // calls, and removes some of the boilerplate for initializing a Widget. Calls
151 // Widget::CloseNow() when destroyed if it hasn't already been done.
152 class TestDesktopWidgetDelegate : public WidgetDelegate {
153 public:
154 TestDesktopWidgetDelegate();
155 ~TestDesktopWidgetDelegate() override;
157 // Initialize the Widget, adding some meaningful default InitParams.
158 void InitWidget(Widget::InitParams init_params);
160 // Set the contents view to be used during Widget initialization. For Widgets
161 // that use non-client views, this will be the contents_view used to
162 // initialize the ClientView in WidgetDelegate::CreateClientView(). Otherwise,
163 // it is the ContentsView of the Widget's RootView. Ownership passes to the
164 // view hierarchy during InitWidget().
165 void set_contents_view(View* contents_view) {
166 contents_view_ = contents_view;
169 int window_closing_count() const { return window_closing_count_; }
170 const gfx::Rect& initial_bounds() { return initial_bounds_; }
172 // WidgetDelegate overrides:
173 void WindowClosing() override;
174 Widget* GetWidget() override;
175 const Widget* GetWidget() const override;
176 View* GetContentsView() override;
177 bool ShouldAdvanceFocusToTopLevelWidget() const override;
179 private:
180 Widget* widget_;
181 View* contents_view_ = nullptr;
182 int window_closing_count_ = 0;
183 gfx::Rect initial_bounds_ = gfx::Rect(100, 100, 200, 200);
185 DISALLOW_COPY_AND_ASSIGN(TestDesktopWidgetDelegate);
188 } // namespace test
189 } // namespace views
191 #endif // UI_VIEWS_TEST_WIDGET_TEST_H_