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 "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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 109 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
110 delegate1.get(), -1234, bounds1, root_window())); | 110 delegate1.get(), -1234, bounds1, root_window())); |
111 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 111 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
112 delegate2.get(), -5678, bounds2, root_window())); | 112 delegate2.get(), -5678, bounds2, root_window())); |
113 | 113 |
114 // Send a mouse event to window1. | 114 // Send a mouse event to window1. |
115 gfx::Point point(101, 201); | 115 gfx::Point point(101, 201); |
116 ui::MouseEvent event1( | 116 ui::MouseEvent event1( |
117 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, | 117 ui::ET_MOUSE_PRESSED, point, point, ui::EF_LEFT_MOUSE_BUTTON, |
118 ui::EF_LEFT_MOUSE_BUTTON); | 118 ui::EF_LEFT_MOUSE_BUTTON); |
119 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&event1); | 119 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&event1); |
120 | 120 |
121 // Event was tested for non-client area for the target window. | 121 // Event was tested for non-client area for the target window. |
122 EXPECT_EQ(1, delegate1->non_client_count()); | 122 EXPECT_EQ(1, delegate1->non_client_count()); |
123 EXPECT_EQ(0, delegate2->non_client_count()); | 123 EXPECT_EQ(0, delegate2->non_client_count()); |
124 // The non-client component test was in local coordinates. | 124 // The non-client component test was in local coordinates. |
125 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); | 125 EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); |
126 // Mouse event was received by target window. | 126 // Mouse event was received by target window. |
127 EXPECT_EQ(1, delegate1->mouse_event_count()); | 127 EXPECT_EQ(1, delegate1->mouse_event_count()); |
128 EXPECT_EQ(0, delegate2->mouse_event_count()); | 128 EXPECT_EQ(0, delegate2->mouse_event_count()); |
129 // Event was in local coordinates. | 129 // Event was in local coordinates. |
(...skipping 22 matching lines...) Expand all Loading... |
152 gfx::Point location; | 152 gfx::Point location; |
153 scoped_ptr<ui::MouseEvent> event; | 153 scoped_ptr<ui::MouseEvent> event; |
154 | 154 |
155 // Press the left button. | 155 // Press the left button. |
156 event.reset(new ui::MouseEvent( | 156 event.reset(new ui::MouseEvent( |
157 ui::ET_MOUSE_PRESSED, | 157 ui::ET_MOUSE_PRESSED, |
158 location, | 158 location, |
159 location, | 159 location, |
160 ui::EF_LEFT_MOUSE_BUTTON, | 160 ui::EF_LEFT_MOUSE_BUTTON, |
161 ui::EF_LEFT_MOUSE_BUTTON)); | 161 ui::EF_LEFT_MOUSE_BUTTON)); |
162 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 162 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); |
163 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 163 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
164 | 164 |
165 // Additionally press the right. | 165 // Additionally press the right. |
166 event.reset(new ui::MouseEvent( | 166 event.reset(new ui::MouseEvent( |
167 ui::ET_MOUSE_PRESSED, | 167 ui::ET_MOUSE_PRESSED, |
168 location, | 168 location, |
169 location, | 169 location, |
170 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, | 170 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON, |
171 ui::EF_RIGHT_MOUSE_BUTTON)); | 171 ui::EF_RIGHT_MOUSE_BUTTON)); |
172 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 172 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); |
173 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 173 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
174 | 174 |
175 // Release the left button. | 175 // Release the left button. |
176 event.reset(new ui::MouseEvent( | 176 event.reset(new ui::MouseEvent( |
177 ui::ET_MOUSE_RELEASED, | 177 ui::ET_MOUSE_RELEASED, |
178 location, | 178 location, |
179 location, | 179 location, |
180 ui::EF_RIGHT_MOUSE_BUTTON, | 180 ui::EF_RIGHT_MOUSE_BUTTON, |
181 ui::EF_LEFT_MOUSE_BUTTON)); | 181 ui::EF_LEFT_MOUSE_BUTTON)); |
182 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 182 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); |
183 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 183 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
184 | 184 |
185 // Release the right button. We should ignore the Shift-is-down flag. | 185 // Release the right button. We should ignore the Shift-is-down flag. |
186 event.reset(new ui::MouseEvent( | 186 event.reset(new ui::MouseEvent( |
187 ui::ET_MOUSE_RELEASED, | 187 ui::ET_MOUSE_RELEASED, |
188 location, | 188 location, |
189 location, | 189 location, |
190 ui::EF_SHIFT_DOWN, | 190 ui::EF_SHIFT_DOWN, |
191 ui::EF_RIGHT_MOUSE_BUTTON)); | 191 ui::EF_RIGHT_MOUSE_BUTTON)); |
192 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 192 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); |
193 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 193 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
194 | 194 |
195 // Press the middle button. | 195 // Press the middle button. |
196 event.reset(new ui::MouseEvent( | 196 event.reset(new ui::MouseEvent( |
197 ui::ET_MOUSE_PRESSED, | 197 ui::ET_MOUSE_PRESSED, |
198 location, | 198 location, |
199 location, | 199 location, |
200 ui::EF_MIDDLE_MOUSE_BUTTON, | 200 ui::EF_MIDDLE_MOUSE_BUTTON, |
201 ui::EF_MIDDLE_MOUSE_BUTTON)); | 201 ui::EF_MIDDLE_MOUSE_BUTTON)); |
202 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(event.get()); | 202 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(event.get()); |
203 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 203 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
204 } | 204 } |
205 | 205 |
206 TEST_F(RootWindowTest, TranslatedEvent) { | 206 TEST_F(RootWindowTest, TranslatedEvent) { |
207 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 207 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, |
208 gfx::Rect(50, 50, 100, 100), root_window())); | 208 gfx::Rect(50, 50, 100, 100), root_window())); |
209 | 209 |
210 gfx::Point origin(100, 100); | 210 gfx::Point origin(100, 100); |
211 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0); | 211 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, 0, 0); |
212 | 212 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 // Prevent w3 from being deleted by the hierarchy since its delegate is owned | 336 // Prevent w3 from being deleted by the hierarchy since its delegate is owned |
337 // by this scope. | 337 // by this scope. |
338 w3->parent()->RemoveChild(w3.get()); | 338 w3->parent()->RemoveChild(w3.get()); |
339 } | 339 } |
340 | 340 |
341 TEST_F(RootWindowTest, IgnoreUnknownKeys) { | 341 TEST_F(RootWindowTest, IgnoreUnknownKeys) { |
342 test::TestEventHandler* filter = new ConsumeKeyHandler; | 342 test::TestEventHandler* filter = new ConsumeKeyHandler; |
343 root_window()->SetEventFilter(filter); // passes ownership | 343 root_window()->SetEventFilter(filter); // passes ownership |
344 | 344 |
345 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); | 345 ui::KeyEvent unknown_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, 0, false); |
346 EXPECT_FALSE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 346 EXPECT_FALSE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( |
347 &unknown_event)); | 347 &unknown_event)); |
348 EXPECT_EQ(0, filter->num_key_events()); | 348 EXPECT_EQ(0, filter->num_key_events()); |
349 | 349 |
350 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); | 350 ui::KeyEvent known_event(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); |
351 EXPECT_TRUE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 351 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( |
352 &known_event)); | 352 &known_event)); |
353 EXPECT_EQ(1, filter->num_key_events()); | 353 EXPECT_EQ(1, filter->num_key_events()); |
354 } | 354 } |
355 | 355 |
356 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) { | 356 TEST_F(RootWindowTest, NoDelegateWindowReceivesKeyEvents) { |
357 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 357 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
358 w1->Show(); | 358 w1->Show(); |
359 w1->Focus(); | 359 w1->Focus(); |
360 | 360 |
361 test::TestEventHandler handler; | 361 test::TestEventHandler handler; |
362 w1->AddPreTargetHandler(&handler); | 362 w1->AddPreTargetHandler(&handler); |
363 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); | 363 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, 0, false); |
364 EXPECT_TRUE(dispatcher()->AsRootWindowHostDelegate()->OnHostKeyEvent( | 364 EXPECT_TRUE(dispatcher()->AsWindowTreeHostDelegate()->OnHostKeyEvent( |
365 &key_press)); | 365 &key_press)); |
366 EXPECT_EQ(1, handler.num_key_events()); | 366 EXPECT_EQ(1, handler.num_key_events()); |
367 | 367 |
368 w1->RemovePreTargetHandler(&handler); | 368 w1->RemovePreTargetHandler(&handler); |
369 } | 369 } |
370 | 370 |
371 // Tests that touch-events that are beyond the bounds of the root-window do get | 371 // Tests that touch-events that are beyond the bounds of the root-window do get |
372 // propagated to the event filters correctly with the root as the target. | 372 // propagated to the event filters correctly with the root as the target. |
373 TEST_F(RootWindowTest, TouchEventsOutsideBounds) { | 373 TEST_F(RootWindowTest, TouchEventsOutsideBounds) { |
374 test::TestEventHandler* filter = new test::TestEventHandler; | 374 test::TestEventHandler* filter = new test::TestEventHandler; |
375 root_window()->SetEventFilter(filter); // passes ownership | 375 root_window()->SetEventFilter(filter); // passes ownership |
376 | 376 |
377 gfx::Point position = root_window()->bounds().origin(); | 377 gfx::Point position = root_window()->bounds().origin(); |
378 position.Offset(-10, -10); | 378 position.Offset(-10, -10); |
379 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); | 379 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); |
380 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 380 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
381 EXPECT_EQ(1, filter->num_touch_events()); | 381 EXPECT_EQ(1, filter->num_touch_events()); |
382 | 382 |
383 position = root_window()->bounds().origin(); | 383 position = root_window()->bounds().origin(); |
384 position.Offset(root_window()->bounds().width() + 10, | 384 position.Offset(root_window()->bounds().width() + 10, |
385 root_window()->bounds().height() + 10); | 385 root_window()->bounds().height() + 10); |
386 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); | 386 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, position, 0, base::TimeDelta()); |
387 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); | 387 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&release); |
388 EXPECT_EQ(2, filter->num_touch_events()); | 388 EXPECT_EQ(2, filter->num_touch_events()); |
389 } | 389 } |
390 | 390 |
391 // Tests that scroll events are dispatched correctly. | 391 // Tests that scroll events are dispatched correctly. |
392 TEST_F(RootWindowTest, ScrollEventDispatch) { | 392 TEST_F(RootWindowTest, ScrollEventDispatch) { |
393 base::TimeDelta now = ui::EventTimeForNow(); | 393 base::TimeDelta now = ui::EventTimeForNow(); |
394 test::TestEventHandler* filter = new test::TestEventHandler; | 394 test::TestEventHandler* filter = new test::TestEventHandler; |
395 root_window()->SetEventFilter(filter); | 395 root_window()->SetEventFilter(filter); |
396 | 396 |
397 test::TestWindowDelegate delegate; | 397 test::TestWindowDelegate delegate; |
398 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 398 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
399 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); | 399 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); |
400 | 400 |
401 // A scroll event on the root-window itself is dispatched. | 401 // A scroll event on the root-window itself is dispatched. |
402 ui::ScrollEvent scroll1(ui::ET_SCROLL, | 402 ui::ScrollEvent scroll1(ui::ET_SCROLL, |
403 gfx::Point(10, 10), | 403 gfx::Point(10, 10), |
404 now, | 404 now, |
405 0, | 405 0, |
406 0, -10, | 406 0, -10, |
407 0, -10, | 407 0, -10, |
408 2); | 408 2); |
409 dispatcher()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll1); | 409 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll1); |
410 EXPECT_EQ(1, filter->num_scroll_events()); | 410 EXPECT_EQ(1, filter->num_scroll_events()); |
411 | 411 |
412 // Scroll event on a window should be dispatched properly. | 412 // Scroll event on a window should be dispatched properly. |
413 ui::ScrollEvent scroll2(ui::ET_SCROLL, | 413 ui::ScrollEvent scroll2(ui::ET_SCROLL, |
414 gfx::Point(25, 30), | 414 gfx::Point(25, 30), |
415 now, | 415 now, |
416 0, | 416 0, |
417 -10, 0, | 417 -10, 0, |
418 -10, 0, | 418 -10, 0, |
419 2); | 419 2); |
420 dispatcher()->AsRootWindowHostDelegate()->OnHostScrollEvent(&scroll2); | 420 dispatcher()->AsWindowTreeHostDelegate()->OnHostScrollEvent(&scroll2); |
421 EXPECT_EQ(2, filter->num_scroll_events()); | 421 EXPECT_EQ(2, filter->num_scroll_events()); |
422 } | 422 } |
423 | 423 |
424 namespace { | 424 namespace { |
425 | 425 |
426 // FilterFilter that tracks the types of events it's seen. | 426 // FilterFilter that tracks the types of events it's seen. |
427 class EventFilterRecorder : public ui::EventHandler { | 427 class EventFilterRecorder : public ui::EventHandler { |
428 public: | 428 public: |
429 typedef std::vector<ui::EventType> Events; | 429 typedef std::vector<ui::EventType> Events; |
430 typedef std::vector<gfx::Point> MouseEventLocations; | 430 typedef std::vector<gfx::Point> MouseEventLocations; |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
585 TEST_F(RootWindowTest, MouseMovesHeld) { | 585 TEST_F(RootWindowTest, MouseMovesHeld) { |
586 EventFilterRecorder* filter = new EventFilterRecorder; | 586 EventFilterRecorder* filter = new EventFilterRecorder; |
587 root_window()->SetEventFilter(filter); // passes ownership | 587 root_window()->SetEventFilter(filter); // passes ownership |
588 | 588 |
589 test::TestWindowDelegate delegate; | 589 test::TestWindowDelegate delegate; |
590 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 590 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
591 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 591 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
592 | 592 |
593 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 593 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
594 gfx::Point(0, 0), 0, 0); | 594 gfx::Point(0, 0), 0, 0); |
595 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 595 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
596 &mouse_move_event); | 596 &mouse_move_event); |
597 // Discard MOUSE_ENTER. | 597 // Discard MOUSE_ENTER. |
598 filter->events().clear(); | 598 filter->events().clear(); |
599 | 599 |
600 dispatcher()->HoldPointerMoves(); | 600 dispatcher()->HoldPointerMoves(); |
601 | 601 |
602 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. | 602 // Check that we don't immediately dispatch the MOUSE_DRAGGED event. |
603 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), | 603 ui::MouseEvent mouse_dragged_event(ui::ET_MOUSE_DRAGGED, gfx::Point(0, 0), |
604 gfx::Point(0, 0), 0, 0); | 604 gfx::Point(0, 0), 0, 0); |
605 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 605 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
606 &mouse_dragged_event); | 606 &mouse_dragged_event); |
607 EXPECT_TRUE(filter->events().empty()); | 607 EXPECT_TRUE(filter->events().empty()); |
608 | 608 |
609 // Check that we do dispatch the held MOUSE_DRAGGED event before another type | 609 // Check that we do dispatch the held MOUSE_DRAGGED event before another type |
610 // of event. | 610 // of event. |
611 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), | 611 ui::MouseEvent mouse_pressed_event(ui::ET_MOUSE_PRESSED, gfx::Point(0, 0), |
612 gfx::Point(0, 0), 0, 0); | 612 gfx::Point(0, 0), 0, 0); |
613 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 613 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
614 &mouse_pressed_event); | 614 &mouse_pressed_event); |
615 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 615 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
616 EventTypesToString(filter->events())); | 616 EventTypesToString(filter->events())); |
617 filter->events().clear(); | 617 filter->events().clear(); |
618 | 618 |
619 // Check that we coalesce held MOUSE_DRAGGED events. | 619 // Check that we coalesce held MOUSE_DRAGGED events. |
620 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), | 620 ui::MouseEvent mouse_dragged_event2(ui::ET_MOUSE_DRAGGED, gfx::Point(1, 1), |
621 gfx::Point(1, 1), 0, 0); | 621 gfx::Point(1, 1), 0, 0); |
622 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 622 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
623 &mouse_dragged_event); | 623 &mouse_dragged_event); |
624 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 624 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
625 &mouse_dragged_event2); | 625 &mouse_dragged_event2); |
626 EXPECT_TRUE(filter->events().empty()); | 626 EXPECT_TRUE(filter->events().empty()); |
627 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 627 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
628 &mouse_pressed_event); | 628 &mouse_pressed_event); |
629 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 629 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
630 EventTypesToString(filter->events())); | 630 EventTypesToString(filter->events())); |
631 filter->events().clear(); | 631 filter->events().clear(); |
632 | 632 |
633 // Check that on ReleasePointerMoves, held events are not dispatched | 633 // Check that on ReleasePointerMoves, held events are not dispatched |
634 // immediately, but posted instead. | 634 // immediately, but posted instead. |
635 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 635 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
636 &mouse_dragged_event); | 636 &mouse_dragged_event); |
637 dispatcher()->ReleasePointerMoves(); | 637 dispatcher()->ReleasePointerMoves(); |
638 EXPECT_TRUE(filter->events().empty()); | 638 EXPECT_TRUE(filter->events().empty()); |
639 RunAllPendingInMessageLoop(); | 639 RunAllPendingInMessageLoop(); |
640 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); | 640 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); |
641 filter->events().clear(); | 641 filter->events().clear(); |
642 | 642 |
643 // However if another message comes in before the dispatch of the posted | 643 // However if another message comes in before the dispatch of the posted |
644 // event, check that the posted event is dispatched before this new event. | 644 // event, check that the posted event is dispatched before this new event. |
645 dispatcher()->HoldPointerMoves(); | 645 dispatcher()->HoldPointerMoves(); |
646 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 646 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
647 &mouse_dragged_event); | 647 &mouse_dragged_event); |
648 dispatcher()->ReleasePointerMoves(); | 648 dispatcher()->ReleasePointerMoves(); |
649 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 649 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
650 &mouse_pressed_event); | 650 &mouse_pressed_event); |
651 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", | 651 EXPECT_EQ("MOUSE_DRAGGED MOUSE_PRESSED", |
652 EventTypesToString(filter->events())); | 652 EventTypesToString(filter->events())); |
653 filter->events().clear(); | 653 filter->events().clear(); |
654 RunAllPendingInMessageLoop(); | 654 RunAllPendingInMessageLoop(); |
655 EXPECT_TRUE(filter->events().empty()); | 655 EXPECT_TRUE(filter->events().empty()); |
656 | 656 |
657 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce | 657 // Check that if the other message is another MOUSE_DRAGGED, we still coalesce |
658 // them. | 658 // them. |
659 dispatcher()->HoldPointerMoves(); | 659 dispatcher()->HoldPointerMoves(); |
660 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 660 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
661 &mouse_dragged_event); | 661 &mouse_dragged_event); |
662 dispatcher()->ReleasePointerMoves(); | 662 dispatcher()->ReleasePointerMoves(); |
663 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent( | 663 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent( |
664 &mouse_dragged_event2); | 664 &mouse_dragged_event2); |
665 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); | 665 EXPECT_EQ("MOUSE_DRAGGED", EventTypesToString(filter->events())); |
666 filter->events().clear(); | 666 filter->events().clear(); |
667 RunAllPendingInMessageLoop(); | 667 RunAllPendingInMessageLoop(); |
668 EXPECT_TRUE(filter->events().empty()); | 668 EXPECT_TRUE(filter->events().empty()); |
669 } | 669 } |
670 | 670 |
671 TEST_F(RootWindowTest, TouchMovesHeld) { | 671 TEST_F(RootWindowTest, TouchMovesHeld) { |
672 EventFilterRecorder* filter = new EventFilterRecorder; | 672 EventFilterRecorder* filter = new EventFilterRecorder; |
673 root_window()->SetEventFilter(filter); // passes ownership | 673 root_window()->SetEventFilter(filter); // passes ownership |
674 | 674 |
675 test::TestWindowDelegate delegate; | 675 test::TestWindowDelegate delegate; |
676 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 676 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
677 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 677 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
678 | 678 |
679 // Starting the touch and throwing out the first few events, since the system | 679 // Starting the touch and throwing out the first few events, since the system |
680 // is going to generate synthetic mouse events that are not relevant to the | 680 // is going to generate synthetic mouse events that are not relevant to the |
681 // test. | 681 // test. |
682 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 682 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
683 0, base::TimeDelta()); | 683 0, base::TimeDelta()); |
684 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent( | 684 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( |
685 &touch_pressed_event); | 685 &touch_pressed_event); |
686 RunAllPendingInMessageLoop(); | 686 RunAllPendingInMessageLoop(); |
687 filter->events().clear(); | 687 filter->events().clear(); |
688 | 688 |
689 dispatcher()->HoldPointerMoves(); | 689 dispatcher()->HoldPointerMoves(); |
690 | 690 |
691 // Check that we don't immediately dispatch the TOUCH_MOVED event. | 691 // Check that we don't immediately dispatch the TOUCH_MOVED event. |
692 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::Point(0, 0), | 692 ui::TouchEvent touch_moved_event(ui::ET_TOUCH_MOVED, gfx::Point(0, 0), |
693 0, base::TimeDelta()); | 693 0, base::TimeDelta()); |
694 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent( | 694 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( |
695 &touch_moved_event); | 695 &touch_moved_event); |
696 EXPECT_TRUE(filter->events().empty()); | 696 EXPECT_TRUE(filter->events().empty()); |
697 | 697 |
698 // Check that on ReleasePointerMoves, held events are not dispatched | 698 // Check that on ReleasePointerMoves, held events are not dispatched |
699 // immediately, but posted instead. | 699 // immediately, but posted instead. |
700 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent( | 700 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( |
701 &touch_moved_event); | 701 &touch_moved_event); |
702 dispatcher()->ReleasePointerMoves(); | 702 dispatcher()->ReleasePointerMoves(); |
703 EXPECT_TRUE(filter->events().empty()); | 703 EXPECT_TRUE(filter->events().empty()); |
704 RunAllPendingInMessageLoop(); | 704 RunAllPendingInMessageLoop(); |
705 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); | 705 EXPECT_EQ("TOUCH_MOVED", EventTypesToString(filter->events())); |
706 filter->events().clear(); | 706 filter->events().clear(); |
707 | 707 |
708 // If another touch event occurs then the held touch should be dispatched | 708 // If another touch event occurs then the held touch should be dispatched |
709 // immediately before it. | 709 // immediately before it. |
710 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), | 710 ui::TouchEvent touch_released_event(ui::ET_TOUCH_RELEASED, gfx::Point(0, 0), |
711 0, base::TimeDelta()); | 711 0, base::TimeDelta()); |
712 filter->events().clear(); | 712 filter->events().clear(); |
713 dispatcher()->HoldPointerMoves(); | 713 dispatcher()->HoldPointerMoves(); |
714 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent( | 714 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( |
715 &touch_moved_event); | 715 &touch_moved_event); |
716 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent( | 716 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent( |
717 &touch_released_event); | 717 &touch_released_event); |
718 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", | 718 EXPECT_EQ("TOUCH_MOVED TOUCH_RELEASED GESTURE_TAP_CANCEL GESTURE_END", |
719 EventTypesToString(filter->events())); | 719 EventTypesToString(filter->events())); |
720 filter->events().clear(); | 720 filter->events().clear(); |
721 dispatcher()->ReleasePointerMoves(); | 721 dispatcher()->ReleasePointerMoves(); |
722 RunAllPendingInMessageLoop(); | 722 RunAllPendingInMessageLoop(); |
723 EXPECT_TRUE(filter->events().empty()); | 723 EXPECT_TRUE(filter->events().empty()); |
724 } | 724 } |
725 | 725 |
726 // Tests that synthetic mouse events are ignored when mouse | 726 // Tests that synthetic mouse events are ignored when mouse |
727 // events are disabled. | 727 // events are disabled. |
728 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) { | 728 TEST_F(RootWindowTest, DispatchSyntheticMouseEvents) { |
729 EventFilterRecorder* filter = new EventFilterRecorder; | 729 EventFilterRecorder* filter = new EventFilterRecorder; |
730 root_window()->SetEventFilter(filter); // passes ownership | 730 root_window()->SetEventFilter(filter); // passes ownership |
731 | 731 |
732 test::TestWindowDelegate delegate; | 732 test::TestWindowDelegate delegate; |
733 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 733 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
734 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 734 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
735 window->Show(); | 735 window->Show(); |
736 window->SetCapture(); | 736 window->SetCapture(); |
737 | 737 |
738 test::TestCursorClient cursor_client(root_window()); | 738 test::TestCursorClient cursor_client(root_window()); |
739 | 739 |
740 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 740 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 741 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
742 gfx::Point(10, 10), 0, 0); | 742 gfx::Point(10, 10), 0, 0); |
743 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); | 743 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); |
744 EXPECT_FALSE(filter->events().empty()); | 744 EXPECT_FALSE(filter->events().empty()); |
745 filter->events().clear(); | 745 filter->events().clear(); |
746 | 746 |
747 // Dispatch a synthetic mouse event when mouse events are enabled. | 747 // Dispatch a synthetic mouse event when mouse events are enabled. |
748 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 748 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
749 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0); | 749 gfx::Point(10, 10), ui::EF_IS_SYNTHESIZED, 0); |
750 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); | 750 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); |
751 EXPECT_FALSE(filter->events().empty()); | 751 EXPECT_FALSE(filter->events().empty()); |
752 filter->events().clear(); | 752 filter->events().clear(); |
753 | 753 |
754 // Dispatch a synthetic mouse event when mouse events are disabled. | 754 // Dispatch a synthetic mouse event when mouse events are disabled. |
755 cursor_client.DisableMouseEvents(); | 755 cursor_client.DisableMouseEvents(); |
756 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse2); | 756 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse2); |
757 EXPECT_TRUE(filter->events().empty()); | 757 EXPECT_TRUE(filter->events().empty()); |
758 } | 758 } |
759 | 759 |
760 // Tests that a mouse exit is dispatched to the last known cursor location | 760 // Tests that a mouse exit is dispatched to the last known cursor location |
761 // when the cursor becomes invisible. | 761 // when the cursor becomes invisible. |
762 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { | 762 TEST_F(RootWindowTest, DispatchMouseExitWhenCursorHidden) { |
763 EventFilterRecorder* filter = new EventFilterRecorder; | 763 EventFilterRecorder* filter = new EventFilterRecorder; |
764 root_window()->SetEventFilter(filter); // passes ownership | 764 root_window()->SetEventFilter(filter); // passes ownership |
765 | 765 |
766 test::TestWindowDelegate delegate; | 766 test::TestWindowDelegate delegate; |
767 gfx::Point window_origin(7, 18); | 767 gfx::Point window_origin(7, 18); |
768 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 768 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
769 &delegate, 1234, gfx::Rect(window_origin, | 769 &delegate, 1234, gfx::Rect(window_origin, |
770 gfx::Size(100, 100)), root_window())); | 770 gfx::Size(100, 100)), root_window())); |
771 window->Show(); | 771 window->Show(); |
772 | 772 |
773 // Dispatch a mouse move event into the window. | 773 // Dispatch a mouse move event into the window. |
774 gfx::Point mouse_location(gfx::Point(15, 25)); | 774 gfx::Point mouse_location(gfx::Point(15, 25)); |
775 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, | 775 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, |
776 mouse_location, 0, 0); | 776 mouse_location, 0, 0); |
777 EXPECT_TRUE(filter->events().empty()); | 777 EXPECT_TRUE(filter->events().empty()); |
778 dispatcher()->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouse1); | 778 dispatcher()->AsWindowTreeHostDelegate()->OnHostMouseEvent(&mouse1); |
779 EXPECT_FALSE(filter->events().empty()); | 779 EXPECT_FALSE(filter->events().empty()); |
780 filter->events().clear(); | 780 filter->events().clear(); |
781 | 781 |
782 // Hide the cursor and verify a mouse exit was dispatched. | 782 // Hide the cursor and verify a mouse exit was dispatched. |
783 dispatcher()->OnCursorVisibilityChanged(false); | 783 dispatcher()->OnCursorVisibilityChanged(false); |
784 EXPECT_FALSE(filter->events().empty()); | 784 EXPECT_FALSE(filter->events().empty()); |
785 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); | 785 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(filter->events())); |
786 | 786 |
787 // Verify the mouse exit was dispatched at the correct location | 787 // Verify the mouse exit was dispatched at the correct location |
788 // (in the correct coordinate space). | 788 // (in the correct coordinate space). |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1219 private: | 1219 private: |
1220 bool* got_destroying_; | 1220 bool* got_destroying_; |
1221 bool* has_valid_root_; | 1221 bool* has_valid_root_; |
1222 | 1222 |
1223 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver); | 1223 DISALLOW_COPY_AND_ASSIGN(ValidRootDuringDestructionWindowObserver); |
1224 }; | 1224 }; |
1225 | 1225 |
1226 } // namespace | 1226 } // namespace |
1227 | 1227 |
1228 #if defined(USE_OZONE) | 1228 #if defined(USE_OZONE) |
1229 // Creating multiple RootWindowHostOzone instances is broken. | 1229 // Creating multiple WindowTreeHostOzone instances is broken. |
1230 #define MAYBE_ValidRootDuringDestruction DISABLED_ValidRootDuringDestruction | 1230 #define MAYBE_ValidRootDuringDestruction DISABLED_ValidRootDuringDestruction |
1231 #else | 1231 #else |
1232 #define MAYBE_ValidRootDuringDestruction ValidRootDuringDestruction | 1232 #define MAYBE_ValidRootDuringDestruction ValidRootDuringDestruction |
1233 #endif | 1233 #endif |
1234 | 1234 |
1235 // Verifies GetRootWindow() from ~Window returns a valid root. | 1235 // Verifies GetRootWindow() from ~Window returns a valid root. |
1236 TEST_F(RootWindowTest, MAYBE_ValidRootDuringDestruction) { | 1236 TEST_F(RootWindowTest, MAYBE_ValidRootDuringDestruction) { |
1237 bool got_destroying = false; | 1237 bool got_destroying = false; |
1238 bool has_valid_root = false; | 1238 bool has_valid_root = false; |
1239 ValidRootDuringDestructionWindowObserver observer(&got_destroying, | 1239 ValidRootDuringDestructionWindowObserver observer(&got_destroying, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1283 } // namespace | 1283 } // namespace |
1284 | 1284 |
1285 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1285 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
1286 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1286 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
1287 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1287 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
1288 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1288 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
1289 // schedule another reposted event. | 1289 // schedule another reposted event. |
1290 TEST_F(RootWindowTest, DontResetHeldEvent) { | 1290 TEST_F(RootWindowTest, DontResetHeldEvent) { |
1291 DontResetHeldEventWindowDelegate delegate(root_window()); | 1291 DontResetHeldEventWindowDelegate delegate(root_window()); |
1292 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1292 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
1293 RootWindowHostDelegate* root_window_delegate = | 1293 WindowTreeHostDelegate* root_window_delegate = |
1294 static_cast<RootWindowHostDelegate*>(root_window()->GetDispatcher()); | 1294 static_cast<WindowTreeHostDelegate*>(root_window()->GetDispatcher()); |
1295 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1295 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
1296 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, | 1296 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, |
1297 gfx::Point(10, 10), gfx::Point(10, 10), | 1297 gfx::Point(10, 10), gfx::Point(10, 10), |
1298 ui::EF_SHIFT_DOWN, 0); | 1298 ui::EF_SHIFT_DOWN, 0); |
1299 root_window()->GetDispatcher()->RepostEvent(pressed); | 1299 root_window()->GetDispatcher()->RepostEvent(pressed); |
1300 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, | 1300 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, |
1301 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); | 1301 gfx::Point(10, 10), gfx::Point(10, 10), 0, 0); |
1302 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). | 1302 // Invoke OnHostMouseEvent() to flush event scheduled by way of RepostEvent(). |
1303 root_window_delegate->OnHostMouseEvent(&pressed2); | 1303 root_window_delegate->OnHostMouseEvent(&pressed2); |
1304 // Delegate should have seen reposted event (identified by way of | 1304 // Delegate should have seen reposted event (identified by way of |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1339 RootWindow* root_; | 1339 RootWindow* root_; |
1340 bool got_mouse_event_; | 1340 bool got_mouse_event_; |
1341 bool got_destroy_; | 1341 bool got_destroy_; |
1342 | 1342 |
1343 DISALLOW_COPY_AND_ASSIGN(DeleteRootFromHeldMouseEventDelegate); | 1343 DISALLOW_COPY_AND_ASSIGN(DeleteRootFromHeldMouseEventDelegate); |
1344 }; | 1344 }; |
1345 | 1345 |
1346 } // namespace | 1346 } // namespace |
1347 | 1347 |
1348 #if defined(USE_OZONE) | 1348 #if defined(USE_OZONE) |
1349 // Creating multiple RootWindowHostOzone instances is broken. | 1349 // Creating multiple WindowTreeHostOzone instances is broken. |
1350 #define MAYBE_DeleteRootFromHeldMouseEvent DISABLED_DeleteRootFromHeldMouseEvent | 1350 #define MAYBE_DeleteRootFromHeldMouseEvent DISABLED_DeleteRootFromHeldMouseEvent |
1351 #else | 1351 #else |
1352 #define MAYBE_DeleteRootFromHeldMouseEvent DeleteRootFromHeldMouseEvent | 1352 #define MAYBE_DeleteRootFromHeldMouseEvent DeleteRootFromHeldMouseEvent |
1353 #endif | 1353 #endif |
1354 | 1354 |
1355 // Verifies if a RootWindow is deleted from dispatching a held mouse event we | 1355 // Verifies if a RootWindow is deleted from dispatching a held mouse event we |
1356 // don't crash. | 1356 // don't crash. |
1357 TEST_F(RootWindowTest, MAYBE_DeleteRootFromHeldMouseEvent) { | 1357 TEST_F(RootWindowTest, MAYBE_DeleteRootFromHeldMouseEvent) { |
1358 // Should be deleted by |delegate|. | 1358 // Should be deleted by |delegate|. |
1359 RootWindow* r2 = | 1359 RootWindow* r2 = |
(...skipping 16 matching lines...) Expand all Loading... |
1376 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { | 1376 TEST_F(RootWindowTest, WindowHideCancelsActiveTouches) { |
1377 EventFilterRecorder* filter = new EventFilterRecorder; | 1377 EventFilterRecorder* filter = new EventFilterRecorder; |
1378 root_window()->SetEventFilter(filter); // passes ownership | 1378 root_window()->SetEventFilter(filter); // passes ownership |
1379 | 1379 |
1380 test::TestWindowDelegate delegate; | 1380 test::TestWindowDelegate delegate; |
1381 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1381 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1382 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1382 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
1383 | 1383 |
1384 gfx::Point position1 = root_window()->bounds().origin(); | 1384 gfx::Point position1 = root_window()->bounds().origin(); |
1385 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); | 1385 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); |
1386 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 1386 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
1387 | 1387 |
1388 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", | 1388 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", |
1389 EventTypesToString(filter->GetAndResetEvents())); | 1389 EventTypesToString(filter->GetAndResetEvents())); |
1390 | 1390 |
1391 window->Hide(); | 1391 window->Hide(); |
1392 | 1392 |
1393 EXPECT_EQ("TOUCH_CANCELLED GESTURE_TAP_CANCEL GESTURE_END", | 1393 EXPECT_EQ("TOUCH_CANCELLED GESTURE_TAP_CANCEL GESTURE_END", |
1394 EventTypesToString(filter->events())); | 1394 EventTypesToString(filter->events())); |
1395 } | 1395 } |
1396 | 1396 |
1397 TEST_F(RootWindowTest, WindowHideCancelsActiveGestures) { | 1397 TEST_F(RootWindowTest, WindowHideCancelsActiveGestures) { |
1398 EventFilterRecorder* filter = new EventFilterRecorder; | 1398 EventFilterRecorder* filter = new EventFilterRecorder; |
1399 root_window()->SetEventFilter(filter); // passes ownership | 1399 root_window()->SetEventFilter(filter); // passes ownership |
1400 | 1400 |
1401 test::TestWindowDelegate delegate; | 1401 test::TestWindowDelegate delegate; |
1402 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1402 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1403 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1403 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
1404 | 1404 |
1405 gfx::Point position1 = root_window()->bounds().origin(); | 1405 gfx::Point position1 = root_window()->bounds().origin(); |
1406 gfx::Point position2 = root_window()->bounds().CenterPoint(); | 1406 gfx::Point position2 = root_window()->bounds().CenterPoint(); |
1407 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); | 1407 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position1, 0, base::TimeDelta()); |
1408 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 1408 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
1409 | 1409 |
1410 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); | 1410 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); |
1411 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); | 1411 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move); |
1412 | 1412 |
1413 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta()); | 1413 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, position1, 1, base::TimeDelta()); |
1414 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); | 1414 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press2); |
1415 | 1415 |
1416 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " | 1416 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " |
1417 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " | 1417 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " |
1418 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN", | 1418 "TOUCH_PRESSED GESTURE_BEGIN GESTURE_PINCH_BEGIN", |
1419 EventTypesToString(filter->GetAndResetEvents())); | 1419 EventTypesToString(filter->GetAndResetEvents())); |
1420 | 1420 |
1421 window->Hide(); | 1421 window->Hide(); |
1422 | 1422 |
1423 EXPECT_EQ("TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " | 1423 EXPECT_EQ("TOUCH_CANCELLED GESTURE_PINCH_END GESTURE_END TOUCH_CANCELLED " |
1424 "GESTURE_SCROLL_END GESTURE_END", | 1424 "GESTURE_SCROLL_END GESTURE_END", |
(...skipping 10 matching lines...) Expand all Loading... |
1435 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); | 1435 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); |
1436 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); | 1436 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); |
1437 | 1437 |
1438 EventFilterRecorder* filter1 = new EventFilterRecorder(); | 1438 EventFilterRecorder* filter1 = new EventFilterRecorder(); |
1439 window1->SetEventFilter(filter1); // passes ownership | 1439 window1->SetEventFilter(filter1); // passes ownership |
1440 EventFilterRecorder* filter2 = new EventFilterRecorder(); | 1440 EventFilterRecorder* filter2 = new EventFilterRecorder(); |
1441 window2->SetEventFilter(filter2); // passes ownership | 1441 window2->SetEventFilter(filter2); // passes ownership |
1442 | 1442 |
1443 gfx::Point position = window1->bounds().origin(); | 1443 gfx::Point position = window1->bounds().origin(); |
1444 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); | 1444 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, position, 0, base::TimeDelta()); |
1445 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 1445 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&press); |
1446 | 1446 |
1447 gfx::Point position2 = window1->bounds().CenterPoint(); | 1447 gfx::Point position2 = window1->bounds().CenterPoint(); |
1448 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); | 1448 ui::TouchEvent move(ui::ET_TOUCH_MOVED, position2, 0, base::TimeDelta()); |
1449 dispatcher()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); | 1449 dispatcher()->AsWindowTreeHostDelegate()->OnHostTouchEvent(&move); |
1450 | 1450 |
1451 window2->SetCapture(); | 1451 window2->SetCapture(); |
1452 | 1452 |
1453 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " | 1453 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN TOUCH_MOVED " |
1454 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " | 1454 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE " |
1455 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", | 1455 "TOUCH_CANCELLED GESTURE_SCROLL_END GESTURE_END", |
1456 EventTypesToString(filter1->events())); | 1456 EventTypesToString(filter1->events())); |
1457 | 1457 |
1458 EXPECT_TRUE(filter2->events().empty()); | 1458 EXPECT_TRUE(filter2->events().empty()); |
1459 } | 1459 } |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 CHECK(!message_loop()->is_running()); | 1532 CHECK(!message_loop()->is_running()); |
1533 // Perform the test in a callback, so that it runs after the message-loop | 1533 // Perform the test in a callback, so that it runs after the message-loop |
1534 // starts. | 1534 // starts. |
1535 message_loop()->PostTask(FROM_HERE, | 1535 message_loop()->PostTask(FROM_HERE, |
1536 base::Bind(&RootWindowTestWithMessageLoop::RunTest, | 1536 base::Bind(&RootWindowTestWithMessageLoop::RunTest, |
1537 base::Unretained(this))); | 1537 base::Unretained(this))); |
1538 message_loop()->Run(); | 1538 message_loop()->Run(); |
1539 } | 1539 } |
1540 | 1540 |
1541 } // namespace aura | 1541 } // namespace aura |
OLD | NEW |