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

Side by Side Diff: content/browser/renderer_host/input/fling/flinger_unittest.cc

Issue 41703006: Move fling implementation from renderer to browser: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright 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/renderer_host/input/fling/flinger.h"
6
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h"
11 #include "content/browser/renderer_host/input/mock_web_input_event_builders.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using base::TimeDelta;
15 using WebKit::WebGestureEvent;
16 using WebKit::WebInputEvent;
17
18 namespace content {
19
20 class FlingerTest : public testing::Test,
21 public FlingHelper {
22 public:
23 FlingerTest() : sent_gesture_event_count_(0) {}
24
25 virtual ~FlingerTest() {}
26
27 // testing::Test
28 virtual void SetUp() OVERRIDE {
29 flinger_.reset(new Flinger(this));
30 }
31
32 virtual void TearDown() OVERRIDE {
33 // Process all pending tasks to avoid leaks.
34 RunUntilIdle();
35 flinger_.reset();
36 }
37
38 // FlingHelper
39 void SendEventForFling(const WebKit::WebInputEvent& event) OVERRIDE {
40 ++sent_gesture_event_count_;
41 }
42
43 void FlingFinished(WebKit::WebGestureEvent::SourceDevice source) OVERRIDE {
44 }
45
46 protected:
47
48 // Returns the result of |GestureEventFilter::ShouldForward()|.
49 bool SimulateGestureEvent(const WebGestureEvent& gesture) {
50 GestureEventWithLatencyInfo gesture_with_latency(gesture,
51 ui::LatencyInfo());
52 return flinger_->HandleGestureEvent(gesture_with_latency);
53 }
54
55 void SimulateGestureEvent(WebInputEvent::Type type,
56 WebGestureEvent::SourceDevice sourceDevice) {
57 SimulateGestureEvent(MockWebGestureEventBuilder::Build(type, sourceDevice));
58 }
59
60 void SimulateGestureScrollUpdateEvent(float dX, float dY, int modifiers) {
61 SimulateGestureEvent(
62 MockWebGestureEventBuilder::BuildScrollUpdate(dX, dY, modifiers));
63 }
64
65 void SimulateGesturePinchUpdateEvent(float scale,
66 float anchorX,
67 float anchorY,
68 int modifiers) {
69 SimulateGestureEvent(
70 MockWebGestureEventBuilder::BuildPinchUpdate(scale,
71 anchorX,
72 anchorY,
73 modifiers));
74 }
75
76 void SimulateGestureFlingStartEvent(
77 float velocityX,
78 float velocityY,
79 WebGestureEvent::SourceDevice sourceDevice) {
80 SimulateGestureEvent(
81 MockWebGestureEventBuilder::BuildFling(velocityX,
82 velocityY,
83 sourceDevice));
84 }
85
86 void SimulateFlingCurveTimerFired() {
87 flinger_->CurveTimerFired();
88 }
89
90 void SendInputEventACK(WebInputEvent::Type type,
91 InputEventAckState ack) {
92 --sent_gesture_event_count_;
93 flinger_->ProcessEventAck(type, ack, ui::LatencyInfo());
94 }
95
96 void RunUntilIdle() {
97 base::MessageLoop::current()->RunUntilIdle();
98 }
99
100 size_t GetAndResetSentGestureEventCount() {
101 size_t count = sent_gesture_event_count_;
102 sent_gesture_event_count_ = 0;
103 return count;
104 }
105
106 bool FlingInProgress() {
107 return flinger_->fling_in_progress_;
108 }
109
110 private:
111 scoped_ptr<Flinger> flinger_;
112 size_t sent_gesture_event_count_;
113 base::MessageLoopForUI message_loop_;
114 };
115
116 #if GTEST_HAS_PARAM_TEST
117 // This is for tests that are to be run for all source devices.
118 class FlingerWithSourceTest
119 : public FlingerTest,
120 public testing::WithParamInterface<WebGestureEvent::SourceDevice> {
121 };
122 #endif // GTEST_HAS_PARAM_TEST
123
124 #if GTEST_HAS_PARAM_TEST
125 TEST_P(FlingerWithSourceTest, GestureFlingCancelsFiltered) {
126 WebGestureEvent::SourceDevice source_device = GetParam();
127
128 // GFC without previous GFS is dropped.
129 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
130 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
131
132 // GFC after GFS stops fling.
133 SimulateGestureFlingStartEvent(0, -10, source_device);
134 EXPECT_TRUE(FlingInProgress());
135 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
136 EXPECT_FALSE(FlingInProgress());
137 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
138
139 // Advance state realistically.
140 SimulateGestureFlingStartEvent(0, -10, source_device);
141 EXPECT_TRUE(FlingInProgress());
142 RunUntilIdle();
143 SimulateFlingCurveTimerFired();
144 SimulateGestureEvent(WebInputEvent::GestureFlingCancel, source_device);
145 EXPECT_FALSE(FlingInProgress());
146 EXPECT_NE(0U, GetAndResetSentGestureEventCount());
147 }
148
149 INSTANTIATE_TEST_CASE_P(AllSources,
150 FlingerWithSourceTest,
151 testing::Values(WebGestureEvent::Touchscreen,
152 WebGestureEvent::Touchpad));
153 #endif // GTEST_HAS_PARAM_TEST
154
155 TEST_F(FlingerTest, DropZeroVelocityFlings) {
156 WebGestureEvent gesture_event;
157 gesture_event.type = WebInputEvent::GestureFlingStart;
158 gesture_event.sourceDevice = WebGestureEvent::Touchpad;
159 gesture_event.data.flingStart.velocityX = 0.f;
160 gesture_event.data.flingStart.velocityY = 0.f;
161 ASSERT_EQ(0U, GetAndResetSentGestureEventCount());
162 EXPECT_TRUE(SimulateGestureEvent(gesture_event));
163 EXPECT_EQ(0U, GetAndResetSentGestureEventCount());
164 EXPECT_FALSE(FlingInProgress());
165 }
166
167 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/input/fling/flinger.cc ('k') | content/browser/renderer_host/input/immediate_input_router.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698