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

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

Issue 7767002: Revert 98434 - Adding a Views scrollbar implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « views/controls/scrollbar/native_scroll_bar_wrapper.h ('k') | views/views.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "views/controls/scrollbar/scroll_bar.h"
6 #include "views/controls/scrollbar/native_scroll_bar.h"
7 #include "views/controls/scrollbar/native_scroll_bar_views.h"
8 #include "views/test/views_test_base.h"
9 #include "views/widget/widget.h"
10
11 namespace {
12
13 // The Scrollbar controller. This is the widget that should do the real
14 // scrolling of contents.
15 class TestScrollBarController : public views::ScrollBarController {
16 public:
17 virtual ~TestScrollBarController() {}
18
19 virtual void ScrollToPosition(views::ScrollBar* source,
20 int position) OVERRIDE {
21 last_source = source;
22 last_position = position;
23 }
24
25 virtual int GetScrollIncrement(views::ScrollBar* source,
26 bool is_page,
27 bool is_positive) OVERRIDE {
28 last_source = source;
29 last_is_page = is_page;
30 last_is_positive = is_positive;
31
32 if (is_page)
33 return 20;
34 return 10;
35 }
36
37 // We save the last values in order to assert the corectness of the scroll
38 // operation.
39 views::ScrollBar* last_source;
40 bool last_is_positive;
41 bool last_is_page;
42 int last_position;
43 };
44
45 } // namespace
46
47 namespace views {
48
49 class NativeScrollBarTest : public ViewsTestBase {
50 public:
51 NativeScrollBarTest()
52 : widget_(NULL),
53 scrollbar_(NULL),
54 controller_(NULL) {
55 }
56
57 virtual void SetUp() {
58 ViewsTestBase::SetUp();
59 Widget::SetPureViews(true);
60 }
61
62 virtual void TearDown() {
63 Widget::SetPureViews(false);
64 if (widget_)
65 widget_->Close();
66 ViewsTestBase::TearDown();
67 }
68
69 void InitScrollBar() {
70 controller_.reset(new TestScrollBarController());
71
72 ASSERT_FALSE(scrollbar_);
73 native_scrollbar_ = new NativeScrollBar(true);
74 native_scrollbar_->SetBounds(0, 0, 100, 100);
75 scrollbar_ = new NativeScrollBarViews(native_scrollbar_);
76 scrollbar_->SetController(controller_.get());
77
78 widget_ = new Widget;
79 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
80 params.bounds = gfx::Rect(0, 0, 100, 100);
81 widget_->Init(params);
82 View* container = new View();
83 widget_->SetContentsView(container);
84 container->AddChildView(scrollbar_);
85 scrollbar_->SetBounds(0, 0, 100, 100);
86 scrollbar_->Update(100, 200, 0);
87
88 track_size_ = scrollbar_->GetTrackBounds().width();
89 }
90
91 protected:
92 Widget* widget_;
93
94 // This is the native scrollbar the Views one wraps around.
95 NativeScrollBar* native_scrollbar_;
96
97 // This is the Views scrollbar.
98 BaseScrollBar* scrollbar_;
99
100 // Keep track of the size of the track. This is how we can tell when we
101 // scroll to the middle.
102 int track_size_;
103
104 scoped_ptr<TestScrollBarController> controller_;
105 };
106
107 // TODO(dnicoara) Can't run the test on Windows since the scrollbar |Part|
108 // isn't handled in NativeTheme.
109 #if defined(OS_WIN)
110 TEST_F(NativeScrollBarTest, DISABLED_Scrolling) {
111 #else
112 TEST_F(NativeScrollBarTest, Scrolling) {
113 #endif
114 InitScrollBar();
115 EXPECT_EQ(scrollbar_->GetPosition(), 0);
116 EXPECT_EQ(scrollbar_->GetMaxPosition(), 100);
117 EXPECT_EQ(scrollbar_->GetMinPosition(), 0);
118
119 // Scroll to middle.
120 scrollbar_->ScrollToThumbPosition(track_size_ / 4, false);
121 EXPECT_EQ(controller_->last_position, 50);
122 EXPECT_EQ(controller_->last_source, native_scrollbar_);
123
124 // Scroll to the end.
125 scrollbar_->ScrollToThumbPosition(track_size_ / 2, false);
126 EXPECT_EQ(controller_->last_position, 100);
127
128 // Overscroll. Last position should be the maximum position.
129 scrollbar_->ScrollToThumbPosition(track_size_, false);
130 EXPECT_EQ(controller_->last_position, 100);
131
132 // Underscroll. Last position should be the minimum position.
133 scrollbar_->ScrollToThumbPosition(-10, false);
134 EXPECT_EQ(controller_->last_position, 0);
135
136 // Test the different fixed scrolling amounts. Generally used by buttons,
137 // or click on track.
138 scrollbar_->ScrollToThumbPosition(0, false);
139 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_LINE);
140 EXPECT_EQ(controller_->last_position, 10);
141
142 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_PREV_LINE);
143 EXPECT_EQ(controller_->last_position, 0);
144
145 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_NEXT_PAGE);
146 EXPECT_EQ(controller_->last_position, 20);
147
148 scrollbar_->ScrollByAmount(BaseScrollBar::SCROLL_PREV_PAGE);
149 EXPECT_EQ(controller_->last_position, 0);
150 }
151
152 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/scrollbar/native_scroll_bar_wrapper.h ('k') | views/views.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698