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

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

Issue 147203004: aura: Remove event-dispatch methods from WindowTreeHostDelegate interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win Created 6 years, 10 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 | « ui/aura/root_window_host_x11_unittest.cc ('k') | ui/aura/test/aura_test_base.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 "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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( 110 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate(
111 delegate1.get(), -1234, bounds1, root_window())); 111 delegate1.get(), -1234, bounds1, root_window()));
112 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( 112 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate(
113 delegate2.get(), -5678, bounds2, root_window())); 113 delegate2.get(), -5678, bounds2, root_window()));
114 114
115 // Send a mouse event to window1. 115 // Send a mouse event to window1.
116 gfx::Point point(101, 201); 116 gfx::Point point(101, 201);
117 ui::MouseEvent event1( 117 ui::MouseEvent event1(
118 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, 118 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON,
119 ui::EF_LEFT_MOUSE_BUTTON); 119 ui::EF_LEFT_MOUSE_BUTTON);
120 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&event1); 120 DispatchEventUsingWindowDispatcher(&event1);
121 121
122 // Event was tested for non-client area for the target window. 122 // Event was tested for non-client area for the target window.
123 EXPECT_EQ(1, delegate1->non_client_count()); 123 EXPECT_EQ(1, delegate1->non_client_count());
124 EXPECT_EQ(0, delegate2->non_client_count()); 124 EXPECT_EQ(0, delegate2->non_client_count());
125 // The non-client component test was in local coordinates. 125 // The non-client component test was in local coordinates.
126 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); 126 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location());
127 // Mouse event was received by target window. 127 // Mouse event was received by target window.
128 EXPECT_EQ(1, delegate1->mouse_event_count()); 128 EXPECT_EQ(1, delegate1->mouse_event_count());
129 EXPECT_EQ(0, delegate2->mouse_event_count()); 129 EXPECT_EQ(0, delegate2->mouse_event_count());
130 // Event was in local coordinates. 130 // Event was in local coordinates.
(...skipping 22 matching lines...) Expand all
153 gfx::Point location; 153 gfx::Point location;
154 scoped_ptr<ui::MouseEvent> event; 154 scoped_ptr<ui::MouseEvent> event;
155 155
156 // Press the left button. 156 // Press the left button.
157 event.reset(new ui::MouseEvent( 157 event.reset(new ui::MouseEvent(
158 ui::ET_MOUSE_PRESSED, 158 ui::ET_MOUSE_PRESSED,
159 location, 159 location,
160 location, 160 location,
161 ui::EF_LEFT_MOUSE_BUTTON, 161 ui::EF_LEFT_MOUSE_BUTTON,
162 ui::EF_LEFT_MOUSE_BUTTON)); 162 ui::EF_LEFT_MOUSE_BUTTON));
163 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 163 DispatchEventUsingWindowDispatcher(event.get());
164 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 164 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
165 165
166 // Additionally press the right. 166 // Additionally press the right.
167 event.reset(new ui::MouseEvent( 167 event.reset(new ui::MouseEvent(
168 ui::ET_MOUSE_PRESSED, 168 ui::ET_MOUSE_PRESSED,
169 location, 169 location,
170 location, 170 location,
171 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, 171 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON,
172 ui::EF_RIGHT_MOUSE_BUTTON)); 172 ui::EF_RIGHT_MOUSE_BUTTON));
173 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 173 DispatchEventUsingWindowDispatcher(event.get());
174 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 174 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
175 175
176 // Release the left button. 176 // Release the left button.
177 event.reset(new ui::MouseEvent( 177 event.reset(new ui::MouseEvent(
178 ui::ET_MOUSE_RELEASED, 178 ui::ET_MOUSE_RELEASED,
179 location, 179 location,
180 location, 180 location,
181 ui::EF_RIGHT_MOUSE_BUTTON, 181 ui::EF_RIGHT_MOUSE_BUTTON,
182 ui::EF_LEFT_MOUSE_BUTTON)); 182 ui::EF_LEFT_MOUSE_BUTTON));
183 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 183 DispatchEventUsingWindowDispatcher(event.get());
184 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 184 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
185 185
186 // Release the right button. We should ignore the Shift-is-down flag. 186 // Release the right button. We should ignore the Shift-is-down flag.
187 event.reset(new ui::MouseEvent( 187 event.reset(new ui::MouseEvent(
188 ui::ET_MOUSE_RELEASED, 188 ui::ET_MOUSE_RELEASED,
189 location, 189 location,
190 location, 190 location,
191 ui::EF_SHIFT_DOWN, 191 ui::EF_SHIFT_DOWN,
192 ui::EF_RIGHT_MOUSE_BUTTON)); 192 ui::EF_RIGHT_MOUSE_BUTTON));
193 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 193 DispatchEventUsingWindowDispatcher(event.get());
194 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); 194 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown());
195 195
196 // Press the middle button. 196 // Press the middle button.
197 event.reset(new ui::MouseEvent( 197 event.reset(new ui::MouseEvent(
198 ui::ET_MOUSE_PRESSED, 198 ui::ET_MOUSE_PRESSED,
199 location, 199 location,
200 location, 200 location,
201 ui::EF_MIDDLE_MOUSE_BUTTON, 201 ui::EF_MIDDLE_MOUSE_BUTTON,
202 ui::EF_MIDDLE_MOUSE_BUTTON)); 202 ui::EF_MIDDLE_MOUSE_BUTTON));
203 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); 203 DispatchEventUsingWindowDispatcher(event.get());
204 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); 204 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown());
205 } 205 }
206 206
207 TEST_F(RootWindowTest, TranslatedEvent) { 207 TEST_F(RootWindowTest, TranslatedEvent) {
208 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, 208 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1,
209 gfx::Rect(50, 50, 100, 100), root_window())); 209 gfx::Rect(50, 50, 100, 100), root_window()));
210 210
211 gfx::Point origin(100, 100); 211 gfx::Point origin(100, 100);
212 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0); 212 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0);
213 213
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 // Prevent w3 from being deleted by the hierarchy since its delegate is owned 338 // Prevent w3 from being deleted by the hierarchy since its delegate is owned
339 // by this scope. 339 // by this scope.
340 w3->parent()->RemoveChild(w3.get()); 340 w3->parent()->RemoveChild(w3.get());
341 } 341 }
342 342
343 TEST_F(RootWindowTest, IgnoreUnknownKeys) { 343 TEST_F(RootWindowTest, IgnoreUnknownKeys) {
344 test::TestEventHandler* filter = new ConsumeKeyHandler; 344 test::TestEventHandler* filter = new ConsumeKeyHandler;
345 root_window()->SetEventFilter(filter); // passes ownership 345 root_window()->SetEventFilter(filter); // passes ownership
346 346
347 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); 347 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false);
348 EXPECT_FALSE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 348 DispatchEventUsingWindowDispatcher(&unknown_event);
349 &unknown_event)); 349 EXPECT_FALSE(unknown_event.handled());
350 EXPECT_EQ(0, filter->num_key_events()); 350 EXPECT_EQ(0, filter->num_key_events());
351 351
352 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 352 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
353 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 353 DispatchEventUsingWindowDispatcher(&known_event);
354 &known_event)); 354 EXPECT_TRUE(known_event.handled());
355 EXPECT_EQ(1, filter->num_key_events()); 355 EXPECT_EQ(1, filter->num_key_events());
356 } 356 }
357 357
358 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) { 358 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) {
359 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); 359 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL));
360 w1->Show(); 360 w1->Show();
361 w1->Focus(); 361 w1->Focus();
362 362
363 test::TestEventHandler handler; 363 test::TestEventHandler handler;
364 w1->AddPreTargetHandler(&handler); 364 w1->AddPreTargetHandler(&handler);
365 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); 365 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false);
366 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( 366 DispatchEventUsingWindowDispatcher(&key_press);
367 &key_press)); 367 EXPECT_TRUE(key_press.handled());
368 EXPECT_EQ(1, handler.num_key_events()); 368 EXPECT_EQ(1, handler.num_key_events());
369 369
370 w1->RemovePreTargetHandler(&handler); 370 w1->RemovePreTargetHandler(&handler);
371 } 371 }
372 372
373 // Tests that touch-events that are beyond the bounds of the root-window do get 373 // Tests that touch-events that are beyond the bounds of the root-window do get
374 // propagated to the event filters correctly with the root as the target. 374 // propagated to the event filters correctly with the root as the target.
375 TEST_F(RootWindowTest, TouchEventsOutsideBounds) { 375 TEST_F(RootWindowTest, TouchEventsOutsideBounds) {
376 test::TestEventHandler* filter = new test::TestEventHandler; 376 test::TestEventHandler* filter = new test::TestEventHandler;
377 root_window()->SetEventFilter(filter); // passes ownership 377 root_window()->SetEventFilter(filter); // passes ownership
378 378
379 gfx::Point position = root_window()->bounds().origin(); 379 gfx::Point position = root_window()->bounds().origin();
380 position.Offset(-10, -10); 380 position.Offset(-10, -10);
381 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); 381 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta());
382 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 382 DispatchEventUsingWindowDispatcher(&press);
383 EXPECT_EQ(1, filter->num_touch_events()); 383 EXPECT_EQ(1, filter->num_touch_events());
384 384
385 position = root_window()->bounds().origin(); 385 position = root_window()->bounds().origin();
386 position.Offset(root_window()->bounds().width() + 10, 386 position.Offset(root_window()->bounds().width() + 10,
387 root_window()->bounds().height() + 10); 387 root_window()->bounds().height() + 10);
388 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); 388 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta());
389 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release); 389 DispatchEventUsingWindowDispatcher(&release);
390 EXPECT_EQ(2, filter->num_touch_events()); 390 EXPECT_EQ(2, filter->num_touch_events());
391 } 391 }
392 392
393 // Tests that scroll events are dispatched correctly. 393 // Tests that scroll events are dispatched correctly.
394 TEST_F(RootWindowTest, ScrollEventDispatch) { 394 TEST_F(RootWindowTest, ScrollEventDispatch) {
395 base::TimeDelta now = ui::EventTimeForNow(); 395 base::TimeDelta now = ui::EventTimeForNow();
396 test::TestEventHandler* filter = new test::TestEventHandler; 396 test::TestEventHandler* filter = new test::TestEventHandler;
397 root_window()->SetEventFilter(filter); 397 root_window()->SetEventFilter(filter);
398 398
399 test::TestWindowDelegate delegate; 399 test::TestWindowDelegate delegate;
400 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 400 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
401 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); 401 w1->SetBounds(gfx::Rect(20, 20, 40, 40));
402 402
403 // A scroll event on the root-window itself is dispatched. 403 // A scroll event on the root-window itself is dispatched.
404 ui::ScrollEvent scroll1(ui::ET_SCROLL, 404 ui::ScrollEvent scroll1(ui::ET_SCROLL,
405 gfx::Point(10, 10), 405 gfx::Point(10, 10),
406 now, 406 now,
407 0, 407 0,
408 0, -10, 408 0, -10,
409 0, -10, 409 0, -10,
410 2); 410 2);
411 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll1); 411 DispatchEventUsingWindowDispatcher(&scroll1);
412 EXPECT_EQ(1, filter->num_scroll_events()); 412 EXPECT_EQ(1, filter->num_scroll_events());
413 413
414 // Scroll event on a window should be dispatched properly. 414 // Scroll event on a window should be dispatched properly.
415 ui::ScrollEvent scroll2(ui::ET_SCROLL, 415 ui::ScrollEvent scroll2(ui::ET_SCROLL,
416 gfx::Point(25, 30), 416 gfx::Point(25, 30),
417 now, 417 now,
418 0, 418 0,
419 -10, 0, 419 -10, 0,
420 -10, 0, 420 -10, 0,
421 2); 421 2);
422 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll2); 422 DispatchEventUsingWindowDispatcher(&scroll2);
423 EXPECT_EQ(2, filter->num_scroll_events()); 423 EXPECT_EQ(2, filter->num_scroll_events());
424 } 424 }
425 425
426 namespace { 426 namespace {
427 427
428 // FilterFilter that tracks the types of events it's seen. 428 // FilterFilter that tracks the types of events it's seen.
429 class EventFilterRecorder : public ui::EventHandler { 429 class EventFilterRecorder : public ui::EventHandler {
430 public: 430 public:
431 typedef std::vector<ui::EventType> Events; 431 typedef std::vector<ui::EventType> Events;
432 typedef std::vector<gfx::Point> EventLocations; 432 typedef std::vector<gfx::Point> EventLocations;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 TEST_F(RootWindowTest, MouseMovesHeld) { 603 TEST_F(RootWindowTest, MouseMovesHeld) {
604 EventFilterRecorder* filter = new EventFilterRecorder; 604 EventFilterRecorder* filter = new EventFilterRecorder;
605 root_window()->SetEventFilter(filter); // passes ownership 605 root_window()->SetEventFilter(filter); // passes ownership
606 606
607 test::TestWindowDelegate delegate; 607 test::TestWindowDelegate delegate;
608 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 608 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
609 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 609 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
610 610
611 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), 611 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0),
612 gfx::Point(0, 0), 0, 0); 612 gfx::Point(0, 0), 0, 0);
613 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 613 DispatchEventUsingWindowDispatcher(&mouse_move_event);
614 &mouse_move_event);
615 // Discard MOUSE_ENTER. 614 // Discard MOUSE_ENTER.
616 filter->Reset(); 615 filter->Reset();
617 616
618 dispatcher()->HoldPointerMoves(); 617 dispatcher()->HoldPointerMoves();
619 618
620 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. 619 // Check that we don't immediately dispatch the MOUSE_DRAGGED event.
621 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), 620 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0),
622 gfx::Point(0, 0), 0, 0); 621 gfx::Point(0, 0), 0, 0);
623 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 622 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
624 &mouse_dragged_event);
625 EXPECT_TRUE(filter->events().empty()); 623 EXPECT_TRUE(filter->events().empty());
626 624
627 // Check that we do dispatch the held MOUSE_DRAGGED event before another type 625 // Check that we do dispatch the held MOUSE_DRAGGED event before another type
628 // of event. 626 // of event.
629 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), 627 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0),
630 gfx::Point(0, 0), 0, 0); 628 gfx::Point(0, 0), 0, 0);
631 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 629 DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
632 &mouse_pressed_event);
633 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 630 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
634 EventTypesToString(filter->events())); 631 EventTypesToString(filter->events()));
635 filter->Reset(); 632 filter->Reset();
636 633
637 // Check that we coalesce held MOUSE_DRAGGED events. 634 // Check that we coalesce held MOUSE_DRAGGED events.
638 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), 635 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1),
639 gfx::Point(1, 1), 0, 0); 636 gfx::Point(1, 1), 0, 0);
640 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 637 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
641 &mouse_dragged_event); 638 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
642 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(
643 &mouse_dragged_event2);
644 EXPECT_TRUE(filter->events().empty()); 639 EXPECT_TRUE(filter->events().empty());
645 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 640 DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
646 &mouse_pressed_event);
647 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 641 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
648 EventTypesToString(filter->events())); 642 EventTypesToString(filter->events()));
649 filter->Reset(); 643 filter->Reset();
650 644
651 // Check that on ReleasePointerMoves, held events are not dispatched 645 // Check that on ReleasePointerMoves, held events are not dispatched
652 // immediately, but posted instead. 646 // immediately, but posted instead.
653 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 647 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
654 &mouse_dragged_event);
655 dispatcher()->ReleasePointerMoves(); 648 dispatcher()->ReleasePointerMoves();
656 EXPECT_TRUE(filter->events().empty()); 649 EXPECT_TRUE(filter->events().empty());
657 RunAllPendingInMessageLoop(); 650 RunAllPendingInMessageLoop();
658 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 651 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
659 filter->Reset(); 652 filter->Reset();
660 653
661 // However if another message comes in before the dispatch of the posted 654 // However if another message comes in before the dispatch of the posted
662 // event, check that the posted event is dispatched before this new event. 655 // event, check that the posted event is dispatched before this new event.
663 dispatcher()->HoldPointerMoves(); 656 dispatcher()->HoldPointerMoves();
664 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 657 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
665 &mouse_dragged_event);
666 dispatcher()->ReleasePointerMoves(); 658 dispatcher()->ReleasePointerMoves();
667 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 659 DispatchEventUsingWindowDispatcher(&mouse_pressed_event);
668 &mouse_pressed_event);
669 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", 660 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED",
670 EventTypesToString(filter->events())); 661 EventTypesToString(filter->events()));
671 filter->Reset(); 662 filter->Reset();
672 RunAllPendingInMessageLoop(); 663 RunAllPendingInMessageLoop();
673 EXPECT_TRUE(filter->events().empty()); 664 EXPECT_TRUE(filter->events().empty());
674 665
675 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce 666 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce
676 // them. 667 // them.
677 dispatcher()->HoldPointerMoves(); 668 dispatcher()->HoldPointerMoves();
678 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 669 DispatchEventUsingWindowDispatcher(&mouse_dragged_event);
679 &mouse_dragged_event);
680 dispatcher()->ReleasePointerMoves(); 670 dispatcher()->ReleasePointerMoves();
681 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( 671 DispatchEventUsingWindowDispatcher(&mouse_dragged_event2);
682 &mouse_dragged_event2);
683 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); 672 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events()));
684 filter->Reset(); 673 filter->Reset();
685 RunAllPendingInMessageLoop(); 674 RunAllPendingInMessageLoop();
686 EXPECT_TRUE(filter->events().empty()); 675 EXPECT_TRUE(filter->events().empty());
687 } 676 }
688 677
689 TEST_F(RootWindowTest, TouchMovesHeld) { 678 TEST_F(RootWindowTest, TouchMovesHeld) {
690 EventFilterRecorder* filter = new EventFilterRecorder; 679 EventFilterRecorder* filter = new EventFilterRecorder;
691 root_window()->SetEventFilter(filter); // passes ownership 680 root_window()->SetEventFilter(filter); // passes ownership
692 681
693 test::TestWindowDelegate delegate; 682 test::TestWindowDelegate delegate;
694 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 683 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
695 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); 684 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window()));
696 685
697 const gfx::Point touch_location(60, 60); 686 const gfx::Point touch_location(60, 60);
698 // Starting the touch and throwing out the first few events, since the system 687 // Starting the touch and throwing out the first few events, since the system
699 // is going to generate synthetic mouse events that are not relevant to the 688 // is going to generate synthetic mouse events that are not relevant to the
700 // test. 689 // test.
701 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location, 690 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, touch_location,
702 0, base::TimeDelta()); 691 0, base::TimeDelta());
703 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 692 DispatchEventUsingWindowDispatcher(&touch_pressed_event);
704 &touch_pressed_event);
705 filter->WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); 693 filter->WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS);
706 filter->Reset(); 694 filter->Reset();
707 695
708 dispatcher()->HoldPointerMoves(); 696 dispatcher()->HoldPointerMoves();
709 697
710 // Check that we don't immediately dispatch the TOUCH_MOVED event. 698 // Check that we don't immediately dispatch the TOUCH_MOVED event.
711 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location, 699 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, touch_location,
712 0, base::TimeDelta()); 700 0, base::TimeDelta());
713 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 701 DispatchEventUsingWindowDispatcher(&touch_moved_event);
714 &touch_moved_event);
715 EXPECT_TRUE(filter->events().empty()); 702 EXPECT_TRUE(filter->events().empty());
716 703
717 // Check that on ReleasePointerMoves, held events are not dispatched 704 // Check that on ReleasePointerMoves, held events are not dispatched
718 // immediately, but posted instead. 705 // immediately, but posted instead.
719 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 706 DispatchEventUsingWindowDispatcher(&touch_moved_event);
720 &touch_moved_event);
721 dispatcher()->ReleasePointerMoves(); 707 dispatcher()->ReleasePointerMoves();
722 EXPECT_TRUE(filter->events().empty()); 708 EXPECT_TRUE(filter->events().empty());
723 709
724 RunAllPendingInMessageLoop(); 710 RunAllPendingInMessageLoop();
725 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); 711 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events()));
726 filter->Reset(); 712 filter->Reset();
727 713
728 // If another touch event occurs then the held touch should be dispatched 714 // If another touch event occurs then the held touch should be dispatched
729 // immediately before it. 715 // immediately before it.
730 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location, 716 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, touch_location,
731 0, base::TimeDelta()); 717 0, base::TimeDelta());
732 filter->Reset(); 718 filter->Reset();
733 dispatcher()->HoldPointerMoves(); 719 dispatcher()->HoldPointerMoves();
734 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( 720 DispatchEventUsingWindowDispatcher(&touch_moved_event);
735 &touch_moved_event); 721 DispatchEventUsingWindowDispatcher(&touch_released_event);
736 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(
737 &touch_released_event);
738 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", 722 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END",
739 EventTypesToString(filter->events())); 723 EventTypesToString(filter->events()));
740 filter->Reset(); 724 filter->Reset();
741 dispatcher()->ReleasePointerMoves(); 725 dispatcher()->ReleasePointerMoves();
742 RunAllPendingInMessageLoop(); 726 RunAllPendingInMessageLoop();
743 EXPECT_TRUE(filter->events().empty()); 727 EXPECT_TRUE(filter->events().empty());
744 } 728 }
745 729
746 class HoldPointerOnScrollHandler : public test::TestEventHandler { 730 class HoldPointerOnScrollHandler : public test::TestEventHandler {
747 public: 731 public:
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 798 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
815 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); 799 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window()));
816 window->Show(); 800 window->Show();
817 window->SetCapture(); 801 window->SetCapture();
818 802
819 test::TestCursorClient cursor_client(root_window()); 803 test::TestCursorClient cursor_client(root_window());
820 804
821 // Dispatch a non-synthetic mouse event when mouse events are enabled. 805 // Dispatch a non-synthetic mouse event when mouse events are enabled.
822 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 806 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
823 gfx::Point(10, 10), 0, 0); 807 gfx::Point(10, 10), 0, 0);
824 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 808 DispatchEventUsingWindowDispatcher(&mouse1);
825 EXPECT_FALSE(filter->events().empty()); 809 EXPECT_FALSE(filter->events().empty());
826 filter->Reset(); 810 filter->Reset();
827 811
828 // Dispatch a synthetic mouse event when mouse events are enabled. 812 // Dispatch a synthetic mouse event when mouse events are enabled.
829 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), 813 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
830 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0); 814 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0);
831 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 815 DispatchEventUsingWindowDispatcher(&mouse2);
832 EXPECT_FALSE(filter->events().empty()); 816 EXPECT_FALSE(filter->events().empty());
833 filter->Reset(); 817 filter->Reset();
834 818
835 // Dispatch a synthetic mouse event when mouse events are disabled. 819 // Dispatch a synthetic mouse event when mouse events are disabled.
836 cursor_client.DisableMouseEvents(); 820 cursor_client.DisableMouseEvents();
837 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); 821 DispatchEventUsingWindowDispatcher(&mouse2);
838 EXPECT_TRUE(filter->events().empty()); 822 EXPECT_TRUE(filter->events().empty());
839 } 823 }
840 824
841 // Tests that a mouse exit is dispatched to the last known cursor location 825 // Tests that a mouse exit is dispatched to the last known cursor location
842 // when the cursor becomes invisible. 826 // when the cursor becomes invisible.
843 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { 827 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) {
844 EventFilterRecorder* filter = new EventFilterRecorder; 828 EventFilterRecorder* filter = new EventFilterRecorder;
845 root_window()->SetEventFilter(filter); // passes ownership 829 root_window()->SetEventFilter(filter); // passes ownership
846 830
847 test::TestWindowDelegate delegate; 831 test::TestWindowDelegate delegate;
848 gfx::Point window_origin(7, 18); 832 gfx::Point window_origin(7, 18);
849 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 833 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
850 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), 834 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)),
851 root_window())); 835 root_window()));
852 window->Show(); 836 window->Show();
853 837
854 // Dispatch a mouse move event into the window. 838 // Dispatch a mouse move event into the window.
855 gfx::Point mouse_location(gfx::Point(15, 25)); 839 gfx::Point mouse_location(gfx::Point(15, 25));
856 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, 840 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location,
857 mouse_location, 0, 0); 841 mouse_location, 0, 0);
858 EXPECT_TRUE(filter->events().empty()); 842 EXPECT_TRUE(filter->events().empty());
859 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); 843 DispatchEventUsingWindowDispatcher(&mouse1);
860 EXPECT_FALSE(filter->events().empty()); 844 EXPECT_FALSE(filter->events().empty());
861 filter->Reset(); 845 filter->Reset();
862 846
863 // Hide the cursor and verify a mouse exit was dispatched. 847 // Hide the cursor and verify a mouse exit was dispatched.
864 dispatcher()->OnCursorVisibilityChanged(false); 848 dispatcher()->OnCursorVisibilityChanged(false);
865 EXPECT_FALSE(filter->events().empty()); 849 EXPECT_FALSE(filter->events().empty());
866 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); 850 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events()));
867 851
868 // Verify the mouse exit was dispatched at the correct location 852 // Verify the mouse exit was dispatched at the correct location
869 // (in the correct coordinate space). 853 // (in the correct coordinate space).
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1364 } // namespace 1348 } // namespace
1365 1349
1366 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after 1350 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after
1367 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which 1351 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which
1368 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events 1352 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events
1369 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to 1353 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to
1370 // schedule another reposted event. 1354 // schedule another reposted event.
1371 TEST_F(RootWindowTest, DontResetHeldEvent) { 1355 TEST_F(RootWindowTest, DontResetHeldEvent) {
1372 DontResetHeldEventWindowDelegate delegate(root_window()); 1356 DontResetHeldEventWindowDelegate delegate(root_window());
1373 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); 1357 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate));
1374 WindowTreeHostDelegate* root_window_delegate =
1375 static_cast<WindowTreeHostDelegate*>(root_window()->GetDispatcher());
1376 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); 1358 w1->SetBounds(gfx::Rect(0, 0, 40, 40));
1377 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, 1359 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED,
1378 gfx::Point(10, 10), gfx::Point(10, 10), 1360 gfx::Point(10, 10), gfx::Point(10, 10),
1379 ui::EF_SHIFT_DOWN, 0); 1361 ui::EF_SHIFT_DOWN, 0);
1380 root_window()->GetDispatcher()->RepostEvent(pressed); 1362 root_window()->GetDispatcher()->RepostEvent(pressed);
1381 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, 1363 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED,
1382 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); 1364 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0);
1383 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). 1365 // Dispatch an event to flush event scheduled by way of RepostEvent().
1384 root_window_delegate->OnHostMouseEvent(&pressed2); 1366 DispatchEventUsingWindowDispatcher(&pressed2);
1385 // Delegate should have seen reposted event (identified by way of 1367 // Delegate should have seen reposted event (identified by way of
1386 // EF_SHIFT_DOWN). Invoke OnHostMouseEvent() to flush the second 1368 // EF_SHIFT_DOWN). Dispatch another event to flush the second
1387 // RepostedEvent(). 1369 // RepostedEvent().
1388 EXPECT_EQ(1, delegate.mouse_event_count()); 1370 EXPECT_EQ(1, delegate.mouse_event_count());
1389 root_window_delegate->OnHostMouseEvent(&pressed2); 1371 DispatchEventUsingWindowDispatcher(&pressed2);
1390 EXPECT_EQ(2, delegate.mouse_event_count()); 1372 EXPECT_EQ(2, delegate.mouse_event_count());
1391 } 1373 }
1392 1374
1393 namespace { 1375 namespace {
1394 1376
1395 // See description above DeleteRootFromHeldMouseEvent for details. 1377 // See description above DeleteRootFromHeldMouseEvent for details.
1396 class DeleteRootFromHeldMouseEventDelegate : public test::TestWindowDelegate { 1378 class DeleteRootFromHeldMouseEventDelegate : public test::TestWindowDelegate {
1397 public: 1379 public:
1398 explicit DeleteRootFromHeldMouseEventDelegate(aura::RootWindow* root) 1380 explicit DeleteRootFromHeldMouseEventDelegate(aura::RootWindow* root)
1399 : root_(root), 1381 : root_(root),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1457 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { 1439 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) {
1458 EventFilterRecorder* filter = new EventFilterRecorder; 1440 EventFilterRecorder* filter = new EventFilterRecorder;
1459 root_window()->SetEventFilter(filter); // passes ownership 1441 root_window()->SetEventFilter(filter); // passes ownership
1460 1442
1461 test::TestWindowDelegate delegate; 1443 test::TestWindowDelegate delegate;
1462 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1444 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1463 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 1445 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
1464 1446
1465 gfx::Point position1 = root_window()->bounds().origin(); 1447 gfx::Point position1 = root_window()->bounds().origin();
1466 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); 1448 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta());
1467 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 1449 DispatchEventUsingWindowDispatcher(&press);
1468 1450
1469 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", 1451 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN",
1470 EventTypesToString(filter->GetAndResetEvents())); 1452 EventTypesToString(filter->GetAndResetEvents()));
1471 1453
1472 window->Hide(); 1454 window->Hide();
1473 1455
1474 EXPECT_EQ("TOUCH_CANCELLED GESTURE_TAP_CANCEL GESTURE_END", 1456 EXPECT_EQ("TOUCH_CANCELLED GESTURE_TAP_CANCEL GESTURE_END",
1475 EventTypesToString(filter->events())); 1457 EventTypesToString(filter->events()));
1476 } 1458 }
1477 1459
1478 TEST_F(RootWindowTest, WindowHideCancelsActiveGestures) { 1460 TEST_F(RootWindowTest, WindowHideCancelsActiveGestures) {
1479 EventFilterRecorder* filter = new EventFilterRecorder; 1461 EventFilterRecorder* filter = new EventFilterRecorder;
1480 root_window()->SetEventFilter(filter); // passes ownership 1462 root_window()->SetEventFilter(filter); // passes ownership
1481 1463
1482 test::TestWindowDelegate delegate; 1464 test::TestWindowDelegate delegate;
1483 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1465 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1484 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); 1466 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window()));
1485 1467
1486 gfx::Point position1 = root_window()->bounds().origin(); 1468 gfx::Point position1 = root_window()->bounds().origin();
1487 gfx::Point position2 = root_window()->bounds().CenterPoint(); 1469 gfx::Point position2 = root_window()->bounds().CenterPoint();
1488 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); 1470 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta());
1489 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 1471 DispatchEventUsingWindowDispatcher(&press);
1490 1472
1491 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); 1473 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta());
1492 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move); 1474 DispatchEventUsingWindowDispatcher(&move);
1493 1475
1494 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta()); 1476 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta());
1495 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press2); 1477 DispatchEventUsingWindowDispatcher(&press2);
1496 1478
1497 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " 1479 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED "
1498 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " 1480 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE "
1499 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN", 1481 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN",
1500 EventTypesToString(filter->GetAndResetEvents())); 1482 EventTypesToString(filter->GetAndResetEvents()));
1501 1483
1502 window->Hide(); 1484 window->Hide();
1503 1485
1504 EXPECT_EQ("TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " 1486 EXPECT_EQ("TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED "
1505 "GESTURE_SCROLL_END GESTURE_END", 1487 "GESTURE_SCROLL_END GESTURE_END",
(...skipping 10 matching lines...) Expand all
1516 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); 1498 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL));
1517 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); 1499 window2->SetBounds(gfx::Rect(40, 0, 40, 40));
1518 1500
1519 EventFilterRecorder* filter1 = new EventFilterRecorder(); 1501 EventFilterRecorder* filter1 = new EventFilterRecorder();
1520 window1->SetEventFilter(filter1); // passes ownership 1502 window1->SetEventFilter(filter1); // passes ownership
1521 EventFilterRecorder* filter2 = new EventFilterRecorder(); 1503 EventFilterRecorder* filter2 = new EventFilterRecorder();
1522 window2->SetEventFilter(filter2); // passes ownership 1504 window2->SetEventFilter(filter2); // passes ownership
1523 1505
1524 gfx::Point position = window1->bounds().origin(); 1506 gfx::Point position = window1->bounds().origin();
1525 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); 1507 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta());
1526 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); 1508 DispatchEventUsingWindowDispatcher(&press);
1527 1509
1528 gfx::Point position2 = window1->bounds().CenterPoint(); 1510 gfx::Point position2 = window1->bounds().CenterPoint();
1529 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); 1511 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta());
1530 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move); 1512 DispatchEventUsingWindowDispatcher(&move);
1531 1513
1532 window2->SetCapture(); 1514 window2->SetCapture();
1533 1515
1534 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " 1516 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED "
1535 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " 1517 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE "
1536 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", 1518 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END",
1537 EventTypesToString(filter1->events())); 1519 EventTypesToString(filter1->events()));
1538 1520
1539 EXPECT_TRUE(filter2->events().empty()); 1521 EXPECT_TRUE(filter2->events().empty());
1540 } 1522 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 1621
1640 test::TestEventHandler handler_child; 1622 test::TestEventHandler handler_child;
1641 test::TestEventHandler handler_root; 1623 test::TestEventHandler handler_root;
1642 root_window()->AddPreTargetHandler(&handler_root); 1624 root_window()->AddPreTargetHandler(&handler_root);
1643 child->AddPreTargetHandler(&handler_child); 1625 child->AddPreTargetHandler(&handler_child);
1644 1626
1645 { 1627 {
1646 ui::MouseEvent move(ui::ET_MOUSE_MOVED, 1628 ui::MouseEvent move(ui::ET_MOUSE_MOVED,
1647 gfx::Point(30, 30), gfx::Point(30, 30), 1629 gfx::Point(30, 30), gfx::Point(30, 30),
1648 ui::EF_NONE, ui::EF_NONE); 1630 ui::EF_NONE, ui::EF_NONE);
1649 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); 1631 DispatchEventUsingWindowDispatcher(&move);
1650 ASSERT_FALSE(details.dispatcher_destroyed);
1651 EXPECT_EQ(0, handler_child.num_mouse_events()); 1632 EXPECT_EQ(0, handler_child.num_mouse_events());
1652 EXPECT_EQ(1, handler_root.num_mouse_events()); 1633 EXPECT_EQ(1, handler_root.num_mouse_events());
1653 } 1634 }
1654 1635
1655 { 1636 {
1656 ui::MouseEvent move(ui::ET_MOUSE_MOVED, 1637 ui::MouseEvent move(ui::ET_MOUSE_MOVED,
1657 gfx::Point(50, 50), gfx::Point(50, 50), 1638 gfx::Point(50, 50), gfx::Point(50, 50),
1658 ui::EF_NONE, ui::EF_NONE); 1639 ui::EF_NONE, ui::EF_NONE);
1659 ui::EventDispatchDetails details = dispatcher()->OnEventFromSource(&move); 1640 DispatchEventUsingWindowDispatcher(&move);
1660 ASSERT_FALSE(details.dispatcher_destroyed);
1661 // The child receives an ENTER, and a MOVED event. 1641 // The child receives an ENTER, and a MOVED event.
1662 EXPECT_EQ(2, handler_child.num_mouse_events()); 1642 EXPECT_EQ(2, handler_child.num_mouse_events());
1663 // The root receives both the ENTER and the MOVED events dispatched to 1643 // The root receives both the ENTER and the MOVED events dispatched to
1664 // |child|, as well as an EXIT event. 1644 // |child|, as well as an EXIT event.
1665 EXPECT_EQ(3, handler_root.num_mouse_events()); 1645 EXPECT_EQ(3, handler_root.num_mouse_events());
1666 } 1646 }
1667 1647
1668 child->RemovePreTargetHandler(&handler_child); 1648 child->RemovePreTargetHandler(&handler_child);
1669 root_window()->RemovePreTargetHandler(&handler_root); 1649 root_window()->RemovePreTargetHandler(&handler_root);
1670 } 1650 }
(...skipping 21 matching lines...) Expand all
1692 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END", 1672 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_SCROLL_END GESTURE_END",
1693 EventTypesToString(events)); 1673 EventTypesToString(events));
1694 ASSERT_EQ(2u, filter->touch_locations().size()); 1674 ASSERT_EQ(2u, filter->touch_locations().size());
1695 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 1675 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
1696 filter->touch_locations()[0].ToString()); 1676 filter->touch_locations()[0].ToString());
1697 EXPECT_EQ(gfx::Point(-40, 10).ToString(), 1677 EXPECT_EQ(gfx::Point(-40, 10).ToString(),
1698 filter->touch_locations()[1].ToString()); 1678 filter->touch_locations()[1].ToString());
1699 } 1679 }
1700 1680
1701 } // namespace aura 1681 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/root_window_host_x11_unittest.cc ('k') | ui/aura/test/aura_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698