| 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 <memory> |
| 8 |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 10 #include "ui/views/controls/native/native_view_host_test_base.h" | 11 #include "ui/views/controls/native/native_view_host_test_base.h" |
| 11 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
| 12 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
| 13 | 14 |
| 14 namespace views { | 15 namespace views { |
| 15 | 16 |
| 16 class NativeViewHostTest : public test::NativeViewHostTestBase { | 17 class NativeViewHostTest : public test::NativeViewHostTestBase { |
| 17 public: | 18 public: |
| 18 NativeViewHostTest() { | 19 NativeViewHostTest() { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 }; | 92 }; |
| 92 | 93 |
| 93 } // namespace | 94 } // namespace |
| 94 | 95 |
| 95 // Verifies NativeViewHierarchyChanged is sent. | 96 // Verifies NativeViewHierarchyChanged is sent. |
| 96 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { | 97 TEST_F(NativeViewHostTest, NativeViewHierarchyChanged) { |
| 97 // Create a child widget. | 98 // Create a child widget. |
| 98 NativeViewHierarchyChangedTestView* test_view = | 99 NativeViewHierarchyChangedTestView* test_view = |
| 99 new NativeViewHierarchyChangedTestView; | 100 new NativeViewHierarchyChangedTestView; |
| 100 NativeViewHost* host = new NativeViewHost; | 101 NativeViewHost* host = new NativeViewHost; |
| 101 scoped_ptr<Widget> child(CreateChildForHost(toplevel()->GetNativeView(), | 102 std::unique_ptr<Widget> child(CreateChildForHost( |
| 102 toplevel()->GetRootView(), | 103 toplevel()->GetNativeView(), toplevel()->GetRootView(), test_view, host)); |
| 103 test_view, | |
| 104 host)); | |
| 105 #if defined(USE_AURA) | 104 #if defined(USE_AURA) |
| 106 // Two notifications are generated from inserting the native view into the | 105 // Two notifications are generated from inserting the native view into the |
| 107 // clipping window and then inserting the clipping window into the root | 106 // clipping window and then inserting the clipping window into the root |
| 108 // window. | 107 // window. |
| 109 EXPECT_EQ(2, test_view->notification_count()); | 108 EXPECT_EQ(2, test_view->notification_count()); |
| 110 #else | 109 #else |
| 111 EXPECT_EQ(0, test_view->notification_count()); | 110 EXPECT_EQ(0, test_view->notification_count()); |
| 112 #endif | 111 #endif |
| 113 test_view->ResetCount(); | 112 test_view->ResetCount(); |
| 114 | 113 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // +-- host0 (NativeViewHost) | 151 // +-- host0 (NativeViewHost) |
| 153 // +-- child0 (Widget, attached to host0) | 152 // +-- child0 (Widget, attached to host0) |
| 154 // +-- test_host (ViewHierarchyChangedTestHost) | 153 // +-- test_host (ViewHierarchyChangedTestHost) |
| 155 // +-- test_child (Widget, attached to test_host) | 154 // +-- test_child (Widget, attached to test_host) |
| 156 // +-- host1 (NativeViewHost) | 155 // +-- host1 (NativeViewHost) |
| 157 // +-- child1 (Widget, attached to host1) | 156 // +-- child1 (Widget, attached to host1) |
| 158 | 157 |
| 159 // Add two children widgets attached to a NativeViewHost, and a test | 158 // Add two children widgets attached to a NativeViewHost, and a test |
| 160 // grandchild as child widget of host0. | 159 // grandchild as child widget of host0. |
| 161 NativeViewHost* host0 = new NativeViewHost; | 160 NativeViewHost* host0 = new NativeViewHost; |
| 162 scoped_ptr<Widget> child0(CreateChildForHost(toplevel()->GetNativeView(), | 161 std::unique_ptr<Widget> child0(CreateChildForHost( |
| 163 toplevel()->GetRootView(), | 162 toplevel()->GetNativeView(), toplevel()->GetRootView(), new View, host0)); |
| 164 new View, | |
| 165 host0)); | |
| 166 NativeViewHost* host1 = new NativeViewHost; | 163 NativeViewHost* host1 = new NativeViewHost; |
| 167 scoped_ptr<Widget> child1(CreateChildForHost(toplevel()->GetNativeView(), | 164 std::unique_ptr<Widget> child1(CreateChildForHost( |
| 168 toplevel()->GetRootView(), | 165 toplevel()->GetNativeView(), toplevel()->GetRootView(), new View, host1)); |
| 169 new View, | |
| 170 host1)); | |
| 171 ViewHierarchyChangedTestHost* test_host = new ViewHierarchyChangedTestHost; | 166 ViewHierarchyChangedTestHost* test_host = new ViewHierarchyChangedTestHost; |
| 172 scoped_ptr<Widget> test_child(CreateChildForHost(host0->native_view(), | 167 std::unique_ptr<Widget> test_child( |
| 173 host0, | 168 CreateChildForHost(host0->native_view(), host0, new View, test_host)); |
| 174 new View, | |
| 175 test_host)); | |
| 176 | 169 |
| 177 // Remove test_host from host0, expect 1 parent change. | 170 // Remove test_host from host0, expect 1 parent change. |
| 178 test_host->ResetParentChanges(); | 171 test_host->ResetParentChanges(); |
| 179 EXPECT_EQ(0, test_host->num_parent_changes()); | 172 EXPECT_EQ(0, test_host->num_parent_changes()); |
| 180 host0->RemoveChildView(test_host); | 173 host0->RemoveChildView(test_host); |
| 181 EXPECT_EQ(1, test_host->num_parent_changes()); | 174 EXPECT_EQ(1, test_host->num_parent_changes()); |
| 182 | 175 |
| 183 // Add test_host back to host0, expect 1 parent change. | 176 // Add test_host back to host0, expect 1 parent change. |
| 184 test_host->ResetParentChanges(); | 177 test_host->ResetParentChanges(); |
| 185 EXPECT_EQ(0, test_host->num_parent_changes()); | 178 EXPECT_EQ(0, test_host->num_parent_changes()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 // +-- child1 (Widget, attached to host1) | 210 // +-- child1 (Widget, attached to host1) |
| 218 | 211 |
| 219 // Add two children views. | 212 // Add two children views. |
| 220 View* view0 = new View; | 213 View* view0 = new View; |
| 221 toplevel()->GetRootView()->AddChildView(view0); | 214 toplevel()->GetRootView()->AddChildView(view0); |
| 222 View* view1 = new View; | 215 View* view1 = new View; |
| 223 toplevel()->GetRootView()->AddChildView(view1); | 216 toplevel()->GetRootView()->AddChildView(view1); |
| 224 | 217 |
| 225 // To each child view, add a child widget. | 218 // To each child view, add a child widget. |
| 226 ViewHierarchyChangedTestHost* host0 = new ViewHierarchyChangedTestHost; | 219 ViewHierarchyChangedTestHost* host0 = new ViewHierarchyChangedTestHost; |
| 227 scoped_ptr<Widget> child0(CreateChildForHost(toplevel()->GetNativeView(), | 220 std::unique_ptr<Widget> child0( |
| 228 view0, | 221 CreateChildForHost(toplevel()->GetNativeView(), view0, new View, host0)); |
| 229 new View, | |
| 230 host0)); | |
| 231 ViewHierarchyChangedTestHost* host1 = new ViewHierarchyChangedTestHost; | 222 ViewHierarchyChangedTestHost* host1 = new ViewHierarchyChangedTestHost; |
| 232 scoped_ptr<Widget> child1(CreateChildForHost(toplevel()->GetNativeView(), | 223 std::unique_ptr<Widget> child1( |
| 233 view1, | 224 CreateChildForHost(toplevel()->GetNativeView(), view1, new View, host1)); |
| 234 new View, | |
| 235 host1)); | |
| 236 | 225 |
| 237 // Remove view0 from top level, expect 1 parent change. | 226 // Remove view0 from top level, expect 1 parent change. |
| 238 host0->ResetParentChanges(); | 227 host0->ResetParentChanges(); |
| 239 EXPECT_EQ(0, host0->num_parent_changes()); | 228 EXPECT_EQ(0, host0->num_parent_changes()); |
| 240 toplevel()->GetRootView()->RemoveChildView(view0); | 229 toplevel()->GetRootView()->RemoveChildView(view0); |
| 241 EXPECT_EQ(1, host0->num_parent_changes()); | 230 EXPECT_EQ(1, host0->num_parent_changes()); |
| 242 | 231 |
| 243 // Add view0 back to top level, expect 1 parent change. | 232 // Add view0 back to top level, expect 1 parent change. |
| 244 host0->ResetParentChanges(); | 233 host0->ResetParentChanges(); |
| 245 EXPECT_EQ(0, host0->num_parent_changes()); | 234 EXPECT_EQ(0, host0->num_parent_changes()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 264 host0->ResetParentChanges(); | 253 host0->ResetParentChanges(); |
| 265 host1->ResetParentChanges(); | 254 host1->ResetParentChanges(); |
| 266 EXPECT_EQ(0, host0->num_parent_changes()); | 255 EXPECT_EQ(0, host0->num_parent_changes()); |
| 267 EXPECT_EQ(0, host1->num_parent_changes()); | 256 EXPECT_EQ(0, host1->num_parent_changes()); |
| 268 child0->GetContentsView()->AddChildView(view1); | 257 child0->GetContentsView()->AddChildView(view1); |
| 269 EXPECT_EQ(0, host0->num_parent_changes()); | 258 EXPECT_EQ(0, host0->num_parent_changes()); |
| 270 EXPECT_EQ(2, host1->num_parent_changes()); | 259 EXPECT_EQ(2, host1->num_parent_changes()); |
| 271 } | 260 } |
| 272 | 261 |
| 273 } // namespace views | 262 } // namespace views |
| OLD | NEW |