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_VIEWS_TEST_WIDGET_TEST_H_ 6 #define UI_VIEWS_TEST_WIDGET_TEST_H_ 7 8 #include "ui/gfx/native_widget_types.h" 9 #include "ui/views/test/views_test_base.h" 10 11 #if defined(USE_AURA) 12 #include "ui/views/widget/native_widget_aura.h" 13 #if !defined(OS_CHROMEOS) 14 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" 15 #endif 16 #elif defined(OS_MACOSX) 17 #include "ui/views/widget/native_widget_mac.h" 18 #endif 19 20 namespace ui { 21 class EventProcessor; 22 } 23 24 namespace views { 25 26 class NativeWidget; 27 class Widget; 28 29 #if defined(USE_AURA) 30 typedef NativeWidgetAura PlatformNativeWidget; 31 #if !defined(OS_CHROMEOS) 32 typedef DesktopNativeWidgetAura PlatformDesktopNativeWidget; 33 #endif 34 #elif defined(OS_MACOSX) 35 typedef NativeWidgetMac PlatformNativeWidget; 36 typedef NativeWidgetMac PlatformDesktopNativeWidget; 37 #endif 38 39 namespace internal { 40 41 class RootView; 42 43 } // namespace internal 44 45 namespace test { 46 47 // A widget that assumes mouse capture always works. It won't on Aura in 48 // testing, so we mock it. 49 class NativeWidgetCapture : public PlatformNativeWidget { 50 public: 51 explicit NativeWidgetCapture(internal::NativeWidgetDelegate* delegate); 52 virtual ~NativeWidgetCapture(); 53 54 virtual void SetCapture() OVERRIDE; 55 virtual void ReleaseCapture() OVERRIDE; 56 virtual bool HasCapture() const OVERRIDE; 57 58 private: 59 bool mouse_capture_; 60 61 DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture); 62 }; 63 64 class WidgetTest : public ViewsTestBase { 65 public: 66 WidgetTest(); 67 virtual ~WidgetTest(); 68 69 NativeWidget* CreatePlatformNativeWidget( 70 internal::NativeWidgetDelegate* delegate); 71 72 Widget* CreateTopLevelPlatformWidget(); 73 74 Widget* CreateTopLevelFramelessPlatformWidget(); 75 76 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view); 77 78 Widget* CreateTopLevelNativeWidget(); 79 80 Widget* CreateChildNativeWidgetWithParent(Widget* parent); 81 82 Widget* CreateChildNativeWidget(); 83 84 View* GetMousePressedHandler(internal::RootView* root_view); 85 86 View* GetMouseMoveHandler(internal::RootView* root_view); 87 88 View* GetGestureHandler(internal::RootView* root_view); 89 90 // Simulate a OS-level destruction of the native widget held by |widget|. 91 static void SimulateNativeDestroy(Widget* widget); 92 93 // Return true if |window| is visible according to the native platform. 94 static bool IsNativeWindowVisible(gfx::NativeWindow window); 95 96 // Return the event processor for |widget|. On aura platforms, this is an 97 // aura::WindowEventDispatcher. Otherwise, it is a bridge to the OS event 98 // processor. 99 static ui::EventProcessor* GetEventProcessor(Widget* widget); 100 101 private: 102 DISALLOW_COPY_AND_ASSIGN(WidgetTest); 103 }; 104 105 } // namespace test 106 } // namespace views 107 108 #endif // UI_VIEWS_TEST_WIDGET_TEST_H_ 109