OLD | NEW |
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 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 dispatcher_(dispatcher), | 339 dispatcher_(dispatcher), |
340 queue_events_(true) { | 340 queue_events_(true) { |
341 } | 341 } |
342 virtual ~QueueTouchEventDelegate() { | 342 virtual ~QueueTouchEventDelegate() { |
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 virtual 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 Loading... |
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 virtual 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~TestEventHandler() {} |
540 | 540 |
541 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | 541 virtual 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 virtual ~RemoveOnTouchCancelHandler() {} |
592 | 592 |
593 private: | 593 private: |
594 // ui::EventHandler: | 594 // ui::EventHandler: |
595 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | 595 virtual 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 Loading... |
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 virtual 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_seconds(0.003); | 639 ui::GestureConfiguration::set_long_press_time_in_seconds(0.003); |
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 2325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2972 | 2972 |
2973 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. | 2973 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. |
2974 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { | 2974 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { |
2975 public: | 2975 public: |
2976 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} | 2976 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} |
2977 virtual ~ConsumesTouchMovesDelegate() {} | 2977 virtual ~ConsumesTouchMovesDelegate() {} |
2978 | 2978 |
2979 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } | 2979 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } |
2980 | 2980 |
2981 private: | 2981 private: |
2982 virtual void OnTouchEvent(ui::TouchEvent* touch) OVERRIDE { | 2982 virtual void OnTouchEvent(ui::TouchEvent* touch) override { |
2983 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) | 2983 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) |
2984 touch->SetHandled(); | 2984 touch->SetHandled(); |
2985 else | 2985 else |
2986 GestureEventConsumeDelegate::OnTouchEvent(touch); | 2986 GestureEventConsumeDelegate::OnTouchEvent(touch); |
2987 } | 2987 } |
2988 | 2988 |
2989 bool consume_touch_move_; | 2989 bool consume_touch_move_; |
2990 | 2990 |
2991 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); | 2991 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); |
2992 }; | 2992 }; |
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4098 } | 4098 } |
4099 | 4099 |
4100 // A delegate that deletes a window on long press. | 4100 // A delegate that deletes a window on long press. |
4101 class GestureEventDeleteWindowOnLongPress : public GestureEventConsumeDelegate { | 4101 class GestureEventDeleteWindowOnLongPress : public GestureEventConsumeDelegate { |
4102 public: | 4102 public: |
4103 GestureEventDeleteWindowOnLongPress() | 4103 GestureEventDeleteWindowOnLongPress() |
4104 : window_(NULL) {} | 4104 : window_(NULL) {} |
4105 | 4105 |
4106 void set_window(aura::Window** window) { window_ = window; } | 4106 void set_window(aura::Window** window) { window_ = window; } |
4107 | 4107 |
4108 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { | 4108 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { |
4109 GestureEventConsumeDelegate::OnGestureEvent(gesture); | 4109 GestureEventConsumeDelegate::OnGestureEvent(gesture); |
4110 if (gesture->type() != ui::ET_GESTURE_LONG_PRESS) | 4110 if (gesture->type() != ui::ET_GESTURE_LONG_PRESS) |
4111 return; | 4111 return; |
4112 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_); | 4112 ui::GestureRecognizer::Get()->CleanupStateForConsumer(*window_); |
4113 delete *window_; | 4113 delete *window_; |
4114 *window_ = NULL; | 4114 *window_ = NULL; |
4115 } | 4115 } |
4116 | 4116 |
4117 private: | 4117 private: |
4118 aura::Window** window_; | 4118 aura::Window** window_; |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4303 ui::TouchEvent move3( | 4303 ui::TouchEvent move3( |
4304 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4304 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
4305 DispatchEventUsingWindowDispatcher(&move3); | 4305 DispatchEventUsingWindowDispatcher(&move3); |
4306 | 4306 |
4307 delegate->ReceivedAck(); | 4307 delegate->ReceivedAck(); |
4308 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4308 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
4309 } | 4309 } |
4310 | 4310 |
4311 } // namespace test | 4311 } // namespace test |
4312 } // namespace aura | 4312 } // namespace aura |
OLD | NEW |