OLD | NEW |
---|---|
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 "ui/views/controls/native/native_view_host.h" | 5 #include "ui/views/controls/native/native_view_host.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 "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/views/test/views_test_base.h" | 10 #include "ui/views/test/views_test_base.h" |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
128 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { | 128 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { |
129 // Create a child widget. | 129 // Create a child widget. |
130 NativeViewHierarchyChangedTestView* test_view = | 130 NativeViewHierarchyChangedTestView* test_view = |
131 new NativeViewHierarchyChangedTestView; | 131 new NativeViewHierarchyChangedTestView; |
132 NativeViewHost* host = new NativeViewHost; | 132 NativeViewHost* host = new NativeViewHost; |
133 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), | 133 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), |
134 toplevel()->GetRootView(), | 134 toplevel()->GetRootView(), |
135 test_view, | 135 test_view, |
136 host)); | 136 host)); |
137 | 137 |
138 #if defined(USE_AURA) | |
139 // One notification is generated from inserting the clipping window into the | |
sky
2014/06/05 15:49:01
I think we can avoid this if you don't call Widget
calamity
2014/06/06 08:13:45
I made this change and it only works for some of t
| |
140 // hierarchy. | |
141 EXPECT_EQ(1, test_view->notification_count()); | |
142 #else | |
138 EXPECT_EQ(0, test_view->notification_count()); | 143 EXPECT_EQ(0, test_view->notification_count()); |
144 #endif | |
139 test_view->ResetCount(); | 145 test_view->ResetCount(); |
140 | 146 |
141 // Detaching should send a NativeViewHierarchyChanged() notification and | 147 // Detaching should send a NativeViewHierarchyChanged() notification and |
142 // change the parent. | 148 // change the parent. |
143 host->Detach(); | 149 host->Detach(); |
150 #if defined(USE_AURA) | |
151 // The clipping window is removed on detach, so there is an extra hiearchy | |
152 // change. | |
153 EXPECT_EQ(2, test_view->notification_count()); | |
154 #else | |
144 EXPECT_EQ(1, test_view->notification_count()); | 155 EXPECT_EQ(1, test_view->notification_count()); |
156 #endif | |
145 EXPECT_NE(toplevel()->GetNativeView(), | 157 EXPECT_NE(toplevel()->GetNativeView(), |
146 GetNativeParent(child->GetNativeView())); | 158 GetNativeParent(child->GetNativeView())); |
147 test_view->ResetCount(); | 159 test_view->ResetCount(); |
148 | 160 |
149 // Attaching should send a NativeViewHierarchyChanged() notification and | 161 // Attaching should send a NativeViewHierarchyChanged() notification and |
150 // reset the parent. | 162 // reset the parent. |
151 host->Attach(child->GetNativeView()); | 163 host->Attach(child->GetNativeView()); |
152 EXPECT_EQ(1, test_view->notification_count()); | 164 EXPECT_EQ(1, test_view->notification_count()); |
165 #if defined(USE_AURA) | |
166 // There is a clipping window inserted above the native view that needs to be | |
167 // accounted for when looking at the relationship between the native views.. | |
168 EXPECT_EQ(toplevel()->GetNativeView(), | |
169 GetNativeParent(GetNativeParent(child->GetNativeView()))); | |
170 #else | |
153 EXPECT_EQ(toplevel()->GetNativeView(), | 171 EXPECT_EQ(toplevel()->GetNativeView(), |
154 GetNativeParent(child->GetNativeView())); | 172 GetNativeParent(child->GetNativeView())); |
173 #endif | |
155 } | 174 } |
156 | 175 |
157 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 176 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
158 // (reparent) operations with correct parent changes. | 177 // (reparent) operations with correct parent changes. |
159 // This exercises the non-recursive code paths in | 178 // This exercises the non-recursive code paths in |
160 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 179 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
161 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 180 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
162 // Original tree: | 181 // Original tree: |
163 // toplevel | 182 // toplevel |
164 // +-- host0 (NativeViewHost) | 183 // +-- host0 (NativeViewHost) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 host0->ResetParentChanges(); | 295 host0->ResetParentChanges(); |
277 host1->ResetParentChanges(); | 296 host1->ResetParentChanges(); |
278 EXPECT_EQ(0, host0->num_parent_changes()); | 297 EXPECT_EQ(0, host0->num_parent_changes()); |
279 EXPECT_EQ(0, host1->num_parent_changes()); | 298 EXPECT_EQ(0, host1->num_parent_changes()); |
280 child0->GetContentsView()->AddChildView(view1); | 299 child0->GetContentsView()->AddChildView(view1); |
281 EXPECT_EQ(0, host0->num_parent_changes()); | 300 EXPECT_EQ(0, host0->num_parent_changes()); |
282 EXPECT_EQ(2, host1->num_parent_changes()); | 301 EXPECT_EQ(2, host1->num_parent_changes()); |
283 } | 302 } |
284 | 303 |
285 } // namespace views | 304 } // namespace views |
OLD | NEW |