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/controls/native/native_view_host_test_base.h" |
10 #include "ui/views/test/views_test_base.h" | 11 #include "ui/views/test/views_test_base.h" |
11 #include "ui/views/widget/widget.h" | 12 #include "ui/views/widget/widget.h" |
12 | 13 |
13 namespace views { | 14 namespace views { |
14 | 15 |
15 class NativeViewHostTest : public ViewsTestBase { | 16 class NativeViewHostTest : public test::NativeViewHostTestBase { |
16 public: | 17 public: |
17 NativeViewHostTest() { | 18 NativeViewHostTest() { |
18 } | 19 } |
19 | 20 |
20 virtual void SetUp() OVERRIDE { | 21 virtual void SetUp() OVERRIDE { |
21 ViewsTestBase::SetUp(); | 22 ViewsTestBase::SetUp(); |
22 | 23 CreateTopLevel(); |
23 // Create the top level widget. | |
24 toplevel_.reset(new Widget); | |
25 Widget::InitParams toplevel_params = | |
26 CreateParams(Widget::InitParams::TYPE_WINDOW); | |
27 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
28 toplevel_->Init(toplevel_params); | |
29 } | |
30 | |
31 // Create a child widget whose native parent is |native_parent_view|, uses | |
32 // |contents_view|, and is attached to |host| which is added as a child to | |
33 // |parent_view|. | |
34 Widget* CreateChildForHost(gfx::NativeView native_parent_view, | |
35 View* parent_view, | |
36 View* contents_view, | |
37 NativeViewHost* host) { | |
38 Widget* child = new Widget; | |
39 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | |
40 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
41 child_params.parent = native_parent_view; | |
42 child->Init(child_params); | |
43 child->SetContentsView(contents_view); | |
44 | |
45 // Owned by |parent_view|. | |
46 parent_view->AddChildView(host); | |
47 host->Attach(child->GetNativeView()); | |
48 | |
49 return child; | |
50 } | |
51 | |
52 Widget* toplevel() { | |
53 return toplevel_.get(); | |
54 } | 24 } |
55 | 25 |
56 private: | 26 private: |
57 scoped_ptr<Widget> toplevel_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(NativeViewHostTest); | 27 DISALLOW_COPY_AND_ASSIGN(NativeViewHostTest); |
60 }; | 28 }; |
61 | 29 |
62 namespace { | 30 namespace { |
63 | 31 |
64 // View implementation used by NativeViewHierarchyChanged to count number of | 32 // View implementation used by NativeViewHierarchyChanged to count number of |
65 // times NativeViewHierarchyChanged() is invoked. | 33 // times NativeViewHierarchyChanged() is invoked. |
66 class NativeViewHierarchyChangedTestView : public View { | 34 class NativeViewHierarchyChangedTestView : public View { |
67 public: | 35 public: |
68 NativeViewHierarchyChangedTestView() : notification_count_(0) { | 36 NativeViewHierarchyChangedTestView() : notification_count_(0) { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 host0->ResetParentChanges(); | 264 host0->ResetParentChanges(); |
297 host1->ResetParentChanges(); | 265 host1->ResetParentChanges(); |
298 EXPECT_EQ(0, host0->num_parent_changes()); | 266 EXPECT_EQ(0, host0->num_parent_changes()); |
299 EXPECT_EQ(0, host1->num_parent_changes()); | 267 EXPECT_EQ(0, host1->num_parent_changes()); |
300 child0->GetContentsView()->AddChildView(view1); | 268 child0->GetContentsView()->AddChildView(view1); |
301 EXPECT_EQ(0, host0->num_parent_changes()); | 269 EXPECT_EQ(0, host0->num_parent_changes()); |
302 EXPECT_EQ(2, host1->num_parent_changes()); | 270 EXPECT_EQ(2, host1->num_parent_changes()); |
303 } | 271 } |
304 | 272 |
305 } // namespace views | 273 } // namespace views |
OLD | NEW |