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

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

Issue 1167013002: Fix OverscrollWindowDelegate to not dispatch superfluous OverscrollModeChange events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Unit test Created 5 years, 6 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 | « content/browser/web_contents/aura/overscroll_window_delegate.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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "content/browser/web_contents/aura/overscroll_window_delegate.h" 5 #include "content/browser/web_contents/aura/overscroll_window_delegate.h"
6 6
7 #include "content/browser/renderer_host/overscroll_controller_delegate.h" 7 #include "content/browser/renderer_host/overscroll_controller_delegate.h"
8 #include "content/public/browser/overscroll_configuration.h" 8 #include "content/public/browser/overscroll_configuration.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
11 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
12 #include "ui/events/gesture_detection/gesture_configuration.h" 12 #include "ui/events/gesture_detection/gesture_configuration.h"
13 #include "ui/events/test/event_generator.h" 13 #include "ui/events/test/event_generator.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 namespace { 17 namespace {
18 const int kTestWindowWidth = 600; 18 const int kTestWindowWidth = 600;
19 } 19 }
20 20
21 class OverscrollWindowDelegateTest : public aura::test::AuraTestBase, 21 class OverscrollWindowDelegateTest : public aura::test::AuraTestBase,
22 public OverscrollControllerDelegate { 22 public OverscrollControllerDelegate {
23 public: 23 public:
24 OverscrollWindowDelegateTest() 24 OverscrollWindowDelegateTest()
25 : window_(nullptr), 25 : window_(nullptr),
26 overscroll_complete_(false), 26 overscroll_complete_(false),
27 overscroll_started_(false), 27 overscroll_started_(false),
28 mode_changed_(false),
28 current_mode_(OVERSCROLL_NONE), 29 current_mode_(OVERSCROLL_NONE),
29 touch_start_threshold_(content::GetOverscrollConfig( 30 touch_start_threshold_(content::GetOverscrollConfig(
30 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN)), 31 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_START_TOUCHSCREEN)),
31 touch_complete_threshold_(content::GetOverscrollConfig( 32 touch_complete_threshold_(content::GetOverscrollConfig(
32 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) { 33 content::OVERSCROLL_CONFIG_HORIZ_THRESHOLD_COMPLETE)) {
33 } 34 }
34 35
35 ~OverscrollWindowDelegateTest() override {} 36 ~OverscrollWindowDelegateTest() override {}
36 37
37 void Reset() { 38 void Reset() {
38 overscroll_complete_ = false; 39 overscroll_complete_ = false;
39 overscroll_started_ = false; 40 overscroll_started_ = false;
41 mode_changed_ = false;
40 current_mode_ = OVERSCROLL_NONE; 42 current_mode_ = OVERSCROLL_NONE;
41 window_.reset(CreateNormalWindow( 43 window_.reset(CreateNormalWindow(
42 0, root_window(), new OverscrollWindowDelegate(this, gfx::Image()))); 44 0, root_window(), new OverscrollWindowDelegate(this, gfx::Image())));
43 window_->SetBounds(gfx::Rect(0, 0, kTestWindowWidth, kTestWindowWidth)); 45 window_->SetBounds(gfx::Rect(0, 0, kTestWindowWidth, kTestWindowWidth));
44 } 46 }
45 47
46 // Accessors. 48 // Accessors.
47 aura::Window* window() { return window_.get(); } 49 aura::Window* window() { return window_.get(); }
48 50
49 bool overscroll_complete() { return overscroll_complete_; } 51 bool overscroll_complete() { return overscroll_complete_; }
50 bool overscroll_started() { return overscroll_started_; } 52 bool overscroll_started() { return overscroll_started_; }
53 bool mode_changed() { return mode_changed_; }
51 54
52 OverscrollMode current_mode() { return current_mode_; } 55 OverscrollMode current_mode() { return current_mode_; }
53 56
54 const float touch_start_threshold() { 57 const float touch_start_threshold() {
55 return touch_start_threshold_; 58 return touch_start_threshold_;
56 } 59 }
57 60
58 const float touch_complete_threshold() { 61 const float touch_complete_threshold() {
59 return kTestWindowWidth * touch_complete_threshold_; 62 return kTestWindowWidth * touch_complete_threshold_;
60 } 63 }
(...skipping 21 matching lines...) Expand all
82 bool OnOverscrollUpdate(float delta_x, float delta_y) override { 85 bool OnOverscrollUpdate(float delta_x, float delta_y) override {
83 return true; 86 return true;
84 } 87 }
85 88
86 void OnOverscrollComplete(OverscrollMode overscroll_mode) override { 89 void OnOverscrollComplete(OverscrollMode overscroll_mode) override {
87 overscroll_complete_ = true; 90 overscroll_complete_ = true;
88 } 91 }
89 92
90 void OnOverscrollModeChange(OverscrollMode old_mode, 93 void OnOverscrollModeChange(OverscrollMode old_mode,
91 OverscrollMode new_mode) override { 94 OverscrollMode new_mode) override {
95 mode_changed_ = true;
92 current_mode_ = new_mode; 96 current_mode_ = new_mode;
93 if (current_mode_ != OVERSCROLL_NONE) 97 if (current_mode_ != OVERSCROLL_NONE)
94 overscroll_started_ = true; 98 overscroll_started_ = true;
95 } 99 }
96 100
97 // Window in which the overscroll window delegate is installed. 101 // Window in which the overscroll window delegate is installed.
98 scoped_ptr<aura::Window> window_; 102 scoped_ptr<aura::Window> window_;
99 103
100 // State flags. 104 // State flags.
101 bool overscroll_complete_; 105 bool overscroll_complete_;
102 bool overscroll_started_; 106 bool overscroll_started_;
103 107 bool mode_changed_;
104 OverscrollMode current_mode_; 108 OverscrollMode current_mode_;
105 109
106 // Config defined constants. 110 // Config defined constants.
107 const float touch_start_threshold_; 111 const float touch_start_threshold_;
108 const float touch_complete_threshold_; 112 const float touch_complete_threshold_;
109 113
110 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegateTest); 114 DISALLOW_COPY_AND_ASSIGN(OverscrollWindowDelegateTest);
111 }; 115 };
112 116
113 // Tests that the basic overscroll gesture works and sends updates to the 117 // Tests that the basic overscroll gesture works and sends updates to the
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_NONE); 164 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_NONE);
161 165
162 // Slide the touch to the left. 166 // Slide the touch to the left.
163 generator.MoveTouch(gfx::Point(0, 0)); 167 generator.MoveTouch(gfx::Point(0, 0));
164 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_WEST); 168 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_WEST);
165 169
166 // Complete the gesture. 170 // Complete the gesture.
167 generator.ReleaseTouch(); 171 generator.ReleaseTouch();
168 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_NONE); 172 EXPECT_EQ(delegate->overscroll_mode_, OVERSCROLL_NONE);
169 EXPECT_TRUE(overscroll_complete()); 173 EXPECT_TRUE(overscroll_complete());
174
175 // Generate a mouse events which normally cancel the overscroll. Confirm
176 // that superfluous mode changed events are not dispatched.
177 Reset();
178 generator.PressLeftButton();
179 generator.MoveMouseTo(gfx::Point(10, 10));
180 EXPECT_FALSE(mode_changed());
170 } 181 }
171 182
172 // Tests that the overscroll does not start until the gesture gets past a 183 // Tests that the overscroll does not start until the gesture gets past a
173 // particular threshold. 184 // particular threshold.
174 TEST_F(OverscrollWindowDelegateTest, OverscrollThreshold) { 185 TEST_F(OverscrollWindowDelegateTest, OverscrollThreshold) {
175 ui::test::EventGenerator generator(root_window()); 186 ui::test::EventGenerator generator(root_window());
176 187
177 // Start an OVERSCROLL_EAST gesture. 188 // Start an OVERSCROLL_EAST gesture.
178 generator.GestureScrollSequence(gfx::Point(0, 0), 189 generator.GestureScrollSequence(gfx::Point(0, 0),
179 gfx::Point(touch_start_threshold(), 0), 190 gfx::Point(touch_start_threshold(), 0),
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 EXPECT_EQ(current_mode(), OVERSCROLL_NONE); 244 EXPECT_EQ(current_mode(), OVERSCROLL_NONE);
234 EXPECT_FALSE(overscroll_complete()); 245 EXPECT_FALSE(overscroll_complete());
235 246
236 // We should be able to restart the overscroll without lifting the finger. 247 // We should be able to restart the overscroll without lifting the finger.
237 generator.MoveTouch(gfx::Point(touch_x + touch_start_threshold() + 1, 0)); 248 generator.MoveTouch(gfx::Point(touch_x + touch_start_threshold() + 1, 0));
238 EXPECT_EQ(current_mode(), OVERSCROLL_EAST); 249 EXPECT_EQ(current_mode(), OVERSCROLL_EAST);
239 EXPECT_FALSE(overscroll_complete()); 250 EXPECT_FALSE(overscroll_complete());
240 } 251 }
241 252
242 } // namespace content 253 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/aura/overscroll_window_delegate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698