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" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/views/border.h" | 12 #include "ui/views/border.h" |
13 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" | 13 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h" |
14 #include "ui/views/controls/scrollbar/native_scroll_bar.h" | |
15 #include "ui/views/controls/scrollbar/native_scroll_bar_views.h" | |
16 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 14 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
| 15 #include "ui/views/controls/scrollbar/scroll_bar_views.h" |
17 #include "ui/views/test/test_views.h" | 16 #include "ui/views/test/test_views.h" |
18 #include "ui/views/test/widget_test.h" | 17 #include "ui/views/test/widget_test.h" |
19 | 18 |
20 #if defined(OS_MACOSX) | 19 #if defined(OS_MACOSX) |
21 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" | 20 #include "ui/base/test/scoped_preferred_scroller_style_mac.h" |
22 #endif | 21 #endif |
23 | 22 |
24 enum ScrollBarOrientation { HORIZONTAL, VERTICAL }; | 23 enum ScrollBarOrientation { HORIZONTAL, VERTICAL }; |
25 | 24 |
26 namespace views { | 25 namespace views { |
27 namespace test { | 26 namespace test { |
28 | 27 |
29 class ScrollViewTestApi { | 28 class ScrollViewTestApi { |
30 public: | 29 public: |
31 explicit ScrollViewTestApi(ScrollView* scroll_view) | 30 explicit ScrollViewTestApi(ScrollView* scroll_view) |
32 : scroll_view_(scroll_view) {} | 31 : scroll_view_(scroll_view) {} |
33 | 32 |
34 BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) { | 33 BaseScrollBar* GetBaseScrollBar(ScrollBarOrientation orientation) { |
35 ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_ | 34 ScrollBar* scroll_bar = orientation == VERTICAL ? scroll_view_->vert_sb_ |
36 : scroll_view_->horiz_sb_; | 35 : scroll_view_->horiz_sb_; |
37 if (scroll_bar->GetClassName() == NativeScrollBar::kViewClassName) { | |
38 return static_cast<NativeScrollBarViews*>( | |
39 static_cast<NativeScrollBar*>(scroll_bar)->native_wrapper_); | |
40 } | |
41 return static_cast<BaseScrollBar*>(scroll_bar); | 36 return static_cast<BaseScrollBar*>(scroll_bar); |
42 } | 37 } |
43 | 38 |
44 const base::Timer& GetScrollBarTimer(ScrollBarOrientation orientation) { | 39 const base::Timer& GetScrollBarTimer(ScrollBarOrientation orientation) { |
45 return GetBaseScrollBar(orientation)->repeater_.timer_for_testing(); | 40 return GetBaseScrollBar(orientation)->repeater_.timer_for_testing(); |
46 } | 41 } |
47 | 42 |
48 BaseScrollBarThumb* GetScrollBarThumb(ScrollBarOrientation orientation) { | 43 BaseScrollBarThumb* GetScrollBarThumb(ScrollBarOrientation orientation) { |
49 return GetBaseScrollBar(orientation)->thumb_; | 44 return GetBaseScrollBar(orientation)->thumb_; |
50 } | 45 } |
(...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
893 // Scroll via ScrollView API. Should be reflected on the impl side. | 888 // Scroll via ScrollView API. Should be reflected on the impl side. |
894 offset.set_y(kDefaultHeight * 4); | 889 offset.set_y(kDefaultHeight * 4); |
895 scroll_view->contents()->ScrollRectToVisible(offset); | 890 scroll_view->contents()->ScrollRectToVisible(offset); |
896 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); | 891 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), test_api.CurrentOffset()); |
897 | 892 |
898 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); | 893 EXPECT_TRUE(compositor->GetScrollOffsetForLayer(layer_id, &impl_offset)); |
899 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); | 894 EXPECT_EQ(gfx::ScrollOffset(0, offset.y()), impl_offset); |
900 } | 895 } |
901 | 896 |
902 } // namespace views | 897 } // namespace views |
OLD | NEW |