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

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: Responded to sky's comments and added some testing 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // Owned by |toplevel|. 52 // Owned by |toplevel|.
53 host_.reset(new NativeViewHost); 53 host_.reset(new NativeViewHost);
54 toplevel_->GetRootView()->AddChildView(host_.get()); 54 toplevel_->GetRootView()->AddChildView(host_.get());
55 host_->Attach(child_->GetNativeView()); 55 host_->Attach(child_->GetNativeView());
56 } 56 }
57 57
58 void DestroyHost() { 58 void DestroyHost() {
59 host_.reset(); 59 host_.reset();
60 } 60 }
61 61
62 gfx::Point CalculateNewNativeViewOrigin(gfx::Rect input_rect,
63 gfx::Rect native_rect) {
64 return native_host()->CalculateNewNativeViewOrigin(input_rect, native_rect);
65 }
66
67 gfx::Point CalculateClipOrigin(gfx::Rect input_rect,
68 gfx::Rect native_rect) {
69 return native_host()->CalculateClipOrigin(input_rect, native_rect);
70 }
71
62 private: 72 private:
63 scoped_ptr<Widget> toplevel_; 73 scoped_ptr<Widget> toplevel_;
64 scoped_ptr<NativeViewHost> host_; 74 scoped_ptr<NativeViewHost> host_;
65 scoped_ptr<Widget> child_; 75 scoped_ptr<Widget> child_;
66 76
67 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest); 77 DISALLOW_COPY_AND_ASSIGN(NativeViewHostAuraTest);
68 }; 78 };
69 79
70 // Verifies NativeViewHostAura stops observing native view on destruction. 80 // Verifies NativeViewHostAura stops observing native view on destruction.
71 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) { 81 TEST_F(NativeViewHostAuraTest, StopObservingNativeViewOnDestruct) {
(...skipping 16 matching lines...) Expand all
88 host()->Detach(); 98 host()->Detach();
89 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); 99 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
90 100
91 host()->Attach(child_win); 101 host()->Attach(child_win);
92 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey)); 102 EXPECT_EQ(host(), child_win->GetProperty(views::kHostViewKey));
93 103
94 DestroyHost(); 104 DestroyHost();
95 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey)); 105 EXPECT_FALSE(child_win->GetProperty(views::kHostViewKey));
96 } 106 }
97 107
108 // Tests that the values being calculated by CalculateNewNativeViewOrigin are
109 // correct.
110 TEST_F(NativeViewHostAuraTest, CalculateNewNativeViewOrigin) {
111 CreateHost();
112
113 gfx::Rect clip_rect(50, 50, 50, 50);
114 gfx::Rect contents_rect(0, 0, 100, 100);
115
116 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
117 EXPECT_EQ(gfx::Point(50, 50),
118 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
119
120 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTH);
121 EXPECT_EQ(gfx::Point(25, 50),
122 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
123
124 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHEAST);
125 EXPECT_EQ(gfx::Point(0, 50),
126 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
127
128 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_EAST);
129 EXPECT_EQ(gfx::Point(0, 25),
130 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
131
132 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
133 EXPECT_EQ(gfx::Point(0, 0),
134 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
135
136 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTH);
137 EXPECT_EQ(gfx::Point(25, 0),
138 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
139
140 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHWEST);
141 EXPECT_EQ(gfx::Point(50, 0),
142 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
143
144 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_WEST);
145 EXPECT_EQ(gfx::Point(50, 25),
146 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
147
148 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_CENTER);
149 EXPECT_EQ(gfx::Point(25, 25),
150 CalculateNewNativeViewOrigin(clip_rect, contents_rect));
151 }
152
153 // Tests that the values being calculated by CalculateClipOrigin are
154 // correct.
155 TEST_F(NativeViewHostAuraTest, CalculateClipOrigin) {
156 CreateHost();
157
158 gfx::Rect clip_rect(50, 50, 50, 50);
159 gfx::Rect contents_rect(0, 0, 100, 100);
160
161 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHWEST);
162 contents_rect.set_origin(gfx::Point(50, 50));
163 EXPECT_EQ(gfx::Point(0,0),
164 CalculateClipOrigin(clip_rect, contents_rect));
165
166 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTH);
167 contents_rect.set_origin(gfx::Point(25, 50));
168 EXPECT_EQ(gfx::Point(-25, 0),
169 CalculateClipOrigin(clip_rect, contents_rect));
170
171 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_NORTHEAST);
172 contents_rect.set_origin(gfx::Point(0, 50));
173 EXPECT_EQ(gfx::Point(-50, 0),
174 CalculateClipOrigin(clip_rect, contents_rect));
175
176 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_EAST);
177 contents_rect.set_origin(gfx::Point(0, 25));
178 EXPECT_EQ(gfx::Point(-50, -25),
179 CalculateClipOrigin(clip_rect, contents_rect));
180
181 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHEAST);
182 contents_rect.set_origin(gfx::Point(0, 0));
183 EXPECT_EQ(gfx::Point(-50, -50),
184 CalculateClipOrigin(clip_rect, contents_rect));
185
186 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTH);
187 contents_rect.set_origin(gfx::Point(25, 0));
188 EXPECT_EQ(gfx::Point(-25, -50),
189 CalculateClipOrigin(clip_rect, contents_rect));
190
191 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_SOUTHWEST);
192 contents_rect.set_origin(gfx::Point(50, 0));
193 EXPECT_EQ(gfx::Point(0, -50),
194 CalculateClipOrigin(clip_rect, contents_rect));
195
196 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_WEST);
197 contents_rect.set_origin(gfx::Point(50, 25));
198 EXPECT_EQ(gfx::Point(0, -25),
199 CalculateClipOrigin(clip_rect, contents_rect));
200
201 host()->set_fast_resize_gravity(NativeViewHost::GRAVITY_CENTER);
202 contents_rect.set_origin(gfx::Point(25, 25));
203 EXPECT_EQ(gfx::Point(-25, -25),
204 CalculateClipOrigin(clip_rect, contents_rect));
205 }
206
98 } // namespace views 207 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698