OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "views/widget/native_widget_views.h" | 5 #include "views/widget/native_widget_views.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view) { | 126 Widget* CreateChildPlatformWidget(gfx::NativeView parent_native_view) { |
127 Widget* child = new Widget; | 127 Widget* child = new Widget; |
128 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | 128 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); |
129 child_params.native_widget = CreatePlatformNativeWidget(child); | 129 child_params.native_widget = CreatePlatformNativeWidget(child); |
130 child_params.parent = parent_native_view; | 130 child_params.parent = parent_native_view; |
131 child->Init(child_params); | 131 child->Init(child_params); |
132 child->SetContentsView(new View); | 132 child->SetContentsView(new View); |
133 return child; | 133 return child; |
134 } | 134 } |
135 | 135 |
| 136 Widget* CreateChildPopupPlatformWidget(gfx::NativeView parent_native_view) { |
| 137 Widget* child = new Widget; |
| 138 Widget::InitParams child_params(Widget::InitParams::TYPE_POPUP); |
| 139 child_params.child = true; |
| 140 child_params.native_widget = CreatePlatformNativeWidget(child); |
| 141 child_params.parent = parent_native_view; |
| 142 child->Init(child_params); |
| 143 child->SetContentsView(new View); |
| 144 return child; |
| 145 } |
| 146 |
136 Widget* CreateTopLevelNativeWidgetViews() { | 147 Widget* CreateTopLevelNativeWidgetViews() { |
137 Widget* toplevel = new Widget; | 148 Widget* toplevel = new Widget; |
138 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); | 149 Widget::InitParams params(Widget::InitParams::TYPE_WINDOW); |
139 params.native_widget = new NativeWidgetViews(toplevel); | 150 params.native_widget = new NativeWidgetViews(toplevel); |
140 toplevel->Init(params); | 151 toplevel->Init(params); |
141 toplevel->SetContentsView(new View); | 152 toplevel->SetContentsView(new View); |
142 return toplevel; | 153 return toplevel; |
143 } | 154 } |
144 | 155 |
145 Widget* CreateChildNativeWidgetViewsWithParent(Widget* parent) { | 156 Widget* CreateChildNativeWidgetViewsWithParent(Widget* parent) { |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 TEST_F(WidgetTest, Visibility) { | 322 TEST_F(WidgetTest, Visibility) { |
312 Widget* toplevel = CreateTopLevelPlatformWidget(); | 323 Widget* toplevel = CreateTopLevelPlatformWidget(); |
313 #if defined(TOOLKIT_USES_GTK) | 324 #if defined(TOOLKIT_USES_GTK) |
314 NativeWidgetGtk* native_widget = | 325 NativeWidgetGtk* native_widget = |
315 static_cast<NativeWidgetGtk*>(toplevel->native_widget()); | 326 static_cast<NativeWidgetGtk*>(toplevel->native_widget()); |
316 gfx::NativeView parent = native_widget->window_contents(); | 327 gfx::NativeView parent = native_widget->window_contents(); |
317 #else | 328 #else |
318 gfx::NativeView parent = toplevel->GetNativeView(); | 329 gfx::NativeView parent = toplevel->GetNativeView(); |
319 #endif | 330 #endif |
320 Widget* child = CreateChildPlatformWidget(parent); | 331 Widget* child = CreateChildPlatformWidget(parent); |
| 332 Widget* child_popup = CreateChildPopupPlatformWidget(parent); |
321 | 333 |
322 EXPECT_FALSE(toplevel->IsVisible()); | 334 EXPECT_FALSE(toplevel->IsVisible()); |
323 EXPECT_FALSE(child->IsVisible()); | 335 EXPECT_FALSE(child->IsVisible()); |
| 336 EXPECT_FALSE(child_popup->IsVisible()); |
324 | 337 |
325 child->Show(); | 338 child->Show(); |
326 | 339 |
327 EXPECT_FALSE(toplevel->IsVisible()); | 340 EXPECT_FALSE(toplevel->IsVisible()); |
328 EXPECT_FALSE(child->IsVisible()); | 341 EXPECT_FALSE(child->IsVisible()); |
329 | 342 |
330 toplevel->Show(); | 343 toplevel->Show(); |
331 | 344 |
332 EXPECT_TRUE(toplevel->IsVisible()); | 345 EXPECT_TRUE(toplevel->IsVisible()); |
333 EXPECT_TRUE(child->IsVisible()); | 346 EXPECT_TRUE(child->IsVisible()); |
| 347 EXPECT_FALSE(child_popup->IsVisible()); |
| 348 |
| 349 child_popup->Show(); |
| 350 |
| 351 EXPECT_TRUE(child_popup->IsVisible()); |
334 | 352 |
335 toplevel->CloseNow(); | 353 toplevel->CloseNow(); |
336 // |child| should be automatically destroyed with |toplevel|. | 354 // |child| should be automatically destroyed with |toplevel|. |
337 } | 355 } |
338 | 356 |
339 // Tests visibility of synthetic child widgets. | 357 // Tests visibility of synthetic child widgets. |
340 TEST_F(WidgetTest, Visibility_Synthetic) { | 358 TEST_F(WidgetTest, Visibility_Synthetic) { |
341 // Create a hierarchy consisting of a desktop platform native widget, | 359 // Create a hierarchy consisting of a desktop platform native widget, |
342 // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. | 360 // a toplevel NativeWidgetViews and a chlid NativeWidgetViews. |
343 Widget* desktop = CreateTopLevelPlatformWidget(); | 361 Widget* desktop = CreateTopLevelPlatformWidget(); |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 EXPECT_EQ(child1, widget_shown()); | 808 EXPECT_EQ(child1, widget_shown()); |
791 | 809 |
792 child2->Show(); | 810 child2->Show(); |
793 EXPECT_EQ(child2, widget_shown()); | 811 EXPECT_EQ(child2, widget_shown()); |
794 | 812 |
795 toplevel->CloseNow(); | 813 toplevel->CloseNow(); |
796 } | 814 } |
797 | 815 |
798 } // namespace | 816 } // namespace |
799 } // namespace views | 817 } // namespace views |
OLD | NEW |