| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/debug/stack_trace.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "ui/views/test/views_test_base.h" | 14 #include "ui/views/test/views_test_base.h" |
| 14 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
| 15 | 16 |
| 16 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
| 17 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 namespace views { | 21 namespace views { |
| 21 | 22 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { | 142 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { |
| 142 // Create a child widget. | 143 // Create a child widget. |
| 143 NativeViewHierarchyChangedTestView* test_view = | 144 NativeViewHierarchyChangedTestView* test_view = |
| 144 new NativeViewHierarchyChangedTestView; | 145 new NativeViewHierarchyChangedTestView; |
| 145 NativeViewHost* host = new NativeViewHost; | 146 NativeViewHost* host = new NativeViewHost; |
| 146 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), | 147 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), |
| 147 toplevel()->GetRootView(), | 148 toplevel()->GetRootView(), |
| 148 test_view, | 149 test_view, |
| 149 host)); | 150 host)); |
| 150 | 151 |
| 152 #if defined(USE_AURA) |
| 153 // One notification is generated from inserting the clipping window into the |
| 154 // hierarchy. |
| 155 EXPECT_EQ(1, test_view->notification_count()); |
| 156 #else |
| 151 EXPECT_EQ(0, test_view->notification_count()); | 157 EXPECT_EQ(0, test_view->notification_count()); |
| 158 #endif |
| 152 test_view->ResetCount(); | 159 test_view->ResetCount(); |
| 153 | 160 |
| 154 // Detaching should send a NativeViewHierarchyChanged() notification and | 161 // Detaching should send a NativeViewHierarchyChanged() notification and |
| 155 // change the parent. | 162 // change the parent. |
| 156 host->Detach(); | 163 host->Detach(); |
| 164 #if defined(USE_AURA) |
| 165 // The clipping window is removed on detach, so there is an extra hiearchy |
| 166 // change. |
| 167 EXPECT_EQ(2, test_view->notification_count()); |
| 168 #else |
| 157 EXPECT_EQ(1, test_view->notification_count()); | 169 EXPECT_EQ(1, test_view->notification_count()); |
| 170 #endif |
| 158 EXPECT_NE(toplevel()->GetNativeView(), | 171 EXPECT_NE(toplevel()->GetNativeView(), |
| 159 GetNativeParent(child->GetNativeView())); | 172 GetNativeParent(child->GetNativeView())); |
| 160 test_view->ResetCount(); | 173 test_view->ResetCount(); |
| 161 | 174 |
| 162 // Attaching should send a NativeViewHierarchyChanged() notification and | 175 // Attaching should send a NativeViewHierarchyChanged() notification and |
| 163 // reset the parent. | 176 // reset the parent. |
| 164 host->Attach(child->GetNativeView()); | 177 host->Attach(child->GetNativeView()); |
| 165 EXPECT_EQ(1, test_view->notification_count()); | 178 EXPECT_EQ(1, test_view->notification_count()); |
| 179 #if defined(USE_AURA) |
| 180 // There is a clipping window inserted above the native view that needs to be |
| 181 // accounted for when looking at the relationship between the native views.. |
| 182 EXPECT_EQ(toplevel()->GetNativeView(), |
| 183 GetNativeParent(GetNativeParent(child->GetNativeView()))); |
| 184 #else |
| 166 EXPECT_EQ(toplevel()->GetNativeView(), | 185 EXPECT_EQ(toplevel()->GetNativeView(), |
| 167 GetNativeParent(child->GetNativeView())); | 186 GetNativeParent(child->GetNativeView())); |
| 187 #endif |
| 168 } | 188 } |
| 169 | 189 |
| 170 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move | 190 // Verifies ViewHierarchyChanged handles NativeViewHost remove, add and move |
| 171 // (reparent) operations with correct parent changes. | 191 // (reparent) operations with correct parent changes. |
| 172 // This exercises the non-recursive code paths in | 192 // This exercises the non-recursive code paths in |
| 173 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). | 193 // View::PropagateRemoveNotifications() and View::PropagateAddNotifications(). |
| 174 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { | 194 TEST_F(NativeViewHostTest, ViewHierarchyChangedForHost) { |
| 175 // Original tree: | 195 // Original tree: |
| 176 // toplevel | 196 // toplevel |
| 177 // +-- host0 (NativeViewHost) | 197 // +-- host0 (NativeViewHost) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 host0->ResetParentChanges(); | 309 host0->ResetParentChanges(); |
| 290 host1->ResetParentChanges(); | 310 host1->ResetParentChanges(); |
| 291 EXPECT_EQ(0, host0->num_parent_changes()); | 311 EXPECT_EQ(0, host0->num_parent_changes()); |
| 292 EXPECT_EQ(0, host1->num_parent_changes()); | 312 EXPECT_EQ(0, host1->num_parent_changes()); |
| 293 child0->GetContentsView()->AddChildView(view1); | 313 child0->GetContentsView()->AddChildView(view1); |
| 294 EXPECT_EQ(0, host0->num_parent_changes()); | 314 EXPECT_EQ(0, host0->num_parent_changes()); |
| 295 EXPECT_EQ(2, host1->num_parent_changes()); | 315 EXPECT_EQ(2, host1->num_parent_changes()); |
| 296 } | 316 } |
| 297 | 317 |
| 298 } // namespace views | 318 } // namespace views |
| OLD | NEW |