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

Unified Diff: ui/views/controls/scroll_view_unittest.cc

Issue 2509783002: Don't reset scroll position of contents on every ScrollView layout. (Closed)
Patch Set: make test work with scrolling by layer (I think) --- i.e. fix mac Created 4 years, 1 month 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
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 f91d0bd73c1e3bdfefe2cedadfce56756fa7a3b7..ceb28b5fb7030a1370fcb26efedb7edb8d3c687c 100644
--- a/ui/views/controls/scroll_view_unittest.cc
+++ b/ui/views/controls/scroll_view_unittest.cc
@@ -869,6 +869,40 @@ TEST_F(ScrollViewTest, ConstrainScrollToBounds) {
EXPECT_EQ(fully_scrolled.x() - 77, test_api.CurrentOffset().x());
}
+// Calling Layout on ScrollView should not reset the scroll location.
+TEST_F(ScrollViewTest, ContentScrollNotResetOnLayout) {
+ ScrollViewTestApi test_api(&scroll_view_);
+
+ CustomView* contents = new CustomView;
+ contents->SetPreferredSize(gfx::Size(300, 300));
+ scroll_view_.SetContents(contents);
+ scroll_view_.ClipHeightTo(0, 150);
+ scroll_view_.SizeToPreferredSize();
+ // ScrollView preferred width matches that of |contents|, with the height
+ // capped at the value we clipped to.
+ EXPECT_EQ(gfx::Size(300, 150), scroll_view_.size());
+
+ // Scroll down.
+ scroll_view_.ScrollToPosition(
+ const_cast<ScrollBar*>(scroll_view_.vertical_scroll_bar()), 25);
+ EXPECT_EQ(25, test_api.CurrentOffset().y());
+ // Call Layout; no change to scroll position.
+ scroll_view_.Layout();
+ EXPECT_EQ(25, test_api.CurrentOffset().y());
+ // Change contents of |contents|, call Layout; still no change to scroll
+ // position.
+ contents->SetPreferredSize(gfx::Size(300, 500));
+ contents->InvalidateLayout();
+ scroll_view_.Layout();
+ EXPECT_EQ(25, test_api.CurrentOffset().y());
+
+ // Change |contents| to be shorter than the ScrollView's clipped height.
+ // This /will/ change the scroll location due to ConstrainScrollToBounds.
+ contents->SetPreferredSize(gfx::Size(300, 50));
+ scroll_view_.Layout();
+ EXPECT_EQ(0, test_api.CurrentOffset().y());
+}
+
// Test scrolling behavior when clicking on the scroll track.
TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) {
// Set up with a vertical scroller.
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698