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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/views/controls/scroll_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/run_loop.h"
9 #include "base/test/test_timeouts.h" 9 #include "base/test/test_timeouts.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 EXPECT_EQ(fully_scrolled.x(), test_api.CurrentOffset().x()); 862 EXPECT_EQ(fully_scrolled.x(), test_api.CurrentOffset().x());
863 863
864 // And 77 pixels wider should scroll left. Also make it short again: the y- 864 // And 77 pixels wider should scroll left. Also make it short again: the y-
865 // offset from the last change should remain. 865 // offset from the last change should remain.
866 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 177, 100)); 866 scroll_view_.SetBoundsRect(gfx::Rect(0, 0, 177, 100));
867 scroll_view_.Layout(); 867 scroll_view_.Layout();
868 EXPECT_EQ(fully_scrolled.y() - 55, test_api.CurrentOffset().y()); 868 EXPECT_EQ(fully_scrolled.y() - 55, test_api.CurrentOffset().y());
869 EXPECT_EQ(fully_scrolled.x() - 77, test_api.CurrentOffset().x()); 869 EXPECT_EQ(fully_scrolled.x() - 77, test_api.CurrentOffset().x());
870 } 870 }
871 871
872 // Calling Layout on ScrollView should not reset the scroll location.
873 TEST_F(ScrollViewTest, ContentScrollNotResetOnLayout) {
874 ScrollViewTestApi test_api(&scroll_view_);
875
876 CustomView* contents = new CustomView;
877 contents->SetPreferredSize(gfx::Size(300, 300));
878 scroll_view_.SetContents(contents);
879 scroll_view_.ClipHeightTo(0, 150);
880 scroll_view_.SizeToPreferredSize();
881 // ScrollView preferred width matches that of |contents|, with the height
882 // capped at the value we clipped to.
883 EXPECT_EQ(gfx::Size(300, 150), scroll_view_.size());
884
885 // Scroll down.
886 scroll_view_.ScrollToPosition(
887 const_cast<ScrollBar*>(scroll_view_.vertical_scroll_bar()), 25);
888 EXPECT_EQ(25, test_api.CurrentOffset().y());
889 // Call Layout; no change to scroll position.
890 scroll_view_.Layout();
891 EXPECT_EQ(25, test_api.CurrentOffset().y());
892 // Change contents of |contents|, call Layout; still no change to scroll
893 // position.
894 contents->SetPreferredSize(gfx::Size(300, 500));
895 contents->InvalidateLayout();
896 scroll_view_.Layout();
897 EXPECT_EQ(25, test_api.CurrentOffset().y());
898
899 // Change |contents| to be shorter than the ScrollView's clipped height.
900 // This /will/ change the scroll location due to ConstrainScrollToBounds.
901 contents->SetPreferredSize(gfx::Size(300, 50));
902 scroll_view_.Layout();
903 EXPECT_EQ(0, test_api.CurrentOffset().y());
904 }
905
872 // Test scrolling behavior when clicking on the scroll track. 906 // Test scrolling behavior when clicking on the scroll track.
873 TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) { 907 TEST_F(WidgetScrollViewTest, ScrollTrackScrolling) {
874 // Set up with a vertical scroller. 908 // Set up with a vertical scroller.
875 ScrollView* scroll_view = 909 ScrollView* scroll_view =
876 AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5)); 910 AddScrollViewWithContentSize(gfx::Size(10, kDefaultHeight * 5));
877 ScrollViewTestApi test_api(scroll_view); 911 ScrollViewTestApi test_api(scroll_view);
878 BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL); 912 BaseScrollBar* scroll_bar = test_api.GetBaseScrollBar(VERTICAL);
879 View* thumb = test_api.GetScrollBarThumb(VERTICAL); 913 View* thumb = test_api.GetScrollBarThumb(VERTICAL);
880 914
881 // Click in the middle of the track, ensuring it's below the thumb. 915 // Click in the middle of the track, ensuring it's below the thumb.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 // Scroll via ScrollView API. Should be reflected on the impl side. 1021 // Scroll via ScrollView API. Should be reflected on the impl side.
988 offset.set_y(kDefaultHeight * 4); 1022 offset.set_y(kDefaultHeight * 4);
989 scroll_view->contents()->ScrollRectToVisible(offset); 1023 scroll_view->contents()->ScrollRectToVisible(offset);
990 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); 1024 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset());
991 1025
992 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); 1026 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset));
993 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); 1027 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset);
994 } 1028 }
995 1029
996 } // namespace views 1030 } // namespace views
OLDNEW
« 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