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

Side by Side Diff: content/browser/renderer_host/input/synthetic_gesture_controller_unittest.cc

Issue 667943003: Standardize usage of virtual/override/final in content/browser/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "base/time/time.h" 7 #include "base/time/time.h"
8 #include "content/browser/renderer_host/input/synthetic_gesture.h" 8 #include "content/browser/renderer_host/input/synthetic_gesture.h"
9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h" 9 #include "content/browser/renderer_host/input/synthetic_gesture_controller.h"
10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h" 10 #include "content/browser/renderer_host/input/synthetic_gesture_target.h"
(...skipping 29 matching lines...) Expand all
40 const float kMinScalingSpanInDips = 27.5f; 40 const float kMinScalingSpanInDips = 27.5f;
41 41
42 class MockSyntheticGesture : public SyntheticGesture { 42 class MockSyntheticGesture : public SyntheticGesture {
43 public: 43 public:
44 MockSyntheticGesture(bool* finished, int num_steps) 44 MockSyntheticGesture(bool* finished, int num_steps)
45 : finished_(finished), 45 : finished_(finished),
46 num_steps_(num_steps), 46 num_steps_(num_steps),
47 step_count_(0) { 47 step_count_(0) {
48 *finished_ = false; 48 *finished_ = false;
49 } 49 }
50 virtual ~MockSyntheticGesture() {} 50 ~MockSyntheticGesture() override {}
51 51
52 virtual Result ForwardInputEvents(const base::TimeTicks& timestamp, 52 Result ForwardInputEvents(const base::TimeTicks& timestamp,
53 SyntheticGestureTarget* target) override { 53 SyntheticGestureTarget* target) override {
54 step_count_++; 54 step_count_++;
55 if (step_count_ == num_steps_) { 55 if (step_count_ == num_steps_) {
56 *finished_ = true; 56 *finished_ = true;
57 return SyntheticGesture::GESTURE_FINISHED; 57 return SyntheticGesture::GESTURE_FINISHED;
58 } else if (step_count_ > num_steps_) { 58 } else if (step_count_ > num_steps_) {
59 *finished_ = true; 59 *finished_ = true;
60 // Return arbitrary failure. 60 // Return arbitrary failure.
61 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED; 61 return SyntheticGesture::GESTURE_SOURCE_TYPE_NOT_IMPLEMENTED;
62 } 62 }
63 63
64 return SyntheticGesture::GESTURE_RUNNING; 64 return SyntheticGesture::GESTURE_RUNNING;
65 } 65 }
66 66
67 protected: 67 protected:
68 bool* finished_; 68 bool* finished_;
69 int num_steps_; 69 int num_steps_;
70 int step_count_; 70 int step_count_;
71 }; 71 };
72 72
73 class MockSyntheticGestureTarget : public SyntheticGestureTarget { 73 class MockSyntheticGestureTarget : public SyntheticGestureTarget {
74 public: 74 public:
75 MockSyntheticGestureTarget() 75 MockSyntheticGestureTarget()
76 : flush_requested_(false), 76 : flush_requested_(false),
77 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {} 77 pointer_assumed_stopped_time_ms_(kPointerAssumedStoppedTimeMs) {}
78 virtual ~MockSyntheticGestureTarget() {} 78 ~MockSyntheticGestureTarget() override {}
79 79
80 // SyntheticGestureTarget: 80 // SyntheticGestureTarget:
81 virtual void DispatchInputEventToPlatform( 81 void DispatchInputEventToPlatform(const WebInputEvent& event) override {}
82 const WebInputEvent& event) override {}
83 82
84 virtual void SetNeedsFlush() override { 83 void SetNeedsFlush() override { flush_requested_ = true; }
85 flush_requested_ = true;
86 }
87 84
88 virtual SyntheticGestureParams::GestureSourceType 85 SyntheticGestureParams::GestureSourceType
89 GetDefaultSyntheticGestureSourceType() const override { 86 GetDefaultSyntheticGestureSourceType() const override {
90 return SyntheticGestureParams::TOUCH_INPUT; 87 return SyntheticGestureParams::TOUCH_INPUT;
91 } 88 }
92 89
93 virtual base::TimeDelta PointerAssumedStoppedTime() const override { 90 base::TimeDelta PointerAssumedStoppedTime() const override {
94 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_); 91 return base::TimeDelta::FromMilliseconds(pointer_assumed_stopped_time_ms_);
95 } 92 }
96 93
97 void set_pointer_assumed_stopped_time_ms(int time_ms) { 94 void set_pointer_assumed_stopped_time_ms(int time_ms) {
98 pointer_assumed_stopped_time_ms_ = time_ms; 95 pointer_assumed_stopped_time_ms_ = time_ms;
99 } 96 }
100 97
101 virtual float GetTouchSlopInDips() const override { 98 float GetTouchSlopInDips() const override { return kTouchSlopInDips; }
102 return kTouchSlopInDips;
103 }
104 99
105 virtual float GetMinScalingSpanInDips() const override { 100 float GetMinScalingSpanInDips() const override {
106 return kMinScalingSpanInDips; 101 return kMinScalingSpanInDips;
107 } 102 }
108 103
109 bool flush_requested() const { return flush_requested_; } 104 bool flush_requested() const { return flush_requested_; }
110 void ClearFlushRequest() { flush_requested_ = false; } 105 void ClearFlushRequest() { flush_requested_ = false; }
111 106
112 private: 107 private:
113 bool flush_requested_; 108 bool flush_requested_;
114 109
115 int pointer_assumed_stopped_time_ms_; 110 int pointer_assumed_stopped_time_ms_;
116 }; 111 };
117 112
118 class MockScrollGestureTarget : public MockSyntheticGestureTarget { 113 class MockScrollGestureTarget : public MockSyntheticGestureTarget {
119 public: 114 public:
120 MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {} 115 MockScrollGestureTarget() : total_abs_scroll_distance_length_(0) {}
121 virtual ~MockScrollGestureTarget() {} 116 ~MockScrollGestureTarget() override {}
122 117
123 gfx::Vector2dF start_to_end_distance() const { 118 gfx::Vector2dF start_to_end_distance() const {
124 return start_to_end_distance_; 119 return start_to_end_distance_;
125 } 120 }
126 float total_abs_scroll_distance_length() const { 121 float total_abs_scroll_distance_length() const {
127 return total_abs_scroll_distance_length_; 122 return total_abs_scroll_distance_length_;
128 } 123 }
129 124
130 protected: 125 protected:
131 gfx::Vector2dF start_to_end_distance_; 126 gfx::Vector2dF start_to_end_distance_;
132 float total_abs_scroll_distance_length_; 127 float total_abs_scroll_distance_length_;
133 }; 128 };
134 129
135 class MockScrollMouseTarget : public MockScrollGestureTarget { 130 class MockScrollMouseTarget : public MockScrollGestureTarget {
136 public: 131 public:
137 MockScrollMouseTarget() {} 132 MockScrollMouseTarget() {}
138 virtual ~MockScrollMouseTarget() {} 133 ~MockScrollMouseTarget() override {}
139 134
140 virtual void DispatchInputEventToPlatform( 135 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
141 const WebInputEvent& event) override {
142 ASSERT_EQ(event.type, WebInputEvent::MouseWheel); 136 ASSERT_EQ(event.type, WebInputEvent::MouseWheel);
143 const WebMouseWheelEvent& mouse_wheel_event = 137 const WebMouseWheelEvent& mouse_wheel_event =
144 static_cast<const WebMouseWheelEvent&>(event); 138 static_cast<const WebMouseWheelEvent&>(event);
145 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY); 139 gfx::Vector2dF delta(mouse_wheel_event.deltaX, mouse_wheel_event.deltaY);
146 start_to_end_distance_ += delta; 140 start_to_end_distance_ += delta;
147 total_abs_scroll_distance_length_ += delta.Length(); 141 total_abs_scroll_distance_length_ += delta.Length();
148 } 142 }
149 }; 143 };
150 144
151 class MockScrollTouchTarget : public MockScrollGestureTarget { 145 class MockScrollTouchTarget : public MockScrollGestureTarget {
152 public: 146 public:
153 MockScrollTouchTarget() : started_(false) {} 147 MockScrollTouchTarget() : started_(false) {}
154 virtual ~MockScrollTouchTarget() {} 148 ~MockScrollTouchTarget() override {}
155 149
156 virtual void DispatchInputEventToPlatform( 150 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
157 const WebInputEvent& event) override {
158 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 151 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
159 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 152 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
160 ASSERT_EQ(touch_event.touchesLength, 1U); 153 ASSERT_EQ(touch_event.touchesLength, 1U);
161 154
162 if (!started_) { 155 if (!started_) {
163 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); 156 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
164 start_.SetPoint(touch_event.touches[0].position.x, 157 start_.SetPoint(touch_event.touches[0].position.x,
165 touch_event.touches[0].position.y); 158 touch_event.touches[0].position.y);
166 last_touch_point_ = start_; 159 last_touch_point_ = start_;
167 started_ = true; 160 started_ = true;
(...skipping 25 matching lines...) Expand all
193 ZOOM_DIRECTION_UNKNOWN, 186 ZOOM_DIRECTION_UNKNOWN,
194 ZOOM_IN, 187 ZOOM_IN,
195 ZOOM_OUT 188 ZOOM_OUT
196 }; 189 };
197 190
198 MockSyntheticPinchTouchTarget() 191 MockSyntheticPinchTouchTarget()
199 : initial_pointer_distance_(0), 192 : initial_pointer_distance_(0),
200 last_pointer_distance_(0), 193 last_pointer_distance_(0),
201 zoom_direction_(ZOOM_DIRECTION_UNKNOWN), 194 zoom_direction_(ZOOM_DIRECTION_UNKNOWN),
202 started_(false) {} 195 started_(false) {}
203 virtual ~MockSyntheticPinchTouchTarget() {} 196 ~MockSyntheticPinchTouchTarget() override {}
204 197
205 virtual void DispatchInputEventToPlatform( 198 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
206 const WebInputEvent& event) override {
207 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 199 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
208 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 200 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
209 ASSERT_EQ(touch_event.touchesLength, 2U); 201 ASSERT_EQ(touch_event.touchesLength, 2U);
210 202
211 if (!started_) { 203 if (!started_) {
212 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart); 204 ASSERT_EQ(touch_event.type, WebInputEvent::TouchStart);
213 205
214 start_0_ = gfx::PointF(touch_event.touches[0].position); 206 start_0_ = gfx::PointF(touch_event.touches[0].position);
215 start_1_ = gfx::PointF(touch_event.touches[1].position); 207 start_1_ = gfx::PointF(touch_event.touches[1].position);
216 last_pointer_distance_ = (start_0_ - start_1_).Length(); 208 last_pointer_distance_ = (start_0_ - start_1_).Length();
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 float last_pointer_distance_; 263 float last_pointer_distance_;
272 ZoomDirection zoom_direction_; 264 ZoomDirection zoom_direction_;
273 gfx::PointF start_0_; 265 gfx::PointF start_0_;
274 gfx::PointF start_1_; 266 gfx::PointF start_1_;
275 bool started_; 267 bool started_;
276 }; 268 };
277 269
278 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget { 270 class MockSyntheticTapGestureTarget : public MockSyntheticGestureTarget {
279 public: 271 public:
280 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {} 272 MockSyntheticTapGestureTarget() : state_(NOT_STARTED) {}
281 virtual ~MockSyntheticTapGestureTarget() {} 273 ~MockSyntheticTapGestureTarget() override {}
282 274
283 bool GestureFinished() const { return state_ == FINISHED; } 275 bool GestureFinished() const { return state_ == FINISHED; }
284 gfx::PointF position() const { return position_; } 276 gfx::PointF position() const { return position_; }
285 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; } 277 base::TimeDelta GetDuration() const { return stop_time_ - start_time_; }
286 278
287 protected: 279 protected:
288 enum GestureState { 280 enum GestureState {
289 NOT_STARTED, 281 NOT_STARTED,
290 STARTED, 282 STARTED,
291 FINISHED 283 FINISHED
292 }; 284 };
293 285
294 gfx::PointF position_; 286 gfx::PointF position_;
295 base::TimeDelta start_time_; 287 base::TimeDelta start_time_;
296 base::TimeDelta stop_time_; 288 base::TimeDelta stop_time_;
297 GestureState state_; 289 GestureState state_;
298 }; 290 };
299 291
300 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget { 292 class MockSyntheticTapTouchTarget : public MockSyntheticTapGestureTarget {
301 public: 293 public:
302 MockSyntheticTapTouchTarget() {} 294 MockSyntheticTapTouchTarget() {}
303 virtual ~MockSyntheticTapTouchTarget() {} 295 ~MockSyntheticTapTouchTarget() override {}
304 296
305 virtual void DispatchInputEventToPlatform( 297 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
306 const WebInputEvent& event) override {
307 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type)); 298 ASSERT_TRUE(WebInputEvent::isTouchEventType(event.type));
308 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event); 299 const WebTouchEvent& touch_event = static_cast<const WebTouchEvent&>(event);
309 ASSERT_EQ(touch_event.touchesLength, 1U); 300 ASSERT_EQ(touch_event.touchesLength, 1U);
310 301
311 switch (state_) { 302 switch (state_) {
312 case NOT_STARTED: 303 case NOT_STARTED:
313 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart); 304 EXPECT_EQ(touch_event.type, WebInputEvent::TouchStart);
314 position_ = gfx::PointF(touch_event.touches[0].position); 305 position_ = gfx::PointF(touch_event.touches[0].position);
315 start_time_ = base::TimeDelta::FromMilliseconds( 306 start_time_ = base::TimeDelta::FromMilliseconds(
316 static_cast<int64>(touch_event.timeStampSeconds * 1000)); 307 static_cast<int64>(touch_event.timeStampSeconds * 1000));
317 state_ = STARTED; 308 state_ = STARTED;
318 break; 309 break;
319 case STARTED: 310 case STARTED:
320 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd); 311 EXPECT_EQ(touch_event.type, WebInputEvent::TouchEnd);
321 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position)); 312 EXPECT_EQ(position_, gfx::PointF(touch_event.touches[0].position));
322 stop_time_ = base::TimeDelta::FromMilliseconds( 313 stop_time_ = base::TimeDelta::FromMilliseconds(
323 static_cast<int64>(touch_event.timeStampSeconds * 1000)); 314 static_cast<int64>(touch_event.timeStampSeconds * 1000));
324 state_ = FINISHED; 315 state_ = FINISHED;
325 break; 316 break;
326 case FINISHED: 317 case FINISHED:
327 EXPECT_FALSE(true); 318 EXPECT_FALSE(true);
328 break; 319 break;
329 } 320 }
330 } 321 }
331 }; 322 };
332 323
333 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget { 324 class MockSyntheticTapMouseTarget : public MockSyntheticTapGestureTarget {
334 public: 325 public:
335 MockSyntheticTapMouseTarget() {} 326 MockSyntheticTapMouseTarget() {}
336 virtual ~MockSyntheticTapMouseTarget() {} 327 ~MockSyntheticTapMouseTarget() override {}
337 328
338 virtual void DispatchInputEventToPlatform( 329 void DispatchInputEventToPlatform(const WebInputEvent& event) override {
339 const WebInputEvent& event) override {
340 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type)); 330 ASSERT_TRUE(WebInputEvent::isMouseEventType(event.type));
341 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event); 331 const WebMouseEvent& mouse_event = static_cast<const WebMouseEvent&>(event);
342 332
343 switch (state_) { 333 switch (state_) {
344 case NOT_STARTED: 334 case NOT_STARTED:
345 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown); 335 EXPECT_EQ(mouse_event.type, WebInputEvent::MouseDown);
346 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft); 336 EXPECT_EQ(mouse_event.button, WebMouseEvent::ButtonLeft);
347 EXPECT_EQ(mouse_event.clickCount, 1); 337 EXPECT_EQ(mouse_event.clickCount, 1);
348 position_ = gfx::PointF(mouse_event.x, mouse_event.y); 338 position_ = gfx::PointF(mouse_event.x, mouse_event.y);
349 start_time_ = base::TimeDelta::FromMilliseconds( 339 start_time_ = base::TimeDelta::FromMilliseconds(
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 EXPECT_TRUE(tap_target->GestureFinished()); 985 EXPECT_TRUE(tap_target->GestureFinished());
996 EXPECT_EQ(tap_target->position(), params.position); 986 EXPECT_EQ(tap_target->position(), params.position);
997 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms); 987 EXPECT_EQ(tap_target->GetDuration().InMilliseconds(), params.duration_ms);
998 EXPECT_GE(GetTotalTime(), 988 EXPECT_GE(GetTotalTime(),
999 base::TimeDelta::FromMilliseconds(params.duration_ms)); 989 base::TimeDelta::FromMilliseconds(params.duration_ms));
1000 } 990 }
1001 991
1002 } // namespace 992 } // namespace
1003 993
1004 } // namespace content 994 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698