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

Side by Side Diff: ui/aura/window_event_dispatcher_unittest.cc

Issue 679633005: Expose native, desktop and mobile gesture detection defaults (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 6 years 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/window_event_dispatcher.cc ('k') | ui/chromeos/touch_exploration_controller.cc » ('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 "ui/aura/window_event_dispatcher.h" 5 #include "ui/aura/window_event_dispatcher.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 namespace { 442 namespace {
443 443
444 // FilterFilter that tracks the types of events it's seen. 444 // FilterFilter that tracks the types of events it's seen.
445 class EventFilterRecorder : public ui::EventHandler { 445 class EventFilterRecorder : public ui::EventHandler {
446 public: 446 public:
447 typedef std::vector<ui::EventType> Events; 447 typedef std::vector<ui::EventType> Events;
448 typedef std::vector<gfx::Point> EventLocations; 448 typedef std::vector<gfx::Point> EventLocations;
449 typedef std::vector<int> EventFlags; 449 typedef std::vector<int> EventFlags;
450 450
451 EventFilterRecorder() 451 EventFilterRecorder()
452 : wait_until_event_(ui::ET_UNKNOWN) { 452 : wait_until_event_(ui::ET_UNKNOWN),
453 last_touch_may_cause_scrolling_(false) {
453 } 454 }
454 455
455 const Events& events() const { return events_; } 456 const Events& events() const { return events_; }
456 457
457 const EventLocations& mouse_locations() const { return mouse_locations_; } 458 const EventLocations& mouse_locations() const { return mouse_locations_; }
458 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; } 459 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; }
459 const EventLocations& touch_locations() const { return touch_locations_; } 460 const EventLocations& touch_locations() const { return touch_locations_; }
460 const EventLocations& gesture_locations() const { return gesture_locations_; } 461 const EventLocations& gesture_locations() const { return gesture_locations_; }
461 const EventFlags& mouse_event_flags() const { return mouse_event_flags_; } 462 const EventFlags& mouse_event_flags() const { return mouse_event_flags_; }
462 463
463 void WaitUntilReceivedEvent(ui::EventType type) { 464 void WaitUntilReceivedEvent(ui::EventType type) {
464 wait_until_event_ = type; 465 wait_until_event_ = type;
465 run_loop_.reset(new base::RunLoop()); 466 run_loop_.reset(new base::RunLoop());
466 run_loop_->Run(); 467 run_loop_->Run();
467 } 468 }
468 469
469 Events GetAndResetEvents() { 470 Events GetAndResetEvents() {
470 Events events = events_; 471 Events events = events_;
471 Reset(); 472 Reset();
472 return events; 473 return events;
473 } 474 }
474 475
475 void Reset() { 476 void Reset() {
476 events_.clear(); 477 events_.clear();
477 mouse_locations_.clear(); 478 mouse_locations_.clear();
478 touch_locations_.clear(); 479 touch_locations_.clear();
479 gesture_locations_.clear(); 480 gesture_locations_.clear();
480 mouse_event_flags_.clear(); 481 mouse_event_flags_.clear();
482 last_touch_may_cause_scrolling_ = false;
481 } 483 }
482 484
483 // ui::EventHandler overrides: 485 // ui::EventHandler overrides:
484 void OnEvent(ui::Event* event) override { 486 void OnEvent(ui::Event* event) override {
485 ui::EventHandler::OnEvent(event); 487 ui::EventHandler::OnEvent(event);
486 events_.push_back(event->type()); 488 events_.push_back(event->type());
487 if (wait_until_event_ == event->type() && run_loop_) { 489 if (wait_until_event_ == event->type() && run_loop_) {
488 run_loop_->Quit(); 490 run_loop_->Quit();
489 wait_until_event_ = ui::ET_UNKNOWN; 491 wait_until_event_ = ui::ET_UNKNOWN;
490 } 492 }
491 } 493 }
492 494
493 void OnMouseEvent(ui::MouseEvent* event) override { 495 void OnMouseEvent(ui::MouseEvent* event) override {
494 mouse_locations_.push_back(event->location()); 496 mouse_locations_.push_back(event->location());
495 mouse_event_flags_.push_back(event->flags()); 497 mouse_event_flags_.push_back(event->flags());
496 } 498 }
497 499
498 void OnTouchEvent(ui::TouchEvent* event) override { 500 void OnTouchEvent(ui::TouchEvent* event) override {
499 touch_locations_.push_back(event->location()); 501 touch_locations_.push_back(event->location());
502 last_touch_may_cause_scrolling_ = event->may_cause_scrolling();
500 } 503 }
501 504
502 void OnGestureEvent(ui::GestureEvent* event) override { 505 void OnGestureEvent(ui::GestureEvent* event) override {
503 gesture_locations_.push_back(event->location()); 506 gesture_locations_.push_back(event->location());
504 } 507 }
505 508
506 bool HasReceivedEvent(ui::EventType type) { 509 bool HasReceivedEvent(ui::EventType type) {
507 return std::find(events_.begin(), events_.end(), type) != events_.end(); 510 return std::find(events_.begin(), events_.end(), type) != events_.end();
508 } 511 }
509 512
513 bool LastTouchMayCauseScrolling() const {
514 return last_touch_may_cause_scrolling_;
515 }
516
510 private: 517 private:
511 scoped_ptr<base::RunLoop> run_loop_; 518 scoped_ptr<base::RunLoop> run_loop_;
512 ui::EventType wait_until_event_; 519 ui::EventType wait_until_event_;
513 520
514 Events events_; 521 Events events_;
515 EventLocations mouse_locations_; 522 EventLocations mouse_locations_;
516 EventLocations touch_locations_; 523 EventLocations touch_locations_;
517 EventLocations gesture_locations_; 524 EventLocations gesture_locations_;
518 EventFlags mouse_event_flags_; 525 EventFlags mouse_event_flags_;
526 bool last_touch_may_cause_scrolling_;
519 527
520 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); 528 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder);
521 }; 529 };
522 530
523 // Converts an EventType to a string. 531 // Converts an EventType to a string.
524 std::string EventTypeToString(ui::EventType type) { 532 std::string EventTypeToString(ui::EventType type) {
525 switch (type) { 533 switch (type) {
526 case ui::ET_TOUCH_RELEASED: 534 case ui::ET_TOUCH_RELEASED:
527 return "TOUCH_RELEASED"; 535 return "TOUCH_RELEASED";
528 536
(...skipping 1842 matching lines...) Expand 10 before | Expand all | Expand 10 after
2371 2379
2372 ASSERT_EQ(1u, recorder.touch_locations().size()); 2380 ASSERT_EQ(1u, recorder.touch_locations().size());
2373 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), 2381 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(),
2374 recorder.touch_locations()[0].ToString()); 2382 recorder.touch_locations()[0].ToString());
2375 2383
2376 ASSERT_EQ(2u, recorder.gesture_locations().size()); 2384 ASSERT_EQ(2u, recorder.gesture_locations().size());
2377 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(), 2385 EXPECT_EQ(gfx::Point(kX - kWindowOffset, kY - kWindowOffset).ToString(),
2378 recorder.gesture_locations()[0].ToString()); 2386 recorder.gesture_locations()[0].ToString());
2379 } 2387 }
2380 2388
2389 // Tests that a scroll-generating touch-event is marked as such.
2390 TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) {
2391 EventFilterRecorder recorder;
2392 root_window()->AddPreTargetHandler(&recorder);
2393
2394 const gfx::Point location(20, 20);
2395 ui::TouchEvent press(
2396 ui::ET_TOUCH_PRESSED, location, 0, ui::EventTimeForNow());
2397 DispatchEventUsingWindowDispatcher(&press);
2398 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling());
2399 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_PRESSED));
2400 recorder.Reset();
2401
2402 ui::TouchEvent move(ui::ET_TOUCH_MOVED,
2403 location + gfx::Vector2d(100, 100),
2404 0,
2405 ui::EventTimeForNow());
2406 DispatchEventUsingWindowDispatcher(&move);
2407 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling());
2408 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
2409 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_BEGIN));
2410 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE));
2411 recorder.Reset();
2412
2413 ui::TouchEvent move2(ui::ET_TOUCH_MOVED,
2414 location + gfx::Vector2d(200, 200),
2415 0,
2416 ui::EventTimeForNow());
2417 DispatchEventUsingWindowDispatcher(&move2);
2418 EXPECT_TRUE(recorder.LastTouchMayCauseScrolling());
2419 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_MOVED));
2420 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_UPDATE));
2421 recorder.Reset();
2422
2423 // Delay the release to avoid fling generation.
2424 ui::TouchEvent release(
2425 ui::ET_TOUCH_RELEASED,
2426 location + gfx::Vector2dF(200, 200),
2427 0,
2428 ui::EventTimeForNow() + base::TimeDelta::FromSeconds(1));
2429 DispatchEventUsingWindowDispatcher(&release);
2430 EXPECT_FALSE(recorder.LastTouchMayCauseScrolling());
2431 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_TOUCH_RELEASED));
2432 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_SCROLL_END));
2433
2434 root_window()->RemovePreTargetHandler(&recorder);
2435 }
2381 } // namespace aura 2436 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window_event_dispatcher.cc ('k') | ui/chromeos/touch_exploration_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698