| 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/window_event_dispatcher.h" | 5 #include "ui/aura/window_event_dispatcher.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 return client::GetFocusClient(window)->GetFocusedWindow() == window; | 102 return client::GetFocusClient(window)->GetFocusedWindow() == window; |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace | 105 } // namespace |
| 106 | 106 |
| 107 typedef test::AuraTestBase WindowEventDispatcherTest; | 107 typedef test::AuraTestBase WindowEventDispatcherTest; |
| 108 | 108 |
| 109 TEST_F(WindowEventDispatcherTest, OnHostMouseEvent) { | 109 TEST_F(WindowEventDispatcherTest, OnHostMouseEvent) { |
| 110 // Create two non-overlapping windows so we don't have to worry about which | 110 // Create two non-overlapping windows so we don't have to worry about which |
| 111 // is on top. | 111 // is on top. |
| 112 scoped_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); | 112 std::unique_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); |
| 113 scoped_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); | 113 std::unique_ptr<NonClientDelegate> delegate2(new NonClientDelegate()); |
| 114 const int kWindowWidth = 123; | 114 const int kWindowWidth = 123; |
| 115 const int kWindowHeight = 45; | 115 const int kWindowHeight = 45; |
| 116 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); | 116 gfx::Rect bounds1(100, 200, kWindowWidth, kWindowHeight); |
| 117 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); | 117 gfx::Rect bounds2(300, 400, kWindowWidth, kWindowHeight); |
| 118 scoped_ptr<aura::Window> window1(CreateTestWindowWithDelegate( | 118 std::unique_ptr<aura::Window> window1(CreateTestWindowWithDelegate( |
| 119 delegate1.get(), -1234, bounds1, root_window())); | 119 delegate1.get(), -1234, bounds1, root_window())); |
| 120 scoped_ptr<aura::Window> window2(CreateTestWindowWithDelegate( | 120 std::unique_ptr<aura::Window> window2(CreateTestWindowWithDelegate( |
| 121 delegate2.get(), -5678, bounds2, root_window())); | 121 delegate2.get(), -5678, bounds2, root_window())); |
| 122 | 122 |
| 123 // Send a mouse event to window1. | 123 // Send a mouse event to window1. |
| 124 gfx::Point point(101, 201); | 124 gfx::Point point(101, 201); |
| 125 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, | 125 ui::MouseEvent event1(ui::ET_MOUSE_PRESSED, point, point, |
| 126 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, | 126 ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, |
| 127 ui::EF_LEFT_MOUSE_BUTTON); | 127 ui::EF_LEFT_MOUSE_BUTTON); |
| 128 DispatchEventUsingWindowDispatcher(&event1); | 128 DispatchEventUsingWindowDispatcher(&event1); |
| 129 | 129 |
| 130 // Event was tested for non-client area for the target window. | 130 // Event was tested for non-client area for the target window. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 159 RunAllPendingInMessageLoop(); | 159 RunAllPendingInMessageLoop(); |
| 160 EXPECT_TRUE(Env::GetInstance()->is_touch_down()); | 160 EXPECT_TRUE(Env::GetInstance()->is_touch_down()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 // Check that we correctly track the state of the mouse buttons in response to | 163 // Check that we correctly track the state of the mouse buttons in response to |
| 164 // button press and release events. | 164 // button press and release events. |
| 165 TEST_F(WindowEventDispatcherTest, MouseButtonState) { | 165 TEST_F(WindowEventDispatcherTest, MouseButtonState) { |
| 166 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 166 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 167 | 167 |
| 168 gfx::Point location; | 168 gfx::Point location; |
| 169 scoped_ptr<ui::MouseEvent> event; | 169 std::unique_ptr<ui::MouseEvent> event; |
| 170 | 170 |
| 171 // Press the left button. | 171 // Press the left button. |
| 172 event.reset(new ui::MouseEvent( | 172 event.reset(new ui::MouseEvent( |
| 173 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 173 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 174 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); | 174 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON)); |
| 175 DispatchEventUsingWindowDispatcher(event.get()); | 175 DispatchEventUsingWindowDispatcher(event.get()); |
| 176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 176 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 177 | 177 |
| 178 // Additionally press the right. | 178 // Additionally press the right. |
| 179 event.reset(new ui::MouseEvent( | 179 event.reset(new ui::MouseEvent( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 199 | 199 |
| 200 // Press the middle button. | 200 // Press the middle button. |
| 201 event.reset(new ui::MouseEvent( | 201 event.reset(new ui::MouseEvent( |
| 202 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), | 202 ui::ET_MOUSE_PRESSED, location, location, ui::EventTimeForNow(), |
| 203 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); | 203 ui::EF_MIDDLE_MOUSE_BUTTON, ui::EF_MIDDLE_MOUSE_BUTTON)); |
| 204 DispatchEventUsingWindowDispatcher(event.get()); | 204 DispatchEventUsingWindowDispatcher(event.get()); |
| 205 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); | 205 EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); |
| 206 } | 206 } |
| 207 | 207 |
| 208 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { | 208 TEST_F(WindowEventDispatcherTest, TranslatedEvent) { |
| 209 scoped_ptr<Window> w1(test::CreateTestWindowWithDelegate(NULL, 1, | 209 std::unique_ptr<Window> w1(test::CreateTestWindowWithDelegate( |
| 210 gfx::Rect(50, 50, 100, 100), root_window())); | 210 NULL, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 211 | 211 |
| 212 gfx::Point origin(100, 100); | 212 gfx::Point origin(100, 100); |
| 213 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, | 213 ui::MouseEvent root(ui::ET_MOUSE_PRESSED, origin, origin, |
| 214 ui::EventTimeForNow(), 0, 0); | 214 ui::EventTimeForNow(), 0, 0); |
| 215 | 215 |
| 216 EXPECT_EQ("100,100", root.location().ToString()); | 216 EXPECT_EQ("100,100", root.location().ToString()); |
| 217 EXPECT_EQ("100,100", root.root_location().ToString()); | 217 EXPECT_EQ("100,100", root.root_location().ToString()); |
| 218 | 218 |
| 219 ui::MouseEvent translated_event( | 219 ui::MouseEvent translated_event( |
| 220 root, static_cast<Window*>(root_window()), w1.get(), | 220 root, static_cast<Window*>(root_window()), w1.get(), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 ui::test::TestEventHandler lock_ef; | 289 ui::test::TestEventHandler lock_ef; |
| 290 client.GetNonLockWindow()->AddPreTargetHandler(&nonlock_ef); | 290 client.GetNonLockWindow()->AddPreTargetHandler(&nonlock_ef); |
| 291 client.GetLockWindow()->AddPreTargetHandler(&lock_ef); | 291 client.GetLockWindow()->AddPreTargetHandler(&lock_ef); |
| 292 | 292 |
| 293 Window* w1 = test::CreateTestWindowWithBounds(gfx::Rect(10, 10, 20, 20), | 293 Window* w1 = test::CreateTestWindowWithBounds(gfx::Rect(10, 10, 20, 20), |
| 294 client.GetNonLockWindow()); | 294 client.GetNonLockWindow()); |
| 295 w1->set_id(1); | 295 w1->set_id(1); |
| 296 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20), | 296 Window* w2 = test::CreateTestWindowWithBounds(gfx::Rect(30, 30, 20, 20), |
| 297 client.GetNonLockWindow()); | 297 client.GetNonLockWindow()); |
| 298 w2->set_id(2); | 298 w2->set_id(2); |
| 299 scoped_ptr<Window> w3( | 299 std::unique_ptr<Window> w3(test::CreateTestWindowWithDelegate( |
| 300 test::CreateTestWindowWithDelegate(&d, 3, gfx::Rect(30, 30, 20, 20), | 300 &d, 3, gfx::Rect(30, 30, 20, 20), client.GetLockWindow())); |
| 301 client.GetLockWindow())); | |
| 302 | 301 |
| 303 w1->Focus(); | 302 w1->Focus(); |
| 304 EXPECT_TRUE(IsFocusedWindow(w1)); | 303 EXPECT_TRUE(IsFocusedWindow(w1)); |
| 305 | 304 |
| 306 client.Lock(); | 305 client.Lock(); |
| 307 | 306 |
| 308 // Since we're locked, the attempt to focus w2 will be ignored. | 307 // Since we're locked, the attempt to focus w2 will be ignored. |
| 309 w2->Focus(); | 308 w2->Focus(); |
| 310 EXPECT_TRUE(IsFocusedWindow(w1)); | 309 EXPECT_TRUE(IsFocusedWindow(w1)); |
| 311 EXPECT_FALSE(IsFocusedWindow(w2)); | 310 EXPECT_FALSE(IsFocusedWindow(w2)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 ui::KeyEvent unknown_key_with_char_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, | 362 ui::KeyEvent unknown_key_with_char_event(ui::ET_KEY_PRESSED, ui::VKEY_UNKNOWN, |
| 364 ui::EF_NONE); | 363 ui::EF_NONE); |
| 365 unknown_key_with_char_event.set_character(0x00e4 /* "ä" */); | 364 unknown_key_with_char_event.set_character(0x00e4 /* "ä" */); |
| 366 DispatchEventUsingWindowDispatcher(&unknown_key_with_char_event); | 365 DispatchEventUsingWindowDispatcher(&unknown_key_with_char_event); |
| 367 EXPECT_TRUE(unknown_key_with_char_event.handled()); | 366 EXPECT_TRUE(unknown_key_with_char_event.handled()); |
| 368 EXPECT_EQ(1, handler.num_key_events()); | 367 EXPECT_EQ(1, handler.num_key_events()); |
| 369 root_window()->RemovePreTargetHandler(&handler); | 368 root_window()->RemovePreTargetHandler(&handler); |
| 370 } | 369 } |
| 371 | 370 |
| 372 TEST_F(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { | 371 TEST_F(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { |
| 373 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 372 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
| 374 w1->Show(); | 373 w1->Show(); |
| 375 w1->Focus(); | 374 w1->Focus(); |
| 376 | 375 |
| 377 ui::test::TestEventHandler handler; | 376 ui::test::TestEventHandler handler; |
| 378 w1->AddPreTargetHandler(&handler); | 377 w1->AddPreTargetHandler(&handler); |
| 379 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); | 378 ui::KeyEvent key_press(ui::ET_KEY_PRESSED, ui::VKEY_A, ui::EF_NONE); |
| 380 DispatchEventUsingWindowDispatcher(&key_press); | 379 DispatchEventUsingWindowDispatcher(&key_press); |
| 381 EXPECT_TRUE(key_press.handled()); | 380 EXPECT_TRUE(key_press.handled()); |
| 382 EXPECT_EQ(1, handler.num_key_events()); | 381 EXPECT_EQ(1, handler.num_key_events()); |
| 383 | 382 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 407 root_window()->RemovePreTargetHandler(&handler); | 406 root_window()->RemovePreTargetHandler(&handler); |
| 408 } | 407 } |
| 409 | 408 |
| 410 // Tests that scroll events are dispatched correctly. | 409 // Tests that scroll events are dispatched correctly. |
| 411 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { | 410 TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { |
| 412 base::TimeDelta now = ui::EventTimeForNow(); | 411 base::TimeDelta now = ui::EventTimeForNow(); |
| 413 ui::test::TestEventHandler handler; | 412 ui::test::TestEventHandler handler; |
| 414 root_window()->AddPreTargetHandler(&handler); | 413 root_window()->AddPreTargetHandler(&handler); |
| 415 | 414 |
| 416 test::TestWindowDelegate delegate; | 415 test::TestWindowDelegate delegate; |
| 417 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 416 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 418 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); | 417 w1->SetBounds(gfx::Rect(20, 20, 40, 40)); |
| 419 | 418 |
| 420 // A scroll event on the root-window itself is dispatched. | 419 // A scroll event on the root-window itself is dispatched. |
| 421 ui::ScrollEvent scroll1(ui::ET_SCROLL, | 420 ui::ScrollEvent scroll1(ui::ET_SCROLL, |
| 422 gfx::Point(10, 10), | 421 gfx::Point(10, 10), |
| 423 now, | 422 now, |
| 424 0, | 423 0, |
| 425 0, -10, | 424 0, -10, |
| 426 0, -10, | 425 0, -10, |
| 427 2); | 426 2); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 | 509 |
| 511 bool HasReceivedEvent(ui::EventType type) { | 510 bool HasReceivedEvent(ui::EventType type) { |
| 512 return std::find(events_.begin(), events_.end(), type) != events_.end(); | 511 return std::find(events_.begin(), events_.end(), type) != events_.end(); |
| 513 } | 512 } |
| 514 | 513 |
| 515 bool LastTouchMayCauseScrolling() const { | 514 bool LastTouchMayCauseScrolling() const { |
| 516 return last_touch_may_cause_scrolling_; | 515 return last_touch_may_cause_scrolling_; |
| 517 } | 516 } |
| 518 | 517 |
| 519 private: | 518 private: |
| 520 scoped_ptr<base::RunLoop> run_loop_; | 519 std::unique_ptr<base::RunLoop> run_loop_; |
| 521 ui::EventType wait_until_event_; | 520 ui::EventType wait_until_event_; |
| 522 | 521 |
| 523 Events events_; | 522 Events events_; |
| 524 EventLocations mouse_locations_; | 523 EventLocations mouse_locations_; |
| 525 EventLocations touch_locations_; | 524 EventLocations touch_locations_; |
| 526 EventLocations gesture_locations_; | 525 EventLocations gesture_locations_; |
| 527 EventFlags mouse_event_flags_; | 526 EventFlags mouse_event_flags_; |
| 528 bool last_touch_may_cause_scrolling_; | 527 bool last_touch_may_cause_scrolling_; |
| 529 | 528 |
| 530 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); | 529 DISALLOW_COPY_AND_ASSIGN(EventFilterRecorder); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 | 626 |
| 628 // Verifies a repost mouse event targets the window with capture (if there is | 627 // Verifies a repost mouse event targets the window with capture (if there is |
| 629 // one). | 628 // one). |
| 630 // Flaky on 32-bit Windows bots. http://crbug.com/388290 | 629 // Flaky on 32-bit Windows bots. http://crbug.com/388290 |
| 631 TEST_F(WindowEventDispatcherTest, MAYBE(RepostTargetsCaptureWindow)) { | 630 TEST_F(WindowEventDispatcherTest, MAYBE(RepostTargetsCaptureWindow)) { |
| 632 // Set capture on |window| generate a mouse event (that is reposted) and not | 631 // Set capture on |window| generate a mouse event (that is reposted) and not |
| 633 // over |window| and verify |window| gets it (|window| gets it because it has | 632 // over |window| and verify |window| gets it (|window| gets it because it has |
| 634 // capture). | 633 // capture). |
| 635 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); | 634 EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); |
| 636 EventFilterRecorder recorder; | 635 EventFilterRecorder recorder; |
| 637 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 636 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 638 window->SetBounds(gfx::Rect(20, 20, 40, 30)); | 637 window->SetBounds(gfx::Rect(20, 20, 40, 30)); |
| 639 window->AddPreTargetHandler(&recorder); | 638 window->AddPreTargetHandler(&recorder); |
| 640 window->SetCapture(); | 639 window->SetCapture(); |
| 641 const ui::MouseEvent press_event( | 640 const ui::MouseEvent press_event( |
| 642 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), | 641 ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(), ui::EventTimeForNow(), |
| 643 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 642 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 644 host()->dispatcher()->RepostEvent(&press_event); | 643 host()->dispatcher()->RepostEvent(&press_event); |
| 645 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). | 644 RunAllPendingInMessageLoop(); // Necessitated by RepostEvent(). |
| 646 // Mouse moves/enters may be generated. We only care about a pressed. | 645 // Mouse moves/enters may be generated. We only care about a pressed. |
| 647 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != | 646 EXPECT_TRUE(EventTypesToString(recorder.events()).find("MOUSE_PRESSED") != |
| 648 std::string::npos) << EventTypesToString(recorder.events()); | 647 std::string::npos) << EventTypesToString(recorder.events()); |
| 649 } | 648 } |
| 650 | 649 |
| 651 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { | 650 TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { |
| 652 EventFilterRecorder recorder; | 651 EventFilterRecorder recorder; |
| 653 root_window()->AddPreTargetHandler(&recorder); | 652 root_window()->AddPreTargetHandler(&recorder); |
| 654 | 653 |
| 655 test::TestWindowDelegate delegate; | 654 test::TestWindowDelegate delegate; |
| 656 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 655 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 657 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 656 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 658 | 657 |
| 659 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), | 658 ui::MouseEvent mouse_move_event(ui::ET_MOUSE_MOVED, gfx::Point(0, 0), |
| 660 gfx::Point(0, 0), ui::EventTimeForNow(), 0, | 659 gfx::Point(0, 0), ui::EventTimeForNow(), 0, |
| 661 0); | 660 0); |
| 662 DispatchEventUsingWindowDispatcher(&mouse_move_event); | 661 DispatchEventUsingWindowDispatcher(&mouse_move_event); |
| 663 // Discard MOUSE_ENTER. | 662 // Discard MOUSE_ENTER. |
| 664 recorder.Reset(); | 663 recorder.Reset(); |
| 665 | 664 |
| 666 host()->dispatcher()->HoldPointerMoves(); | 665 host()->dispatcher()->HoldPointerMoves(); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 EXPECT_EQ(gfx::Point(13, 13), recorder.mouse_location(0)); | 772 EXPECT_EQ(gfx::Point(13, 13), recorder.mouse_location(0)); |
| 774 recorder.Reset(); | 773 recorder.Reset(); |
| 775 root_window()->RemovePreTargetHandler(&recorder); | 774 root_window()->RemovePreTargetHandler(&recorder); |
| 776 } | 775 } |
| 777 | 776 |
| 778 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { | 777 TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { |
| 779 EventFilterRecorder recorder; | 778 EventFilterRecorder recorder; |
| 780 root_window()->AddPreTargetHandler(&recorder); | 779 root_window()->AddPreTargetHandler(&recorder); |
| 781 | 780 |
| 782 test::TestWindowDelegate delegate; | 781 test::TestWindowDelegate delegate; |
| 783 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 782 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 784 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 783 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 785 | 784 |
| 786 // Starting the touch and throwing out the first few events, since the system | 785 // Starting the touch and throwing out the first few events, since the system |
| 787 // is going to generate synthetic mouse events that are not relevant to the | 786 // is going to generate synthetic mouse events that are not relevant to the |
| 788 // test. | 787 // test. |
| 789 ui::TouchEvent touch_pressed_event( | 788 ui::TouchEvent touch_pressed_event( |
| 790 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); | 789 ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 0, ui::EventTimeForNow()); |
| 791 DispatchEventUsingWindowDispatcher(&touch_pressed_event); | 790 DispatchEventUsingWindowDispatcher(&touch_pressed_event); |
| 792 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); | 791 recorder.WaitUntilReceivedEvent(ui::ET_GESTURE_SHOW_PRESS); |
| 793 recorder.Reset(); | 792 recorder.Reset(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 root_window()->RemovePreTargetHandler(&recorder); | 831 root_window()->RemovePreTargetHandler(&recorder); |
| 833 } | 832 } |
| 834 | 833 |
| 835 // Tests that mouse move event has a right location | 834 // Tests that mouse move event has a right location |
| 836 // when there isn't the target window | 835 // when there isn't the target window |
| 837 TEST_F(WindowEventDispatcherTest, MouseEventWithoutTargetWindow) { | 836 TEST_F(WindowEventDispatcherTest, MouseEventWithoutTargetWindow) { |
| 838 EventFilterRecorder recorder_first; | 837 EventFilterRecorder recorder_first; |
| 839 EventFilterRecorder recorder_second; | 838 EventFilterRecorder recorder_second; |
| 840 | 839 |
| 841 test::TestWindowDelegate delegate; | 840 test::TestWindowDelegate delegate; |
| 842 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( | 841 std::unique_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( |
| 843 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 842 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 844 window_first->Show(); | 843 window_first->Show(); |
| 845 window_first->AddPreTargetHandler(&recorder_first); | 844 window_first->AddPreTargetHandler(&recorder_first); |
| 846 | 845 |
| 847 scoped_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( | 846 std::unique_ptr<aura::Window> window_second(CreateTestWindowWithDelegate( |
| 848 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); | 847 &delegate, 2, gfx::Rect(20, 30, 10, 20), root_window())); |
| 849 window_second->Show(); | 848 window_second->Show(); |
| 850 window_second->AddPreTargetHandler(&recorder_second); | 849 window_second->AddPreTargetHandler(&recorder_second); |
| 851 | 850 |
| 852 const gfx::Point event_location(22, 33); | 851 const gfx::Point event_location(22, 33); |
| 853 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 852 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 854 ui::EventTimeForNow(), 0, 0); | 853 ui::EventTimeForNow(), 0, 0); |
| 855 DispatchEventUsingWindowDispatcher(&mouse); | 854 DispatchEventUsingWindowDispatcher(&mouse); |
| 856 | 855 |
| 857 EXPECT_TRUE(recorder_first.events().empty()); | 856 EXPECT_TRUE(recorder_first.events().empty()); |
| 858 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", | 857 EXPECT_EQ("MOUSE_ENTERED MOUSE_MOVED", |
| 859 EventTypesToString(recorder_second.events())); | 858 EventTypesToString(recorder_second.events())); |
| 860 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); | 859 ASSERT_EQ(2u, recorder_second.mouse_locations().size()); |
| 861 EXPECT_EQ(gfx::Point(2, 3).ToString(), | 860 EXPECT_EQ(gfx::Point(2, 3).ToString(), |
| 862 recorder_second.mouse_locations()[0].ToString()); | 861 recorder_second.mouse_locations()[0].ToString()); |
| 863 } | 862 } |
| 864 | 863 |
| 865 // Tests that a mouse exit is dispatched to the last mouse location when | 864 // Tests that a mouse exit is dispatched to the last mouse location when |
| 866 // the window is hiddden. | 865 // the window is hiddden. |
| 867 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { | 866 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { |
| 868 EventFilterRecorder recorder; | 867 EventFilterRecorder recorder; |
| 869 | 868 |
| 870 test::TestWindowDelegate delegate; | 869 test::TestWindowDelegate delegate; |
| 871 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 870 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 872 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); | 871 &delegate, 1, gfx::Rect(10, 10, 50, 50), root_window())); |
| 873 window->Show(); | 872 window->Show(); |
| 874 window->AddPreTargetHandler(&recorder); | 873 window->AddPreTargetHandler(&recorder); |
| 875 | 874 |
| 876 // Dispatch a mouse move event into the window. | 875 // Dispatch a mouse move event into the window. |
| 877 const gfx::Point event_location(22, 33); | 876 const gfx::Point event_location(22, 33); |
| 878 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, | 877 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, event_location, event_location, |
| 879 ui::EventTimeForNow(), 0, 0); | 878 ui::EventTimeForNow(), 0, 0); |
| 880 DispatchEventUsingWindowDispatcher(&mouse); | 879 DispatchEventUsingWindowDispatcher(&mouse); |
| 881 EXPECT_FALSE(recorder.events().empty()); | 880 EXPECT_FALSE(recorder.events().empty()); |
| 882 recorder.Reset(); | 881 recorder.Reset(); |
| 883 | 882 |
| 884 // Hide the window and verify a mouse exit event's location. | 883 // Hide the window and verify a mouse exit event's location. |
| 885 window->Hide(); | 884 window->Hide(); |
| 886 EXPECT_FALSE(recorder.events().empty()); | 885 EXPECT_FALSE(recorder.events().empty()); |
| 887 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); | 886 EXPECT_EQ("MOUSE_EXITED", EventTypesToString(recorder.events())); |
| 888 ASSERT_EQ(1u, recorder.mouse_locations().size()); | 887 ASSERT_EQ(1u, recorder.mouse_locations().size()); |
| 889 EXPECT_EQ(gfx::Point(12, 23).ToString(), | 888 EXPECT_EQ(gfx::Point(12, 23).ToString(), |
| 890 recorder.mouse_locations()[0].ToString()); | 889 recorder.mouse_locations()[0].ToString()); |
| 891 } | 890 } |
| 892 | 891 |
| 893 // Verifies that a direct call to ProcessedTouchEvent() does not cause a crash. | 892 // Verifies that a direct call to ProcessedTouchEvent() does not cause a crash. |
| 894 TEST_F(WindowEventDispatcherTest, CallToProcessedTouchEvent) { | 893 TEST_F(WindowEventDispatcherTest, CallToProcessedTouchEvent) { |
| 895 test::TestWindowDelegate delegate; | 894 test::TestWindowDelegate delegate; |
| 896 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 895 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 897 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 896 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 898 | 897 |
| 899 host()->dispatcher()->ProcessedTouchEvent(0, window.get(), ui::ER_UNHANDLED); | 898 host()->dispatcher()->ProcessedTouchEvent(0, window.get(), ui::ER_UNHANDLED); |
| 900 } | 899 } |
| 901 | 900 |
| 902 // This event handler requests the dispatcher to start holding pointer-move | 901 // This event handler requests the dispatcher to start holding pointer-move |
| 903 // events when it receives the first scroll-update gesture. | 902 // events when it receives the first scroll-update gesture. |
| 904 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { | 903 class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { |
| 905 public: | 904 public: |
| 906 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, | 905 HoldPointerOnScrollHandler(WindowEventDispatcher* dispatcher, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 930 DISALLOW_COPY_AND_ASSIGN(HoldPointerOnScrollHandler); | 929 DISALLOW_COPY_AND_ASSIGN(HoldPointerOnScrollHandler); |
| 931 }; | 930 }; |
| 932 | 931 |
| 933 // Tests that touch-move events don't contribute to an in-progress scroll | 932 // Tests that touch-move events don't contribute to an in-progress scroll |
| 934 // gesture if touch-move events are being held by the dispatcher. | 933 // gesture if touch-move events are being held by the dispatcher. |
| 935 TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { | 934 TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { |
| 936 EventFilterRecorder recorder; | 935 EventFilterRecorder recorder; |
| 937 root_window()->AddPreTargetHandler(&recorder); | 936 root_window()->AddPreTargetHandler(&recorder); |
| 938 test::TestWindowDelegate delegate; | 937 test::TestWindowDelegate delegate; |
| 939 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); | 938 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); |
| 940 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 939 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 941 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 940 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 942 window->AddPreTargetHandler(&handler); | 941 window->AddPreTargetHandler(&handler); |
| 943 | 942 |
| 944 ui::test::EventGenerator generator(root_window()); | 943 ui::test::EventGenerator generator(root_window()); |
| 945 generator.GestureScrollSequence( | 944 generator.GestureScrollSequence( |
| 946 gfx::Point(60, 60), gfx::Point(10, 60), | 945 gfx::Point(60, 60), gfx::Point(10, 60), |
| 947 base::TimeDelta::FromMilliseconds(100), 25); | 946 base::TimeDelta::FromMilliseconds(100), 25); |
| 948 | 947 |
| 949 // |handler| will have reset |filter| and started holding the touch-move | 948 // |handler| will have reset |filter| and started holding the touch-move |
| 950 // events when scrolling started. At the end of the scroll (i.e. upon | 949 // events when scrolling started. At the end of the scroll (i.e. upon |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 root_window()->RemovePreTargetHandler(&recorder); | 997 root_window()->RemovePreTargetHandler(&recorder); |
| 999 } | 998 } |
| 1000 | 999 |
| 1001 // Tests that synthetic mouse events are ignored when mouse | 1000 // Tests that synthetic mouse events are ignored when mouse |
| 1002 // events are disabled. | 1001 // events are disabled. |
| 1003 TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { | 1002 TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { |
| 1004 EventFilterRecorder recorder; | 1003 EventFilterRecorder recorder; |
| 1005 root_window()->AddPreTargetHandler(&recorder); | 1004 root_window()->AddPreTargetHandler(&recorder); |
| 1006 | 1005 |
| 1007 test::TestWindowDelegate delegate; | 1006 test::TestWindowDelegate delegate; |
| 1008 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1007 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1009 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1008 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1010 window->Show(); | 1009 window->Show(); |
| 1011 window->SetCapture(); | 1010 window->SetCapture(); |
| 1012 | 1011 |
| 1013 test::TestCursorClient cursor_client(root_window()); | 1012 test::TestCursorClient cursor_client(root_window()); |
| 1014 | 1013 |
| 1015 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1014 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1016 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1015 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 1017 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1016 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); |
| 1018 DispatchEventUsingWindowDispatcher(&mouse1); | 1017 DispatchEventUsingWindowDispatcher(&mouse1); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1031 cursor_client.DisableMouseEvents(); | 1030 cursor_client.DisableMouseEvents(); |
| 1032 DispatchEventUsingWindowDispatcher(&mouse2); | 1031 DispatchEventUsingWindowDispatcher(&mouse2); |
| 1033 EXPECT_TRUE(recorder.events().empty()); | 1032 EXPECT_TRUE(recorder.events().empty()); |
| 1034 root_window()->RemovePreTargetHandler(&recorder); | 1033 root_window()->RemovePreTargetHandler(&recorder); |
| 1035 } | 1034 } |
| 1036 | 1035 |
| 1037 // Tests that a mouse-move event is not synthesized when a mouse-button is down. | 1036 // Tests that a mouse-move event is not synthesized when a mouse-button is down. |
| 1038 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { | 1037 TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { |
| 1039 EventFilterRecorder recorder; | 1038 EventFilterRecorder recorder; |
| 1040 test::TestWindowDelegate delegate; | 1039 test::TestWindowDelegate delegate; |
| 1041 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1040 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1042 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1041 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1043 window->Show(); | 1042 window->Show(); |
| 1044 | 1043 |
| 1045 window->AddPreTargetHandler(&recorder); | 1044 window->AddPreTargetHandler(&recorder); |
| 1046 // Dispatch a non-synthetic mouse event when mouse events are enabled. | 1045 // Dispatch a non-synthetic mouse event when mouse events are enabled. |
| 1047 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1046 ui::MouseEvent mouse1(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), |
| 1048 gfx::Point(10, 10), ui::EventTimeForNow(), | 1047 gfx::Point(10, 10), ui::EventTimeForNow(), |
| 1049 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); | 1048 ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); |
| 1050 DispatchEventUsingWindowDispatcher(&mouse1); | 1049 DispatchEventUsingWindowDispatcher(&mouse1); |
| 1051 ASSERT_EQ(1u, recorder.events().size()); | 1050 ASSERT_EQ(1u, recorder.events().size()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1068 #define MAYBE(x) x | 1067 #define MAYBE(x) x |
| 1069 #endif | 1068 #endif |
| 1070 | 1069 |
| 1071 // Tests synthetic mouse events generated when window bounds changes such that | 1070 // Tests synthetic mouse events generated when window bounds changes such that |
| 1072 // the cursor previously outside the window becomes inside, or vice versa. | 1071 // the cursor previously outside the window becomes inside, or vice versa. |
| 1073 // Do not synthesize events if the window ignores events or is invisible. | 1072 // Do not synthesize events if the window ignores events or is invisible. |
| 1074 // Flaky on 32-bit Windows bots. http://crbug.com/388272 | 1073 // Flaky on 32-bit Windows bots. http://crbug.com/388272 |
| 1075 TEST_F(WindowEventDispatcherTest, | 1074 TEST_F(WindowEventDispatcherTest, |
| 1076 MAYBE(SynthesizeMouseEventsOnWindowBoundsChanged)) { | 1075 MAYBE(SynthesizeMouseEventsOnWindowBoundsChanged)) { |
| 1077 test::TestWindowDelegate delegate; | 1076 test::TestWindowDelegate delegate; |
| 1078 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1077 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1079 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); | 1078 &delegate, 1234, gfx::Rect(5, 5, 100, 100), root_window())); |
| 1080 window->Show(); | 1079 window->Show(); |
| 1081 window->SetCapture(); | 1080 window->SetCapture(); |
| 1082 | 1081 |
| 1083 EventFilterRecorder recorder; | 1082 EventFilterRecorder recorder; |
| 1084 window->AddPreTargetHandler(&recorder); | 1083 window->AddPreTargetHandler(&recorder); |
| 1085 | 1084 |
| 1086 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. | 1085 // Dispatch a non-synthetic mouse event to place cursor inside window bounds. |
| 1087 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), | 1086 ui::MouseEvent mouse(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 1088 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1087 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 } | 1124 } |
| 1126 | 1125 |
| 1127 // Tests that a mouse exit is dispatched to the last known cursor location | 1126 // Tests that a mouse exit is dispatched to the last known cursor location |
| 1128 // when the cursor becomes invisible. | 1127 // when the cursor becomes invisible. |
| 1129 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenCursorHidden) { | 1128 TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenCursorHidden) { |
| 1130 EventFilterRecorder recorder; | 1129 EventFilterRecorder recorder; |
| 1131 root_window()->AddPreTargetHandler(&recorder); | 1130 root_window()->AddPreTargetHandler(&recorder); |
| 1132 | 1131 |
| 1133 test::TestWindowDelegate delegate; | 1132 test::TestWindowDelegate delegate; |
| 1134 gfx::Point window_origin(7, 18); | 1133 gfx::Point window_origin(7, 18); |
| 1135 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1134 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1136 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1135 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1137 root_window())); | 1136 root_window())); |
| 1138 window->Show(); | 1137 window->Show(); |
| 1139 | 1138 |
| 1140 // Dispatch a mouse move event into the window. | 1139 // Dispatch a mouse move event into the window. |
| 1141 gfx::Point mouse_location(gfx::Point(15, 25)); | 1140 gfx::Point mouse_location(gfx::Point(15, 25)); |
| 1142 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1141 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, |
| 1143 ui::EventTimeForNow(), 0, 0); | 1142 ui::EventTimeForNow(), 0, 0); |
| 1144 EXPECT_TRUE(recorder.events().empty()); | 1143 EXPECT_TRUE(recorder.events().empty()); |
| 1145 DispatchEventUsingWindowDispatcher(&mouse1); | 1144 DispatchEventUsingWindowDispatcher(&mouse1); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1162 | 1161 |
| 1163 // Tests that a synthetic mouse exit is dispatched to the last known cursor | 1162 // Tests that a synthetic mouse exit is dispatched to the last known cursor |
| 1164 // location after mouse events are disabled on the cursor client. | 1163 // location after mouse events are disabled on the cursor client. |
| 1165 TEST_F(WindowEventDispatcherTest, | 1164 TEST_F(WindowEventDispatcherTest, |
| 1166 DispatchSyntheticMouseExitAfterMouseEventsDisabled) { | 1165 DispatchSyntheticMouseExitAfterMouseEventsDisabled) { |
| 1167 EventFilterRecorder recorder; | 1166 EventFilterRecorder recorder; |
| 1168 root_window()->AddPreTargetHandler(&recorder); | 1167 root_window()->AddPreTargetHandler(&recorder); |
| 1169 | 1168 |
| 1170 test::TestWindowDelegate delegate; | 1169 test::TestWindowDelegate delegate; |
| 1171 gfx::Point window_origin(7, 18); | 1170 gfx::Point window_origin(7, 18); |
| 1172 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1171 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1173 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), | 1172 &delegate, 1234, gfx::Rect(window_origin, gfx::Size(100, 100)), |
| 1174 root_window())); | 1173 root_window())); |
| 1175 window->Show(); | 1174 window->Show(); |
| 1176 | 1175 |
| 1177 // Dispatch a mouse move event into the window. | 1176 // Dispatch a mouse move event into the window. |
| 1178 gfx::Point mouse_location(gfx::Point(15, 25)); | 1177 gfx::Point mouse_location(gfx::Point(15, 25)); |
| 1179 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, | 1178 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, mouse_location, mouse_location, |
| 1180 ui::EventTimeForNow(), 0, 0); | 1179 ui::EventTimeForNow(), 0, 0); |
| 1181 EXPECT_TRUE(recorder.events().empty()); | 1180 EXPECT_TRUE(recorder.events().empty()); |
| 1182 DispatchEventUsingWindowDispatcher(&mouse1); | 1181 DispatchEventUsingWindowDispatcher(&mouse1); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1266 bool delete_during_handle_; | 1265 bool delete_during_handle_; |
| 1267 bool got_event_; | 1266 bool got_event_; |
| 1268 | 1267 |
| 1269 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); | 1268 DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); |
| 1270 }; | 1269 }; |
| 1271 | 1270 |
| 1272 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringDispatch) { | 1271 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringDispatch) { |
| 1273 // Verifies that we can delete a window during each phase of event handling. | 1272 // Verifies that we can delete a window during each phase of event handling. |
| 1274 // Deleting the window should not cause a crash, only prevent further | 1273 // Deleting the window should not cause a crash, only prevent further |
| 1275 // processing from occurring. | 1274 // processing from occurring. |
| 1276 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 1275 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
| 1277 DeletingWindowDelegate d11; | 1276 DeletingWindowDelegate d11; |
| 1278 Window* w11 = CreateNormalWindow(11, w1.get(), &d11); | 1277 Window* w11 = CreateNormalWindow(11, w1.get(), &d11); |
| 1279 WindowTracker tracker; | 1278 WindowTracker tracker; |
| 1280 DeletingEventFilter w1_filter; | 1279 DeletingEventFilter w1_filter; |
| 1281 w1->AddPreTargetHandler(&w1_filter); | 1280 w1->AddPreTargetHandler(&w1_filter); |
| 1282 client::GetFocusClient(w1.get())->FocusWindow(w11); | 1281 client::GetFocusClient(w1.get())->FocusWindow(w11); |
| 1283 | 1282 |
| 1284 ui::test::EventGenerator generator(root_window(), w11); | 1283 ui::test::EventGenerator generator(root_window(), w11); |
| 1285 | 1284 |
| 1286 // First up, no one deletes anything. | 1285 // First up, no one deletes anything. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 | 1333 |
| 1335 DISALLOW_COPY_AND_ASSIGN(DetachesParentOnTapDelegate); | 1334 DISALLOW_COPY_AND_ASSIGN(DetachesParentOnTapDelegate); |
| 1336 }; | 1335 }; |
| 1337 | 1336 |
| 1338 } // namespace | 1337 } // namespace |
| 1339 | 1338 |
| 1340 // Tests that the gesture recognizer is reset for all child windows when a | 1339 // Tests that the gesture recognizer is reset for all child windows when a |
| 1341 // window hides. No expectations, just checks that the test does not crash. | 1340 // window hides. No expectations, just checks that the test does not crash. |
| 1342 TEST_F(WindowEventDispatcherTest, | 1341 TEST_F(WindowEventDispatcherTest, |
| 1343 GestureRecognizerResetsTargetWhenParentHides) { | 1342 GestureRecognizerResetsTargetWhenParentHides) { |
| 1344 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 1343 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
| 1345 DetachesParentOnTapDelegate delegate; | 1344 DetachesParentOnTapDelegate delegate; |
| 1346 scoped_ptr<Window> parent(CreateNormalWindow(22, w1.get(), NULL)); | 1345 std::unique_ptr<Window> parent(CreateNormalWindow(22, w1.get(), NULL)); |
| 1347 Window* child = CreateNormalWindow(11, parent.get(), &delegate); | 1346 Window* child = CreateNormalWindow(11, parent.get(), &delegate); |
| 1348 ui::test::EventGenerator generator(root_window(), child); | 1347 ui::test::EventGenerator generator(root_window(), child); |
| 1349 generator.GestureTapAt(gfx::Point(40, 40)); | 1348 generator.GestureTapAt(gfx::Point(40, 40)); |
| 1350 } | 1349 } |
| 1351 | 1350 |
| 1352 namespace { | 1351 namespace { |
| 1353 | 1352 |
| 1354 // A window delegate that processes nested gestures on tap. | 1353 // A window delegate that processes nested gestures on tap. |
| 1355 class NestedGestureDelegate : public test::TestWindowDelegate { | 1354 class NestedGestureDelegate : public test::TestWindowDelegate { |
| 1356 public: | 1355 public: |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1386 const gfx::Point tap_location_; | 1385 const gfx::Point tap_location_; |
| 1387 int gesture_end_count_; | 1386 int gesture_end_count_; |
| 1388 DISALLOW_COPY_AND_ASSIGN(NestedGestureDelegate); | 1387 DISALLOW_COPY_AND_ASSIGN(NestedGestureDelegate); |
| 1389 }; | 1388 }; |
| 1390 | 1389 |
| 1391 } // namespace | 1390 } // namespace |
| 1392 | 1391 |
| 1393 // Tests that gesture end is delivered after nested gesture processing. | 1392 // Tests that gesture end is delivered after nested gesture processing. |
| 1394 TEST_F(WindowEventDispatcherTest, GestureEndDeliveredAfterNestedGestures) { | 1393 TEST_F(WindowEventDispatcherTest, GestureEndDeliveredAfterNestedGestures) { |
| 1395 NestedGestureDelegate d1(NULL, gfx::Point()); | 1394 NestedGestureDelegate d1(NULL, gfx::Point()); |
| 1396 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &d1)); | 1395 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &d1)); |
| 1397 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); | 1396 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); |
| 1398 | 1397 |
| 1399 ui::test::EventGenerator nested_generator(root_window(), w1.get()); | 1398 ui::test::EventGenerator nested_generator(root_window(), w1.get()); |
| 1400 NestedGestureDelegate d2(&nested_generator, w1->bounds().CenterPoint()); | 1399 NestedGestureDelegate d2(&nested_generator, w1->bounds().CenterPoint()); |
| 1401 scoped_ptr<Window> w2(CreateNormalWindow(1, root_window(), &d2)); | 1400 std::unique_ptr<Window> w2(CreateNormalWindow(1, root_window(), &d2)); |
| 1402 w2->SetBounds(gfx::Rect(100, 0, 100, 100)); | 1401 w2->SetBounds(gfx::Rect(100, 0, 100, 100)); |
| 1403 | 1402 |
| 1404 // Tap on w2 which triggers nested gestures for w1. | 1403 // Tap on w2 which triggers nested gestures for w1. |
| 1405 ui::test::EventGenerator generator(root_window(), w2.get()); | 1404 ui::test::EventGenerator generator(root_window(), w2.get()); |
| 1406 generator.GestureTapAt(w2->bounds().CenterPoint()); | 1405 generator.GestureTapAt(w2->bounds().CenterPoint()); |
| 1407 | 1406 |
| 1408 // Both windows should get their gesture end events. | 1407 // Both windows should get their gesture end events. |
| 1409 EXPECT_EQ(1, d1.gesture_end_count()); | 1408 EXPECT_EQ(1, d1.gesture_end_count()); |
| 1410 EXPECT_EQ(1, d2.gesture_end_count()); | 1409 EXPECT_EQ(1, d2.gesture_end_count()); |
| 1411 } | 1410 } |
| 1412 | 1411 |
| 1413 // Tests whether we can repost the Tap down gesture event. | 1412 // Tests whether we can repost the Tap down gesture event. |
| 1414 TEST_F(WindowEventDispatcherTest, RepostTapdownGestureTest) { | 1413 TEST_F(WindowEventDispatcherTest, RepostTapdownGestureTest) { |
| 1415 EventFilterRecorder recorder; | 1414 EventFilterRecorder recorder; |
| 1416 root_window()->AddPreTargetHandler(&recorder); | 1415 root_window()->AddPreTargetHandler(&recorder); |
| 1417 | 1416 |
| 1418 test::TestWindowDelegate delegate; | 1417 test::TestWindowDelegate delegate; |
| 1419 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1418 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1420 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1419 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1421 | 1420 |
| 1422 ui::GestureEventDetails details(ui::ET_GESTURE_TAP_DOWN); | 1421 ui::GestureEventDetails details(ui::ET_GESTURE_TAP_DOWN); |
| 1423 gfx::Point point(10, 10); | 1422 gfx::Point point(10, 10); |
| 1424 ui::GestureEvent event(point.x(), | 1423 ui::GestureEvent event(point.x(), |
| 1425 point.y(), | 1424 point.y(), |
| 1426 0, | 1425 0, |
| 1427 ui::EventTimeForNow(), | 1426 ui::EventTimeForNow(), |
| 1428 details); | 1427 details); |
| 1429 host()->dispatcher()->RepostEvent(&event); | 1428 host()->dispatcher()->RepostEvent(&event); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE TOUCH_MOVED " | 1499 "GESTURE_TAP_CANCEL GESTURE_SCROLL_BEGIN GESTURE_SCROLL_UPDATE TOUCH_MOVED " |
| 1501 "GESTURE_SCROLL_UPDATE TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED " | 1500 "GESTURE_SCROLL_UPDATE TOUCH_MOVED GESTURE_SCROLL_UPDATE TOUCH_RELEASED " |
| 1502 "GESTURE_SCROLL_END GESTURE_END"; | 1501 "GESTURE_SCROLL_END GESTURE_END"; |
| 1503 // We create two windows. | 1502 // We create two windows. |
| 1504 // The first window (repost_source) is the one to which the initial tap | 1503 // The first window (repost_source) is the one to which the initial tap |
| 1505 // gesture is sent. It reposts this event to the second window | 1504 // gesture is sent. It reposts this event to the second window |
| 1506 // (repost_target). | 1505 // (repost_target). |
| 1507 // We then generate the scroll sequence for repost_target and look for two | 1506 // We then generate the scroll sequence for repost_target and look for two |
| 1508 // ET_GESTURE_TAP_DOWN events in the event list at the end. | 1507 // ET_GESTURE_TAP_DOWN events in the event list at the end. |
| 1509 test::TestWindowDelegate delegate; | 1508 test::TestWindowDelegate delegate; |
| 1510 scoped_ptr<aura::Window> repost_target(CreateTestWindowWithDelegate( | 1509 std::unique_ptr<aura::Window> repost_target(CreateTestWindowWithDelegate( |
| 1511 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1510 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1512 | 1511 |
| 1513 scoped_ptr<aura::Window> repost_source(CreateTestWindowWithDelegate( | 1512 std::unique_ptr<aura::Window> repost_source(CreateTestWindowWithDelegate( |
| 1514 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); | 1513 &delegate, 1, gfx::Rect(0, 0, 50, 50), root_window())); |
| 1515 | 1514 |
| 1516 RepostGestureEventRecorder repost_event_recorder(repost_source.get(), | 1515 RepostGestureEventRecorder repost_event_recorder(repost_source.get(), |
| 1517 repost_target.get()); | 1516 repost_target.get()); |
| 1518 root_window()->AddPreTargetHandler(&repost_event_recorder); | 1517 root_window()->AddPreTargetHandler(&repost_event_recorder); |
| 1519 | 1518 |
| 1520 // Generate a tap down gesture for the repost_source. This will be reposted | 1519 // Generate a tap down gesture for the repost_source. This will be reposted |
| 1521 // to repost_target. | 1520 // to repost_target. |
| 1522 ui::test::EventGenerator repost_generator(root_window(), repost_source.get()); | 1521 ui::test::EventGenerator repost_generator(root_window(), repost_source.get()); |
| 1523 repost_generator.GestureTapAt(gfx::Point(40, 40)); | 1522 repost_generator.GestureTapAt(gfx::Point(40, 40)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1575 | 1574 |
| 1576 DISALLOW_COPY_AND_ASSIGN(OnMouseExitDeletingEventFilter); | 1575 DISALLOW_COPY_AND_ASSIGN(OnMouseExitDeletingEventFilter); |
| 1577 }; | 1576 }; |
| 1578 | 1577 |
| 1579 // Tests that RootWindow drops mouse-moved event that is supposed to be sent to | 1578 // Tests that RootWindow drops mouse-moved event that is supposed to be sent to |
| 1580 // a child, but the child is destroyed because of the synthesized mouse-exit | 1579 // a child, but the child is destroyed because of the synthesized mouse-exit |
| 1581 // event generated on the previous mouse_moved_handler_. | 1580 // event generated on the previous mouse_moved_handler_. |
| 1582 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { | 1581 TEST_F(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { |
| 1583 // Create window 1 and set its event filter. Window 1 will take ownership of | 1582 // Create window 1 and set its event filter. Window 1 will take ownership of |
| 1584 // the event filter. | 1583 // the event filter. |
| 1585 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); | 1584 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); |
| 1586 OnMouseExitDeletingEventFilter<Window> w1_filter; | 1585 OnMouseExitDeletingEventFilter<Window> w1_filter; |
| 1587 w1->AddPreTargetHandler(&w1_filter); | 1586 w1->AddPreTargetHandler(&w1_filter); |
| 1588 w1->SetBounds(gfx::Rect(20, 20, 60, 60)); | 1587 w1->SetBounds(gfx::Rect(20, 20, 60, 60)); |
| 1589 EXPECT_EQ(NULL, host()->dispatcher()->mouse_moved_handler()); | 1588 EXPECT_EQ(NULL, host()->dispatcher()->mouse_moved_handler()); |
| 1590 | 1589 |
| 1591 ui::test::EventGenerator generator(root_window(), w1.get()); | 1590 ui::test::EventGenerator generator(root_window(), w1.get()); |
| 1592 | 1591 |
| 1593 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the | 1592 // Move mouse over window 1 to set it as the |mouse_moved_handler_| for the |
| 1594 // root window. | 1593 // root window. |
| 1595 generator.MoveMouseTo(51, 51); | 1594 generator.MoveMouseTo(51, 51); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1690 | 1689 |
| 1691 } // namespace | 1690 } // namespace |
| 1692 | 1691 |
| 1693 // Verifies GetRootWindow() from ~Window returns a valid root. | 1692 // Verifies GetRootWindow() from ~Window returns a valid root. |
| 1694 TEST_F(WindowEventDispatcherTest, ValidRootDuringDestruction) { | 1693 TEST_F(WindowEventDispatcherTest, ValidRootDuringDestruction) { |
| 1695 bool got_destroying = false; | 1694 bool got_destroying = false; |
| 1696 bool has_valid_root = false; | 1695 bool has_valid_root = false; |
| 1697 ValidRootDuringDestructionWindowObserver observer(&got_destroying, | 1696 ValidRootDuringDestructionWindowObserver observer(&got_destroying, |
| 1698 &has_valid_root); | 1697 &has_valid_root); |
| 1699 { | 1698 { |
| 1700 scoped_ptr<WindowTreeHost> host( | 1699 std::unique_ptr<WindowTreeHost> host( |
| 1701 WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100))); | 1700 WindowTreeHost::Create(gfx::Rect(0, 0, 100, 100))); |
| 1702 host->InitHost(); | 1701 host->InitHost(); |
| 1703 // Owned by WindowEventDispatcher. | 1702 // Owned by WindowEventDispatcher. |
| 1704 Window* w1 = CreateNormalWindow(1, host->window(), NULL); | 1703 Window* w1 = CreateNormalWindow(1, host->window(), NULL); |
| 1705 w1->AddObserver(&observer); | 1704 w1->AddObserver(&observer); |
| 1706 } | 1705 } |
| 1707 EXPECT_TRUE(got_destroying); | 1706 EXPECT_TRUE(got_destroying); |
| 1708 EXPECT_TRUE(has_valid_root); | 1707 EXPECT_TRUE(has_valid_root); |
| 1709 } | 1708 } |
| 1710 | 1709 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 1740 | 1739 |
| 1741 } // namespace | 1740 } // namespace |
| 1742 | 1741 |
| 1743 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after | 1742 // Verifies RootWindow doesn't reset |RootWindow::held_repostable_event_| after |
| 1744 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which | 1743 // dispatching. This is done by using DontResetHeldEventWindowDelegate, which |
| 1745 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events | 1744 // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events |
| 1746 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to | 1745 // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to |
| 1747 // schedule another reposted event. | 1746 // schedule another reposted event. |
| 1748 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { | 1747 TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { |
| 1749 DontResetHeldEventWindowDelegate delegate(root_window()); | 1748 DontResetHeldEventWindowDelegate delegate(root_window()); |
| 1750 scoped_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); | 1749 std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); |
| 1751 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1750 w1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1752 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1751 ui::MouseEvent pressed(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), |
| 1753 gfx::Point(10, 10), ui::EventTimeForNow(), | 1752 gfx::Point(10, 10), ui::EventTimeForNow(), |
| 1754 ui::EF_SHIFT_DOWN, 0); | 1753 ui::EF_SHIFT_DOWN, 0); |
| 1755 root_window()->GetHost()->dispatcher()->RepostEvent(&pressed); | 1754 root_window()->GetHost()->dispatcher()->RepostEvent(&pressed); |
| 1756 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 1755 ui::MouseEvent pressed2(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), |
| 1757 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); | 1756 gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0); |
| 1758 // Dispatch an event to flush event scheduled by way of RepostEvent(). | 1757 // Dispatch an event to flush event scheduled by way of RepostEvent(). |
| 1759 DispatchEventUsingWindowDispatcher(&pressed2); | 1758 DispatchEventUsingWindowDispatcher(&pressed2); |
| 1760 // Delegate should have seen reposted event (identified by way of | 1759 // Delegate should have seen reposted event (identified by way of |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 RunAllPendingInMessageLoop(); | 1817 RunAllPendingInMessageLoop(); |
| 1819 EXPECT_TRUE(delegate.got_mouse_event()); | 1818 EXPECT_TRUE(delegate.got_mouse_event()); |
| 1820 EXPECT_TRUE(delegate.got_destroy()); | 1819 EXPECT_TRUE(delegate.got_destroy()); |
| 1821 } | 1820 } |
| 1822 | 1821 |
| 1823 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { | 1822 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { |
| 1824 EventFilterRecorder recorder; | 1823 EventFilterRecorder recorder; |
| 1825 root_window()->AddPreTargetHandler(&recorder); | 1824 root_window()->AddPreTargetHandler(&recorder); |
| 1826 | 1825 |
| 1827 test::TestWindowDelegate delegate; | 1826 test::TestWindowDelegate delegate; |
| 1828 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1827 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1829 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1828 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1830 | 1829 |
| 1831 gfx::Point position1 = root_window()->bounds().origin(); | 1830 gfx::Point position1 = root_window()->bounds().origin(); |
| 1832 ui::TouchEvent press( | 1831 ui::TouchEvent press( |
| 1833 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); | 1832 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); |
| 1834 DispatchEventUsingWindowDispatcher(&press); | 1833 DispatchEventUsingWindowDispatcher(&press); |
| 1835 | 1834 |
| 1836 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", | 1835 EXPECT_EQ("TOUCH_PRESSED GESTURE_BEGIN GESTURE_TAP_DOWN", |
| 1837 EventTypesToString(recorder.GetAndResetEvents())); | 1836 EventTypesToString(recorder.GetAndResetEvents())); |
| 1838 | 1837 |
| 1839 window->Hide(); | 1838 window->Hide(); |
| 1840 | 1839 |
| 1841 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, recorder.events()[0]); | 1840 EXPECT_EQ(ui::ET_TOUCH_CANCELLED, recorder.events()[0]); |
| 1842 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_TAP_CANCEL)); | 1841 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_TAP_CANCEL)); |
| 1843 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_END)); | 1842 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_GESTURE_END)); |
| 1844 EXPECT_EQ(3U, recorder.events().size()); | 1843 EXPECT_EQ(3U, recorder.events().size()); |
| 1845 root_window()->RemovePreTargetHandler(&recorder); | 1844 root_window()->RemovePreTargetHandler(&recorder); |
| 1846 } | 1845 } |
| 1847 | 1846 |
| 1848 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { | 1847 TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { |
| 1849 EventFilterRecorder recorder; | 1848 EventFilterRecorder recorder; |
| 1850 root_window()->AddPreTargetHandler(&recorder); | 1849 root_window()->AddPreTargetHandler(&recorder); |
| 1851 | 1850 |
| 1852 test::TestWindowDelegate delegate; | 1851 test::TestWindowDelegate delegate; |
| 1853 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1852 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 1854 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); | 1853 &delegate, 1, gfx::Rect(0, 0, 100, 100), root_window())); |
| 1855 | 1854 |
| 1856 gfx::Point position1 = root_window()->bounds().origin(); | 1855 gfx::Point position1 = root_window()->bounds().origin(); |
| 1857 gfx::Point position2 = root_window()->bounds().CenterPoint(); | 1856 gfx::Point position2 = root_window()->bounds().CenterPoint(); |
| 1858 ui::TouchEvent press( | 1857 ui::TouchEvent press( |
| 1859 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); | 1858 ui::ET_TOUCH_PRESSED, position1, 0, ui::EventTimeForNow()); |
| 1860 DispatchEventUsingWindowDispatcher(&press); | 1859 DispatchEventUsingWindowDispatcher(&press); |
| 1861 | 1860 |
| 1862 ui::TouchEvent move( | 1861 ui::TouchEvent move( |
| 1863 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); | 1862 ui::ET_TOUCH_MOVED, position2, 0, ui::EventTimeForNow()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1896 | 1895 |
| 1897 root_window()->RemovePreTargetHandler(&recorder); | 1896 root_window()->RemovePreTargetHandler(&recorder); |
| 1898 } | 1897 } |
| 1899 | 1898 |
| 1900 // Places two windows side by side. Presses down on one window, and starts a | 1899 // Places two windows side by side. Presses down on one window, and starts a |
| 1901 // scroll. Sets capture on the other window and ensures that the "ending" events | 1900 // scroll. Sets capture on the other window and ensures that the "ending" events |
| 1902 // aren't sent to the window which gained capture. | 1901 // aren't sent to the window which gained capture. |
| 1903 TEST_F(WindowEventDispatcherTest, EndingEventDoesntRetarget) { | 1902 TEST_F(WindowEventDispatcherTest, EndingEventDoesntRetarget) { |
| 1904 EventFilterRecorder recorder1; | 1903 EventFilterRecorder recorder1; |
| 1905 EventFilterRecorder recorder2; | 1904 EventFilterRecorder recorder2; |
| 1906 scoped_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); | 1905 std::unique_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); |
| 1907 window1->SetBounds(gfx::Rect(0, 0, 40, 40)); | 1906 window1->SetBounds(gfx::Rect(0, 0, 40, 40)); |
| 1908 | 1907 |
| 1909 scoped_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); | 1908 std::unique_ptr<Window> window2(CreateNormalWindow(2, root_window(), NULL)); |
| 1910 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); | 1909 window2->SetBounds(gfx::Rect(40, 0, 40, 40)); |
| 1911 | 1910 |
| 1912 window1->AddPreTargetHandler(&recorder1); | 1911 window1->AddPreTargetHandler(&recorder1); |
| 1913 window2->AddPreTargetHandler(&recorder2); | 1912 window2->AddPreTargetHandler(&recorder2); |
| 1914 | 1913 |
| 1915 gfx::Point position = window1->bounds().origin(); | 1914 gfx::Point position = window1->bounds().origin(); |
| 1916 ui::TouchEvent press( | 1915 ui::TouchEvent press( |
| 1917 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); | 1916 ui::ET_TOUCH_PRESSED, position, 0, ui::EventTimeForNow()); |
| 1918 DispatchEventUsingWindowDispatcher(&press); | 1917 DispatchEventUsingWindowDispatcher(&press); |
| 1919 | 1918 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 void OnCaptureLost() override { capture_window_.reset(); } | 1953 void OnCaptureLost() override { capture_window_.reset(); } |
| 1955 | 1954 |
| 1956 void OnWindowDestroyed(Window* window) override { | 1955 void OnWindowDestroyed(Window* window) override { |
| 1957 TestWindowDelegate::OnWindowDestroyed(window); | 1956 TestWindowDelegate::OnWindowDestroyed(window); |
| 1958 capture_window_.reset(); | 1957 capture_window_.reset(); |
| 1959 } | 1958 } |
| 1960 | 1959 |
| 1961 aura::Window* capture_window() { return capture_window_.get(); } | 1960 aura::Window* capture_window() { return capture_window_.get(); } |
| 1962 | 1961 |
| 1963 private: | 1962 private: |
| 1964 scoped_ptr<aura::Window> capture_window_; | 1963 std::unique_ptr<aura::Window> capture_window_; |
| 1965 | 1964 |
| 1966 DISALLOW_COPY_AND_ASSIGN(CaptureWindowTracker); | 1965 DISALLOW_COPY_AND_ASSIGN(CaptureWindowTracker); |
| 1967 }; | 1966 }; |
| 1968 | 1967 |
| 1969 } | 1968 } |
| 1970 | 1969 |
| 1971 // Verifies handling loss of capture by the capture window being hidden. | 1970 // Verifies handling loss of capture by the capture window being hidden. |
| 1972 TEST_F(WindowEventDispatcherTest, CaptureWindowHidden) { | 1971 TEST_F(WindowEventDispatcherTest, CaptureWindowHidden) { |
| 1973 CaptureWindowTracker capture_window_tracker; | 1972 CaptureWindowTracker capture_window_tracker; |
| 1974 capture_window_tracker.CreateCaptureWindow(root_window()); | 1973 capture_window_tracker.CreateCaptureWindow(root_window()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2007 ~WindowEventDispatcherTestWithMessageLoop() override {} | 2006 ~WindowEventDispatcherTestWithMessageLoop() override {} |
| 2008 | 2007 |
| 2009 void RunTest() { | 2008 void RunTest() { |
| 2010 // Reset any event the window may have received when bringing up the window | 2009 // Reset any event the window may have received when bringing up the window |
| 2011 // (e.g. mouse-move events if the mouse cursor is over the window). | 2010 // (e.g. mouse-move events if the mouse cursor is over the window). |
| 2012 handler_.Reset(); | 2011 handler_.Reset(); |
| 2013 | 2012 |
| 2014 // Start a nested message-loop, post an event to be dispatched, and then | 2013 // Start a nested message-loop, post an event to be dispatched, and then |
| 2015 // terminate the message-loop. When the message-loop unwinds and gets back, | 2014 // terminate the message-loop. When the message-loop unwinds and gets back, |
| 2016 // the reposted event should not have fired. | 2015 // the reposted event should not have fired. |
| 2017 scoped_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( | 2016 std::unique_ptr<ui::MouseEvent> mouse(new ui::MouseEvent( |
| 2018 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), | 2017 ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), gfx::Point(10, 10), |
| 2019 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); | 2018 ui::EventTimeForNow(), ui::EF_NONE, ui::EF_NONE)); |
| 2020 message_loop()->PostTask( | 2019 message_loop()->PostTask( |
| 2021 FROM_HERE, | 2020 FROM_HERE, |
| 2022 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, | 2021 base::Bind(&WindowEventDispatcherTestWithMessageLoop::RepostEventHelper, |
| 2023 host()->dispatcher(), | 2022 host()->dispatcher(), |
| 2024 base::Passed(&mouse))); | 2023 base::Passed(&mouse))); |
| 2025 message_loop()->PostTask(FROM_HERE, message_loop()->QuitWhenIdleClosure()); | 2024 message_loop()->PostTask(FROM_HERE, message_loop()->QuitWhenIdleClosure()); |
| 2026 | 2025 |
| 2027 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); | 2026 base::MessageLoop::ScopedNestableTaskAllower allow(message_loop()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2045 } | 2044 } |
| 2046 | 2045 |
| 2047 void TearDown() override { | 2046 void TearDown() override { |
| 2048 window_.reset(); | 2047 window_.reset(); |
| 2049 WindowEventDispatcherTest::TearDown(); | 2048 WindowEventDispatcherTest::TearDown(); |
| 2050 } | 2049 } |
| 2051 | 2050 |
| 2052 private: | 2051 private: |
| 2053 // Used to avoid a copying |event| when binding to a closure. | 2052 // Used to avoid a copying |event| when binding to a closure. |
| 2054 static void RepostEventHelper(WindowEventDispatcher* dispatcher, | 2053 static void RepostEventHelper(WindowEventDispatcher* dispatcher, |
| 2055 scoped_ptr<ui::MouseEvent> event) { | 2054 std::unique_ptr<ui::MouseEvent> event) { |
| 2056 dispatcher->RepostEvent(event.get()); | 2055 dispatcher->RepostEvent(event.get()); |
| 2057 } | 2056 } |
| 2058 | 2057 |
| 2059 scoped_ptr<Window> window_; | 2058 std::unique_ptr<Window> window_; |
| 2060 ExitMessageLoopOnMousePress handler_; | 2059 ExitMessageLoopOnMousePress handler_; |
| 2061 | 2060 |
| 2062 DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcherTestWithMessageLoop); | 2061 DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcherTestWithMessageLoop); |
| 2063 }; | 2062 }; |
| 2064 | 2063 |
| 2065 TEST_F(WindowEventDispatcherTestWithMessageLoop, EventRepostedInNonNestedLoop) { | 2064 TEST_F(WindowEventDispatcherTestWithMessageLoop, EventRepostedInNonNestedLoop) { |
| 2066 CHECK(!message_loop()->is_running()); | 2065 CHECK(!message_loop()->is_running()); |
| 2067 // Perform the test in a callback, so that it runs after the message-loop | 2066 // Perform the test in a callback, so that it runs after the message-loop |
| 2068 // starts. | 2067 // starts. |
| 2069 message_loop()->PostTask( | 2068 message_loop()->PostTask( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2084 | 2083 |
| 2085 protected: | 2084 protected: |
| 2086 void SetUp() override { | 2085 void SetUp() override { |
| 2087 WindowEventDispatcherTest::SetUp(); | 2086 WindowEventDispatcherTest::SetUp(); |
| 2088 test_screen()->SetDeviceScaleFactor(2.f); | 2087 test_screen()->SetDeviceScaleFactor(2.f); |
| 2089 } | 2088 } |
| 2090 }; | 2089 }; |
| 2091 | 2090 |
| 2092 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { | 2091 TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { |
| 2093 test::TestWindowDelegate delegate; | 2092 test::TestWindowDelegate delegate; |
| 2094 scoped_ptr<aura::Window> child(test::CreateTestWindowWithDelegate(&delegate, | 2093 std::unique_ptr<aura::Window> child(test::CreateTestWindowWithDelegate( |
| 2095 1234, gfx::Rect(20, 20, 100, 100), root_window())); | 2094 &delegate, 1234, gfx::Rect(20, 20, 100, 100), root_window())); |
| 2096 child->Show(); | 2095 child->Show(); |
| 2097 | 2096 |
| 2098 ui::test::TestEventHandler handler_child; | 2097 ui::test::TestEventHandler handler_child; |
| 2099 ui::test::TestEventHandler handler_root; | 2098 ui::test::TestEventHandler handler_root; |
| 2100 root_window()->AddPreTargetHandler(&handler_root); | 2099 root_window()->AddPreTargetHandler(&handler_root); |
| 2101 child->AddPreTargetHandler(&handler_child); | 2100 child->AddPreTargetHandler(&handler_child); |
| 2102 | 2101 |
| 2103 { | 2102 { |
| 2104 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(30, 30), | 2103 ui::MouseEvent move(ui::ET_MOUSE_MOVED, gfx::Point(30, 30), |
| 2105 gfx::Point(30, 30), ui::EventTimeForNow(), ui::EF_NONE, | 2104 gfx::Point(30, 30), ui::EventTimeForNow(), ui::EF_NONE, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2123 | 2122 |
| 2124 child->RemovePreTargetHandler(&handler_child); | 2123 child->RemovePreTargetHandler(&handler_child); |
| 2125 root_window()->RemovePreTargetHandler(&handler_root); | 2124 root_window()->RemovePreTargetHandler(&handler_root); |
| 2126 } | 2125 } |
| 2127 | 2126 |
| 2128 TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) { | 2127 TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) { |
| 2129 EventFilterRecorder recorder; | 2128 EventFilterRecorder recorder; |
| 2130 root_window()->AddPreTargetHandler(&recorder); | 2129 root_window()->AddPreTargetHandler(&recorder); |
| 2131 test::TestWindowDelegate delegate; | 2130 test::TestWindowDelegate delegate; |
| 2132 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); | 2131 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); |
| 2133 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2132 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 2134 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 2133 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 2135 window->AddPreTargetHandler(&handler); | 2134 window->AddPreTargetHandler(&handler); |
| 2136 | 2135 |
| 2137 ui::test::EventGenerator generator(root_window()); | 2136 ui::test::EventGenerator generator(root_window()); |
| 2138 generator.GestureScrollSequence( | 2137 generator.GestureScrollSequence( |
| 2139 gfx::Point(120, 120), gfx::Point(20, 120), | 2138 gfx::Point(120, 120), gfx::Point(20, 120), |
| 2140 base::TimeDelta::FromMilliseconds(100), 25); | 2139 base::TimeDelta::FromMilliseconds(100), 25); |
| 2141 | 2140 |
| 2142 // |handler| will have reset |filter| and started holding the touch-move | 2141 // |handler| will have reset |filter| and started holding the touch-move |
| 2143 // events when scrolling started. At the end of the scroll (i.e. upon | 2142 // events when scrolling started. At the end of the scroll (i.e. upon |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2190 gfx::Point mouse_move_location_; | 2189 gfx::Point mouse_move_location_; |
| 2191 | 2190 |
| 2192 DISALLOW_COPY_AND_ASSIGN(TriggerNestedLoopOnRightMousePress); | 2191 DISALLOW_COPY_AND_ASSIGN(TriggerNestedLoopOnRightMousePress); |
| 2193 }; | 2192 }; |
| 2194 | 2193 |
| 2195 // Tests that if dispatching a 'held' event triggers a nested message loop, then | 2194 // Tests that if dispatching a 'held' event triggers a nested message loop, then |
| 2196 // the events that are dispatched from the nested message loop are transformed | 2195 // the events that are dispatched from the nested message loop are transformed |
| 2197 // correctly. | 2196 // correctly. |
| 2198 TEST_F(WindowEventDispatcherTestInHighDPI, | 2197 TEST_F(WindowEventDispatcherTestInHighDPI, |
| 2199 EventsTransformedInRepostedEventTriggeredNestedLoop) { | 2198 EventsTransformedInRepostedEventTriggeredNestedLoop) { |
| 2200 scoped_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); | 2199 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); |
| 2201 // Make sure the window is visible. | 2200 // Make sure the window is visible. |
| 2202 RunAllPendingInMessageLoop(); | 2201 RunAllPendingInMessageLoop(); |
| 2203 | 2202 |
| 2204 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(80, 80), | 2203 ui::MouseEvent mouse_move(ui::ET_MOUSE_MOVED, gfx::Point(80, 80), |
| 2205 gfx::Point(80, 80), ui::EventTimeForNow(), | 2204 gfx::Point(80, 80), ui::EventTimeForNow(), |
| 2206 ui::EF_NONE, ui::EF_NONE); | 2205 ui::EF_NONE, ui::EF_NONE); |
| 2207 const base::Closure callback_on_right_click = base::Bind( | 2206 const base::Closure callback_on_right_click = base::Bind( |
| 2208 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), | 2207 base::IgnoreResult(&WindowEventDispatcherTestInHighDPI::DispatchEvent), |
| 2209 base::Unretained(this), base::Unretained(&mouse_move)); | 2208 base::Unretained(this), base::Unretained(&mouse_move)); |
| 2210 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); | 2209 TriggerNestedLoopOnRightMousePress handler(callback_on_right_click); |
| 2211 window->AddPreTargetHandler(&handler); | 2210 window->AddPreTargetHandler(&handler); |
| 2212 | 2211 |
| 2213 scoped_ptr<ui::MouseEvent> mouse( | 2212 std::unique_ptr<ui::MouseEvent> mouse( |
| 2214 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), | 2213 new ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(10, 10), |
| 2215 gfx::Point(10, 10), ui::EventTimeForNow(), | 2214 gfx::Point(10, 10), ui::EventTimeForNow(), |
| 2216 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); | 2215 ui::EF_RIGHT_MOUSE_BUTTON, ui::EF_RIGHT_MOUSE_BUTTON)); |
| 2217 host()->dispatcher()->RepostEvent(mouse.get()); | 2216 host()->dispatcher()->RepostEvent(mouse.get()); |
| 2218 EXPECT_EQ(0, handler.num_mouse_events()); | 2217 EXPECT_EQ(0, handler.num_mouse_events()); |
| 2219 | 2218 |
| 2220 base::RunLoop run_loop; | 2219 base::RunLoop run_loop; |
| 2221 run_loop.RunUntilIdle(); | 2220 run_loop.RunUntilIdle(); |
| 2222 // The window should receive the mouse-press and the mouse-move events. | 2221 // The window should receive the mouse-press and the mouse-move events. |
| 2223 EXPECT_EQ(2, handler.num_mouse_events()); | 2222 EXPECT_EQ(2, handler.num_mouse_events()); |
| 2224 // The mouse-move event location should be transformed because of the DSF | 2223 // The mouse-move event location should be transformed because of the DSF |
| 2225 // before it reaches the window. | 2224 // before it reaches the window. |
| 2226 EXPECT_EQ(gfx::Point(40, 40).ToString(), | 2225 EXPECT_EQ(gfx::Point(40, 40).ToString(), |
| 2227 handler.mouse_move_location().ToString()); | 2226 handler.mouse_move_location().ToString()); |
| 2228 EXPECT_EQ(gfx::Point(40, 40).ToString(), | 2227 EXPECT_EQ(gfx::Point(40, 40).ToString(), |
| 2229 Env::GetInstance()->last_mouse_location().ToString()); | 2228 Env::GetInstance()->last_mouse_location().ToString()); |
| 2230 window->RemovePreTargetHandler(&handler); | 2229 window->RemovePreTargetHandler(&handler); |
| 2231 } | 2230 } |
| 2232 | 2231 |
| 2233 class SelfDestructDelegate : public test::TestWindowDelegate { | 2232 class SelfDestructDelegate : public test::TestWindowDelegate { |
| 2234 public: | 2233 public: |
| 2235 SelfDestructDelegate() {} | 2234 SelfDestructDelegate() {} |
| 2236 ~SelfDestructDelegate() override {} | 2235 ~SelfDestructDelegate() override {} |
| 2237 | 2236 |
| 2238 void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); } | 2237 void OnMouseEvent(ui::MouseEvent* event) override { window_.reset(); } |
| 2239 | 2238 |
| 2240 void set_window(scoped_ptr<aura::Window> window) { | 2239 void set_window(std::unique_ptr<aura::Window> window) { |
| 2241 window_ = std::move(window); | 2240 window_ = std::move(window); |
| 2242 } | 2241 } |
| 2243 bool has_window() const { return !!window_.get(); } | 2242 bool has_window() const { return !!window_.get(); } |
| 2244 | 2243 |
| 2245 private: | 2244 private: |
| 2246 scoped_ptr<aura::Window> window_; | 2245 std::unique_ptr<aura::Window> window_; |
| 2247 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); | 2246 DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); |
| 2248 }; | 2247 }; |
| 2249 | 2248 |
| 2250 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { | 2249 TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { |
| 2251 ui::test::EventGenerator generator(root_window()); | 2250 ui::test::EventGenerator generator(root_window()); |
| 2252 generator.MoveMouseTo(10, 10); | 2251 generator.MoveMouseTo(10, 10); |
| 2253 EXPECT_EQ("10,10", | 2252 EXPECT_EQ("10,10", |
| 2254 Env::GetInstance()->last_mouse_location().ToString()); | 2253 Env::GetInstance()->last_mouse_location().ToString()); |
| 2255 | 2254 |
| 2256 // Synthesized event should not update the mouse location. | 2255 // Synthesized event should not update the mouse location. |
| 2257 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), | 2256 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::Point(), gfx::Point(), |
| 2258 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); | 2257 ui::EventTimeForNow(), ui::EF_IS_SYNTHESIZED, 0); |
| 2259 generator.Dispatch(&mouseev); | 2258 generator.Dispatch(&mouseev); |
| 2260 EXPECT_EQ("10,10", | 2259 EXPECT_EQ("10,10", |
| 2261 Env::GetInstance()->last_mouse_location().ToString()); | 2260 Env::GetInstance()->last_mouse_location().ToString()); |
| 2262 | 2261 |
| 2263 generator.MoveMouseTo(0, 0); | 2262 generator.MoveMouseTo(0, 0); |
| 2264 EXPECT_EQ("0,0", | 2263 EXPECT_EQ("0,0", |
| 2265 Env::GetInstance()->last_mouse_location().ToString()); | 2264 Env::GetInstance()->last_mouse_location().ToString()); |
| 2266 | 2265 |
| 2267 // Make sure the location gets updated when a syntheiszed enter | 2266 // Make sure the location gets updated when a syntheiszed enter |
| 2268 // event destroyed the window. | 2267 // event destroyed the window. |
| 2269 SelfDestructDelegate delegate; | 2268 SelfDestructDelegate delegate; |
| 2270 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2269 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 2271 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); | 2270 &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); |
| 2272 delegate.set_window(std::move(window)); | 2271 delegate.set_window(std::move(window)); |
| 2273 EXPECT_TRUE(delegate.has_window()); | 2272 EXPECT_TRUE(delegate.has_window()); |
| 2274 | 2273 |
| 2275 generator.MoveMouseTo(100, 100); | 2274 generator.MoveMouseTo(100, 100); |
| 2276 EXPECT_FALSE(delegate.has_window()); | 2275 EXPECT_FALSE(delegate.has_window()); |
| 2277 EXPECT_EQ("100,100", | 2276 EXPECT_EQ("100,100", |
| 2278 Env::GetInstance()->last_mouse_location().ToString()); | 2277 Env::GetInstance()->last_mouse_location().ToString()); |
| 2279 } | 2278 } |
| 2280 | 2279 |
| 2281 // Tests that the window which has capture can get destroyed as a result of | 2280 // Tests that the window which has capture can get destroyed as a result of |
| 2282 // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in | 2281 // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in |
| 2283 // WindowEventDispatcher::UpdateCapture without causing a "use after free". | 2282 // WindowEventDispatcher::UpdateCapture without causing a "use after free". |
| 2284 TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { | 2283 TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { |
| 2285 SelfDestructDelegate delegate; | 2284 SelfDestructDelegate delegate; |
| 2286 scoped_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( | 2285 std::unique_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( |
| 2287 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); | 2286 &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2288 Window* window_first_raw = window_first.get(); | 2287 Window* window_first_raw = window_first.get(); |
| 2289 window_first->Show(); | 2288 window_first->Show(); |
| 2290 window_first->SetCapture(); | 2289 window_first->SetCapture(); |
| 2291 delegate.set_window(std::move(window_first)); | 2290 delegate.set_window(std::move(window_first)); |
| 2292 EXPECT_TRUE(delegate.has_window()); | 2291 EXPECT_TRUE(delegate.has_window()); |
| 2293 | 2292 |
| 2294 scoped_ptr<aura::Window> window_second( | 2293 std::unique_ptr<aura::Window> window_second( |
| 2295 test::CreateTestWindowWithId(2, root_window())); | 2294 test::CreateTestWindowWithId(2, root_window())); |
| 2296 window_second->Show(); | 2295 window_second->Show(); |
| 2297 | 2296 |
| 2298 client::CaptureDelegate* capture_delegate = host()->dispatcher(); | 2297 client::CaptureDelegate* capture_delegate = host()->dispatcher(); |
| 2299 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); | 2298 capture_delegate->UpdateCapture(window_first_raw, window_second.get()); |
| 2300 EXPECT_FALSE(delegate.has_window()); | 2299 EXPECT_FALSE(delegate.has_window()); |
| 2301 } | 2300 } |
| 2302 | 2301 |
| 2303 class StaticFocusClient : public client::FocusClient { | 2302 class StaticFocusClient : public client::FocusClient { |
| 2304 public: | 2303 public: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2316 | 2315 |
| 2317 Window* focused_; | 2316 Window* focused_; |
| 2318 | 2317 |
| 2319 DISALLOW_COPY_AND_ASSIGN(StaticFocusClient); | 2318 DISALLOW_COPY_AND_ASSIGN(StaticFocusClient); |
| 2320 }; | 2319 }; |
| 2321 | 2320 |
| 2322 // Tests that host-cancel-mode event can be dispatched to a dispatcher safely | 2321 // Tests that host-cancel-mode event can be dispatched to a dispatcher safely |
| 2323 // when the focused window does not live in the dispatcher's tree. | 2322 // when the focused window does not live in the dispatcher's tree. |
| 2324 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { | 2323 TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { |
| 2325 test::TestWindowDelegate delegate; | 2324 test::TestWindowDelegate delegate; |
| 2326 scoped_ptr<Window> focused(CreateTestWindowWithDelegate(&delegate, 123, | 2325 std::unique_ptr<Window> focused(CreateTestWindowWithDelegate( |
| 2327 gfx::Rect(20, 30, 100, 50), NULL)); | 2326 &delegate, 123, gfx::Rect(20, 30, 100, 50), NULL)); |
| 2328 StaticFocusClient focus_client(focused.get()); | 2327 StaticFocusClient focus_client(focused.get()); |
| 2329 client::SetFocusClient(root_window(), &focus_client); | 2328 client::SetFocusClient(root_window(), &focus_client); |
| 2330 EXPECT_FALSE(root_window()->Contains(focused.get())); | 2329 EXPECT_FALSE(root_window()->Contains(focused.get())); |
| 2331 EXPECT_EQ(focused.get(), | 2330 EXPECT_EQ(focused.get(), |
| 2332 client::GetFocusClient(root_window())->GetFocusedWindow()); | 2331 client::GetFocusClient(root_window())->GetFocusedWindow()); |
| 2333 host()->dispatcher()->DispatchCancelModeEvent(); | 2332 host()->dispatcher()->DispatchCancelModeEvent(); |
| 2334 EXPECT_EQ(focused.get(), | 2333 EXPECT_EQ(focused.get(), |
| 2335 client::GetFocusClient(root_window())->GetFocusedWindow()); | 2334 client::GetFocusClient(root_window())->GetFocusedWindow()); |
| 2336 } | 2335 } |
| 2337 | 2336 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2388 Window* window_to_move_; | 2387 Window* window_to_move_; |
| 2389 Window* root_window_to_move_to_; | 2388 Window* root_window_to_move_to_; |
| 2390 | 2389 |
| 2391 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler); | 2390 DISALLOW_COPY_AND_ASSIGN(MoveWindowHandler); |
| 2392 }; | 2391 }; |
| 2393 | 2392 |
| 2394 // Tests that nested event dispatch works correctly if the target of the older | 2393 // Tests that nested event dispatch works correctly if the target of the older |
| 2395 // event being dispatched is moved to a different dispatcher in response to an | 2394 // event being dispatched is moved to a different dispatcher in response to an |
| 2396 // event in the inner loop. | 2395 // event in the inner loop. |
| 2397 TEST_F(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { | 2396 TEST_F(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { |
| 2398 scoped_ptr<WindowTreeHost> second_host( | 2397 std::unique_ptr<WindowTreeHost> second_host( |
| 2399 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); | 2398 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); |
| 2400 second_host->InitHost(); | 2399 second_host->InitHost(); |
| 2401 Window* second_root = second_host->window(); | 2400 Window* second_root = second_host->window(); |
| 2402 | 2401 |
| 2403 // Create two windows parented to |root_window()|. | 2402 // Create two windows parented to |root_window()|. |
| 2404 test::TestWindowDelegate delegate; | 2403 test::TestWindowDelegate delegate; |
| 2405 scoped_ptr<Window> first(CreateTestWindowWithDelegate(&delegate, 123, | 2404 std::unique_ptr<Window> first(CreateTestWindowWithDelegate( |
| 2406 gfx::Rect(20, 10, 10, 20), root_window())); | 2405 &delegate, 123, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2407 scoped_ptr<Window> second(CreateTestWindowWithDelegate(&delegate, 234, | 2406 std::unique_ptr<Window> second(CreateTestWindowWithDelegate( |
| 2408 gfx::Rect(40, 10, 50, 20), root_window())); | 2407 &delegate, 234, gfx::Rect(40, 10, 50, 20), root_window())); |
| 2409 | 2408 |
| 2410 // Setup a handler on |first| so that it dispatches an event to |second| when | 2409 // Setup a handler on |first| so that it dispatches an event to |second| when |
| 2411 // |first| receives an event. | 2410 // |first| receives an event. |
| 2412 DispatchEventHandler dispatch_event(second.get()); | 2411 DispatchEventHandler dispatch_event(second.get()); |
| 2413 first->AddPreTargetHandler(&dispatch_event); | 2412 first->AddPreTargetHandler(&dispatch_event); |
| 2414 | 2413 |
| 2415 // Setup a handler on |second| so that it moves |first| into |second_root| | 2414 // Setup a handler on |second| so that it moves |first| into |second_root| |
| 2416 // when |second| receives an event. | 2415 // when |second| receives an event. |
| 2417 MoveWindowHandler move_window(first.get(), second_root); | 2416 MoveWindowHandler move_window(first.get(), second_root); |
| 2418 second->AddPreTargetHandler(&move_window); | 2417 second->AddPreTargetHandler(&move_window); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2446 private: | 2445 private: |
| 2447 // InputStateLookup: | 2446 // InputStateLookup: |
| 2448 bool IsMouseButtonDown() const override { return true; } | 2447 bool IsMouseButtonDown() const override { return true; } |
| 2449 | 2448 |
| 2450 DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup); | 2449 DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup); |
| 2451 }; | 2450 }; |
| 2452 | 2451 |
| 2453 TEST_F(WindowEventDispatcherTest, | 2452 TEST_F(WindowEventDispatcherTest, |
| 2454 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { | 2453 CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { |
| 2455 test::EventCountDelegate delegate; | 2454 test::EventCountDelegate delegate; |
| 2456 scoped_ptr<Window> window(CreateTestWindowWithDelegate(&delegate, 123, | 2455 std::unique_ptr<Window> window(CreateTestWindowWithDelegate( |
| 2457 gfx::Rect(20, 10, 10, 20), root_window())); | 2456 &delegate, 123, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2458 window->Show(); | 2457 window->Show(); |
| 2459 | 2458 |
| 2460 scoped_ptr<WindowTreeHost> second_host( | 2459 std::unique_ptr<WindowTreeHost> second_host( |
| 2461 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); | 2460 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); |
| 2462 second_host->InitHost(); | 2461 second_host->InitHost(); |
| 2463 WindowEventDispatcher* second_dispatcher = second_host->dispatcher(); | 2462 WindowEventDispatcher* second_dispatcher = second_host->dispatcher(); |
| 2464 | 2463 |
| 2465 // Install an InputStateLookup on the Env that always claims that a | 2464 // Install an InputStateLookup on the Env that always claims that a |
| 2466 // mouse-button is down. | 2465 // mouse-button is down. |
| 2467 test::EnvTestHelper(Env::GetInstance()).SetInputStateLookup( | 2466 test::EnvTestHelper(Env::GetInstance()) |
| 2468 scoped_ptr<InputStateLookup>(new AlwaysMouseDownInputStateLookup())); | 2467 .SetInputStateLookup(std::unique_ptr<InputStateLookup>( |
| 2468 new AlwaysMouseDownInputStateLookup())); |
| 2469 | 2469 |
| 2470 window->SetCapture(); | 2470 window->SetCapture(); |
| 2471 | 2471 |
| 2472 // Because the mouse button is down, setting the capture on |window| will set | 2472 // Because the mouse button is down, setting the capture on |window| will set |
| 2473 // it as the mouse-move handler for |root_window()|. | 2473 // it as the mouse-move handler for |root_window()|. |
| 2474 EXPECT_EQ(window.get(), host()->dispatcher()->mouse_moved_handler()); | 2474 EXPECT_EQ(window.get(), host()->dispatcher()->mouse_moved_handler()); |
| 2475 | 2475 |
| 2476 // This does not set |window| as the mouse-move handler for the second | 2476 // This does not set |window| as the mouse-move handler for the second |
| 2477 // dispatcher. | 2477 // dispatcher. |
| 2478 EXPECT_EQ(NULL, second_dispatcher->mouse_moved_handler()); | 2478 EXPECT_EQ(NULL, second_dispatcher->mouse_moved_handler()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2489 | 2489 |
| 2490 // Notify both hosts that the cursor is now hidden. This should send a single | 2490 // Notify both hosts that the cursor is now hidden. This should send a single |
| 2491 // mouse-exit event to |window|. | 2491 // mouse-exit event to |window|. |
| 2492 host()->OnCursorVisibilityChanged(false); | 2492 host()->OnCursorVisibilityChanged(false); |
| 2493 second_host->OnCursorVisibilityChanged(false); | 2493 second_host->OnCursorVisibilityChanged(false); |
| 2494 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); | 2494 EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); |
| 2495 } | 2495 } |
| 2496 | 2496 |
| 2497 TEST_F(WindowEventDispatcherTest, | 2497 TEST_F(WindowEventDispatcherTest, |
| 2498 RedirectedEventToDifferentDispatcherLocation) { | 2498 RedirectedEventToDifferentDispatcherLocation) { |
| 2499 scoped_ptr<WindowTreeHost> second_host( | 2499 std::unique_ptr<WindowTreeHost> second_host( |
| 2500 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); | 2500 WindowTreeHost::Create(gfx::Rect(20, 30, 100, 50))); |
| 2501 second_host->InitHost(); | 2501 second_host->InitHost(); |
| 2502 client::SetCaptureClient(second_host->window(), | 2502 client::SetCaptureClient(second_host->window(), |
| 2503 client::GetCaptureClient(root_window())); | 2503 client::GetCaptureClient(root_window())); |
| 2504 | 2504 |
| 2505 test::EventCountDelegate delegate; | 2505 test::EventCountDelegate delegate; |
| 2506 scoped_ptr<Window> window_first(CreateTestWindowWithDelegate(&delegate, 123, | 2506 std::unique_ptr<Window> window_first(CreateTestWindowWithDelegate( |
| 2507 gfx::Rect(20, 10, 10, 20), root_window())); | 2507 &delegate, 123, gfx::Rect(20, 10, 10, 20), root_window())); |
| 2508 window_first->Show(); | 2508 window_first->Show(); |
| 2509 | 2509 |
| 2510 scoped_ptr<Window> window_second(CreateTestWindowWithDelegate(&delegate, 12, | 2510 std::unique_ptr<Window> window_second(CreateTestWindowWithDelegate( |
| 2511 gfx::Rect(10, 10, 20, 30), second_host->window())); | 2511 &delegate, 12, gfx::Rect(10, 10, 20, 30), second_host->window())); |
| 2512 window_second->Show(); | 2512 window_second->Show(); |
| 2513 | 2513 |
| 2514 window_second->SetCapture(); | 2514 window_second->SetCapture(); |
| 2515 EXPECT_EQ(window_second.get(), | 2515 EXPECT_EQ(window_second.get(), |
| 2516 client::GetCaptureWindow(root_window())); | 2516 client::GetCaptureWindow(root_window())); |
| 2517 | 2517 |
| 2518 // Send an event to the first host. Make sure it goes to |window_second| in | 2518 // Send an event to the first host. Make sure it goes to |window_second| in |
| 2519 // |second_host| instead (since it has capture). | 2519 // |second_host| instead (since it has capture). |
| 2520 EventFilterRecorder recorder_first; | 2520 EventFilterRecorder recorder_first; |
| 2521 window_first->AddPreTargetHandler(&recorder_first); | 2521 window_first->AddPreTargetHandler(&recorder_first); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2561 // co-ordinates in the right co-ordinate space. | 2561 // co-ordinates in the right co-ordinate space. |
| 2562 TEST_F(WindowEventDispatcherTest, GestureEventCoordinates) { | 2562 TEST_F(WindowEventDispatcherTest, GestureEventCoordinates) { |
| 2563 const float kX = 67.3f; | 2563 const float kX = 67.3f; |
| 2564 const float kY = 97.8f; | 2564 const float kY = 97.8f; |
| 2565 | 2565 |
| 2566 const int kWindowOffset = 50; | 2566 const int kWindowOffset = 50; |
| 2567 EventFilterRecorder recorder; | 2567 EventFilterRecorder recorder; |
| 2568 root_window()->AddPreTargetHandler(&recorder); | 2568 root_window()->AddPreTargetHandler(&recorder); |
| 2569 AsyncWindowDelegate delegate(host()->dispatcher()); | 2569 AsyncWindowDelegate delegate(host()->dispatcher()); |
| 2570 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); | 2570 HoldPointerOnScrollHandler handler(host()->dispatcher(), &recorder); |
| 2571 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2571 std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
| 2572 &delegate, | 2572 &delegate, 1, gfx::Rect(kWindowOffset, kWindowOffset, 100, 100), |
| 2573 1, | |
| 2574 gfx::Rect(kWindowOffset, kWindowOffset, 100, 100), | |
| 2575 root_window())); | 2573 root_window())); |
| 2576 window->AddPreTargetHandler(&handler); | 2574 window->AddPreTargetHandler(&handler); |
| 2577 | 2575 |
| 2578 delegate.set_window(window.get()); | 2576 delegate.set_window(window.get()); |
| 2579 | 2577 |
| 2580 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(), 0, | 2578 ui::TouchEvent touch_pressed_event(ui::ET_TOUCH_PRESSED, gfx::Point(), 0, |
| 2581 ui::EventTimeForNow()); | 2579 ui::EventTimeForNow()); |
| 2582 touch_pressed_event.set_location_f(gfx::PointF(kX, kY)); | 2580 touch_pressed_event.set_location_f(gfx::PointF(kX, kY)); |
| 2583 touch_pressed_event.set_root_location_f(gfx::PointF(kX, kY)); | 2581 touch_pressed_event.set_root_location_f(gfx::PointF(kX, kY)); |
| 2584 | 2582 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2640 root_window()->RemovePreTargetHandler(&recorder); | 2638 root_window()->RemovePreTargetHandler(&recorder); |
| 2641 } | 2639 } |
| 2642 | 2640 |
| 2643 // OnCursorMovedToRootLocation() is sometimes called instead of | 2641 // OnCursorMovedToRootLocation() is sometimes called instead of |
| 2644 // WindowTreeHost::MoveCursorTo() when the cursor did not move but the | 2642 // WindowTreeHost::MoveCursorTo() when the cursor did not move but the |
| 2645 // cursor's position in root coordinates has changed (e.g. when the displays's | 2643 // cursor's position in root coordinates has changed (e.g. when the displays's |
| 2646 // scale factor changed). Test that hover effects are properly updated. | 2644 // scale factor changed). Test that hover effects are properly updated. |
| 2647 TEST_F(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { | 2645 TEST_F(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { |
| 2648 WindowEventDispatcher* dispatcher = host()->dispatcher(); | 2646 WindowEventDispatcher* dispatcher = host()->dispatcher(); |
| 2649 | 2647 |
| 2650 scoped_ptr<Window> w(CreateNormalWindow(1, root_window(), nullptr)); | 2648 std::unique_ptr<Window> w(CreateNormalWindow(1, root_window(), nullptr)); |
| 2651 w->SetBounds(gfx::Rect(20, 20, 20, 20)); | 2649 w->SetBounds(gfx::Rect(20, 20, 20, 20)); |
| 2652 w->Show(); | 2650 w->Show(); |
| 2653 | 2651 |
| 2654 // Move the cursor off of |w|. | 2652 // Move the cursor off of |w|. |
| 2655 dispatcher->OnCursorMovedToRootLocation(gfx::Point(100, 100)); | 2653 dispatcher->OnCursorMovedToRootLocation(gfx::Point(100, 100)); |
| 2656 | 2654 |
| 2657 EventFilterRecorder recorder; | 2655 EventFilterRecorder recorder; |
| 2658 w->AddPreTargetHandler(&recorder); | 2656 w->AddPreTargetHandler(&recorder); |
| 2659 dispatcher->OnCursorMovedToRootLocation(gfx::Point(22, 22)); | 2657 dispatcher->OnCursorMovedToRootLocation(gfx::Point(22, 22)); |
| 2660 RunAllPendingInMessageLoop(); | 2658 RunAllPendingInMessageLoop(); |
| 2661 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_ENTERED)); | 2659 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_ENTERED)); |
| 2662 recorder.Reset(); | 2660 recorder.Reset(); |
| 2663 | 2661 |
| 2664 // The cursor should not be over |w| after changing the device scale factor to | 2662 // The cursor should not be over |w| after changing the device scale factor to |
| 2665 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2663 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
| 2666 test_screen()->SetDeviceScaleFactor(2.f); | 2664 test_screen()->SetDeviceScaleFactor(2.f); |
| 2667 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2665 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
| 2668 RunAllPendingInMessageLoop(); | 2666 RunAllPendingInMessageLoop(); |
| 2669 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2667 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
| 2670 | 2668 |
| 2671 w->RemovePreTargetHandler(&recorder); | 2669 w->RemovePreTargetHandler(&recorder); |
| 2672 } | 2670 } |
| 2673 | 2671 |
| 2674 } // namespace aura | 2672 } // namespace aura |
| OLD | NEW |