| 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(); |
| 163 #if defined(USE_AURA) |
| 164 // The clipping window is removed on detach, so there is an extra hiearchy |
| 165 // change. |
| 166 EXPECT_EQ(2, test_view->notification_count()); |
| 167 #else |
| 157 EXPECT_EQ(1, test_view->notification_count()); | 168 EXPECT_EQ(1, test_view->notification_count()); |
| 169 #endif |
| 158 EXPECT_NE(toplevel()->GetNativeView(), | 170 EXPECT_NE(toplevel()->GetNativeView(), |
| 159 GetNativeParent(child->GetNativeView())); | 171 GetNativeParent(child->GetNativeView())); |
| 160 test_view->ResetCount(); | 172 test_view->ResetCount(); |
| 161 | 173 |
| 162 // Attaching should send a NativeViewHierarchyChanged() notification and | 174 // Attaching should send a NativeViewHierarchyChanged() notification and |
| 163 // reset the parent. | 175 // reset the parent. |
| 164 host->Attach(child->GetNativeView()); | 176 host->Attach(child->GetNativeView()); |
| 165 EXPECT_EQ(1, test_view->notification_count()); | 177 EXPECT_EQ(1, test_view->notification_count()); |
| 178 #if defined(USE_AURA) |
| 179 // There is a clipping window inserted above the native view that needs to be |
| 180 // accounted for when looking at the relationship between the native views.. |
| 181 EXPECT_EQ(toplevel()->GetNativeView(), |
| 182 GetNativeParent(GetNativeParent(child->GetNativeView()))); |
| 183 #else |
| 166 EXPECT_EQ(toplevel()->GetNativeView(), | 184 EXPECT_EQ(toplevel()->GetNativeView(), |
| 167 GetNativeParent(child->GetNativeView())); | 185 GetNativeParent(child->GetNativeView())); |
| 186 #endif |
| 168 } | 187 } |
| 169 | 188 |
| 170 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 189 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
| 171 // (reparent) operations with correct parent changes. | 190 // (reparent) operations with correct parent changes. |
| 172 // This exercises the non-recursive code paths in | 191 // This exercises the non-recursive code paths in |
| 173 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 192 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
| 174 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 193 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
| 175 // Original tree: | 194 // Original tree: |
| 176 // toplevel | 195 // toplevel |
| 177 // +-- host0 (NativeViewHost) | 196 // +-- host0 (NativeViewHost) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 host0->ResetParentChanges(); | 308 host0->ResetParentChanges(); |
| 290 host1->ResetParentChanges(); | 309 host1->ResetParentChanges(); |
| 291 EXPECT_EQ(0, host0->num_parent_changes()); | 310 EXPECT_EQ(0, host0->num_parent_changes()); |
| 292 EXPECT_EQ(0, host1->num_parent_changes()); | 311 EXPECT_EQ(0, host1->num_parent_changes()); |
| 293 child0->GetContentsView()->AddChildView(view1); | 312 child0->GetContentsView()->AddChildView(view1); |
| 294 EXPECT_EQ(0, host0->num_parent_changes()); | 313 EXPECT_EQ(0, host0->num_parent_changes()); |
| 295 EXPECT_EQ(2, host1->num_parent_changes()); | 314 EXPECT_EQ(2, host1->num_parent_changes()); |
| 296 } | 315 } |
| 297 | 316 |
| 298 } // namespace views | 317 } // namespace views |
| OLD | NEW |