Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: ui/views/controls/native/native_view_host_aura_unittest.cc

Issue 530933002: MacViews: Implement NativeViewHostMac (take 3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: acceptsFirstResponder, cleanup strays Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/client/aura_constants.h" 9 #include "ui/aura/client/aura_constants.h"
10 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
11 #include "ui/base/cursor/cursor.h" 11 #include "ui/base/cursor/cursor.h"
12 #include "ui/views/controls/native/native_view_host.h" 12 #include "ui/views/controls/native/native_view_host.h"
13 #include "ui/views/test/views_test_base.h" 13 #include "ui/views/controls/native/native_view_host_test_base.h"
14 #include "ui/views/view.h" 14 #include "ui/views/view.h"
15 #include "ui/views/view_constants_aura.h" 15 #include "ui/views/view_constants_aura.h"
16 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
17 17
18 namespace views { 18 namespace views {
19 19
20 // Testing wrapper of the NativeViewHost
21 class NativeViewHostTesting : public NativeViewHost {
22 public:
23 NativeViewHostTesting() {}
24 virtual ~NativeViewHostTesting() { destroyed_count_++; }
25
26 static void ResetDestroyedCount() { destroyed_count_ = 0; }
27
28 static int destroyed_count() { return destroyed_count_; }
29
30 private:
31 static int destroyed_count_;
32
33 DISALLOW_COPY_AND_ASSIGN(NativeViewHostTesting);
34 };
35 int NativeViewHostTesting::destroyed_count_ = 0;
36
37 // Observer watching for window visibility and bounds change events. This is 20 // Observer watching for window visibility and bounds change events. This is
38 // used to verify that the child and clipping window operations are done in the 21 // used to verify that the child and clipping window operations are done in the
39 // right order. 22 // right order.
40 class NativeViewHostWindowObserver : public aura::WindowObserver { 23 class NativeViewHostWindowObserver : public aura::WindowObserver {
41 public: 24 public:
42 enum EventType { 25 enum EventType {
43 EVENT_NONE, 26 EVENT_NONE,
44 EVENT_SHOWN, 27 EVENT_SHOWN,
45 EVENT_HIDDEN, 28 EVENT_HIDDEN,
46 EVENT_BOUNDS_CHANGED, 29 EVENT_BOUNDS_CHANGED,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 events_.push_back(event); 67 events_.push_back(event);
85 } 68 }
86 69
87 private: 70 private:
88 std::vector<EventDetails> events_; 71 std::vector<EventDetails> events_;
89 gfx::Rect bounds_at_visibility_changed_; 72 gfx::Rect bounds_at_visibility_changed_;
90 73
91 DISALLOW_COPY_AND_ASSIGN(NativeViewHostWindowObserver); 74 DISALLOW_COPY_AND_ASSIGN(NativeViewHostWindowObserver);
92 }; 75 };
93 76
94 class NativeViewHostAuraTest : public ViewsTestBase { 77 class NativeViewHostAuraTest : public test::NativeViewHostTestBase {
95 public: 78 public:
96 NativeViewHostAuraTest() { 79 NativeViewHostAuraTest() {
97 } 80 }
98 81
99 NativeViewHostAura* native_host() { 82 NativeViewHostAura* native_host() {
100 return static_cast<NativeViewHostAura*>(host_->native_wrapper_.get()); 83 return static_cast<NativeViewHostAura*>(GetNativeWrapper());
101 }
102
103 Widget* toplevel() {
104 return toplevel_.get();
105 }
106
107 NativeViewHost* host() {
108 return host_.get();
109 } 84 }
110 85
111 Widget* child() { 86 Widget* child() {
112 return child_.get(); 87 return child_.get();
113 } 88 }
114 89
115 aura::Window* clipping_window() { return &(native_host()->clipping_window_); } 90 aura::Window* clipping_window() { return &(native_host()->clipping_window_); }
116 91
117 void CreateHost() { 92 void CreateHost() {
118 // Create the top level widget. 93 CreateTopLevel();
119 toplevel_.reset(new Widget); 94 CreateTestingHost();
120 Widget::InitParams toplevel_params = 95 child_.reset(CreateChildForHost(toplevel()->GetNativeView(),
121 CreateParams(Widget::InitParams::TYPE_WINDOW); 96 toplevel()->GetRootView(),
122 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 97 new View,
123 toplevel_->Init(toplevel_params); 98 host()));
124
125 // And the child widget.
126 child_.reset(new Widget);
127 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
128 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
129 child_params.parent = toplevel_->GetNativeView();
130 child_->Init(child_params);
131 child_->SetContentsView(new View);
132
133 // Owned by |toplevel|.
134 host_.reset(new NativeViewHostTesting);
135 toplevel_->GetRootView()->AddChildView(host_.get());
136 host_->Attach(child_->GetNativeView());
137 } 99 }
138 100
139 void DestroyHost() {
140 host_.reset();
141 }
142
143 NativeViewHostTesting* ReleaseHost() { return host_.release(); }
144
145 void DestroyTopLevel() { toplevel_.reset(); }
146
147 private: 101 private:
148 scoped_ptr<Widget> toplevel_;
149 scoped_ptr<NativeViewHostTesting> host_;
150 scoped_ptr<Widget> child_; 102 scoped_ptr<Widget> child_;
151 103
152 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); 104 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest);
153 }; 105 };
154 106
155 // Verifies NativeViewHostAura stops observing native view on destruction. 107 // Verifies NativeViewHostAura stops observing native view on destruction.
156 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { 108 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) {
157 CreateHost(); 109 CreateHost();
158 aura::Window* child_win = child()->GetNativeView(); 110 aura::Window* child_win = child()->GetNativeView();
159 NativeViewHostAura* aura_host = native_host(); 111 NativeViewHostAura* aura_host = native_host();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 152
201 EXPECT_EQ(ui::kCursorWait, host()->GetCursor(move_event).native_type()); 153 EXPECT_EQ(ui::kCursorWait, host()->GetCursor(move_event).native_type());
202 154
203 DestroyHost(); 155 DestroyHost();
204 } 156 }
205 157
206 // Test that destroying the top level widget before destroying the attached 158 // Test that destroying the top level widget before destroying the attached
207 // NativeViewHost works correctly. Specifically the associated NVH should be 159 // NativeViewHost works correctly. Specifically the associated NVH should be
208 // destroyed and there shouldn't be any errors. 160 // destroyed and there shouldn't be any errors.
209 TEST_F(NativeViewHostAuraTest, DestroyWidget) { 161 TEST_F(NativeViewHostAuraTest, DestroyWidget) {
210 NativeViewHostTesting::ResetDestroyedCount(); 162 ResetHostDestroyedCount();
211 CreateHost(); 163 CreateHost();
212 ReleaseHost(); 164 ReleaseHost();
213 EXPECT_EQ(0, NativeViewHostTesting::destroyed_count()); 165 EXPECT_EQ(0, host_destroyed_count());
214 DestroyTopLevel(); 166 DestroyTopLevel();
215 EXPECT_EQ(1, NativeViewHostTesting::destroyed_count()); 167 EXPECT_EQ(1, host_destroyed_count());
216 } 168 }
217 169
218 // Test that the fast resize path places the clipping and content windows were 170 // Test that the fast resize path places the clipping and content windows were
219 // they are supposed to be. 171 // they are supposed to be.
220 TEST_F(NativeViewHostAuraTest, FastResizePath) { 172 TEST_F(NativeViewHostAuraTest, FastResizePath) {
221 CreateHost(); 173 CreateHost();
222 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100)); 174 toplevel()->SetBounds(gfx::Rect(20, 20, 100, 100));
223 175
224 // Without fast resize, the clipping window should size to the native view 176 // Without fast resize, the clipping window should size to the native view
225 // with the native view positioned at the origin of the clipping window and 177 // with the native view positioned at the origin of the clipping window and
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 340
389 host()->SetVisible(false); 341 host()->SetVisible(false);
390 EXPECT_FALSE(clipping_window()->IsVisible()); 342 EXPECT_FALSE(clipping_window()->IsVisible());
391 EXPECT_FALSE(child()->IsVisible()); 343 EXPECT_FALSE(child()->IsVisible());
392 344
393 DestroyHost(); 345 DestroyHost();
394 DestroyTopLevel(); 346 DestroyTopLevel();
395 } 347 }
396 348
397 } // namespace views 349 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/native/native_view_host.h ('k') | ui/views/controls/native/native_view_host_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698