OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_aura.h" | 5 #include "ui/views/controls/native/native_view_host_aura.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/base/cursor/cursor.h" | 10 #include "ui/base/cursor/cursor.h" |
11 #include "ui/views/controls/native/native_view_host.h" | 11 #include "ui/views/controls/native/native_view_host.h" |
12 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
13 #include "ui/views/view.h" | 13 #include "ui/views/view.h" |
14 #include "ui/views/view_constants_aura.h" | 14 #include "ui/views/view_constants_aura.h" |
15 #include "ui/views/widget/widget.h" | 15 #include "ui/views/widget/widget.h" |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 // Testing wrapper of the NativeViewHost | |
20 class NativeViewHostTesting : public NativeViewHost { | |
21 public: | |
22 NativeViewHostTesting() {} | |
23 virtual ~NativeViewHostTesting() { destroyed_count_++; } | |
24 | |
25 static void ResetDestroyedCount() { destroyed_count_ = 0; } | |
26 | |
27 static int destroyed_count() { return destroyed_count_; } | |
28 | |
29 private: | |
30 static int destroyed_count_; | |
31 }; | |
sky
2014/06/05 15:49:01
DISALLOW_...
calamity
2014/06/06 08:13:44
Done.
| |
32 int NativeViewHostTesting::destroyed_count_ = 0; | |
33 | |
19 class NativeViewHostAuraTest : public ViewsTestBase { | 34 class NativeViewHostAuraTest : public ViewsTestBase { |
20 public: | 35 public: |
21 NativeViewHostAuraTest() { | 36 NativeViewHostAuraTest() { |
22 } | 37 } |
23 | 38 |
24 NativeViewHostAura* native_host() { | 39 NativeViewHostAura* native_host() { |
25 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get()); | 40 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get()); |
26 } | 41 } |
27 | 42 |
28 Widget* toplevel() { | 43 Widget* toplevel() { |
29 return toplevel_.get(); | 44 return toplevel_.get(); |
30 } | 45 } |
31 | 46 |
32 NativeViewHost* host() { | 47 NativeViewHost* host() { |
33 return host_.get(); | 48 return host_.get(); |
34 } | 49 } |
35 | 50 |
36 Widget* child() { | 51 Widget* child() { |
37 return child_.get(); | 52 return child_.get(); |
38 } | 53 } |
39 | 54 |
55 aura::Window* clipping_window() { return &(native_host()->clipping_window_); } | |
56 | |
40 void CreateHost() { | 57 void CreateHost() { |
41 // Create the top level widget. | 58 // Create the top level widget. |
42 toplevel_.reset(new Widget); | 59 toplevel_.reset(new Widget); |
43 Widget::InitParams toplevel_params = | 60 Widget::InitParams toplevel_params = |
44 CreateParams(Widget::InitParams::TYPE_WINDOW); | 61 CreateParams(Widget::InitParams::TYPE_WINDOW); |
45 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 62 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
46 toplevel_->Init(toplevel_params); | 63 toplevel_->Init(toplevel_params); |
47 | 64 |
48 // And the child widget. | 65 // And the child widget. |
49 View* test_view = new View; | 66 View* test_view = new View; |
50 child_.reset(new Widget); | 67 child_.reset(new Widget); |
51 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); | 68 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); |
52 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 69 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
53 child_params.parent = toplevel_->GetNativeView(); | 70 child_params.parent = toplevel_->GetNativeView(); |
54 child_->Init(child_params); | 71 child_->Init(child_params); |
55 child_->SetContentsView(test_view); | 72 child_->SetContentsView(test_view); |
56 | 73 |
57 // Owned by |toplevel|. | 74 // Owned by |toplevel|. |
58 host_.reset(new NativeViewHost); | 75 host_.reset(new NativeViewHostTesting); |
59 toplevel_->GetRootView()->AddChildView(host_.get()); | 76 toplevel_->GetRootView()->AddChildView(host_.get()); |
60 host_->Attach(child_->GetNativeView()); | 77 host_->Attach(child_->GetNativeView()); |
61 } | 78 } |
62 | 79 |
63 void DestroyHost() { | 80 void DestroyHost() { |
64 host_.reset(); | 81 host_.reset(); |
65 } | 82 } |
66 | 83 |
84 NativeViewHostTesting* ReleaseHost() { return host_.release(); } | |
85 | |
86 void DestroyTopLevel() { toplevel_.reset(); } | |
87 | |
67 private: | 88 private: |
68 scoped_ptr<Widget> toplevel_; | 89 scoped_ptr<Widget> toplevel_; |
69 scoped_ptr<NativeViewHost> host_; | 90 scoped_ptr<NativeViewHostTesting> host_; |
70 scoped_ptr<Widget> child_; | 91 scoped_ptr<Widget> child_; |
71 | 92 |
72 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); | 93 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); |
73 }; | 94 }; |
74 | 95 |
75 // Verifies NativeViewHostAura stops observing native view on destruction. | 96 // Verifies NativeViewHostAura stops observing native view on destruction. |
76 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { | 97 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { |
77 CreateHost(); | 98 CreateHost(); |
78 aura::Window* child_win = child()->GetNativeView(); | 99 aura::Window* child_win = child()->GetNativeView(); |
79 NativeViewHostAura* aura_host = native_host(); | 100 NativeViewHostAura* aura_host = native_host(); |
(...skipping 27 matching lines...) Expand all Loading... | |
107 toplevel()->SetCursor(ui::kCursorHand); | 128 toplevel()->SetCursor(ui::kCursorHand); |
108 child()->SetCursor(ui::kCursorWait); | 129 child()->SetCursor(ui::kCursorWait); |
109 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 130 ui::MouseEvent move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
110 gfx::Point(0, 0), 0, 0); | 131 gfx::Point(0, 0), 0, 0); |
111 | 132 |
112 EXPECT_EQ(ui::kCursorWait, host()->GetCursor(move_event).native_type()); | 133 EXPECT_EQ(ui::kCursorWait, host()->GetCursor(move_event).native_type()); |
113 | 134 |
114 DestroyHost(); | 135 DestroyHost(); |
115 } | 136 } |
116 | 137 |
138 // Test that the fast resize path places the clipping and content windows were | |
139 // they are supposed to be. | |
140 TEST_F(NativeViewHostAuraTest, FastResizePath) { | |
141 CreateHost(); | |
142 | |
143 host()->set_fast_resize(false); | |
144 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); | |
145 native_host()->ShowWidget(0, 0, 100, 100); | |
146 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | |
147 host()->native_view()->layer()->bounds().ToString()); | |
148 | |
149 host()->set_fast_resize(true); | |
150 native_host()->ShowWidget(10, 25, 50, 50); | |
151 EXPECT_EQ(gfx::Rect(0, 0, 100, 100).ToString(), | |
152 host()->native_view()->layer()->bounds().ToString()); | |
153 EXPECT_EQ(gfx::Rect(10, 25, 50, 50).ToString(), | |
154 clipping_window()->layer()->bounds().ToString()); | |
155 | |
156 DestroyHost(); | |
157 } | |
158 | |
159 // Test that destroying the top level widget before destroying the attached | |
160 // NativeViewHost works correctly. Specifically the associated NVH should be | |
161 // destroyed and there shouldn't be any errors. | |
162 TEST_F(NativeViewHostAuraTest, DestroyWidget) { | |
163 NativeViewHostTesting::ResetDestroyedCount(); | |
164 CreateHost(); | |
165 ReleaseHost(); | |
166 EXPECT_EQ(0, NativeViewHostTesting::destroyed_count()); | |
167 DestroyTopLevel(); | |
168 EXPECT_EQ(1, NativeViewHostTesting::destroyed_count()); | |
169 } | |
170 | |
117 } // namespace views | 171 } // namespace views |
OLD | NEW |