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

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

Issue 136843003: Wait for SHOW_PRESS gesture to avoid flake in root_window_unittest.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase? Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/root_window.h" 5 #include "ui/aura/root_window.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 412 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 423 }
424 424
425 namespace { 425 namespace {
426 426
427 // FilterFilter that tracks the types of events it's seen. 427 // FilterFilter that tracks the types of events it's seen.
428 class EventFilterRecorder : public ui::EventHandler { 428 class EventFilterRecorder : public ui::EventHandler {
429 public: 429 public:
430 typedef std::vector<ui::EventType> Events; 430 typedef std::vector<ui::EventType> Events;
431 typedef std::vector<gfx::Point> EventLocations; 431 typedef std::vector<gfx::Point> EventLocations;
432 432
433 EventFilterRecorder() {} 433 EventFilterRecorder()
434 : wait_until_event_(ui::ET_UNKNOWN) {
435 }
434 436
435 const Events& events() const { return events_; } 437 const Events& events() const { return events_; }
436 438
437 const EventLocations& mouse_locations() const { return mouse_locations_; } 439 const EventLocations& mouse_locations() const { return mouse_locations_; }
438 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; } 440 gfx::Point mouse_location(int i) const { return mouse_locations_[i]; }
439 const EventLocations& touch_locations() const { return touch_locations_; } 441 const EventLocations& touch_locations() const { return touch_locations_; }
440 442
443 void WaitUntilReceivedGesture(ui::EventType type) {
sadrul 2014/01/15 19:08:59 Call this WaitUntilReceivedEvent
tdresser 2014/01/15 19:30:41 Done.
444 wait_until_event_ = type;
445 run_loop_.reset(new base::RunLoop(
446 Env::GetInstance()->GetDispatcher()));
447 run_loop_->Run();
448 }
449
441 Events GetAndResetEvents() { 450 Events GetAndResetEvents() {
442 Events events = events_; 451 Events events = events_;
443 Reset(); 452 Reset();
444 return events; 453 return events;
445 } 454 }
446 455
447 void Reset() { 456 void Reset() {
448 events_.clear(); 457 events_.clear();
449 mouse_locations_.clear(); 458 mouse_locations_.clear();
450 touch_locations_.clear(); 459 touch_locations_.clear();
451 } 460 }
452 461
453 // ui::EventHandler overrides: 462 // ui::EventHandler overrides:
454 virtual void OnEvent(ui::Event* event) OVERRIDE { 463 virtual void OnEvent(ui::Event* event) OVERRIDE {
455 ui::EventHandler::OnEvent(event); 464 ui::EventHandler::OnEvent(event);
456 events_.push_back(event->type()); 465 events_.push_back(event->type());
457 } 466 }
458 467
459 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 468 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE {
460 mouse_locations_.push_back(event->location()); 469 mouse_locations_.push_back(event->location());
461 } 470 }
462 471
463 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 472 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
464 touch_locations_.push_back(event->location()); 473 touch_locations_.push_back(event->location());
465 } 474 }
466 475
476 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE {
477 if (wait_until_event_ == event->type() && run_loop_) {
478 run_loop_->Quit();
479 wait_until_event_ = ui::ET_UNKNOWN;
sadrul 2014/01/15 19:08:59 Do this in OnEvent
tdresser 2014/01/15 19:30:41 Done.
480 }
481 }
482
467 private: 483 private:
484 scoped_ptr<base::RunLoop> run_loop_;
485 ui::EventType wait_until_event_;
486
468 Events events_; 487 Events events_;
469 EventLocations mouse_locations_; 488 EventLocations mouse_locations_;
470 EventLocations touch_locations_; 489 EventLocations touch_locations_;
471 490
472 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); 491 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder);
473 }; 492 };
474 493
475 // Converts an EventType to a string. 494 // Converts an EventType to a string.
476 std::string EventTypeToString(ui::EventType type) { 495 std::string EventTypeToString(ui::EventType type) {
477 switch (type) { 496 switch (type) {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 &mouse_dragged_event); 681 &mouse_dragged_event);
663 dispatcher()->ReleasePointerMoves(); 682 dispatcher()->ReleasePointerMoves();
664 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 683 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
665 &mouse_dragged_event2); 684 &mouse_dragged_event2);
666 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 685 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
667 filter->Reset(); 686 filter->Reset();
668 RunAllPendingInMessageLoop(); 687 RunAllPendingInMessageLoop();
669 EXPECT_TRUE(filter->events().empty()); 688 EXPECT_TRUE(filter->events().empty());
670 } 689 }
671 690
672 #if defined(OS_CHROMEOS) 691 TEST_F(RootWindowTest, TouchMovesHeld) {
673 // This test may be flaky on Chromium OS valgrind bots: http://crbug.com/333644
674 #define MAYBE_TouchMovesHeld DISABLED_TouchMovesHeld
675 #else
676 #define MAYBE_TouchMovesHeld TouchMovesHeld
677 #endif
678 TEST_F(RootWindowTest, MAYBE_TouchMovesHeld) {
679 EventFilterRecorder* filter = new EventFilterRecorder; 692 EventFilterRecorder* filter = new EventFilterRecorder;
680 root_window()->SetEventFilter(filter); // passes ownership 693 root_window()->SetEventFilter(filter); // passes ownership
681 694
682 test::TestWindowDelegate delegate; 695 test::TestWindowDelegate delegate;
683 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 696 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
684 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); 697 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
685 698
686 const gfx::Point touch_location(60, 60); 699 const gfx::Point touch_location(60, 60);
687 // Starting the touch and throwing out the first few events, since the system 700 // Starting the touch and throwing out the first few events, since the system
688 // is going to generate synthetic mouse events that are not relevant to the 701 // is going to generate synthetic mouse events that are not relevant to the
689 // test. 702 // test.
690 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location, 703 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location,
691 0, base::TimeDelta()); 704 0, base::TimeDelta());
692 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 705 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
693 &touch_pressed_event); 706 &touch_pressed_event);
694 RunAllPendingInMessageLoop(); 707 filter->WaitUntilReceivedGesture(ui::ET_GESTURE_SHOW_PRESS);
695 filter->Reset(); 708 filter->Reset();
696 709
697 dispatcher()->HoldPointerMoves(); 710 dispatcher()->HoldPointerMoves();
698 711
699 // Check that we don't immediately dispatch the TOUCH_MOVED event. 712 // Check that we don't immediately dispatch the TOUCH_MOVED event.
700 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location, 713 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location,
701 0, base::TimeDelta()); 714 0, base::TimeDelta());
702 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 715 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
703 &touch_moved_event); 716 &touch_moved_event);
704 EXPECT_TRUE(filter->events().empty()); 717 EXPECT_TRUE(filter->events().empty());
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 CHECK(!message_loop()->is_running()); 1615 CHECK(!message_loop()->is_running());
1603 // Perform the test in a callback, so that it runs after the message-loop 1616 // Perform the test in a callback, so that it runs after the message-loop
1604 // starts. 1617 // starts.
1605 message_loop()->PostTask(FROM_HERE, 1618 message_loop()->PostTask(FROM_HERE,
1606 base::Bind(&RootWindowTestWithMessageLoop::RunTest, 1619 base::Bind(&RootWindowTestWithMessageLoop::RunTest,
1607 base::Unretained(this))); 1620 base::Unretained(this)));
1608 message_loop()->Run(); 1621 message_loop()->Run();
1609 } 1622 }
1610 1623
1611 } // namespace aura 1624 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698