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

Side by Side Diff: content/browser/web_contents/aura/overscroll_window_delegate_unittest.cc

Issue 895543005: Refactor GestureNavigation to eliminate code redundancy (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simple OWD tests, better ONO tests. Created 5 years, 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2013 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 "content/browser/web_contents/aura/overscroll_window_delegate.h"
6
7 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
8 #include "content/public/browser/overscroll_configuration.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/test/aura_test_base.h"
11 #include "ui/aura/window.h"
12 #include "ui/events/test/event_generator.h"
13
14 namespace content {
15
16 namespace {
17 const int kTestWindowWidth = 600;
18 }
19
20 class OverscrollWindowDelegateTest : public aura::test::AuraTestBase,
21 public OverscrollControllerDelegate {
22 public:
23 OverscrollWindowDelegateTest()
24 : window_(nullptr),
25 overscroll_complete_(false),
26 overscroll_started_(false),
27 current_mode_(OVERSCROLL_NONE),
28 touch_start_threshold_(content::GetOverscrollConfig(
29 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN)),
30 touch_complete_threshold_(content::GetOverscrollConfig(
31 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) {}
32
33 ~OverscrollWindowDelegateTest() override {}
34
35 void Reset() {
36 overscroll_complete_ = false;
37 overscroll_started_ = false;
38 current_mode_ = OVERSCROLL_NONE;
39 window_.reset(CreateNormalWindow(
40 0, root_window(), new OverscrollWindowDelegate(this, gfx::Image())));
41 window_->SetBounds(gfx::Rect(0, 0, kTestWindowWidth, kTestWindowWidth));
42 }
43
44 // Accessors.
45 aura::Window* window() { return window_.get(); }
46
47 bool overscroll_complete() { return overscroll_complete_; }
48 bool overscroll_started() { return overscroll_started_; }
49
50 OverscrollMode current_mode() { return current_mode_; }
51
52 const float touch_start_threshold() {
53 return touch_start_threshold_;
54 }
55
56 const float touch_complete_threshold() {
57 return kTestWindowWidth * touch_complete_threshold_;
58 }
59
60 protected:
61 // aura::test::AuraTestBase:
62 void SetUp() override {
63 aura::test::AuraTestBase::SetUp();
64 Reset();
65 }
66
67 void TearDown() override {
68 window_.reset();
69 aura::test::AuraTestBase::TearDown();
70 }
71
72 private:
73 // OverscrollControllerDelegate:
74 gfx::Rect GetVisibleBounds() const override {
75 return gfx::Rect(600, 0);
76 }
77
78 bool OnOverscrollUpdate(float delta_x, float delta_y) override {
79 return true;
80 }
81
82 void OnOverscrollComplete(OverscrollMode overscroll_mode) override {
83 overscroll_complete_ = true;
84 }
85
86 void OnOverscrollModeChange(OverscrollMode old_mode,
87 OverscrollMode new_mode) override {
88 current_mode_ = new_mode;
89 if (current_mode_ != OVERSCROLL_NONE)
90 overscroll_started_ = true;
91 }
92
93 // Window in which the overscroll window delegate is installed.
94 scoped_ptr<aura::Window> window_;
95
96 // State flags.
97 bool overscroll_complete_;
98 bool overscroll_started_;
99
100 OverscrollMode current_mode_;
101
102 // Config defined constants.
103 const float touch_start_threshold_;
104 const float touch_complete_threshold_;
105
106 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegateTest);
107 };
108
109 // Tests that the basic overscroll gesture works and sends updates to the
110 // delegate.
111 TEST_F(OverscrollWindowDelegateTest, BasicOverscroll) {
112 ui::test::EventGenerator generator(root_window());
113
114 // Start an OVERSCROLL_EAST gesture.
115 generator.GestureScrollSequence(
116 gfx::Point(10, 10),
117 gfx::Point(20 + touch_complete_threshold(), 10),
mfomitchev 2015/03/27 00:14:05 10 + touch_complete_threshold() + 1?
Nina 2015/03/27 17:52:37 By using 10, we add 1 per motion, which I thought
mfomitchev 2015/03/31 22:16:31 We want to ensure that if we are over the threshol
Nina 2015/04/01 18:10:00 OK, modified test accordingly.
118 base::TimeDelta::FromMilliseconds(10),
119 10);
120 EXPECT_TRUE(overscroll_started());
121 EXPECT_EQ(current_mode(), OVERSCROLL_EAST);
mfomitchev 2015/03/27 00:14:05 SO by the end of the gesture I'd think the mode wo
Nina 2015/03/27 17:52:37 Yes, the mode in OWD is changed to none. However,
mfomitchev 2015/03/31 22:16:31 Acknowledged.
122 EXPECT_TRUE(overscroll_complete());
123
124 Reset();
125 // Start an OVERSCROLL_WEST gesture.
126 generator.GestureScrollSequence(
127 gfx::Point(20 + touch_complete_threshold(), 10),
128 gfx::Point(10, 10),
129 base::TimeDelta::FromMilliseconds(10),
130 10);
131 EXPECT_TRUE(overscroll_started());
132 EXPECT_EQ(current_mode(), OVERSCROLL_WEST);
133 EXPECT_TRUE(overscroll_complete());
134 }
135
136 // Tests that the overscroll does not start until the gesture gets past a
137 // particular threshold.
138 TEST_F(OverscrollWindowDelegateTest, OverscrollThreshold) {
139 ui::test::EventGenerator generator(root_window());
140
141 // Start an OVERSCROLL_EAST gesture.
142 generator.GestureScrollSequence(
143 gfx::Point(10, 10),
144 gfx::Point(10 + touch_start_threshold(), 10),
145 base::TimeDelta::FromMilliseconds(10),
146 10);
147 EXPECT_FALSE(overscroll_started());
148 EXPECT_EQ(current_mode(), OVERSCROLL_NONE);
149 EXPECT_FALSE(overscroll_complete());
150
151 Reset();
152 // Start an OVERSCROLL_WEST gesture.
153 generator.GestureScrollSequence(
154 gfx::Point(10 + touch_start_threshold(), 10),
155 gfx::Point(10, 10),
156 base::TimeDelta::FromMilliseconds(10),
157 10);
158 EXPECT_FALSE(overscroll_started());
159 EXPECT_EQ(current_mode(), OVERSCROLL_NONE);
160 EXPECT_FALSE(overscroll_complete());
161 }
162
163 // Tests that the overscroll is aborted if the gesture does not get past the
164 // completion threshold.
165 TEST_F(OverscrollWindowDelegateTest, AbortOverscrollThreshold) {
166 ui::test::EventGenerator generator(root_window());
167
168 // Start an OVERSCROLL_EAST gesture.
169 generator.GestureScrollSequence(
170 gfx::Point(10, 10),
171 gfx::Point(10 + touch_start_threshold() + 10, 10),
mfomitchev 2015/03/27 00:14:05 10 + touch_start_threshold() + 1?
Nina 2015/03/27 17:52:37 Same comment as above, I think it's cleaner (espec
mfomitchev 2015/03/31 22:16:31 ditto
Nina 2015/04/01 18:10:00 Done.
172 base::TimeDelta::FromMilliseconds(10),
173 10);
174 EXPECT_TRUE(overscroll_started());
175 EXPECT_EQ(current_mode(), OVERSCROLL_NONE);
176 EXPECT_FALSE(overscroll_complete());
177
178 Reset();
179 // Start an OVERSCROLL_WEST gesture.
180 generator.GestureScrollSequence(
181 gfx::Point(10 + touch_start_threshold() + 10, 10),
182 gfx::Point(10, 10),
183 base::TimeDelta::FromMilliseconds(10),
184 10);
185 EXPECT_TRUE(overscroll_started());
186 EXPECT_EQ(current_mode(), OVERSCROLL_NONE);
187 EXPECT_FALSE(overscroll_complete());
188 }
189
190 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698