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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/controls/scroll_view_unittest.cc
diff --git a/ui/views/controls/scroll_view_unittest.cc b/ui/views/controls/scroll_view_unittest.cc
index d90784ca906d5d57097fece67c4518275f0ea19c..03f5233b3a3412e915a0d4e9109822a0f0fd91c3 100644
--- a/ui/views/controls/scroll_view_unittest.cc
+++ b/ui/views/controls/scroll_view_unittest.cc
@@ -5,16 +5,64 @@
#include "ui/views/controls/scroll_view.h"
#include "base/macros.h"
+#include "base/run_loop.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/border.h"
+#include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
+#include "ui/views/controls/scrollbar/native_scroll_bar.h"
+#include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
#include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
#include "ui/views/test/test_views.h"
+#include "ui/views/test/widget_test.h"
#if defined(OS_MACOSX)
#include "ui/base/test/scoped_preferred_scroller_style_mac.h"
#endif
+enum ScrollBarOrientation { HORIZONTAL, VERTICAL };
+
namespace views {
+namespace test {
+
+class ScrollViewTestApi {
+ public:
+ explicit ScrollViewTestApi(ScrollView* scroll_view)
+ : scroll_view_(scroll_view) {}
+
+ BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) {
+ ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_
+ : scroll_view_->horiz_sb_;
+ if (scroll_bar->GetClassName() == NativeScrollBar::kViewClassName) {
+ return static_cast<NativeScrollBarViews*>(
+ static_cast<NativeScrollBar*>(scroll_bar)->native_wrapper_);
+ }
+ return static_cast<BaseScrollBar*>(scroll_bar);
+ }
+
+ const base::Timer& GetScrollBarTimer(ScrollBarOrientation orientation) {
+ return GetBaseScrollBar(orientation)->repeater_.timer_for_testing();
+ }
+
+ BaseScrollBarThumb* GetScrollBarThumb(ScrollBarOrientation orientation) {
+ return GetBaseScrollBar(orientation)->thumb_;
+ }
+
+ gfx::Point IntegralViewOffset() {
+ return gfx::Point() - gfx::ScrollOffsetToFlooredVector2d(CurrentOffset());
+ }
+
+ gfx::ScrollOffset CurrentOffset() { return scroll_view_->CurrentOffset(); }
+
+ View* corner_view() { return scroll_view_->corner_view_; }
+ View* contents_viewport() { return scroll_view_->contents_viewport_; }
+
+ private:
+ ScrollView* scroll_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScrollViewTestApi);
+};
+
+} // namespace test
namespace {
@@ -22,8 +70,6 @@ const int kWidth = 100;
const int kMinHeight = 50;
const int kMaxHeight = 100;
-enum ScrollBarOrientation { HORIZONTAL, VERTICAL };
-
// View implementation that allows setting the preferred size.
class CustomView : public View {
public:
@@ -67,16 +113,76 @@ void CheckScrollbarVisibility(const ScrollView& scroll_view,
}
}
+ui::MouseEvent TestLeftMouseAt(const gfx::Point& location, ui::EventType type) {
+ return ui::MouseEvent(type, location, location, base::TimeTicks(),
+ ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON);
+}
+
} // namespace
+using test::ScrollViewTestApi;
+
+// Test harness that includes a Widget to help test ui::Event handling.
+class WidgetScrollViewTest : public test::WidgetTest {
+ public:
+ const int kDefaultHeight = 100;
+ const int kDefaultWidth = 100;
+
+ WidgetScrollViewTest() {
+#if defined(OS_MACOSX)
+ // Disable scrollbar hiding (i.e. disable overlay scrollbars) by default.
+ scroller_style_.reset(new ui::test::ScopedPreferredScrollerStyle(false));
+#endif
+ }
+
+ // Adds a ScrollView with a contents view of the given |size| and does layout.
+ ScrollView* AddScrollViewWithContentSize(const gfx::Size& contents_size) {
+ const gfx::Rect default_bounds(50, 50, kDefaultWidth, kDefaultHeight);
+ widget_ = CreateTopLevelFramelessPlatformWidget();
+
+ ScrollView* scroll_view = new ScrollView();
+ View* contents = new View;
+ scroll_view->SetContents(contents);
+ contents->SetSize(contents_size);
+
+ widget_->SetBounds(default_bounds);
+ widget_->Show();
+
+ widget_->SetContentsView(scroll_view);
+ scroll_view->Layout();
+
+ // Ensure the Compositor has committed layer changes before attempting to
+ // use them for impl-side scrolling.
+ base::RunLoop().RunUntilIdle();
+ return scroll_view;
+ }
+
+ // testing::Test:
+ void TearDown() override {
+ if (widget_)
+ widget_->CloseNow();
+ WidgetTest::TearDown();
+ }
+
+ private:
+ Widget* widget_ = nullptr;
+
+#if defined(OS_MACOSX)
+ std::unique_ptr<ui::test::ScopedPreferredScrollerStyle> scroller_style_;
+#endif
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetScrollViewTest);
+};
+
// Verifies the viewport is sized to fit the available space.
TEST(ScrollViewTest, ViewportSizedToFit) {
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
View* contents = new View;
scroll_view.SetContents(contents);
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
scroll_view.Layout();
- EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString());
+ EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
}
// Verifies the scrollbars are added as necessary.
@@ -87,6 +193,7 @@ TEST(ScrollViewTest, ScrollBars) {
#endif
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
View* contents = new View;
scroll_view.SetContents(contents);
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
@@ -94,8 +201,9 @@ TEST(ScrollViewTest, ScrollBars) {
// Size the contents such that vertical scrollbar is needed.
contents->SetBounds(0, 0, 50, 400);
scroll_view.Layout();
- EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width());
- EXPECT_EQ(100, contents->parent()->height());
+ EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
+ test_api.contents_viewport()->width());
+ EXPECT_EQ(100, test_api.contents_viewport()->height());
CheckScrollbarVisibility(scroll_view, VERTICAL, true);
CheckScrollbarVisibility(scroll_view, HORIZONTAL, false);
EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() ||
@@ -106,18 +214,19 @@ TEST(ScrollViewTest, ScrollBars) {
// Size the contents such that horizontal scrollbar is needed.
contents->SetBounds(0, 0, 400, 50);
scroll_view.Layout();
- EXPECT_EQ(100, contents->parent()->width());
+ EXPECT_EQ(100, test_api.contents_viewport()->width());
EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
- contents->parent()->height());
+ test_api.contents_viewport()->height());
CheckScrollbarVisibility(scroll_view, VERTICAL, false);
CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
// Both horizontal and vertical.
contents->SetBounds(0, 0, 300, 400);
scroll_view.Layout();
- EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width());
+ EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
+ test_api.contents_viewport()->width());
EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
- contents->parent()->height());
+ test_api.contents_viewport()->height());
CheckScrollbarVisibility(scroll_view, VERTICAL, true);
CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
@@ -132,8 +241,9 @@ TEST(ScrollViewTest, ScrollBars) {
scroll_view.Layout();
EXPECT_EQ(
100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding,
- contents->parent()->width());
- EXPECT_EQ(100 - kTopPadding - kBottomPadding, contents->parent()->height());
+ test_api.contents_viewport()->width());
+ EXPECT_EQ(100 - kTopPadding - kBottomPadding,
+ test_api.contents_viewport()->height());
EXPECT_TRUE(!scroll_view.horizontal_scroll_bar() ||
!scroll_view.horizontal_scroll_bar()->visible());
ASSERT_TRUE(scroll_view.vertical_scroll_bar() != NULL);
@@ -147,10 +257,11 @@ TEST(ScrollViewTest, ScrollBars) {
// Horizontal with border.
contents->SetBounds(0, 0, 400, 50);
scroll_view.Layout();
- EXPECT_EQ(100 - kLeftPadding - kRightPadding, contents->parent()->width());
+ EXPECT_EQ(100 - kLeftPadding - kRightPadding,
+ test_api.contents_viewport()->width());
EXPECT_EQ(
100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding,
- contents->parent()->height());
+ test_api.contents_viewport()->height());
ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
EXPECT_TRUE(scroll_view.horizontal_scroll_bar()->visible());
EXPECT_TRUE(!scroll_view.vertical_scroll_bar() ||
@@ -167,10 +278,10 @@ TEST(ScrollViewTest, ScrollBars) {
scroll_view.Layout();
EXPECT_EQ(
100 - scroll_view.GetScrollBarWidth() - kLeftPadding - kRightPadding,
- contents->parent()->width());
+ test_api.contents_viewport()->width());
EXPECT_EQ(
100 - scroll_view.GetScrollBarHeight() - kTopPadding - kBottomPadding,
- contents->parent()->height());
+ test_api.contents_viewport()->height());
bounds = scroll_view.horizontal_scroll_bar()->bounds();
// Check horiz.
ASSERT_TRUE(scroll_view.horizontal_scroll_bar() != NULL);
@@ -196,6 +307,7 @@ TEST(ScrollViewTest, ScrollBars) {
// Assertions around adding a header.
TEST(ScrollViewTest, Header) {
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
View* contents = new View;
CustomView* header = new CustomView;
scroll_view.SetHeader(header);
@@ -206,24 +318,25 @@ TEST(ScrollViewTest, Header) {
// |header|s preferred size is empty, which should result in all space going
// to contents.
EXPECT_EQ("0,0 100x0", header->parent()->bounds().ToString());
- EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString());
+ EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
// Get the header a height of 20.
header->SetPreferredSize(gfx::Size(10, 20));
EXPECT_EQ("0,0 100x20", header->parent()->bounds().ToString());
- EXPECT_EQ("0,20 100x80", contents->parent()->bounds().ToString());
+ EXPECT_EQ("0,20 100x80", test_api.contents_viewport()->bounds().ToString());
// Remove the header.
scroll_view.SetHeader(NULL);
// SetHeader(NULL) deletes header.
header = NULL;
EXPECT_EQ("0,0 100x0", header_parent->bounds().ToString());
- EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString());
+ EXPECT_EQ("0,0 100x100", test_api.contents_viewport()->bounds().ToString());
}
// Verifies the scrollbars are added as necessary when a header is present.
TEST(ScrollViewTest, ScrollBarsWithHeader) {
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
View* contents = new View;
scroll_view.SetContents(contents);
CustomView* header = new CustomView;
@@ -235,10 +348,11 @@ TEST(ScrollViewTest, ScrollBarsWithHeader) {
// Size the contents such that vertical scrollbar is needed.
contents->SetBounds(0, 0, 50, 400);
scroll_view.Layout();
- EXPECT_EQ(0, contents->parent()->x());
- EXPECT_EQ(20, contents->parent()->y());
- EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width());
- EXPECT_EQ(80, contents->parent()->height());
+ EXPECT_EQ(0, test_api.contents_viewport()->x());
+ EXPECT_EQ(20, test_api.contents_viewport()->y());
+ EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
+ test_api.contents_viewport()->width());
+ EXPECT_EQ(80, test_api.contents_viewport()->height());
EXPECT_EQ(0, header->parent()->x());
EXPECT_EQ(0, header->parent()->y());
EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width());
@@ -254,11 +368,11 @@ TEST(ScrollViewTest, ScrollBarsWithHeader) {
// Size the contents such that horizontal scrollbar is needed.
contents->SetBounds(0, 0, 400, 50);
scroll_view.Layout();
- EXPECT_EQ(0, contents->parent()->x());
- EXPECT_EQ(20, contents->parent()->y());
- EXPECT_EQ(100, contents->parent()->width());
+ EXPECT_EQ(0, test_api.contents_viewport()->x());
+ EXPECT_EQ(20, test_api.contents_viewport()->y());
+ EXPECT_EQ(100, test_api.contents_viewport()->width());
EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20,
- contents->parent()->height());
+ test_api.contents_viewport()->height());
EXPECT_EQ(0, header->parent()->x());
EXPECT_EQ(0, header->parent()->y());
EXPECT_EQ(100, header->parent()->width());
@@ -271,11 +385,12 @@ TEST(ScrollViewTest, ScrollBarsWithHeader) {
// Both horizontal and vertical.
contents->SetBounds(0, 0, 300, 400);
scroll_view.Layout();
- EXPECT_EQ(0, contents->parent()->x());
- EXPECT_EQ(20, contents->parent()->y());
- EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width());
+ EXPECT_EQ(0, test_api.contents_viewport()->x());
+ EXPECT_EQ(20, test_api.contents_viewport()->y());
+ EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
+ test_api.contents_viewport()->width());
EXPECT_EQ(100 - scroll_view.GetScrollBarHeight() - 20,
- contents->parent()->height());
+ test_api.contents_viewport()->height());
EXPECT_EQ(0, header->parent()->x());
EXPECT_EQ(0, header->parent()->y());
EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), header->parent()->width());
@@ -289,6 +404,7 @@ TEST(ScrollViewTest, ScrollBarsWithHeader) {
// Verifies the header scrolls horizontally with the content.
TEST(ScrollViewTest, HeaderScrollsWithContent) {
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
CustomView* contents = new CustomView;
scroll_view.SetContents(contents);
contents->SetPreferredSize(gfx::Size(500, 500));
@@ -298,44 +414,53 @@ TEST(ScrollViewTest, HeaderScrollsWithContent) {
header->SetPreferredSize(gfx::Size(500, 20));
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
- EXPECT_EQ("0,0", contents->bounds().origin().ToString());
+ EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
EXPECT_EQ("0,0", header->bounds().origin().ToString());
// Scroll the horizontal scrollbar.
ASSERT_TRUE(scroll_view.horizontal_scroll_bar());
scroll_view.ScrollToPosition(
const_cast<ScrollBar*>(scroll_view.horizontal_scroll_bar()), 1);
- EXPECT_EQ("-1,0", contents->bounds().origin().ToString());
+ EXPECT_EQ("-1,0", test_api.IntegralViewOffset().ToString());
EXPECT_EQ("-1,0", header->bounds().origin().ToString());
// Scrolling the vertical scrollbar shouldn't effect the header.
ASSERT_TRUE(scroll_view.vertical_scroll_bar());
scroll_view.ScrollToPosition(
const_cast<ScrollBar*>(scroll_view.vertical_scroll_bar()), 1);
- EXPECT_EQ("-1,-1", contents->bounds().origin().ToString());
+ EXPECT_EQ("-1,-1", test_api.IntegralViewOffset().ToString());
EXPECT_EQ("-1,0", header->bounds().origin().ToString());
}
// Verifies ScrollRectToVisible() on the child works.
TEST(ScrollViewTest, ScrollRectToVisible) {
+#if defined(OS_MACOSX)
+ ui::test::ScopedPreferredScrollerStyle scroller_style_override(false);
+#endif
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
CustomView* contents = new CustomView;
scroll_view.SetContents(contents);
contents->SetPreferredSize(gfx::Size(500, 1000));
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
scroll_view.Layout();
- EXPECT_EQ("0,0", contents->bounds().origin().ToString());
+ EXPECT_EQ("0,0", test_api.IntegralViewOffset().ToString());
// Scroll to y=405 height=10, this should make the y position of the content
// at (405 + 10) - viewport_height (scroll region bottom aligned).
contents->ScrollRectToVisible(gfx::Rect(0, 405, 10, 10));
- const int viewport_height = contents->parent()->height();
- EXPECT_EQ(-(415 - viewport_height), contents->y());
+ const int viewport_height = test_api.contents_viewport()->height();
+
+ // Expect there to be a horizontal scrollbar, making the viewport shorter.
+ EXPECT_LT(viewport_height, 100);
+
+ gfx::ScrollOffset offset = test_api.CurrentOffset();
+ EXPECT_EQ(415 - viewport_height, offset.y());
// Scroll to the current y-location and 10x10; should do nothing.
- contents->ScrollRectToVisible(gfx::Rect(0, -contents->y(), 10, 10));
- EXPECT_EQ(-(415 - viewport_height), contents->y());
+ contents->ScrollRectToVisible(gfx::Rect(0, offset.y(), 10, 10));
+ EXPECT_EQ(415 - viewport_height, test_api.CurrentOffset().y());
}
// Verifies ClipHeightTo() uses the height of the content when it is between the
@@ -436,7 +561,7 @@ TEST(ScrollViewTest, CornerViewVisibility) {
View* contents = new View;
scroll_view.SetContents(contents);
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
- View* corner_view = scroll_view.corner_view_;
+ View* corner_view = ScrollViewTestApi(&scroll_view).corner_view();
// Corner view should be visible when both scrollbars are visible.
contents->SetBounds(0, 0, 200, 200);
@@ -481,6 +606,7 @@ TEST(ScrollViewTest, CocoaOverlayScrollBars) {
scroller_style_override.reset(
new ui::test::ScopedPreferredScrollerStyle(true));
ScrollView scroll_view;
+ ScrollViewTestApi test_api(&scroll_view);
View* contents = new View;
scroll_view.SetContents(contents);
scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100));
@@ -489,8 +615,8 @@ TEST(ScrollViewTest, CocoaOverlayScrollBars) {
// Since it is overlaid, the ViewPort size should match the ScrollView.
contents->SetBounds(0, 0, 50, 400);
scroll_view.Layout();
- EXPECT_EQ(100, contents->parent()->width());
- EXPECT_EQ(100, contents->parent()->height());
+ EXPECT_EQ(100, test_api.contents_viewport()->width());
+ EXPECT_EQ(100, test_api.contents_viewport()->height());
EXPECT_EQ(0, scroll_view.GetScrollBarWidth());
CheckScrollbarVisibility(scroll_view, VERTICAL, true);
CheckScrollbarVisibility(scroll_view, HORIZONTAL, false);
@@ -498,8 +624,8 @@ TEST(ScrollViewTest, CocoaOverlayScrollBars) {
// Size the contents such that horizontal scrollbar is needed.
contents->SetBounds(0, 0, 400, 50);
scroll_view.Layout();
- EXPECT_EQ(100, contents->parent()->width());
- EXPECT_EQ(100, contents->parent()->height());
+ EXPECT_EQ(100, test_api.contents_viewport()->width());
+ EXPECT_EQ(100, test_api.contents_viewport()->height());
EXPECT_EQ(0, scroll_view.GetScrollBarHeight());
CheckScrollbarVisibility(scroll_view, VERTICAL, false);
CheckScrollbarVisibility(scroll_view, HORIZONTAL, true);
@@ -507,8 +633,8 @@ TEST(ScrollViewTest, CocoaOverlayScrollBars) {
// Both horizontal and vertical scrollbars.
contents->SetBounds(0, 0, 300, 400);
scroll_view.Layout();
- EXPECT_EQ(100, contents->parent()->width());
- EXPECT_EQ(100, contents->parent()->height());
+ EXPECT_EQ(100, test_api.contents_viewport()->width());
+ EXPECT_EQ(100, test_api.contents_viewport()->height());
EXPECT_EQ(0, scroll_view.GetScrollBarWidth());
EXPECT_EQ(0, scroll_view.GetScrollBarHeight());
CheckScrollbarVisibility(scroll_view, VERTICAL, true);
@@ -524,12 +650,46 @@ TEST(ScrollViewTest, CocoaOverlayScrollBars) {
// to be smaller, and ScrollbarWidth and ScrollbarHeight are non-zero.
scroller_style_override.reset(
new ui::test::ScopedPreferredScrollerStyle(false));
- EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(), contents->parent()->width());
+ EXPECT_EQ(100 - scroll_view.GetScrollBarWidth(),
+ test_api.contents_viewport()->width());
EXPECT_EQ(100 - scroll_view.GetScrollBarHeight(),
- contents->parent()->height());
+ test_api.contents_viewport()->height());
EXPECT_NE(0, scroll_view.GetScrollBarWidth());
EXPECT_NE(0, scroll_view.GetScrollBarHeight());
}
#endif
+// Test scrolling behavior when clicking on the scroll track.
+TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) {
+ // Set up with a vertical scroller.
+ ScrollView* scroll_view =
+ AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5));
+ ScrollViewTestApi test_api(scroll_view);
+ BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL);
+ View* thumb = test_api.GetScrollBarThumb(VERTICAL);
+
+ // Click in the middle of the track, ensuring it's below the thumb.
+ const gfx::Point location = scroll_bar->bounds().CenterPoint();
+ EXPECT_GT(location.y(), thumb->bounds().bottom());
+ ui::MouseEvent press(TestLeftMouseAt(location, ui::ET_MOUSE_PRESSED));
+ ui::MouseEvent release(TestLeftMouseAt(location, ui::ET_MOUSE_RELEASED));
+
+ const base::Timer& timer = test_api.GetScrollBarTimer(VERTICAL);
+ EXPECT_FALSE(timer.IsRunning());
+
+ EXPECT_EQ(0, scroll_view->GetVisibleRect().y());
+ scroll_bar->OnMouseEvent(&press);
+
+ // Clicking the scroll track should scroll one "page".
+ EXPECT_EQ(kDefaultHeight, scroll_view->GetVisibleRect().y());
+
+ // While the mouse is pressed, timer should trigger more scroll events.
+ EXPECT_TRUE(timer.IsRunning());
+
+ // Upon release timer should stop (and scroll position should remain).
+ scroll_bar->OnMouseEvent(&release);
+ EXPECT_FALSE(timer.IsRunning());
+ EXPECT_EQ(kDefaultHeight, scroll_view->GetVisibleRect().y());
+}
+
} // namespace views

Powered by Google App Engine
This is Rietveld 408576698