Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: ui/views/widget/widget_unittest.cc

Issue 2645253002: DesktopAura: Track windows "owned" via the DesktopWindowTreeHost (Closed)
Patch Set: Add context, comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/widget/widget.cc ('k') | ui/views/win/hwnd_message_handler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 #include <memory> 6 #include <memory>
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after
2983 EXPECT_EQ(expected.size(), child_widgets.size()); 2983 EXPECT_EQ(expected.size(), child_widgets.size());
2984 EXPECT_TRUE( 2984 EXPECT_TRUE(
2985 std::equal(expected.begin(), expected.end(), child_widgets.begin())); 2985 std::equal(expected.begin(), expected.end(), child_widgets.begin()));
2986 2986
2987 // Check GetAllOwnedWidgets(). On Aura, this includes "transient" children. 2987 // Check GetAllOwnedWidgets(). On Aura, this includes "transient" children.
2988 // Otherwise (on all platforms), it should be the same as GetAllChildWidgets() 2988 // Otherwise (on all platforms), it should be the same as GetAllChildWidgets()
2989 // except the root Widget is not included. 2989 // except the root Widget is not included.
2990 EXPECT_EQ(1u, expected.erase(toplevel.get())); 2990 EXPECT_EQ(1u, expected.erase(toplevel.get()));
2991 2991
2992 std::set<Widget*> owned_widgets; 2992 std::set<Widget*> owned_widgets;
2993 Widget::GetAllOwnedWidgets(toplevel->GetNativeView(), &owned_widgets); 2993 Widget::GetAllOwnedWidgets(toplevel->GetNativeView(), &owned_widgets, true);
2994 2994
2995 EXPECT_EQ(expected.size(), owned_widgets.size()); 2995 EXPECT_EQ(expected.size(), owned_widgets.size());
2996 EXPECT_TRUE( 2996 EXPECT_TRUE(
2997 std::equal(expected.begin(), expected.end(), owned_widgets.begin())); 2997 std::equal(expected.begin(), expected.end(), owned_widgets.begin()));
2998 } 2998 }
2999 2999
3000 // Used by DestroyChildWidgetsInOrder. On destruction adds the supplied name to 3000 // Used by DestroyChildWidgetsInOrder. On destruction adds the supplied name to
3001 // a vector. 3001 // a vector.
3002 class DestroyedTrackingView : public View { 3002 class DestroyedTrackingView : public View {
3003 public: 3003 public:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
3083 DestroyChildWidgetsInOrderWithDesktopNativeWidgetForBoth) { 3083 DestroyChildWidgetsInOrderWithDesktopNativeWidgetForBoth) {
3084 RunDestroyChildWidgetsTest(true, true); 3084 RunDestroyChildWidgetsTest(true, true);
3085 } 3085 }
3086 #endif // !defined(OS_CHROMEOS) 3086 #endif // !defined(OS_CHROMEOS)
3087 3087
3088 // See description of RunDestroyChildWidgetsTest(). 3088 // See description of RunDestroyChildWidgetsTest().
3089 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) { 3089 TEST_F(WidgetChildDestructionTest, DestroyChildWidgetsInOrder) {
3090 RunDestroyChildWidgetsTest(false, false); 3090 RunDestroyChildWidgetsTest(false, false);
3091 } 3091 }
3092 3092
3093 Widget* TrackedTopLevelWidgetWithParent(Widget::InitParams params,
3094 bool* destroyed,
3095 Widget* parent) {
3096 Widget* widget = new Widget(); // Owned by Native Widget.
3097
3098 params.bounds = gfx::Rect(100, 100, 100, 100);
3099 params.parent = parent ? parent->GetNativeView() : nullptr;
3100 params.native_widget =
3101 CreatePlatformDesktopNativeWidgetImpl(params, widget, destroyed);
3102 widget->Init(params);
3103 widget->Show();
3104 return widget;
3105 }
3106
3107 // Test Widget::GetAllOwnedWidgets() for top-level child windows.
3108 // Also ensure that if a Widget is created with parent and is created using a
3109 // top-level Widget, then it is destroyed when the parent Widget goes away.
3110 TEST_F(WidgetTest, OwnedTopLevelChildWindows) {
3111 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
3112
3113 bool parent_destroyed = false;
3114 bool child_destroyed = false;
3115 bool grandchild_destroyed = false;
3116
3117 Widget* parent =
3118 TrackedTopLevelWidgetWithParent(params, &parent_destroyed, nullptr);
3119 Widget* child =
3120 TrackedTopLevelWidgetWithParent(params, &child_destroyed, parent);
3121 Widget* grandchild =
3122 TrackedTopLevelWidgetWithParent(params, &grandchild_destroyed, child);
3123
3124 // |child| and |grandchild| are destroyed when their parents go away, so they
3125 // should be considered "owned".
3126 std::set<Widget*> owned_widgets;
3127 Widget::GetAllOwnedWidgets(parent->GetNativeView(), &owned_widgets, true);
3128 EXPECT_EQ(0u, owned_widgets.count(parent));
3129 EXPECT_EQ(1u, owned_widgets.count(child));
3130 EXPECT_EQ(1u, owned_widgets.count(grandchild));
3131
3132 owned_widgets.clear();
3133 Widget::GetAllOwnedWidgets(child->GetNativeView(), &owned_widgets, true);
3134 EXPECT_EQ(0u, owned_widgets.count(parent));
3135 EXPECT_EQ(0u, owned_widgets.count(child));
3136 EXPECT_EQ(1u, owned_widgets.count(grandchild));
3137
3138 // Trigger child destruction via a call to one of the following on the parent
3139 // window: DesktopWindowTreeHostX11::CloseNow(), ::DestroyWindow(),
3140 // DesktopWindowTreeHostMus::CloseNow(), or BridgedNativeWidget::
3141 // OnWindowWillClose().
3142 parent->CloseNow();
3143 EXPECT_TRUE(parent_destroyed);
3144 EXPECT_TRUE(child_destroyed);
3145 EXPECT_TRUE(grandchild_destroyed);
3146 }
3147
3093 // Verifies nativeview visbility matches that of Widget visibility when 3148 // Verifies nativeview visbility matches that of Widget visibility when
3094 // SetFullscreen is invoked. 3149 // SetFullscreen is invoked.
3095 TEST_F(WidgetTest, FullscreenStatePropagated) { 3150 TEST_F(WidgetTest, FullscreenStatePropagated) {
3096 Widget::InitParams init_params = 3151 Widget::InitParams init_params =
3097 CreateParams(Widget::InitParams::TYPE_WINDOW); 3152 CreateParams(Widget::InitParams::TYPE_WINDOW);
3098 init_params.show_state = ui::SHOW_STATE_NORMAL; 3153 init_params.show_state = ui::SHOW_STATE_NORMAL;
3099 init_params.bounds = gfx::Rect(0, 0, 500, 500); 3154 init_params.bounds = gfx::Rect(0, 0, 500, 500);
3100 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 3155 init_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
3101 3156
3102 Widget top_level_widget; 3157 Widget top_level_widget;
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after
3872 } 3927 }
3873 3928
3874 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetTranslucent) { 3929 TEST_F(CompositingWidgetTest, Transparency_DesktopWidgetTranslucent) {
3875 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW); 3930 CheckAllWidgetsForOpacity(Widget::InitParams::TRANSLUCENT_WINDOW);
3876 } 3931 }
3877 3932
3878 #endif // !defined(OS_CHROMEOS) 3933 #endif // !defined(OS_CHROMEOS)
3879 3934
3880 } // namespace test 3935 } // namespace test
3881 } // namespace views 3936 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/widget/widget.cc ('k') | ui/views/win/hwnd_message_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698