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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 // Verifies NativeViewHierarchyChanged is sent. | 127 // Verifies NativeViewHierarchyChanged is sent. |
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 #if defined(USE_AURA) |
| 138 // One notification is generated from inserting the native view into the |
| 139 // clipping window. |
| 140 EXPECT_EQ(1, test_view->notification_count()); |
| 141 #else |
138 EXPECT_EQ(0, test_view->notification_count()); | 142 EXPECT_EQ(0, test_view->notification_count()); |
| 143 #endif |
139 test_view->ResetCount(); | 144 test_view->ResetCount(); |
140 | 145 |
141 // Detaching should send a NativeViewHierarchyChanged() notification and | 146 // Detaching should send a NativeViewHierarchyChanged() notification and |
142 // change the parent. | 147 // change the parent. |
143 host->Detach(); | 148 host->Detach(); |
144 EXPECT_EQ(1, test_view->notification_count()); | 149 EXPECT_EQ(1, test_view->notification_count()); |
145 EXPECT_NE(toplevel()->GetNativeView(), | 150 EXPECT_NE(toplevel()->GetNativeView(), |
146 GetNativeParent(child->GetNativeView())); | 151 GetNativeParent(child->GetNativeView())); |
147 test_view->ResetCount(); | 152 test_view->ResetCount(); |
148 | 153 |
149 // Attaching should send a NativeViewHierarchyChanged() notification and | 154 // Attaching should send a NativeViewHierarchyChanged() notification and |
150 // reset the parent. | 155 // reset the parent. |
151 host->Attach(child->GetNativeView()); | 156 host->Attach(child->GetNativeView()); |
152 EXPECT_EQ(1, test_view->notification_count()); | 157 EXPECT_EQ(1, test_view->notification_count()); |
| 158 #if defined(USE_AURA) |
| 159 // There is a clipping window inserted above the native view that needs to be |
| 160 // accounted for when looking at the relationship between the native views. |
| 161 EXPECT_EQ(toplevel()->GetNativeView(), |
| 162 GetNativeParent(GetNativeParent(child->GetNativeView()))); |
| 163 #else |
153 EXPECT_EQ(toplevel()->GetNativeView(), | 164 EXPECT_EQ(toplevel()->GetNativeView(), |
154 GetNativeParent(child->GetNativeView())); | 165 GetNativeParent(child->GetNativeView())); |
| 166 #endif |
155 } | 167 } |
156 | 168 |
157 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 169 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
158 // (reparent) operations with correct parent changes. | 170 // (reparent) operations with correct parent changes. |
159 // This exercises the non-recursive code paths in | 171 // This exercises the non-recursive code paths in |
160 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 172 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
161 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 173 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
162 // Original tree: | 174 // Original tree: |
163 // toplevel | 175 // toplevel |
164 // +-- host0 (NativeViewHost) | 176 // +-- host0 (NativeViewHost) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 host0->ResetParentChanges(); | 288 host0->ResetParentChanges(); |
277 host1->ResetParentChanges(); | 289 host1->ResetParentChanges(); |
278 EXPECT_EQ(0, host0->num_parent_changes()); | 290 EXPECT_EQ(0, host0->num_parent_changes()); |
279 EXPECT_EQ(0, host1->num_parent_changes()); | 291 EXPECT_EQ(0, host1->num_parent_changes()); |
280 child0->GetContentsView()->AddChildView(view1); | 292 child0->GetContentsView()->AddChildView(view1); |
281 EXPECT_EQ(0, host0->num_parent_changes()); | 293 EXPECT_EQ(0, host0->num_parent_changes()); |
282 EXPECT_EQ(2, host1->num_parent_changes()); | 294 EXPECT_EQ(2, host1->num_parent_changes()); |
283 } | 295 } |
284 | 296 |
285 } // namespace views | 297 } // namespace views |
OLD | NEW |