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

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

Issue 24299004: Implement features in NativeViewHostAura for scroll end effect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responsed to sky's comments and finished tests Created 7 years, 2 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 | Annotate | Revision Log
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/window.h" 9 #include "ui/aura/window.h"
10 #include "ui/views/controls/native/native_view_host.h" 10 #include "ui/views/controls/native/native_view_host.h"
(...skipping 14 matching lines...) Expand all
25 } 25 }
26 26
27 NativeViewHost* host() { 27 NativeViewHost* host() {
28 return host_.get(); 28 return host_.get();
29 } 29 }
30 30
31 Widget* child() { 31 Widget* child() {
32 return child_.get(); 32 return child_.get();
33 } 33 }
34 34
35 aura::Window* clipping_window() {
36 return native_host()->clipping_window_;
37 }
38
39 Widget* toplevel() {
40 return toplevel_.get();
41 }
42
35 void CreateHost() { 43 void CreateHost() {
36 // Create the top level widget. 44 // Create the top level widget.
37 toplevel_.reset(new Widget); 45 toplevel_.reset(new Widget);
38 Widget::InitParams toplevel_params = 46 Widget::InitParams toplevel_params =
39 CreateParams(Widget::InitParams::TYPE_WINDOW); 47 CreateParams(Widget::InitParams::TYPE_WINDOW);
40 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 48 toplevel_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
41 toplevel_->Init(toplevel_params); 49 toplevel_->Init(toplevel_params);
42 50
43 // And the child widget. 51 // And the child widget.
44 View* test_view = new View; 52 View* test_view = new View;
45 child_.reset(new Widget); 53 child_.reset(new Widget);
46 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL); 54 Widget::InitParams child_params(Widget::InitParams::TYPE_CONTROL);
47 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 55 child_params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
48 child_params.parent = toplevel_->GetNativeView(); 56 child_params.parent = toplevel_->GetNativeView();
49 child_->Init(child_params); 57 child_->Init(child_params);
50 child_->SetContentsView(test_view); 58 child_->SetContentsView(test_view);
51 59
52 // Owned by |toplevel|. 60 // Owned by |toplevel|.
53 host_.reset(new NativeViewHost); 61 host_.reset(new NativeViewHost);
54 toplevel_->GetRootView()->AddChildView(host_.get()); 62 toplevel_->GetRootView()->AddChildView(host_.get());
55 host_->Attach(child_->GetNativeView()); 63 host_->Attach(child_->GetNativeView());
56 } 64 }
57 65
58 void DestroyHost() { 66 void DestroyHost() {
59 host_.reset(); 67 host_.reset();
60 } 68 }
61 69
70 gfx::Point CalculateNativeViewOrigin(gfx::Rect input_rect,
71 gfx::Rect native_rect) {
72 return native_host()->CalculateNativeViewOrigin(input_rect, native_rect);
73 }
74
62 private: 75 private:
63 scoped_ptr<Widget> toplevel_; 76 scoped_ptr<Widget> toplevel_;
64 scoped_ptr<NativeViewHost> host_; 77 scoped_ptr<NativeViewHost> host_;
65 scoped_ptr<Widget> child_; 78 scoped_ptr<Widget> child_;
66 79
67 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); 80 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest);
68 }; 81 };
69 82
70 // Verifies NativeViewHostAura stops observing native view on destruction. 83 // Verifies NativeViewHostAura stops observing native view on destruction.
71 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { 84 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) {
(...skipping 16 matching lines...) Expand all
88 host()->Detach(); 101 host()->Detach();
89 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); 102 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
90 103
91 host()->Attach(child_win); 104 host()->Attach(child_win);
92 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey)); 105 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey));
93 106
94 DestroyHost(); 107 DestroyHost();
95 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); 108 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
96 } 109 }
97 110
111 // Tests that the values being calculated by CalculateNativeViewOrigin are
112 // correct.
113 TEST_F(NativeViewHostAuraTest, CalculateNewNativeViewOrigin) {
114 CreateHost();
115
116 gfx::Rect clip_rect(0, 0, 50, 50);
117 gfx::Rect contents_rect(50, 50, 100, 100);
118
119 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
120 EXPECT_EQ(gfx::Point(0, 0),
121 CalculateNativeViewOrigin(clip_rect, contents_rect));
122
123 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTH);
124 EXPECT_EQ(gfx::Point(-25, 0),
125 CalculateNativeViewOrigin(clip_rect, contents_rect));
126
127 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHEAST);
128 EXPECT_EQ(gfx::Point(-50, 0),
129 CalculateNativeViewOrigin(clip_rect, contents_rect));
130
131 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_EAST);
132 EXPECT_EQ(gfx::Point(-50, -25),
133 CalculateNativeViewOrigin(clip_rect, contents_rect));
134
135 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
136 EXPECT_EQ(gfx::Point(-50, -50),
137 CalculateNativeViewOrigin(clip_rect, contents_rect));
138
139 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTH);
140 EXPECT_EQ(gfx::Point(-25, -50),
141 CalculateNativeViewOrigin(clip_rect, contents_rect));
142
143 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHWEST);
144 EXPECT_EQ(gfx::Point(0, -50),
145 CalculateNativeViewOrigin(clip_rect, contents_rect));
146
147 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_WEST);
148 EXPECT_EQ(gfx::Point(0, -25),
149 CalculateNativeViewOrigin(clip_rect, contents_rect));
150
151 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_CENTER);
152 EXPECT_EQ(gfx::Point(-25, -25),
153 CalculateNativeViewOrigin(clip_rect, contents_rect));
154
155 DestroyHost();
156 }
157
158 // Test that the fast resize path places the clipping and content windows were
159 // they are supposed to be.
160 TEST_F(NativeViewHostAuraTest, FastResizePath) {
161 CreateHost();
162 host()->set_fast_resize(false);
163 toplevel()->SetBounds(gfx::Rect(0, 0, 100, 100));
164 native_host()->ShowWidget(0, 0, 100, 100);
165 host()->set_fast_resize(true);
166
167 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
168 native_host()->ShowWidget(0, 0, 50, 50);
169 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
170 host()->native_view()->layer()->bounds());
171 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), clipping_window()->layer()->bounds());
172
173 host()->set_fast_resize(false);
174 native_host()->ShowWidget(0, 0, 100, 100);
175 host()->set_fast_resize(true);
176
177 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
178 EXPECT_EQ(gfx::Rect(0, 0, 100, 100),
179 host()->native_view()->layer()->bounds());
180 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), clipping_window()->layer()->bounds());
181
182 native_host()->ShowWidget(0, 0, 50, 50);
183 EXPECT_EQ(gfx::Rect(-50, -50, 100, 100),
184 host()->native_view()->layer()->bounds());
185 EXPECT_EQ(gfx::Rect(0, 0, 50, 50), clipping_window()->layer()->bounds());
186
187 DestroyHost();
188 }
189
98 } // namespace views 190 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698