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

Side by Side Diff: ui/views/controls/scroll_view_unittest.cc

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Combined rebase Created 4 years, 4 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) 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/scroll_view.h" 5 #include "ui/views/controls/scroll_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/run_loop.h"
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/views/border.h" 10 #include "ui/views/border.h"
11 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
12 #include "ui/views/controls/scrollbar/native_scroll_bar.h"
13 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
10 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" 14 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
11 #include "ui/views/test/test_views.h" 15 #include "ui/views/test/test_views.h"
16 #include "ui/views/test/widget_test.h"
12 17
13 #if defined(OS_MACOSX) 18 #if defined(OS_MACOSX)
14 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" 19 #include "ui/base/test/scoped_preferred_scroller_style_mac.h"
15 #endif 20 #endif
16 21
22 enum ScrollBarOrientation { HORIZONTAL, VERTICAL };
23
17 namespace views { 24 namespace views {
25 namespace test {
26
27 class ScrollViewTestApi {
28 public:
29 explicit ScrollViewTestApi(ScrollView* scroll_view)
30 : scroll_view_(scroll_view) {}
31
32 BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) {
33 ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_
34 : scroll_view_->horiz_sb_;
35 if (scroll_bar->GetClassName() == NativeScrollBar::kViewClassName) {
36 return static_cast<NativeScrollBarViews*>(
37 static_cast<NativeScrollBar*>(scroll_bar)->native_wrapper_);
38 }
39 return static_cast<BaseScrollBar*>(scroll_bar);
40 }
41
42 const base::Timer& GetScrollBarTimer(ScrollBarOrientation orientation) {
43 return GetBaseScrollBar(orientation)->repeater_.timer_for_testing();
44 }
45
46 BaseScrollBarThumb* GetScrollBarThumb(ScrollBarOrientation orientation) {
47 return GetBaseScrollBar(orientation)->thumb_;
48 }
49
50 gfx::Point IntegralViewOffset() {
51 return gfx::Point() - gfx::ScrollOffsetToFlooredVector2d(CurrentOffset());
52 }
53
54 gfx::ScrollOffset CurrentOffset() { return scroll_view_->CurrentOffset(); }
55
56 View* corner_view() { return scroll_view_->corner_view_; }
57 View* contents_viewport() { return scroll_view_->contents_viewport_; }
58
59 private:
60 ScrollView* scroll_view_;
61
62 DISALLOW_COPY_AND_ASSIGN(ScrollViewTestApi);
63 };
64
65 } // namespace test
18 66
19 namespace { 67 namespace {
20 68
21 const int kWidth = 100; 69 const int kWidth = 100;
22 const int kMinHeight = 50; 70 const int kMinHeight = 50;
23 const int kMaxHeight = 100; 71 const int kMaxHeight = 100;
24 72
25 enum ScrollBarOrientation { HORIZONTAL, VERTICAL };
26
27 // View implementation that allows setting the preferred size. 73 // View implementation that allows setting the preferred size.
28 class CustomView : public View { 74 class CustomView : public View {
29 public: 75 public:
30 CustomView() {} 76 CustomView() {}
31 77
32 void SetPreferredSize(const gfx::Size& size) { 78 void SetPreferredSize(const gfx::Size& size) {
33 preferred_size_ = size; 79 preferred_size_ = size;
34 PreferredSizeChanged(); 80 PreferredSizeChanged();
35 } 81 }
36 82
(...skipping 23 matching lines...) Expand all
60 ? scroll_view.horizontal_scroll_bar() 106 ? scroll_view.horizontal_scroll_bar()
61 : scroll_view.vertical_scroll_bar(); 107 : scroll_view.vertical_scroll_bar();
62 if (should_be_visible) { 108 if (should_be_visible) {
63 ASSERT_TRUE(scrollbar); 109 ASSERT_TRUE(scrollbar);
64 EXPECT_TRUE(scrollbar->visible()); 110 EXPECT_TRUE(scrollbar->visible());
65 } else { 111 } else {
66 EXPECT_TRUE(!scrollbar || !scrollbar->visible()); 112 EXPECT_TRUE(!scrollbar || !scrollbar->visible());
67 } 113 }
68 } 114 }
69 115
116 ui::MouseEvent TestLeftMouseAt(const gfx::Point& location, ui::EventType type) {
117 return ui::MouseEvent(type, location, location, base::TimeTicks(),
118 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
119 }
120
70 } // namespace 121 } // namespace
71 122
123 using test::ScrollViewTestApi;
124
125 // Test harness that includes a Widget to help test ui::Event handling.
126 class WidgetScrollViewTest : public test::WidgetTest {
127 public:
128 const int kDefaultHeight = 100;
129 const int kDefaultWidth = 100;
130
131 WidgetScrollViewTest() {
132 #if defined(OS_MACOSX)
133 // Disable scrollbar hiding (i.e. disable overlay scrollbars) by default.
134 scroller_style_.reset(new ui::test::ScopedPreferredScrollerStyle(false));
135 #endif
136 }
137
138 // Adds a ScrollView with a contents view of the given |size| and does layout.
139 ScrollView* AddScrollViewWithContentSize(const gfx::Size& contents_size) {
140 const gfx::Rect default_bounds(50, 50, kDefaultWidth, kDefaultHeight);
141 widget_ = CreateTopLevelFramelessPlatformWidget();
142
143 ScrollView* scroll_view = new ScrollView();
144 View* contents = new View;
145 scroll_view->SetContents(contents);
146 contents->SetSize(contents_size);
147
148 widget_->SetBounds(default_bounds);
149 widget_->Show();
150
151 widget_->SetContentsView(scroll_view);
152 scroll_view->Layout();
153
154 // Ensure the Compositor has committed layer changes before attempting to
155 // use them for impl-side scrolling.
156 base::RunLoop().RunUntilIdle();
157 return scroll_view;
158 }
159
160 // testing::Test:
161 void TearDown() override {
162 if (widget_)
163 widget_->CloseNow();
164 WidgetTest::TearDown();
165 }
166
167 private:
168 Widget* widget_ = nullptr;
169
170 #if defined(OS_MACOSX)
171 std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_;
172 #endif
173
174 DISALLOW_COPY_AND_ASSIGN(WidgetScrollViewTest);
175 };
176
72 // Verifies the viewport is sized to fit the available space. 177 // Verifies the viewport is sized to fit the available space.
73 TEST(ScrollViewTest, ViewportSizedToFit) { 178 TEST(ScrollViewTest, ViewportSizedToFit) {
74 ScrollView scroll_view; 179 ScrollView scroll_view;
180 ScrollViewTestApi test_api(&scroll_view);
75 View* contents = new View; 181 View* contents = new View;
76 scroll_view.SetContents(contents); 182 scroll_view.SetContents(contents);
77 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 183 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
78 scroll_view.Layout(); 184 scroll_view.Layout();
79 EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString()); 185 EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
80 } 186 }
81 187
82 // Verifies the scrollbars are added as necessary. 188 // Verifies the scrollbars are added as necessary.
83 // If on Mac, test the non-overlay scrollbars. 189 // If on Mac, test the non-overlay scrollbars.
84 TEST(ScrollViewTest, ScrollBars) { 190 TEST(ScrollViewTest, ScrollBars) {
85 #if defined(OS_MACOSX) 191 #if defined(OS_MACOSX)
86 ui::test::ScopedPreferredScrollerStyle scroller_style_override(false); 192 ui::test::ScopedPreferredScrollerStyle scroller_style_override(false);
87 #endif 193 #endif
88 194
89 ScrollView scroll_view; 195 ScrollView scroll_view;
196 ScrollViewTestApi test_api(&scroll_view);
90 View* contents = new View; 197 View* contents = new View;
91 scroll_view.SetContents(contents); 198 scroll_view.SetContents(contents);
92 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 199 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
93 200
94 // Size the contents such that vertical scrollbar is needed. 201 // Size the contents such that vertical scrollbar is needed.
95 contents->SetBounds(0, 0, 50, 400); 202 contents->SetBounds(0, 0, 50, 400);
96 scroll_view.Layout(); 203 scroll_view.Layout();
97 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width()); 204 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
98 EXPECT_EQ(100, contents->parent()->height()); 205 test_api.contents_viewport()->width());
206 EXPECT_EQ(100, test_api.contents_viewport()->height());
99 CheckScrollbarVisibility(scroll_view, VERTICAL, true); 207 CheckScrollbarVisibility(scroll_view, VERTICAL, true);
100 CheckScrollbarVisibility(scroll_view, HORIZONTAL, false); 208 CheckScrollbarVisibility(scroll_view, HORIZONTAL, false);
101 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() || 209 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() ||
102 !scroll_view.horizontal_scroll_bar()->visible()); 210 !scroll_view.horizontal_scroll_bar()->visible());
103 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL); 211 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
104 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible()); 212 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
105 213
106 // Size the contents such that horizontal scrollbar is needed. 214 // Size the contents such that horizontal scrollbar is needed.
107 contents->SetBounds(0, 0, 400, 50); 215 contents->SetBounds(0, 0, 400, 50);
108 scroll_view.Layout(); 216 scroll_view.Layout();
109 EXPECT_EQ(100, contents->parent()->width()); 217 EXPECT_EQ(100, test_api.contents_viewport()->width());
110 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(), 218 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
111 contents->parent()->height()); 219 test_api.contents_viewport()->height());
112 CheckScrollbarVisibility(scroll_view, VERTICAL, false); 220 CheckScrollbarVisibility(scroll_view, VERTICAL, false);
113 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true); 221 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
114 222
115 // Both horizontal and vertical. 223 // Both horizontal and vertical.
116 contents->SetBounds(0, 0, 300, 400); 224 contents->SetBounds(0, 0, 300, 400);
117 scroll_view.Layout(); 225 scroll_view.Layout();
118 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width()); 226 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
227 test_api.contents_viewport()->width());
119 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(), 228 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
120 contents->parent()->height()); 229 test_api.contents_viewport()->height());
121 CheckScrollbarVisibility(scroll_view, VERTICAL, true); 230 CheckScrollbarVisibility(scroll_view, VERTICAL, true);
122 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true); 231 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
123 232
124 // Add a border, test vertical scrollbar. 233 // Add a border, test vertical scrollbar.
125 const int kTopPadding = 1; 234 const int kTopPadding = 1;
126 const int kLeftPadding = 2; 235 const int kLeftPadding = 2;
127 const int kBottomPadding = 3; 236 const int kBottomPadding = 3;
128 const int kRightPadding = 4; 237 const int kRightPadding = 4;
129 scroll_view.SetBorder(Border::CreateEmptyBorder( 238 scroll_view.SetBorder(Border::CreateEmptyBorder(
130 kTopPadding, kLeftPadding, kBottomPadding, kRightPadding)); 239 kTopPadding, kLeftPadding, kBottomPadding, kRightPadding));
131 contents->SetBounds(0, 0, 50, 400); 240 contents->SetBounds(0, 0, 50, 400);
132 scroll_view.Layout(); 241 scroll_view.Layout();
133 EXPECT_EQ( 242 EXPECT_EQ(
134 100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding, 243 100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding,
135 contents->parent()->width()); 244 test_api.contents_viewport()->width());
136 EXPECT_EQ(100 - kTopPadding - kBottomPadding, contents->parent()->height()); 245 EXPECT_EQ(100 - kTopPadding - kBottomPadding,
246 test_api.contents_viewport()->height());
137 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() || 247 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() ||
138 !scroll_view.horizontal_scroll_bar()->visible()); 248 !scroll_view.horizontal_scroll_bar()->visible());
139 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL); 249 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
140 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible()); 250 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
141 gfx::Rect bounds = scroll_view.vertical_scroll_bar()->bounds(); 251 gfx::Rect bounds = scroll_view.vertical_scroll_bar()->bounds();
142 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth() - kRightPadding, bounds.x()); 252 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth() - kRightPadding, bounds.x());
143 EXPECT_EQ(100 - kRightPadding, bounds.right()); 253 EXPECT_EQ(100 - kRightPadding, bounds.right());
144 EXPECT_EQ(kTopPadding, bounds.y()); 254 EXPECT_EQ(kTopPadding, bounds.y());
145 EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); 255 EXPECT_EQ(100 - kBottomPadding, bounds.bottom());
146 256
147 // Horizontal with border. 257 // Horizontal with border.
148 contents->SetBounds(0, 0, 400, 50); 258 contents->SetBounds(0, 0, 400, 50);
149 scroll_view.Layout(); 259 scroll_view.Layout();
150 EXPECT_EQ(100 - kLeftPadding - kRightPadding, contents->parent()->width()); 260 EXPECT_EQ(100 - kLeftPadding - kRightPadding,
261 test_api.contents_viewport()->width());
151 EXPECT_EQ( 262 EXPECT_EQ(
152 100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding, 263 100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding,
153 contents->parent()->height()); 264 test_api.contents_viewport()->height());
154 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL); 265 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
155 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible()); 266 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible());
156 EXPECT_TRUE(!scroll_view.vertical_scroll_bar() || 267 EXPECT_TRUE(!scroll_view.vertical_scroll_bar() ||
157 !scroll_view.vertical_scroll_bar()->visible()); 268 !scroll_view.vertical_scroll_bar()->visible());
158 bounds = scroll_view.horizontal_scroll_bar()->bounds(); 269 bounds = scroll_view.horizontal_scroll_bar()->bounds();
159 EXPECT_EQ(kLeftPadding, bounds.x()); 270 EXPECT_EQ(kLeftPadding, bounds.x());
160 EXPECT_EQ(100 - kRightPadding, bounds.right()); 271 EXPECT_EQ(100 - kRightPadding, bounds.right());
161 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(), 272 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(),
162 bounds.y()); 273 bounds.y());
163 EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); 274 EXPECT_EQ(100 - kBottomPadding, bounds.bottom());
164 275
165 // Both horizontal and vertical with border. 276 // Both horizontal and vertical with border.
166 contents->SetBounds(0, 0, 300, 400); 277 contents->SetBounds(0, 0, 300, 400);
167 scroll_view.Layout(); 278 scroll_view.Layout();
168 EXPECT_EQ( 279 EXPECT_EQ(
169 100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding, 280 100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding,
170 contents->parent()->width()); 281 test_api.contents_viewport()->width());
171 EXPECT_EQ( 282 EXPECT_EQ(
172 100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding, 283 100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding,
173 contents->parent()->height()); 284 test_api.contents_viewport()->height());
174 bounds = scroll_view.horizontal_scroll_bar()->bounds(); 285 bounds = scroll_view.horizontal_scroll_bar()->bounds();
175 // Check horiz. 286 // Check horiz.
176 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL); 287 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
177 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible()); 288 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible());
178 bounds = scroll_view.horizontal_scroll_bar()->bounds(); 289 bounds = scroll_view.horizontal_scroll_bar()->bounds();
179 EXPECT_EQ(kLeftPadding, bounds.x()); 290 EXPECT_EQ(kLeftPadding, bounds.x());
180 EXPECT_EQ(100 - kRightPadding - scroll_view.GetScrollBarWidth(), 291 EXPECT_EQ(100 - kRightPadding - scroll_view.GetScrollBarWidth(),
181 bounds.right()); 292 bounds.right());
182 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(), 293 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(),
183 bounds.y()); 294 bounds.y());
184 EXPECT_EQ(100 - kBottomPadding, bounds.bottom()); 295 EXPECT_EQ(100 - kBottomPadding, bounds.bottom());
185 // Check vert. 296 // Check vert.
186 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL); 297 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
187 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible()); 298 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
188 bounds = scroll_view.vertical_scroll_bar()->bounds(); 299 bounds = scroll_view.vertical_scroll_bar()->bounds();
189 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth() - kRightPadding, bounds.x()); 300 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth() - kRightPadding, bounds.x());
190 EXPECT_EQ(100 - kRightPadding, bounds.right()); 301 EXPECT_EQ(100 - kRightPadding, bounds.right());
191 EXPECT_EQ(kTopPadding, bounds.y()); 302 EXPECT_EQ(kTopPadding, bounds.y());
192 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(), 303 EXPECT_EQ(100 - kBottomPadding - scroll_view.GetScrollBarHeight(),
193 bounds.bottom()); 304 bounds.bottom());
194 } 305 }
195 306
196 // Assertions around adding a header. 307 // Assertions around adding a header.
197 TEST(ScrollViewTest, Header) { 308 TEST(ScrollViewTest, Header) {
198 ScrollView scroll_view; 309 ScrollView scroll_view;
310 ScrollViewTestApi test_api(&scroll_view);
199 View* contents = new View; 311 View* contents = new View;
200 CustomView* header = new CustomView; 312 CustomView* header = new CustomView;
201 scroll_view.SetHeader(header); 313 scroll_view.SetHeader(header);
202 View* header_parent = header->parent(); 314 View* header_parent = header->parent();
203 scroll_view.SetContents(contents); 315 scroll_view.SetContents(contents);
204 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 316 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
205 scroll_view.Layout(); 317 scroll_view.Layout();
206 // |header|s preferred size is empty, which should result in all space going 318 // |header|s preferred size is empty, which should result in all space going
207 // to contents. 319 // to contents.
208 EXPECT_EQ("0,0 100x0", header->parent()->bounds().ToString()); 320 EXPECT_EQ("0,0 100x0", header->parent()->bounds().ToString());
209 EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString()); 321 EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
210 322
211 // Get the header a height of 20. 323 // Get the header a height of 20.
212 header->SetPreferredSize(gfx::Size(10, 20)); 324 header->SetPreferredSize(gfx::Size(10, 20));
213 EXPECT_EQ("0,0 100x20", header->parent()->bounds().ToString()); 325 EXPECT_EQ("0,0 100x20", header->parent()->bounds().ToString());
214 EXPECT_EQ("0,20 100x80", contents->parent()->bounds().ToString()); 326 EXPECT_EQ("0,20 100x80", test_api.contents_viewport()->bounds().ToString());
215 327
216 // Remove the header. 328 // Remove the header.
217 scroll_view.SetHeader(NULL); 329 scroll_view.SetHeader(NULL);
218 // SetHeader(NULL) deletes header. 330 // SetHeader(NULL) deletes header.
219 header = NULL; 331 header = NULL;
220 EXPECT_EQ("0,0 100x0", header_parent->bounds().ToString()); 332 EXPECT_EQ("0,0 100x0", header_parent->bounds().ToString());
221 EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString()); 333 EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
222 } 334 }
223 335
224 // Verifies the scrollbars are added as necessary when a header is present. 336 // Verifies the scrollbars are added as necessary when a header is present.
225 TEST(ScrollViewTest, ScrollBarsWithHeader) { 337 TEST(ScrollViewTest, ScrollBarsWithHeader) {
226 ScrollView scroll_view; 338 ScrollView scroll_view;
339 ScrollViewTestApi test_api(&scroll_view);
227 View* contents = new View; 340 View* contents = new View;
228 scroll_view.SetContents(contents); 341 scroll_view.SetContents(contents);
229 CustomView* header = new CustomView; 342 CustomView* header = new CustomView;
230 scroll_view.SetHeader(header); 343 scroll_view.SetHeader(header);
231 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 344 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
232 345
233 header->SetPreferredSize(gfx::Size(10, 20)); 346 header->SetPreferredSize(gfx::Size(10, 20));
234 347
235 // Size the contents such that vertical scrollbar is needed. 348 // Size the contents such that vertical scrollbar is needed.
236 contents->SetBounds(0, 0, 50, 400); 349 contents->SetBounds(0, 0, 50, 400);
237 scroll_view.Layout(); 350 scroll_view.Layout();
238 EXPECT_EQ(0, contents->parent()->x()); 351 EXPECT_EQ(0, test_api.contents_viewport()->x());
239 EXPECT_EQ(20, contents->parent()->y()); 352 EXPECT_EQ(20, test_api.contents_viewport()->y());
240 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width()); 353 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
241 EXPECT_EQ(80, contents->parent()->height()); 354 test_api.contents_viewport()->width());
355 EXPECT_EQ(80, test_api.contents_viewport()->height());
242 EXPECT_EQ(0, header->parent()->x()); 356 EXPECT_EQ(0, header->parent()->x());
243 EXPECT_EQ(0, header->parent()->y()); 357 EXPECT_EQ(0, header->parent()->y());
244 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width()); 358 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width());
245 EXPECT_EQ(20, header->parent()->height()); 359 EXPECT_EQ(20, header->parent()->height());
246 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() || 360 EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() ||
247 !scroll_view.horizontal_scroll_bar()->visible()); 361 !scroll_view.horizontal_scroll_bar()->visible());
248 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL); 362 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
249 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible()); 363 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
250 // Make sure the vertical scrollbar overlaps the header. 364 // Make sure the vertical scrollbar overlaps the header.
251 EXPECT_EQ(header->y(), scroll_view.vertical_scroll_bar()->y()); 365 EXPECT_EQ(header->y(), scroll_view.vertical_scroll_bar()->y());
252 EXPECT_EQ(header->y(), contents->y()); 366 EXPECT_EQ(header->y(), contents->y());
253 367
254 // Size the contents such that horizontal scrollbar is needed. 368 // Size the contents such that horizontal scrollbar is needed.
255 contents->SetBounds(0, 0, 400, 50); 369 contents->SetBounds(0, 0, 400, 50);
256 scroll_view.Layout(); 370 scroll_view.Layout();
257 EXPECT_EQ(0, contents->parent()->x()); 371 EXPECT_EQ(0, test_api.contents_viewport()->x());
258 EXPECT_EQ(20, contents->parent()->y()); 372 EXPECT_EQ(20, test_api.contents_viewport()->y());
259 EXPECT_EQ(100, contents->parent()->width()); 373 EXPECT_EQ(100, test_api.contents_viewport()->width());
260 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20, 374 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20,
261 contents->parent()->height()); 375 test_api.contents_viewport()->height());
262 EXPECT_EQ(0, header->parent()->x()); 376 EXPECT_EQ(0, header->parent()->x());
263 EXPECT_EQ(0, header->parent()->y()); 377 EXPECT_EQ(0, header->parent()->y());
264 EXPECT_EQ(100, header->parent()->width()); 378 EXPECT_EQ(100, header->parent()->width());
265 EXPECT_EQ(20, header->parent()->height()); 379 EXPECT_EQ(20, header->parent()->height());
266 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL); 380 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
267 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible()); 381 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible());
268 EXPECT_TRUE(!scroll_view.vertical_scroll_bar() || 382 EXPECT_TRUE(!scroll_view.vertical_scroll_bar() ||
269 !scroll_view.vertical_scroll_bar()->visible()); 383 !scroll_view.vertical_scroll_bar()->visible());
270 384
271 // Both horizontal and vertical. 385 // Both horizontal and vertical.
272 contents->SetBounds(0, 0, 300, 400); 386 contents->SetBounds(0, 0, 300, 400);
273 scroll_view.Layout(); 387 scroll_view.Layout();
274 EXPECT_EQ(0, contents->parent()->x()); 388 EXPECT_EQ(0, test_api.contents_viewport()->x());
275 EXPECT_EQ(20, contents->parent()->y()); 389 EXPECT_EQ(20, test_api.contents_viewport()->y());
276 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width()); 390 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
391 test_api.contents_viewport()->width());
277 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20, 392 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20,
278 contents->parent()->height()); 393 test_api.contents_viewport()->height());
279 EXPECT_EQ(0, header->parent()->x()); 394 EXPECT_EQ(0, header->parent()->x());
280 EXPECT_EQ(0, header->parent()->y()); 395 EXPECT_EQ(0, header->parent()->y());
281 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width()); 396 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width());
282 EXPECT_EQ(20, header->parent()->height()); 397 EXPECT_EQ(20, header->parent()->height());
283 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL); 398 ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
284 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible()); 399 EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible());
285 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL); 400 ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
286 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible()); 401 EXPECT_TRUE(scroll_view.vertical_scroll_bar()->visible());
287 } 402 }
288 403
289 // Verifies the header scrolls horizontally with the content. 404 // Verifies the header scrolls horizontally with the content.
290 TEST(ScrollViewTest, HeaderScrollsWithContent) { 405 TEST(ScrollViewTest, HeaderScrollsWithContent) {
291 ScrollView scroll_view; 406 ScrollView scroll_view;
407 ScrollViewTestApi test_api(&scroll_view);
292 CustomView* contents = new CustomView; 408 CustomView* contents = new CustomView;
293 scroll_view.SetContents(contents); 409 scroll_view.SetContents(contents);
294 contents->SetPreferredSize(gfx::Size(500, 500)); 410 contents->SetPreferredSize(gfx::Size(500, 500));
295 411
296 CustomView* header = new CustomView; 412 CustomView* header = new CustomView;
297 scroll_view.SetHeader(header); 413 scroll_view.SetHeader(header);
298 header->SetPreferredSize(gfx::Size(500, 20)); 414 header->SetPreferredSize(gfx::Size(500, 20));
299 415
300 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 416 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
301 EXPECT_EQ("0,0", contents->bounds().origin().ToString()); 417 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
302 EXPECT_EQ("0,0", header->bounds().origin().ToString()); 418 EXPECT_EQ("0,0", header->bounds().origin().ToString());
303 419
304 // Scroll the horizontal scrollbar. 420 // Scroll the horizontal scrollbar.
305 ASSERT_TRUE(scroll_view.horizontal_scroll_bar()); 421 ASSERT_TRUE(scroll_view.horizontal_scroll_bar());
306 scroll_view.ScrollToPosition( 422 scroll_view.ScrollToPosition(
307 const_cast<ScrollBar*>(scroll_view.horizontal_scroll_bar()), 1); 423 const_cast<ScrollBar*>(scroll_view.horizontal_scroll_bar()), 1);
308 EXPECT_EQ("-1,0", contents->bounds().origin().ToString()); 424 EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString());
309 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 425 EXPECT_EQ("-1,0", header->bounds().origin().ToString());
310 426
311 // Scrolling the vertical scrollbar shouldn't effect the header. 427 // Scrolling the vertical scrollbar shouldn't effect the header.
312 ASSERT_TRUE(scroll_view.vertical_scroll_bar()); 428 ASSERT_TRUE(scroll_view.vertical_scroll_bar());
313 scroll_view.ScrollToPosition( 429 scroll_view.ScrollToPosition(
314 const_cast<ScrollBar*>(scroll_view.vertical_scroll_bar()), 1); 430 const_cast<ScrollBar*>(scroll_view.vertical_scroll_bar()), 1);
315 EXPECT_EQ("-1,-1", contents->bounds().origin().ToString()); 431 EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString());
316 EXPECT_EQ("-1,0", header->bounds().origin().ToString()); 432 EXPECT_EQ("-1,0", header->bounds().origin().ToString());
317 } 433 }
318 434
319 // Verifies ScrollRectToVisible() on the child works. 435 // Verifies ScrollRectToVisible() on the child works.
320 TEST(ScrollViewTest, ScrollRectToVisible) { 436 TEST(ScrollViewTest, ScrollRectToVisible) {
437 #if defined(OS_MACOSX)
438 ui::test::ScopedPreferredScrollerStyle scroller_style_override(false);
439 #endif
321 ScrollView scroll_view; 440 ScrollView scroll_view;
441 ScrollViewTestApi test_api(&scroll_view);
322 CustomView* contents = new CustomView; 442 CustomView* contents = new CustomView;
323 scroll_view.SetContents(contents); 443 scroll_view.SetContents(contents);
324 contents->SetPreferredSize(gfx::Size(500, 1000)); 444 contents->SetPreferredSize(gfx::Size(500, 1000));
325 445
326 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 446 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
327 scroll_view.Layout(); 447 scroll_view.Layout();
328 EXPECT_EQ("0,0", contents->bounds().origin().ToString()); 448 EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
329 449
330 // Scroll to y=405 height=10, this should make the y position of the content 450 // Scroll to y=405 height=10, this should make the y position of the content
331 // at (405 + 10) - viewport_height (scroll region bottom aligned). 451 // at (405 + 10) - viewport_height (scroll region bottom aligned).
332 contents->ScrollRectToVisible(gfx::Rect(0, 405, 10, 10)); 452 contents->ScrollRectToVisible(gfx::Rect(0, 405, 10, 10));
333 const int viewport_height = contents->parent()->height(); 453 const int viewport_height = test_api.contents_viewport()->height();
334 EXPECT_EQ(-(415 - viewport_height), contents->y()); 454
455 // Expect there to be a horizontal scrollbar, making the viewport shorter.
456 EXPECT_LT(viewport_height, 100);
457
458 gfx::ScrollOffset offset = test_api.CurrentOffset();
459 EXPECT_EQ(415 - viewport_height, offset.y());
335 460
336 // Scroll to the current y-location and 10x10; should do nothing. 461 // Scroll to the current y-location and 10x10; should do nothing.
337 contents->ScrollRectToVisible(gfx::Rect(0, -contents->y(), 10, 10)); 462 contents->ScrollRectToVisible(gfx::Rect(0, offset.y(), 10, 10));
338 EXPECT_EQ(-(415 - viewport_height), contents->y()); 463 EXPECT_EQ(415 - viewport_height, test_api.CurrentOffset().y());
339 } 464 }
340 465
341 // Verifies ClipHeightTo() uses the height of the content when it is between the 466 // Verifies ClipHeightTo() uses the height of the content when it is between the
342 // minimum and maximum height values. 467 // minimum and maximum height values.
343 TEST(ScrollViewTest, ClipHeightToNormalContentHeight) { 468 TEST(ScrollViewTest, ClipHeightToNormalContentHeight) {
344 ScrollView scroll_view; 469 ScrollView scroll_view;
345 470
346 scroll_view.ClipHeightTo(kMinHeight, kMaxHeight); 471 scroll_view.ClipHeightTo(kMinHeight, kMaxHeight);
347 472
348 const int kNormalContentHeight = 75; 473 const int kNormalContentHeight = 75;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width); 554 EXPECT_EQ(scroll_view.contents()->size().width(), expected_width);
430 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width); 555 EXPECT_EQ(scroll_view.contents()->size().height(), 1000 * expected_width);
431 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size()); 556 EXPECT_EQ(gfx::Size(kWidth, kMaxHeight), scroll_view.size());
432 } 557 }
433 558
434 TEST(ScrollViewTest, CornerViewVisibility) { 559 TEST(ScrollViewTest, CornerViewVisibility) {
435 ScrollView scroll_view; 560 ScrollView scroll_view;
436 View* contents = new View; 561 View* contents = new View;
437 scroll_view.SetContents(contents); 562 scroll_view.SetContents(contents);
438 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 563 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
439 View* corner_view = scroll_view.corner_view_; 564 View* corner_view = ScrollViewTestApi(&scroll_view).corner_view();
440 565
441 // Corner view should be visible when both scrollbars are visible. 566 // Corner view should be visible when both scrollbars are visible.
442 contents->SetBounds(0, 0, 200, 200); 567 contents->SetBounds(0, 0, 200, 200);
443 scroll_view.Layout(); 568 scroll_view.Layout();
444 EXPECT_EQ(&scroll_view, corner_view->parent()); 569 EXPECT_EQ(&scroll_view, corner_view->parent());
445 EXPECT_TRUE(corner_view->visible()); 570 EXPECT_TRUE(corner_view->visible());
446 571
447 // Corner view should be aligned to the scrollbars. 572 // Corner view should be aligned to the scrollbars.
448 EXPECT_EQ(scroll_view.vertical_scroll_bar()->x(), corner_view->x()); 573 EXPECT_EQ(scroll_view.vertical_scroll_bar()->x(), corner_view->x());
449 EXPECT_EQ(scroll_view.horizontal_scroll_bar()->y(), corner_view->y()); 574 EXPECT_EQ(scroll_view.horizontal_scroll_bar()->y(), corner_view->y());
(...skipping 24 matching lines...) Expand all
474 599
475 #if defined(OS_MACOSX) 600 #if defined(OS_MACOSX)
476 // Tests the overlay scrollbars on Mac. Ensure that they show up properly and 601 // Tests the overlay scrollbars on Mac. Ensure that they show up properly and
477 // do not overlap each other. 602 // do not overlap each other.
478 TEST(ScrollViewTest, CocoaOverlayScrollBars) { 603 TEST(ScrollViewTest, CocoaOverlayScrollBars) {
479 std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> 604 std::unique_ptr<ui::test::ScopedPreferredScrollerStyle>
480 scroller_style_override; 605 scroller_style_override;
481 scroller_style_override.reset( 606 scroller_style_override.reset(
482 new ui::test::ScopedPreferredScrollerStyle(true)); 607 new ui::test::ScopedPreferredScrollerStyle(true));
483 ScrollView scroll_view; 608 ScrollView scroll_view;
609 ScrollViewTestApi test_api(&scroll_view);
484 View* contents = new View; 610 View* contents = new View;
485 scroll_view.SetContents(contents); 611 scroll_view.SetContents(contents);
486 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); 612 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
487 613
488 // Size the contents such that vertical scrollbar is needed. 614 // Size the contents such that vertical scrollbar is needed.
489 // Since it is overlaid, the ViewPort size should match the ScrollView. 615 // Since it is overlaid, the ViewPort size should match the ScrollView.
490 contents->SetBounds(0, 0, 50, 400); 616 contents->SetBounds(0, 0, 50, 400);
491 scroll_view.Layout(); 617 scroll_view.Layout();
492 EXPECT_EQ(100, contents->parent()->width()); 618 EXPECT_EQ(100, test_api.contents_viewport()->width());
493 EXPECT_EQ(100, contents->parent()->height()); 619 EXPECT_EQ(100, test_api.contents_viewport()->height());
494 EXPECT_EQ(0, scroll_view.GetScrollBarWidth()); 620 EXPECT_EQ(0, scroll_view.GetScrollBarWidth());
495 CheckScrollbarVisibility(scroll_view, VERTICAL, true); 621 CheckScrollbarVisibility(scroll_view, VERTICAL, true);
496 CheckScrollbarVisibility(scroll_view, HORIZONTAL, false); 622 CheckScrollbarVisibility(scroll_view, HORIZONTAL, false);
497 623
498 // Size the contents such that horizontal scrollbar is needed. 624 // Size the contents such that horizontal scrollbar is needed.
499 contents->SetBounds(0, 0, 400, 50); 625 contents->SetBounds(0, 0, 400, 50);
500 scroll_view.Layout(); 626 scroll_view.Layout();
501 EXPECT_EQ(100, contents->parent()->width()); 627 EXPECT_EQ(100, test_api.contents_viewport()->width());
502 EXPECT_EQ(100, contents->parent()->height()); 628 EXPECT_EQ(100, test_api.contents_viewport()->height());
503 EXPECT_EQ(0, scroll_view.GetScrollBarHeight()); 629 EXPECT_EQ(0, scroll_view.GetScrollBarHeight());
504 CheckScrollbarVisibility(scroll_view, VERTICAL, false); 630 CheckScrollbarVisibility(scroll_view, VERTICAL, false);
505 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true); 631 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
506 632
507 // Both horizontal and vertical scrollbars. 633 // Both horizontal and vertical scrollbars.
508 contents->SetBounds(0, 0, 300, 400); 634 contents->SetBounds(0, 0, 300, 400);
509 scroll_view.Layout(); 635 scroll_view.Layout();
510 EXPECT_EQ(100, contents->parent()->width()); 636 EXPECT_EQ(100, test_api.contents_viewport()->width());
511 EXPECT_EQ(100, contents->parent()->height()); 637 EXPECT_EQ(100, test_api.contents_viewport()->height());
512 EXPECT_EQ(0, scroll_view.GetScrollBarWidth()); 638 EXPECT_EQ(0, scroll_view.GetScrollBarWidth());
513 EXPECT_EQ(0, scroll_view.GetScrollBarHeight()); 639 EXPECT_EQ(0, scroll_view.GetScrollBarHeight());
514 CheckScrollbarVisibility(scroll_view, VERTICAL, true); 640 CheckScrollbarVisibility(scroll_view, VERTICAL, true);
515 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true); 641 CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
516 642
517 // Make sure the horizontal and vertical scrollbars don't overlap each other. 643 // Make sure the horizontal and vertical scrollbars don't overlap each other.
518 gfx::Rect vert_bounds = scroll_view.vertical_scroll_bar()->bounds(); 644 gfx::Rect vert_bounds = scroll_view.vertical_scroll_bar()->bounds();
519 gfx::Rect horiz_bounds = scroll_view.horizontal_scroll_bar()->bounds(); 645 gfx::Rect horiz_bounds = scroll_view.horizontal_scroll_bar()->bounds();
520 EXPECT_EQ(vert_bounds.x(), horiz_bounds.right()); 646 EXPECT_EQ(vert_bounds.x(), horiz_bounds.right());
521 EXPECT_EQ(horiz_bounds.y(), vert_bounds.bottom()); 647 EXPECT_EQ(horiz_bounds.y(), vert_bounds.bottom());
522 648
523 // Switch to the non-overlay style and check that the ViewPort is now sized 649 // Switch to the non-overlay style and check that the ViewPort is now sized
524 // to be smaller, and ScrollbarWidth and ScrollbarHeight are non-zero. 650 // to be smaller, and ScrollbarWidth and ScrollbarHeight are non-zero.
525 scroller_style_override.reset( 651 scroller_style_override.reset(
526 new ui::test::ScopedPreferredScrollerStyle(false)); 652 new ui::test::ScopedPreferredScrollerStyle(false));
527 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width()); 653 EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
654 test_api.contents_viewport()->width());
528 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(), 655 EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
529 contents->parent()->height()); 656 test_api.contents_viewport()->height());
530 EXPECT_NE(0, scroll_view.GetScrollBarWidth()); 657 EXPECT_NE(0, scroll_view.GetScrollBarWidth());
531 EXPECT_NE(0, scroll_view.GetScrollBarHeight()); 658 EXPECT_NE(0, scroll_view.GetScrollBarHeight());
532 } 659 }
533 #endif 660 #endif
534 661
662 // Test scrolling behavior when clicking on the scroll track.
663 TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) {
664 // Set up with a vertical scroller.
665 ScrollView* scroll_view =
666 AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5));
667 ScrollViewTestApi test_api(scroll_view);
668 BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL);
669 View* thumb = test_api.GetScrollBarThumb(VERTICAL);
670
671 // Click in the middle of the track, ensuring it's below the thumb.
672 const gfx::Point location = scroll_bar->bounds().CenterPoint();
673 EXPECT_GT(location.y(), thumb->bounds().bottom());
674 ui::MouseEvent press(TestLeftMouseAt(location, ui::ET_MOUSE_PRESSED));
675 ui::MouseEvent release(TestLeftMouseAt(location, ui::ET_MOUSE_RELEASED));
676
677 const base::Timer& timer = test_api.GetScrollBarTimer(VERTICAL);
678 EXPECT_FALSE(timer.IsRunning());
679
680 EXPECT_EQ(0, scroll_view->GetVisibleRect().y());
681 scroll_bar->OnMouseEvent(&press);
682
683 // Clicking the scroll track should scroll one "page".
684 EXPECT_EQ(kDefaultHeight, scroll_view->GetVisibleRect().y());
685
686 // While the mouse is pressed, timer should trigger more scroll events.
687 EXPECT_TRUE(timer.IsRunning());
688
689 // Upon release timer should stop (and scroll position should remain).
690 scroll_bar->OnMouseEvent(&release);
691 EXPECT_FALSE(timer.IsRunning());
692 EXPECT_EQ(kDefaultHeight, scroll_view->GetVisibleRect().y());
693 }
694
535 } // namespace views 695 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698