Commit aabe7161 authored by Ryan Meier's avatar Ryan Meier Committed by Commit Bot

Re-enable two tests in scrollbar_unittest.cc, fix rounding precision loss in base_scroll_bar.cc

Change-Id: I6d2fcdf455cb65faa67450754b8fea4084783afb
Reviewed-on: https://chromium-review.googlesource.com/c/1340957
Commit-Queue: Ryan Meier <rameier@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#610133}
parent 6ca899a6
...@@ -84,8 +84,8 @@ void BaseScrollBar::ScrollByAmount(ScrollAmount amount) { ...@@ -84,8 +84,8 @@ void BaseScrollBar::ScrollByAmount(ScrollAmount amount) {
void BaseScrollBar::ScrollToThumbPosition(int thumb_position, void BaseScrollBar::ScrollToThumbPosition(int thumb_position,
bool scroll_to_middle) { bool scroll_to_middle) {
contents_scroll_offset_ = contents_scroll_offset_ = CalculateContentsOffset(
CalculateContentsOffset(thumb_position, scroll_to_middle); static_cast<float>(thumb_position), scroll_to_middle);
if (contents_scroll_offset_ < GetMinPosition()) { if (contents_scroll_offset_ < GetMinPosition()) {
contents_scroll_offset_ = GetMinPosition(); contents_scroll_offset_ = GetMinPosition();
} else if (contents_scroll_offset_ > GetMaxPosition()) { } else if (contents_scroll_offset_ > GetMaxPosition()) {
...@@ -460,16 +460,17 @@ int BaseScrollBar::CalculateThumbPosition(int contents_scroll_offset) const { ...@@ -460,16 +460,17 @@ int BaseScrollBar::CalculateThumbPosition(int contents_scroll_offset) const {
(contents_size_ - viewport_size_); (contents_size_ - viewport_size_);
} }
int BaseScrollBar::CalculateContentsOffset(int thumb_position, int BaseScrollBar::CalculateContentsOffset(float thumb_position,
bool scroll_to_middle) const { bool scroll_to_middle) const {
int thumb_size = thumb_->GetSize(); float thumb_size = static_cast<float>(thumb_->GetSize());
int track_size = GetTrackSize(); int track_size = GetTrackSize();
if (track_size == thumb_size) if (track_size == thumb_size)
return 0; return 0;
if (scroll_to_middle) if (scroll_to_middle)
thumb_position = thumb_position - (thumb_size / 2); thumb_position = thumb_position - (thumb_size / 2);
return (thumb_position * (contents_size_ - viewport_size_)) / float result = (thumb_position * (contents_size_ - viewport_size_)) /
(track_size - thumb_size); (track_size - thumb_size);
return static_cast<int>(result);
} }
} // namespace views } // namespace views
...@@ -135,7 +135,7 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar, ...@@ -135,7 +135,7 @@ class VIEWS_EXPORT BaseScrollBar : public ScrollBar,
// Calculates the current value of the contents offset (contents coordinates) // Calculates the current value of the contents offset (contents coordinates)
// based on the current thumb position (thumb track coordinates). See // based on the current thumb position (thumb track coordinates). See
// |ScrollToThumbPosition| for an explanation of |scroll_to_middle|. // |ScrollToThumbPosition| for an explanation of |scroll_to_middle|.
int CalculateContentsOffset(int thumb_position, int CalculateContentsOffset(float thumb_position,
bool scroll_to_middle) const; bool scroll_to_middle) const;
// Called when the state of the thumb track changes (e.g. by the user // Called when the state of the thumb track changes (e.g. by the user
......
...@@ -87,17 +87,7 @@ class ScrollBarViewsTest : public ViewsTestBase { ...@@ -87,17 +87,7 @@ class ScrollBarViewsTest : public ViewsTestBase {
std::unique_ptr<TestScrollBarController> controller_; std::unique_ptr<TestScrollBarController> controller_;
}; };
// TODO(dnicoara) Can't run the test on Windows since the scrollbar |Part| TEST_F(ScrollBarViewsTest, Scrolling) {
// isn't handled in NativeTheme.
#if defined(OS_WIN)
#define MAYBE_Scrolling DISABLED_Scrolling
#define MAYBE_ScrollBarFitsToBottom DISABLED_ScrollBarFitsToBottom
#else
#define MAYBE_Scrolling Scrolling
#define MAYBE_ScrollBarFitsToBottom ScrollBarFitsToBottom
#endif
TEST_F(ScrollBarViewsTest, MAYBE_Scrolling) {
EXPECT_EQ(0, scrollbar_->GetPosition()); EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(900, scrollbar_->GetMaxPosition()); EXPECT_EQ(900, scrollbar_->GetMaxPosition());
EXPECT_EQ(0, scrollbar_->GetMinPosition()); EXPECT_EQ(0, scrollbar_->GetMinPosition());
...@@ -135,7 +125,7 @@ TEST_F(ScrollBarViewsTest, MAYBE_Scrolling) { ...@@ -135,7 +125,7 @@ TEST_F(ScrollBarViewsTest, MAYBE_Scrolling) {
EXPECT_EQ(0, controller_->last_position); EXPECT_EQ(0, controller_->last_position);
} }
TEST_F(ScrollBarViewsTest, MAYBE_ScrollBarFitsToBottom) { TEST_F(ScrollBarViewsTest, ScrollBarFitsToBottom) {
scrollbar_->Update(100, 1999, 0); scrollbar_->Update(100, 1999, 0);
EXPECT_EQ(0, scrollbar_->GetPosition()); EXPECT_EQ(0, scrollbar_->GetPosition());
EXPECT_EQ(1899, scrollbar_->GetMaxPosition()); EXPECT_EQ(1899, scrollbar_->GetMaxPosition());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment