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 #if defined(OS_WIN) && !defined(USE_AURA) | 7 #if defined(OS_WIN) && !defined(USE_AURA) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { | 141 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { |
142 // Create a child widget. | 142 // Create a child widget. |
143 NativeViewHierarchyChangedTestView* test_view = | 143 NativeViewHierarchyChangedTestView* test_view = |
144 new NativeViewHierarchyChangedTestView; | 144 new NativeViewHierarchyChangedTestView; |
145 NativeViewHost* host = new NativeViewHost; | 145 NativeViewHost* host = new NativeViewHost; |
146 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), | 146 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), |
147 toplevel()->GetRootView(), | 147 toplevel()->GetRootView(), |
148 test_view, | 148 test_view, |
149 host)); | 149 host)); |
150 | 150 |
| 151 #if defined(USE_AURA) |
| 152 // One notification is generated from inserting the clipping window into the |
| 153 // hierarchy. |
| 154 EXPECT_EQ(1, test_view->notification_count()); |
| 155 #else |
151 EXPECT_EQ(0, test_view->notification_count()); | 156 EXPECT_EQ(0, test_view->notification_count()); |
| 157 #endif |
152 test_view->ResetCount(); | 158 test_view->ResetCount(); |
153 | 159 |
154 // Detaching should send a NativeViewHierarchyChanged() notification and | 160 // Detaching should send a NativeViewHierarchyChanged() notification and |
155 // change the parent. | 161 // change the parent. |
156 host->Detach(); | 162 host->Detach(); |
157 EXPECT_EQ(1, test_view->notification_count()); | 163 EXPECT_EQ(1, test_view->notification_count()); |
158 EXPECT_NE(toplevel()->GetNativeView(), | 164 EXPECT_NE(toplevel()->GetNativeView(), |
159 GetNativeParent(child->GetNativeView())); | 165 GetNativeParent(child->GetNativeView())); |
160 test_view->ResetCount(); | 166 test_view->ResetCount(); |
161 | 167 |
162 // Attaching should send a NativeViewHierarchyChanged() notification and | 168 // Attaching should send a NativeViewHierarchyChanged() notification and |
163 // reset the parent. | 169 // reset the parent. |
164 host->Attach(child->GetNativeView()); | 170 host->Attach(child->GetNativeView()); |
165 EXPECT_EQ(1, test_view->notification_count()); | 171 EXPECT_EQ(1, test_view->notification_count()); |
| 172 #if defined(USE_AURA) |
| 173 // There is a clipping window inserted above the native view that needs to be |
| 174 // accounted for when looking at the relationship between the native views.. |
| 175 EXPECT_EQ(toplevel()->GetNativeView(), |
| 176 GetNativeParent(GetNativeParent(child->GetNativeView()))); |
| 177 #else |
166 EXPECT_EQ(toplevel()->GetNativeView(), | 178 EXPECT_EQ(toplevel()->GetNativeView(), |
167 GetNativeParent(child->GetNativeView())); | 179 GetNativeParent(child->GetNativeView())); |
| 180 #endif |
168 } | 181 } |
169 | 182 |
170 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 183 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
171 // (reparent) operations with correct parent changes. | 184 // (reparent) operations with correct parent changes. |
172 // This exercises the non-recursive code paths in | 185 // This exercises the non-recursive code paths in |
173 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 186 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
174 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 187 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
175 // Original tree: | 188 // Original tree: |
176 // toplevel | 189 // toplevel |
177 // +-- host0 (NativeViewHost) | 190 // +-- host0 (NativeViewHost) |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 host0->ResetParentChanges(); | 302 host0->ResetParentChanges(); |
290 host1->ResetParentChanges(); | 303 host1->ResetParentChanges(); |
291 EXPECT_EQ(0, host0->num_parent_changes()); | 304 EXPECT_EQ(0, host0->num_parent_changes()); |
292 EXPECT_EQ(0, host1->num_parent_changes()); | 305 EXPECT_EQ(0, host1->num_parent_changes()); |
293 child0->GetContentsView()->AddChildView(view1); | 306 child0->GetContentsView()->AddChildView(view1); |
294 EXPECT_EQ(0, host0->num_parent_changes()); | 307 EXPECT_EQ(0, host0->num_parent_changes()); |
295 EXPECT_EQ(2, host1->num_parent_changes()); | 308 EXPECT_EQ(2, host1->num_parent_changes()); |
296 } | 309 } |
297 | 310 |
298 } // namespace views | 311 } // namespace views |
OLD | NEW |