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

Side by Side Diff: ui/views/controls/scrollbar/scrollbar_unittest.cc

Issue 1769553003: Guard against division by zero for useless scroll bars. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar.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 "build/build_config.h" 5 #include "build/build_config.h"
6 #include "ui/views/controls/scrollbar/native_scroll_bar.h" 6 #include "ui/views/controls/scrollbar/native_scroll_bar.h"
7 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" 7 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h"
8 #include "ui/views/controls/scrollbar/scroll_bar.h" 8 #include "ui/views/controls/scrollbar/scroll_bar.h"
9 #include "ui/views/test/views_test_base.h" 9 #include "ui/views/test/views_test_base.h"
10 #include "ui/views/widget/widget.h" 10 #include "ui/views/widget/widget.h"
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 // Scroll to the end of the content. 168 // Scroll to the end of the content.
169 scrollbar_->Update(100, 1001, 0); 169 scrollbar_->Update(100, 1001, 0);
170 EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1)); 170 EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
171 // Shrink and then re-expand the content. 171 // Shrink and then re-expand the content.
172 scrollbar_->Update(100, 1000, 0); 172 scrollbar_->Update(100, 1000, 0);
173 scrollbar_->Update(100, 1001, 0); 173 scrollbar_->Update(100, 1001, 0);
174 // Ensure the scrollbar allows scrolling to the end. 174 // Ensure the scrollbar allows scrolling to the end.
175 EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1)); 175 EXPECT_TRUE(scrollbar_->ScrollByContentsOffset(-1));
176 } 176 }
177 177
178 TEST_F(NativeScrollBarTest, ThumbFullLengthOfTrack) {
179 // Shrink content so that it fits within the viewport.
180 scrollbar_->Update(100, 10, 0);
181 EXPECT_EQ(scrollbar_->GetTrackBounds().width(),
182 scrollbar_->GetThumbSizeForTest());
183 // Emulate a click on the full size scroll bar.
184 scrollbar_->ScrollToThumbPosition(0, false);
185 EXPECT_EQ(0, scrollbar_->GetPosition());
186 // Emulate a key down.
187 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_LINE);
188 EXPECT_EQ(0, scrollbar_->GetPosition());
189
190 // Expand content so that it fits *exactly* within the viewport.
191 scrollbar_->Update(100, 100, 0);
192 EXPECT_EQ(scrollbar_->GetTrackBounds().width(),
193 scrollbar_->GetThumbSizeForTest());
194 // Emulate a click on the full size scroll bar.
195 scrollbar_->ScrollToThumbPosition(0, false);
196 EXPECT_EQ(0, scrollbar_->GetPosition());
197 // Emulate a key down.
198 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_LINE);
199 EXPECT_EQ(0, scrollbar_->GetPosition());
200 }
201
178 } // namespace views 202 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/base_scroll_bar.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698