| OLD | NEW |
| 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 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 // Verifies the viewport is sized to fit the available space. | 235 // Verifies the viewport is sized to fit the available space. |
| 236 TEST(ScrollViewTest, ViewportSizedToFit) { | 236 TEST(ScrollViewTest, ViewportSizedToFit) { |
| 237 ScrollView scroll_view; | 237 ScrollView scroll_view; |
| 238 View* contents = new View; | 238 View* contents = new View; |
| 239 scroll_view.SetContents(contents); | 239 scroll_view.SetContents(contents); |
| 240 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); | 240 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 241 scroll_view.Layout(); | 241 scroll_view.Layout(); |
| 242 EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString()); | 242 EXPECT_EQ("0,0 100x100", contents->parent()->bounds().ToString()); |
| 243 } | 243 } |
| 244 | 244 |
| 245 // Verifies the viewport and content is sized to fit the available space for |
| 246 // bounded scroll view. |
| 247 TEST(ScrollViewTest, BoundedViewportSizedToFit) { |
| 248 ScrollView scroll_view; |
| 249 View* contents = new View; |
| 250 scroll_view.SetContents(contents); |
| 251 scroll_view.ClipHeightTo(100, 200); |
| 252 scroll_view.SetBoundsRect(gfx::Rect(0, 0, 100, 100)); |
| 253 scroll_view.SetBorder(Border::CreateSolidBorder(2, 0)); |
| 254 scroll_view.Layout(); |
| 255 EXPECT_EQ("2,2 96x96", contents->parent()->bounds().ToString()); |
| 256 |
| 257 // Make sure the width of |contents| is set properly not to overflow the |
| 258 // viewport. |
| 259 EXPECT_EQ(96, contents->width()); |
| 260 } |
| 261 |
| 245 // Verifies the scrollbars are added as necessary. | 262 // Verifies the scrollbars are added as necessary. |
| 246 // If on Mac, test the non-overlay scrollbars. | 263 // If on Mac, test the non-overlay scrollbars. |
| 247 TEST(ScrollViewTest, ScrollBars) { | 264 TEST(ScrollViewTest, ScrollBars) { |
| 248 #if defined(OS_MACOSX) | 265 #if defined(OS_MACOSX) |
| 249 ui::test::ScopedPreferredScrollerStyle scroller_style_override(false); | 266 ui::test::ScopedPreferredScrollerStyle scroller_style_override(false); |
| 250 #endif | 267 #endif |
| 251 | 268 |
| 252 ScrollView scroll_view; | 269 ScrollView scroll_view; |
| 253 View* contents = new View; | 270 View* contents = new View; |
| 254 scroll_view.SetContents(contents); | 271 scroll_view.SetContents(contents); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 // Scroll via ScrollView API. Should be reflected on the impl side. | 894 // Scroll via ScrollView API. Should be reflected on the impl side. |
| 878 offset.set_y(kDefaultHeight * 4); | 895 offset.set_y(kDefaultHeight * 4); |
| 879 scroll_view->contents()->ScrollRectToVisible(offset); | 896 scroll_view->contents()->ScrollRectToVisible(offset); |
| 880 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 897 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |
| 881 | 898 |
| 882 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 899 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |
| 883 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 900 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |
| 884 } | 901 } |
| 885 | 902 |
| 886 } // namespace views | 903 } // namespace views |
| OLD | NEW |