Index: views/widget/widget_unittest.cc |
=================================================================== |
--- views/widget/widget_unittest.cc (revision 110826) |
+++ views/widget/widget_unittest.cc (working copy) |
@@ -2,15 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "views/widget/native_widget_views.h" |
- |
#include "base/basictypes.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "ui/views/test/test_views_delegate.h" |
#include "ui/views/test/views_test_base.h" |
+#include "ui/gfx/point.h" |
+#include "ui/gfx/native_widget_types.h" |
#include "views/views_delegate.h" |
+#include "views/widget/native_widget_delegate.h" |
#if defined(USE_AURA) |
#include "ui/aura/window.h" |
@@ -24,14 +25,25 @@ |
namespace views { |
namespace { |
-#if defined(TOOLKIT_USES_GTK) |
-// A widget that assumes mouse capture always works. |
-class NativeWidgetGtkCapture : public NativeWidgetGtk { |
+// A generic typedef to pick up relevant NativeWidget implementations. |
+#if defined(USE_AURA) |
+typedef NativeWidgetAura NativeWidgetPlatform; |
+#elif defined(OS_WIN) |
+typedef NativeWidgetWin NativeWidgetPlatform; |
+#elif defined(TOOLKIT_USES_GTK) |
+typedef NativeWidgetGtk NativeWidgetPlatform; |
+#endif |
+ |
+// A widget that assumes mouse capture always works. It won't on Gtk/Aura in |
+// testing, so we mock it. |
+#if defined(TOOLKIT_USES_GTK) || defined(USE_AURA) |
+class NativeWidgetCapture : public NativeWidgetPlatform { |
public: |
- NativeWidgetGtkCapture(internal::NativeWidgetDelegate* delegate) |
- : NativeWidgetGtk(delegate), |
+ NativeWidgetCapture(internal::NativeWidgetDelegate* delegate) |
+ : NativeWidgetPlatform(delegate), |
mouse_capture_(false) {} |
- virtual ~NativeWidgetGtkCapture() {} |
+ virtual ~NativeWidgetCapture() {} |
+ |
virtual void SetMouseCapture() OVERRIDE { |
mouse_capture_ = true; |
} |
@@ -47,10 +59,20 @@ |
private: |
bool mouse_capture_; |
- DISALLOW_COPY_AND_ASSIGN(NativeWidgetGtkCapture); |
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetCapture); |
}; |
#endif |
+// A typedef that inserts our mock-capture NativeWidget implementation for |
+// relevant platforms. |
+#if defined(USE_AURA) |
+typedef NativeWidgetCapture NativeWidgetPlatformForTest; |
+#elif defined(OS_WIN) |
+typedef NativeWidgetWin NativeWidgetPlatformForTest; |
+#elif defined(TOOLKIT_USES_GTK) |
+typedef NativeWidgetCapture NativeWidgetPlatformForTest; |
+#endif |
+ |
// A view that always processes all mouse events. |
class MouseView : public View { |
public: |
@@ -63,56 +85,11 @@ |
} |
}; |
-class WidgetTestViewsDelegate : public TestViewsDelegate { |
- public: |
- WidgetTestViewsDelegate() : default_parent_view_(NULL) { |
- } |
- virtual ~WidgetTestViewsDelegate() {} |
+typedef ViewsTestBase WidgetTest; |
- void set_default_parent_view(View* default_parent_view) { |
- default_parent_view_ = default_parent_view; |
- } |
- |
- // Overridden from TestViewsDelegate: |
- virtual View* GetDefaultParentView() OVERRIDE { |
- return default_parent_view_; |
- } |
- |
- private: |
- View* default_parent_view_; |
- |
- DISALLOW_COPY_AND_ASSIGN(WidgetTestViewsDelegate); |
-}; |
- |
-class WidgetTest : public ViewsTestBase { |
- public: |
- WidgetTest() { |
- } |
- virtual ~WidgetTest() { |
- } |
- |
- virtual void SetUp() OVERRIDE { |
- set_views_delegate(new WidgetTestViewsDelegate()); |
- ViewsTestBase::SetUp(); |
- } |
- |
- WidgetTestViewsDelegate& widget_views_delegate() const { |
- return static_cast<WidgetTestViewsDelegate&>(views_delegate()); |
- } |
- |
- private: |
- DISALLOW_COPY_AND_ASSIGN(WidgetTest); |
-}; |
- |
NativeWidget* CreatePlatformNativeWidget( |
internal::NativeWidgetDelegate* delegate) { |
-#if defined(USE_AURA) |
- return new NativeWidgetAura(delegate); |
-#elif defined(OS_WIN) |
- return new NativeWidgetWin(delegate); |
-#elif defined(TOOLKIT_USES_GTK) |
- return new NativeWidgetGtkCapture(delegate); |
-#endif |
+ return new NativeWidgetPlatformForTest(delegate); |
} |
Widget* CreateTopLevelPlatformWidget() { |
@@ -147,32 +124,30 @@ |
} |
#endif |
-Widget* CreateTopLevelNativeWidgetViews() { |
+Widget* CreateTopLevelNativeWidget() { |
Widget* toplevel = new Widget; |
Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
- params.native_widget = new NativeWidgetViews(toplevel); |
toplevel->Init(params); |
toplevel->SetContentsView(new View); |
return toplevel; |
} |
-Widget* CreateChildNativeWidgetViewsWithParent(Widget* parent) { |
+Widget* CreateChildNativeWidgetWithParent(Widget* parent) { |
Widget* child = new Widget; |
Widget::InitParams params(Widget::InitParams::TYPE_CONTROL); |
- params.native_widget = new NativeWidgetViews(child); |
params.parent_widget = parent; |
child->Init(params); |
child->SetContentsView(new View); |
return child; |
} |
-Widget* CreateChildNativeWidgetViews() { |
- return CreateChildNativeWidgetViewsWithParent(NULL); |
+Widget* CreateChildNativeWidget() { |
+ return CreateChildNativeWidgetWithParent(NULL); |
} |
bool WidgetHasMouseCapture(const Widget* widget) { |
return static_cast<const internal::NativeWidgetPrivate*>(widget-> |
- native_widget())-> HasMouseCapture(); |
+ native_widget())->HasMouseCapture(); |
} |
//////////////////////////////////////////////////////////////////////////////// |
@@ -199,10 +174,9 @@ |
TEST_F(WidgetTest, GetTopLevelWidget_Synthetic) { |
// Create a hierarchy consisting of a top level platform native widget and a |
- // child NativeWidgetViews. |
+ // child NativeWidget. |
Widget* toplevel = CreateTopLevelPlatformWidget(); |
- widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); |
- Widget* child = CreateTopLevelNativeWidgetViews(); |
+ Widget* child = CreateTopLevelNativeWidget(); |
EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
EXPECT_EQ(child, child->GetTopLevelWidget()); |
@@ -212,18 +186,16 @@ |
} |
// Creates a hierarchy consisting of a desktop platform native widget, a |
-// toplevel NativeWidgetViews, and a child of that toplevel, another |
-// NativeWidgetViews. |
+// toplevel NativeWidget, and a child of that toplevel, another NativeWidget. |
TEST_F(WidgetTest, GetTopLevelWidget_SyntheticDesktop) { |
// Create a hierarchy consisting of a desktop platform native widget, |
- // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. |
+ // a toplevel NativeWidget and a chlid NativeWidget. |
Widget* desktop = CreateTopLevelPlatformWidget(); |
- widget_views_delegate().set_default_parent_view(desktop->GetRootView()); |
- Widget* toplevel = CreateTopLevelNativeWidgetViews(); // Will be parented |
- // automatically to |
- // |toplevel|. |
+ Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented |
+ // automatically to |
+ // |toplevel|. |
- Widget* child = CreateChildNativeWidgetViewsWithParent(toplevel); |
+ Widget* child = CreateChildNativeWidgetWithParent(toplevel); |
EXPECT_EQ(desktop, desktop->GetTopLevelWidget()); |
EXPECT_EQ(toplevel, toplevel->GetTopLevelWidget()); |
@@ -233,17 +205,11 @@ |
// |toplevel|, |child| should be automatically destroyed with |toplevel|. |
} |
-// This is flaky on touch build. See crbug.com/94137. |
-#if defined(TOUCH_UI) |
-#define MAYBE_GrabUngrab DISABLED_GrabUngrab |
-#else |
-#define MAYBE_GrabUngrab GrabUngrab |
-#endif |
// Tests some grab/ungrab events. |
-TEST_F(WidgetTest, MAYBE_GrabUngrab) { |
+TEST_F(WidgetTest, DISABLED_GrabUngrab) { |
Widget* toplevel = CreateTopLevelPlatformWidget(); |
- Widget* child1 = CreateChildNativeWidgetViewsWithParent(toplevel); |
- Widget* child2 = CreateChildNativeWidgetViewsWithParent(toplevel); |
+ Widget* child1 = CreateChildNativeWidgetWithParent(toplevel); |
+ Widget* child2 = CreateChildNativeWidgetWithParent(toplevel); |
toplevel->SetBounds(gfx::Rect(0, 0, 500, 500)); |
@@ -379,16 +345,15 @@ |
// Tests visibility of synthetic child widgets. |
TEST_F(WidgetTest, Visibility_Synthetic) { |
// Create a hierarchy consisting of a desktop platform native widget, |
- // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. |
+ // a toplevel NativeWidget and a chlid NativeWidget. |
Widget* desktop = CreateTopLevelPlatformWidget(); |
desktop->Show(); |
- widget_views_delegate().set_default_parent_view(desktop->GetRootView()); |
- Widget* toplevel = CreateTopLevelNativeWidgetViews(); // Will be parented |
- // automatically to |
- // |toplevel|. |
+ Widget* toplevel = CreateTopLevelNativeWidget(); // Will be parented |
+ // automatically to |
+ // |toplevel|. |
- Widget* child = CreateChildNativeWidgetViewsWithParent(toplevel); |
+ Widget* child = CreateChildNativeWidgetWithParent(toplevel); |
EXPECT_FALSE(toplevel->IsVisible()); |
EXPECT_FALSE(child->IsVisible()); |
@@ -412,8 +377,7 @@ |
// Tests various permutations of Widget ownership specified in the |
// InitParams::Ownership param. |
-// A WidgetTest that supplies a toplevel widget for NativeWidgetViews to parent |
-// to. |
+// A WidgetTest that supplies a toplevel widget for NativeWidget to parent to. |
class WidgetOwnershipTest : public WidgetTest { |
public: |
WidgetOwnershipTest() {} |
@@ -422,8 +386,6 @@ |
virtual void SetUp() { |
WidgetTest::SetUp(); |
desktop_widget_ = CreateTopLevelPlatformWidget(); |
- widget_views_delegate().set_default_parent_view( |
- desktop_widget_->GetRootView()); |
} |
virtual void TearDown() { |
@@ -447,25 +409,12 @@ |
// A platform NativeWidget subclass that updates a bag of state when it is |
// destroyed. |
-class OwnershipTestNativeWidget : |
-#if defined(USE_AURA) |
- public NativeWidgetAura { |
-#elif defined(OS_WIN) |
- public NativeWidgetWin { |
-#elif defined(TOOLKIT_USES_GTK) |
- public NativeWidgetGtk { |
-#endif |
-public: |
+class OwnershipTestNativeWidget : public NativeWidgetPlatform { |
+ public: |
OwnershipTestNativeWidget(internal::NativeWidgetDelegate* delegate, |
OwnershipTestState* state) |
-#if defined(USE_AURA) |
- : NativeWidgetAura(delegate), |
-#elif defined(OS_WIN) |
- : NativeWidgetWin(delegate), |
-#elif defined(TOOLKIT_USES_GTK) |
- : NativeWidgetGtk(delegate), |
-#endif |
- state_(state) { |
+ : NativeWidgetPlatform(delegate), |
+ state_(state) { |
} |
virtual ~OwnershipTestNativeWidget() { |
state_->native_widget_deleted = true; |
@@ -479,21 +428,21 @@ |
// A views NativeWidget subclass that updates a bag of state when it is |
// destroyed. |
-class OwnershipTestNativeWidgetViews : public NativeWidgetViews { |
+class OwnershipTestNativeWidgetPlatform : public NativeWidgetPlatformForTest { |
public: |
- OwnershipTestNativeWidgetViews(internal::NativeWidgetDelegate* delegate, |
- OwnershipTestState* state) |
- : NativeWidgetViews(delegate), |
+ OwnershipTestNativeWidgetPlatform(internal::NativeWidgetDelegate* delegate, |
+ OwnershipTestState* state) |
+ : NativeWidgetPlatformForTest(delegate), |
state_(state) { |
} |
- virtual ~OwnershipTestNativeWidgetViews() { |
+ virtual ~OwnershipTestNativeWidgetPlatform() { |
state_->native_widget_deleted = true; |
} |
private: |
OwnershipTestState* state_; |
- DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetViews); |
+ DISALLOW_COPY_AND_ASSIGN(OwnershipTestNativeWidgetPlatform); |
}; |
// A Widget subclass that updates a bag of state when it is destroyed. |
@@ -517,7 +466,8 @@ |
scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidget(widget.get(), &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
widget->Init(params); |
@@ -531,14 +481,14 @@ |
// being deleted out from under the Widget. |
} |
-// Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidgetViews. |
+// Widget owns its NativeWidget, part 2: NativeWidget is a NativeWidget. |
TEST_F(WidgetOwnershipTest, Ownership_WidgetOwnsViewsNativeWidget) { |
OwnershipTestState state; |
scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
params.native_widget = |
- new OwnershipTestNativeWidgetViews(widget.get(), &state); |
+ new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
widget->Init(params); |
@@ -552,7 +502,7 @@ |
// being deleted out from under the Widget. |
} |
-// Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidgetViews, |
+// Widget owns its NativeWidget, part 3: NativeWidget is a NativeWidget, |
// destroy the parent view. |
TEST_F(WidgetOwnershipTest, |
Ownership_WidgetOwnsViewsNativeWidget_DestroyParentView) { |
@@ -562,8 +512,8 @@ |
scoped_ptr<Widget> widget(new OwnershipTestWidget(&state)); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidgetViews(widget.get(), |
- &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget.get(), &state); |
params.parent_widget = toplevel; |
params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
widget->Init(params); |
@@ -592,7 +542,8 @@ |
Widget* widget = new OwnershipTestWidget(&state); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidget(widget, &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget, &state); |
widget->Init(params); |
// Now destroy the native widget. |
@@ -602,7 +553,7 @@ |
EXPECT_TRUE(state.native_widget_deleted); |
} |
-// NativeWidget owns its Widget, part 2: NativeWidget is a NativeWidgetViews. |
+// NativeWidget owns its Widget, part 2: NativeWidget is a NativeWidget. |
TEST_F(WidgetOwnershipTest, Ownership_ViewsNativeWidgetOwnsWidget) { |
OwnershipTestState state; |
@@ -610,16 +561,16 @@ |
Widget* widget = new OwnershipTestWidget(&state); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget, &state); |
params.parent_widget = toplevel; |
widget->Init(params); |
// Now destroy the native widget. This is achieved by closing the toplevel. |
toplevel->CloseNow(); |
- // The NativeWidgetViews won't be deleted until after a return to the message |
- // loop so we have to run pending messages before testing the destruction |
- // status. |
+ // The NativeWidget won't be deleted until after a return to the message loop |
+ // so we have to run pending messages before testing the destruction status. |
RunPendingMessages(); |
EXPECT_TRUE(state.widget_deleted); |
@@ -634,7 +585,8 @@ |
Widget* widget = new OwnershipTestWidget(&state); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidget(widget, &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget, &state); |
widget->Init(params); |
// Now simulate a destroy of the platform native widget from the OS: |
@@ -650,7 +602,7 @@ |
EXPECT_TRUE(state.native_widget_deleted); |
} |
-// NativeWidget owns its Widget, part 4: NativeWidget is a NativeWidgetViews, |
+// NativeWidget owns its Widget, part 4: NativeWidget is a NativeWidget, |
// destroyed by the view hierarchy that contains it. |
TEST_F(WidgetOwnershipTest, |
Ownership_ViewsNativeWidgetOwnsWidget_NativeDestroy) { |
@@ -660,23 +612,23 @@ |
Widget* widget = new OwnershipTestWidget(&state); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget, &state); |
params.parent_widget = toplevel; |
widget->Init(params); |
// Destroy the widget (achieved by closing the toplevel). |
toplevel->CloseNow(); |
- // The NativeWidgetViews won't be deleted until after a return to the message |
- // loop so we have to run pending messages before testing the destruction |
- // status. |
+ // The NativeWidget won't be deleted until after a return to the message loop |
+ // so we have to run pending messages before testing the destruction status. |
RunPendingMessages(); |
EXPECT_TRUE(state.widget_deleted); |
EXPECT_TRUE(state.native_widget_deleted); |
} |
-// NativeWidget owns its Widget, part 5: NativeWidget is a NativeWidgetViews, |
+// NativeWidget owns its Widget, part 5: NativeWidget is a NativeWidget, |
// we close it directly. |
TEST_F(WidgetOwnershipTest, |
Ownership_ViewsNativeWidgetOwnsWidget_Close) { |
@@ -686,7 +638,8 @@ |
Widget* widget = new OwnershipTestWidget(&state); |
Widget::InitParams params(Widget::InitParams::TYPE_POPUP); |
- params.native_widget = new OwnershipTestNativeWidgetViews(widget, &state); |
+ params.native_widget = |
+ new OwnershipTestNativeWidgetPlatform(widget, &state); |
params.parent_widget = toplevel; |
widget->Init(params); |
@@ -694,9 +647,8 @@ |
widget->Close(); |
toplevel->CloseNow(); |
- // The NativeWidgetViews won't be deleted until after a return to the message |
- // loop so we have to run pending messages before testing the destruction |
- // status. |
+ // The NativeWidget won't be deleted until after a return to the message loop |
+ // so we have to run pending messages before testing the destruction status. |
RunPendingMessages(); |
EXPECT_TRUE(state.widget_deleted); |
@@ -758,7 +710,7 @@ |
} |
Widget* NewWidget() { |
- Widget* widget = CreateTopLevelNativeWidgetViews(); |
+ Widget* widget = CreateTopLevelNativeWidget(); |
widget->AddObserver(this); |
return widget; |
} |
@@ -781,9 +733,8 @@ |
Widget* widget_hidden_; |
}; |
-TEST_F(WidgetObserverTest, ActivationChange) { |
+TEST_F(WidgetObserverTest, DISABLED_ActivationChange) { |
Widget* toplevel = CreateTopLevelPlatformWidget(); |
- widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); |
Widget* toplevel1 = NewWidget(); |
Widget* toplevel2 = NewWidget(); |
@@ -807,9 +758,8 @@ |
toplevel->CloseNow(); |
} |
-TEST_F(WidgetObserverTest, VisibilityChange) { |
+TEST_F(WidgetObserverTest, DISABLED_VisibilityChange) { |
Widget* toplevel = CreateTopLevelPlatformWidget(); |
- widget_views_delegate().set_default_parent_view(toplevel->GetRootView()); |
Widget* child1 = NewWidget(); |
Widget* child2 = NewWidget(); |