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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 684483002: Standardize usage of virtual/override/final specifiers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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
« no previous file with comments | « ui/aura/env.h ('k') | ui/aura/scoped_window_targeter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/memory/scoped_vector.h" 6 #include "base/memory/scoped_vector.h"
7 #include "base/run_loop.h" 7 #include "base/run_loop.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 scroll_velocity_x_(0), 92 scroll_velocity_x_(0),
93 scroll_velocity_y_(0), 93 scroll_velocity_y_(0),
94 velocity_x_(0), 94 velocity_x_(0),
95 velocity_y_(0), 95 velocity_y_(0),
96 scroll_x_hint_(0), 96 scroll_x_hint_(0),
97 scroll_y_hint_(0), 97 scroll_y_hint_(0),
98 tap_count_(0), 98 tap_count_(0),
99 flags_(0), 99 flags_(0),
100 wait_until_event_(ui::ET_UNKNOWN) {} 100 wait_until_event_(ui::ET_UNKNOWN) {}
101 101
102 virtual ~GestureEventConsumeDelegate() {} 102 ~GestureEventConsumeDelegate() override {}
103 103
104 void Reset() { 104 void Reset() {
105 events_.clear(); 105 events_.clear();
106 tap_ = false; 106 tap_ = false;
107 tap_down_ = false; 107 tap_down_ = false;
108 tap_cancel_ = false; 108 tap_cancel_ = false;
109 begin_ = false; 109 begin_ = false;
110 end_ = false; 110 end_ = false;
111 scroll_begin_ = false; 111 scroll_begin_ = false;
112 scroll_update_ = false; 112 scroll_update_ = false;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 int tap_count() const { return tap_count_; } 189 int tap_count() const { return tap_count_; }
190 int flags() const { return flags_; } 190 int flags() const { return flags_; }
191 const ui::LatencyInfo& latency_info() const { return latency_info_; } 191 const ui::LatencyInfo& latency_info() const { return latency_info_; }
192 192
193 void WaitUntilReceivedGesture(ui::EventType type) { 193 void WaitUntilReceivedGesture(ui::EventType type) {
194 wait_until_event_ = type; 194 wait_until_event_ = type;
195 run_loop_.reset(new base::RunLoop()); 195 run_loop_.reset(new base::RunLoop());
196 run_loop_->Run(); 196 run_loop_->Run();
197 } 197 }
198 198
199 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { 199 void OnGestureEvent(ui::GestureEvent* gesture) override {
200 events_.push_back(gesture->type()); 200 events_.push_back(gesture->type());
201 bounding_box_ = gesture->details().bounding_box(); 201 bounding_box_ = gesture->details().bounding_box();
202 flags_ = gesture->flags(); 202 flags_ = gesture->flags();
203 latency_info_ = *gesture->latency(); 203 latency_info_ = *gesture->latency();
204 switch (gesture->type()) { 204 switch (gesture->type()) {
205 case ui::ET_GESTURE_TAP: 205 case ui::ET_GESTURE_TAP:
206 tap_location_ = gesture->location(); 206 tap_location_ = gesture->location();
207 tap_count_ = gesture->details().tap_count(); 207 tap_count_ = gesture->details().tap_count();
208 tap_ = true; 208 tap_ = true;
209 break; 209 break;
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 332 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate);
333 }; 333 };
334 334
335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 335 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
336 public: 336 public:
337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher) 337 explicit QueueTouchEventDelegate(WindowEventDispatcher* dispatcher)
338 : window_(NULL), 338 : window_(NULL),
339 dispatcher_(dispatcher), 339 dispatcher_(dispatcher),
340 queue_events_(true) { 340 queue_events_(true) {
341 } 341 }
342 virtual ~QueueTouchEventDelegate() { 342 ~QueueTouchEventDelegate() override {
343 while(!queue_.empty()) { 343 while(!queue_.empty()) {
344 delete queue_.front(); 344 delete queue_.front();
345 queue_.pop(); 345 queue_.pop();
346 } 346 }
347 } 347 }
348 348
349 virtual void OnTouchEvent(ui::TouchEvent* event) override { 349 void OnTouchEvent(ui::TouchEvent* event) override {
350 if (queue_events_) { 350 if (queue_events_) {
351 queue_.push(new ui::TouchEvent(*event, window_, window_)); 351 queue_.push(new ui::TouchEvent(*event, window_, window_));
352 event->StopPropagation(); 352 event->StopPropagation();
353 } 353 }
354 } 354 }
355 355
356 void ReceivedAck() { 356 void ReceivedAck() {
357 ReceivedAckImpl(false); 357 ReceivedAckImpl(false);
358 } 358 }
359 359
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 double_click_ = false; 402 double_click_ = false;
403 } 403 }
404 404
405 bool mouse_enter() const { return mouse_enter_; } 405 bool mouse_enter() const { return mouse_enter_; }
406 bool mouse_exit() const { return mouse_exit_; } 406 bool mouse_exit() const { return mouse_exit_; }
407 bool mouse_press() const { return mouse_press_; } 407 bool mouse_press() const { return mouse_press_; }
408 bool mouse_move() const { return mouse_move_; } 408 bool mouse_move() const { return mouse_move_; }
409 bool mouse_release() const { return mouse_release_; } 409 bool mouse_release() const { return mouse_release_; }
410 bool double_click() const { return double_click_; } 410 bool double_click() const { return double_click_; }
411 411
412 virtual void OnMouseEvent(ui::MouseEvent* event) override { 412 void OnMouseEvent(ui::MouseEvent* event) override {
413 switch (event->type()) { 413 switch (event->type()) {
414 case ui::ET_MOUSE_PRESSED: 414 case ui::ET_MOUSE_PRESSED:
415 double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK; 415 double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK;
416 mouse_press_ = true; 416 mouse_press_ = true;
417 break; 417 break;
418 case ui::ET_MOUSE_RELEASED: 418 case ui::ET_MOUSE_RELEASED:
419 mouse_release_ = true; 419 mouse_release_ = true;
420 break; 420 break;
421 case ui::ET_MOUSE_MOVED: 421 case ui::ET_MOUSE_MOVED:
422 mouse_move_ = true; 422 mouse_move_ = true;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 }; 529 };
530 530
531 // An event handler to keep track of events. 531 // An event handler to keep track of events.
532 class TestEventHandler : public ui::EventHandler { 532 class TestEventHandler : public ui::EventHandler {
533 public: 533 public:
534 TestEventHandler() 534 TestEventHandler()
535 : touch_released_count_(0), 535 : touch_released_count_(0),
536 touch_pressed_count_(0), 536 touch_pressed_count_(0),
537 touch_moved_count_(0) {} 537 touch_moved_count_(0) {}
538 538
539 virtual ~TestEventHandler() {} 539 ~TestEventHandler() override {}
540 540
541 virtual void OnTouchEvent(ui::TouchEvent* event) override { 541 void OnTouchEvent(ui::TouchEvent* event) override {
542 switch (event->type()) { 542 switch (event->type()) {
543 case ui::ET_TOUCH_RELEASED: 543 case ui::ET_TOUCH_RELEASED:
544 touch_released_count_++; 544 touch_released_count_++;
545 break; 545 break;
546 case ui::ET_TOUCH_PRESSED: 546 case ui::ET_TOUCH_PRESSED:
547 touch_pressed_count_++; 547 touch_pressed_count_++;
548 break; 548 break;
549 case ui::ET_TOUCH_MOVED: 549 case ui::ET_TOUCH_MOVED:
550 touch_moved_count_++; 550 touch_moved_count_++;
551 break; 551 break;
(...skipping 29 matching lines...) Expand all
581 std::vector<gfx::PointF> cancelled_touch_points_; 581 std::vector<gfx::PointF> cancelled_touch_points_;
582 582
583 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 583 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
584 }; 584 };
585 585
586 // Removes the target window from its parent when it receives a touch-cancel 586 // Removes the target window from its parent when it receives a touch-cancel
587 // event. 587 // event.
588 class RemoveOnTouchCancelHandler : public TestEventHandler { 588 class RemoveOnTouchCancelHandler : public TestEventHandler {
589 public: 589 public:
590 RemoveOnTouchCancelHandler() {} 590 RemoveOnTouchCancelHandler() {}
591 virtual ~RemoveOnTouchCancelHandler() {} 591 ~RemoveOnTouchCancelHandler() override {}
592 592
593 private: 593 private:
594 // ui::EventHandler: 594 // ui::EventHandler:
595 virtual void OnTouchEvent(ui::TouchEvent* event) override { 595 void OnTouchEvent(ui::TouchEvent* event) override {
596 TestEventHandler::OnTouchEvent(event); 596 TestEventHandler::OnTouchEvent(event);
597 if (event->type() == ui::ET_TOUCH_CANCELLED) { 597 if (event->type() == ui::ET_TOUCH_CANCELLED) {
598 Window* target = static_cast<Window*>(event->target()); 598 Window* target = static_cast<Window*>(event->target());
599 // This is tiptoeing around crbug.com/310172. If this event handler isn't 599 // This is tiptoeing around crbug.com/310172. If this event handler isn't
600 // removed, we enter an infinite loop. 600 // removed, we enter an infinite loop.
601 target->RemovePreTargetHandler(this); 601 target->RemovePreTargetHandler(this);
602 target->parent()->RemoveChild(target); 602 target->parent()->RemoveChild(target);
603 } 603 }
604 } 604 }
605 605
(...skipping 20 matching lines...) Expand all
626 run_loop.Run(); 626 run_loop.Run();
627 } 627 }
628 628
629 } // namespace 629 } // namespace
630 630
631 class GestureRecognizerTest : public AuraTestBase, 631 class GestureRecognizerTest : public AuraTestBase,
632 public ::testing::WithParamInterface<bool> { 632 public ::testing::WithParamInterface<bool> {
633 public: 633 public:
634 GestureRecognizerTest() {} 634 GestureRecognizerTest() {}
635 635
636 virtual void SetUp() override { 636 void SetUp() override {
637 AuraTestBase::SetUp(); 637 AuraTestBase::SetUp();
638 ui::GestureConfiguration::set_show_press_delay_in_ms(2); 638 ui::GestureConfiguration::set_show_press_delay_in_ms(2);
639 ui::GestureConfiguration::set_long_press_time_in_ms(3); 639 ui::GestureConfiguration::set_long_press_time_in_ms(3);
640 } 640 }
641 641
642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 642 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest);
643 }; 643 };
644 644
645 // Check that appropriate touch events generate tap gesture events. 645 // Check that appropriate touch events generate tap gesture events.
646 TEST_F(GestureRecognizerTest, GestureEventTap) { 646 TEST_F(GestureRecognizerTest, GestureEventTap) {
(...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2970 2970
2971 delegate->Reset(); 2971 delegate->Reset();
2972 delegate->ReceivedAckPreventDefaulted(); 2972 delegate->ReceivedAckPreventDefaulted();
2973 EXPECT_FALSE(delegate->long_press()); 2973 EXPECT_FALSE(delegate->long_press());
2974 } 2974 }
2975 2975
2976 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. 2976 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
2977 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { 2977 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate {
2978 public: 2978 public:
2979 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} 2979 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
2980 virtual ~ConsumesTouchMovesDelegate() {} 2980 ~ConsumesTouchMovesDelegate() override {}
2981 2981
2982 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } 2982 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; }
2983 2983
2984 private: 2984 private:
2985 virtual void OnTouchEvent(ui::TouchEvent* touch) override { 2985 void OnTouchEvent(ui::TouchEvent* touch) override {
2986 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) 2986 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED)
2987 touch->SetHandled(); 2987 touch->SetHandled();
2988 else 2988 else
2989 GestureEventConsumeDelegate::OnTouchEvent(touch); 2989 GestureEventConsumeDelegate::OnTouchEvent(touch);
2990 } 2990 }
2991 2991
2992 bool consume_touch_move_; 2992 bool consume_touch_move_;
2993 2993
2994 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 2994 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
2995 }; 2995 };
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 } 4101 }
4102 4102
4103 // A delegate that deletes a window on long press. 4103 // A delegate that deletes a window on long press.
4104 class GestureEventDeleteWindowOnLongPress : public GestureEventConsumeDelegate { 4104 class GestureEventDeleteWindowOnLongPress : public GestureEventConsumeDelegate {
4105 public: 4105 public:
4106 GestureEventDeleteWindowOnLongPress() 4106 GestureEventDeleteWindowOnLongPress()
4107 : window_(NULL) {} 4107 : window_(NULL) {}
4108 4108
4109 void set_window(aura::Window** window) { window_ = window; } 4109 void set_window(aura::Window** window) { window_ = window; }
4110 4110
4111 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { 4111 void OnGestureEvent(ui::GestureEvent* gesture) override {
4112 GestureEventConsumeDelegate::OnGestureEvent(gesture); 4112 GestureEventConsumeDelegate::OnGestureEvent(gesture);
4113 if (gesture->type() != ui::ET_GESTURE_LONG_PRESS) 4113 if (gesture->type() != ui::ET_GESTURE_LONG_PRESS)
4114 return; 4114 return;
4115 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_); 4115 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_);
4116 delete *window_; 4116 delete *window_;
4117 *window_ = NULL; 4117 *window_ = NULL;
4118 } 4118 }
4119 4119
4120 private: 4120 private:
4121 aura::Window** window_; 4121 aura::Window** window_;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
4306 ui::TouchEvent move3( 4306 ui::TouchEvent move3(
4307 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); 4307 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now());
4308 DispatchEventUsingWindowDispatcher(&move3); 4308 DispatchEventUsingWindowDispatcher(&move3);
4309 4309
4310 delegate->ReceivedAck(); 4310 delegate->ReceivedAck();
4311 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 4311 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE);
4312 } 4312 }
4313 4313
4314 } // namespace test 4314 } // namespace test
4315 } // namespace aura 4315 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/env.h ('k') | ui/aura/scoped_window_targeter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698