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 #if defined(USE_AURA) | 137 #if defined(USE_AURA) |
138 // One notification is generated from inserting the native view into the | 138 // Two notifications are generated from inserting the native view into the |
139 // clipping window. | 139 // clipping window and then inserting the clipping window into the root |
140 EXPECT_EQ(1, test_view->notification_count()); | 140 // window. |
| 141 EXPECT_EQ(2, test_view->notification_count()); |
141 #else | 142 #else |
142 EXPECT_EQ(0, test_view->notification_count()); | 143 EXPECT_EQ(0, test_view->notification_count()); |
143 #endif | 144 #endif |
144 test_view->ResetCount(); | 145 test_view->ResetCount(); |
145 | 146 |
146 // Detaching should send a NativeViewHierarchyChanged() notification and | 147 // Detaching should send a NativeViewHierarchyChanged() notification and |
147 // change the parent. | 148 // change the parent. |
148 host->Detach(); | 149 host->Detach(); |
149 #if defined(USE_AURA) | 150 #if defined(USE_AURA) |
150 // Two notifications are generated from removing the native view from the | 151 // Two notifications are generated from removing the native view from the |
151 // clipping window and then reparenting it to the root window. | 152 // clipping window and then reparenting it to the root window. |
152 EXPECT_EQ(2, test_view->notification_count()); | 153 EXPECT_EQ(2, test_view->notification_count()); |
153 #else | 154 #else |
154 EXPECT_EQ(1, test_view->notification_count()); | 155 EXPECT_EQ(1, test_view->notification_count()); |
155 #endif | 156 #endif |
156 EXPECT_NE(toplevel()->GetNativeView(), | 157 EXPECT_NE(toplevel()->GetNativeView(), |
157 GetNativeParent(child->GetNativeView())); | 158 GetNativeParent(child->GetNativeView())); |
158 test_view->ResetCount(); | 159 test_view->ResetCount(); |
159 | 160 |
160 // Attaching should send a NativeViewHierarchyChanged() notification and | 161 // Attaching should send a NativeViewHierarchyChanged() notification and |
161 // reset the parent. | 162 // reset the parent. |
162 host->Attach(child->GetNativeView()); | 163 host->Attach(child->GetNativeView()); |
163 EXPECT_EQ(1, test_view->notification_count()); | |
164 #if defined(USE_AURA) | 164 #if defined(USE_AURA) |
165 // There is a clipping window inserted above the native view that needs to be | 165 // There is a clipping window inserted above the native view that needs to be |
166 // accounted for when looking at the relationship between the native views. | 166 // accounted for when looking at the relationship between the native views. |
| 167 EXPECT_EQ(2, test_view->notification_count()); |
167 EXPECT_EQ(toplevel()->GetNativeView(), | 168 EXPECT_EQ(toplevel()->GetNativeView(), |
168 GetNativeParent(GetNativeParent(child->GetNativeView()))); | 169 GetNativeParent(GetNativeParent(child->GetNativeView()))); |
169 #else | 170 #else |
| 171 EXPECT_EQ(1, test_view->notification_count()); |
170 EXPECT_EQ(toplevel()->GetNativeView(), | 172 EXPECT_EQ(toplevel()->GetNativeView(), |
171 GetNativeParent(child->GetNativeView())); | 173 GetNativeParent(child->GetNativeView())); |
172 #endif | 174 #endif |
173 } | 175 } |
174 | 176 |
175 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 177 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
176 // (reparent) operations with correct parent changes. | 178 // (reparent) operations with correct parent changes. |
177 // This exercises the non-recursive code paths in | 179 // This exercises the non-recursive code paths in |
178 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 180 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
179 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 181 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 host0->ResetParentChanges(); | 296 host0->ResetParentChanges(); |
295 host1->ResetParentChanges(); | 297 host1->ResetParentChanges(); |
296 EXPECT_EQ(0, host0->num_parent_changes()); | 298 EXPECT_EQ(0, host0->num_parent_changes()); |
297 EXPECT_EQ(0, host1->num_parent_changes()); | 299 EXPECT_EQ(0, host1->num_parent_changes()); |
298 child0->GetContentsView()->AddChildView(view1); | 300 child0->GetContentsView()->AddChildView(view1); |
299 EXPECT_EQ(0, host0->num_parent_changes()); | 301 EXPECT_EQ(0, host0->num_parent_changes()); |
300 EXPECT_EQ(2, host1->num_parent_changes()); | 302 EXPECT_EQ(2, host1->num_parent_changes()); |
301 } | 303 } |
302 | 304 |
303 } // namespace views | 305 } // namespace views |
OLD | NEW |