diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-07-31 15:50:41 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:35:23 +0000 |
commit | 7b2ffa587235a47d4094787d72f38102089f402a (patch) | |
tree | 30e82af9cbab08a7fa028bb18f4f2987a3f74dfa /chromium/ui/aura/window_event_dispatcher_unittest.cc | |
parent | d94af01c90575348c4e81a418257f254b6f8d225 (diff) | |
download | qtwebengine-chromium-7b2ffa587235a47d4094787d72f38102089f402a.tar.gz |
BASELINE: Update Chromium to 76.0.3809.94
Change-Id: I321c3f5f929c105aec0f98c5091ef6108822e647
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/ui/aura/window_event_dispatcher_unittest.cc')
-rw-r--r-- | chromium/ui/aura/window_event_dispatcher_unittest.cc | 489 |
1 files changed, 62 insertions, 427 deletions
diff --git a/chromium/ui/aura/window_event_dispatcher_unittest.cc b/chromium/ui/aura/window_event_dispatcher_unittest.cc index 8701b964e7d..a3ee340abf0 100644 --- a/chromium/ui/aura/window_event_dispatcher_unittest.cc +++ b/chromium/ui/aura/window_event_dispatcher_unittest.cc @@ -18,13 +18,11 @@ #include "base/test/metrics/histogram_tester.h" #include "base/threading/thread_task_runner_handle.h" #include "build/build_config.h" -#include "services/ws/public/mojom/window_tree_constants.mojom.h" #include "testing/gtest/include/gtest/gtest.h" #include "ui/aura/client/capture_client.h" #include "ui/aura/client/event_client.h" #include "ui/aura/client/focus_client.h" #include "ui/aura/env.h" -#include "ui/aura/mus/window_tree_client.h" #include "ui/aura/test/aura_test_base.h" #include "ui/aura/test/env_test_helper.h" #include "ui/aura/test/test_cursor_client.h" @@ -116,9 +114,9 @@ bool IsFocusedWindow(aura::Window* window) { } // namespace -using WindowEventDispatcherTest = test::AuraTestBaseWithType; +using WindowEventDispatcherTest = test::AuraTestBase; -TEST_P(WindowEventDispatcherTest, OnHostMouseEvent) { +TEST_F(WindowEventDispatcherTest, OnHostMouseEvent) { // Create two non-overlapping windows so we don't have to worry about which // is on top. std::unique_ptr<NonClientDelegate> delegate1(new NonClientDelegate()); @@ -139,11 +137,8 @@ TEST_P(WindowEventDispatcherTest, OnHostMouseEvent) { ui::EF_LEFT_MOUSE_BUTTON); DispatchEventUsingWindowDispatcher(&event1); - // Event was tested for non-client area for the target window. The expected - // value is 2 when mode is MUS, since ClientSideWindowMoveHandler also invokes - // it. - EXPECT_EQ((Env::GetInstance()->mode() == Env::Mode::MUS) ? 2 : 1, - delegate1->non_client_count()); + // Event was tested for non-client area for the target window. + EXPECT_EQ(1, delegate1->non_client_count()); EXPECT_EQ(0, delegate2->non_client_count()); // The non-client component test was in local coordinates. EXPECT_EQ(gfx::Point(1, 1), delegate1->non_client_location()); @@ -156,7 +151,7 @@ TEST_P(WindowEventDispatcherTest, OnHostMouseEvent) { EXPECT_TRUE(delegate1->mouse_event_flags() & ui::EF_IS_NON_CLIENT); } -TEST_P(WindowEventDispatcherTest, RepostEvent) { +TEST_F(WindowEventDispatcherTest, RepostEvent) { // Test RepostEvent in RootWindow. It only works for Mouse Press and touch // press. EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); @@ -178,7 +173,7 @@ TEST_P(WindowEventDispatcherTest, RepostEvent) { // Check that we correctly track whether any touch devices are down in response // to touch press and release events with two WindowTreeHost. -TEST_P(WindowEventDispatcherTest, TouchDownState) { +TEST_F(WindowEventDispatcherTest, TouchDownState) { std::unique_ptr<WindowTreeHost> second_host = WindowTreeHost::Create( ui::PlatformWindowInitProperties{gfx::Rect(20, 30, 100, 50)}); second_host->InitHost(); @@ -210,7 +205,7 @@ TEST_P(WindowEventDispatcherTest, TouchDownState) { // Check that we correctly track the state of the mouse buttons in response to // button press and release events. -TEST_P(WindowEventDispatcherTest, MouseButtonState) { +TEST_F(WindowEventDispatcherTest, MouseButtonState) { EXPECT_FALSE(Env::GetInstance()->IsMouseButtonDown()); gfx::Point location; @@ -253,7 +248,7 @@ TEST_P(WindowEventDispatcherTest, MouseButtonState) { EXPECT_TRUE(Env::GetInstance()->IsMouseButtonDown()); } -TEST_P(WindowEventDispatcherTest, TranslatedEvent) { +TEST_F(WindowEventDispatcherTest, TranslatedEvent) { std::unique_ptr<Window> w1(test::CreateTestWindowWithDelegate( NULL, 1, gfx::Rect(50, 50, 100, 100), root_window())); @@ -329,7 +324,7 @@ class TestEventClient : public client::EventClient { } // namespace -TEST_P(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) { +TEST_F(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) { TestEventClient client(root_window()); test::TestWindowDelegate d; @@ -387,7 +382,7 @@ TEST_P(WindowEventDispatcherTest, CanProcessEventsWithinSubtree) { client.GetLockWindow()->RemovePreTargetHandler(&lock_ef); } -TEST_P(WindowEventDispatcherTest, DontIgnoreUnknownKeys) { +TEST_F(WindowEventDispatcherTest, DontIgnoreUnknownKeys) { ConsumeKeyHandler handler; root_window()->AddPreTargetHandler(&handler); @@ -419,7 +414,7 @@ TEST_P(WindowEventDispatcherTest, DontIgnoreUnknownKeys) { root_window()->RemovePreTargetHandler(&handler); } -TEST_P(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { +TEST_F(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); w1->Show(); w1->Focus(); @@ -436,7 +431,7 @@ TEST_P(WindowEventDispatcherTest, NoDelegateWindowReceivesKeyEvents) { // Tests that touch-events that are beyond the bounds of the root-window do get // propagated to the event filters correctly with the root as the target. -TEST_P(WindowEventDispatcherTest, TouchEventsOutsideBounds) { +TEST_F(WindowEventDispatcherTest, TouchEventsOutsideBounds) { ui::test::TestEventHandler handler; root_window()->AddPreTargetHandler(&handler); @@ -460,7 +455,7 @@ TEST_P(WindowEventDispatcherTest, TouchEventsOutsideBounds) { } // Tests that scroll events are dispatched correctly. -TEST_P(WindowEventDispatcherTest, ScrollEventDispatch) { +TEST_F(WindowEventDispatcherTest, ScrollEventDispatch) { base::TimeTicks now = ui::EventTimeForNow(); ui::test::TestEventHandler handler; root_window()->AddPreTargetHandler(&handler); @@ -680,7 +675,7 @@ std::string EventTypesToString(const EventFilterRecorder::Events& events) { // Verifies a repost mouse event targets the window with capture (if there is // one). // Flaky on 32-bit Windows bots. http://crbug.com/388290 -TEST_P(WindowEventDispatcherTest, MAYBE(RepostTargetsCaptureWindow)) { +TEST_F(WindowEventDispatcherTest, MAYBE(RepostTargetsCaptureWindow)) { // Set capture on |window| generate a mouse event (that is reposted) and not // over |window| and verify |window| gets it (|window| gets it because it has // capture). @@ -701,7 +696,7 @@ TEST_P(WindowEventDispatcherTest, MAYBE(RepostTargetsCaptureWindow)) { window->RemovePreTargetHandler(&recorder); } -TEST_P(WindowEventDispatcherTest, MouseMovesHeld) { +TEST_F(WindowEventDispatcherTest, MouseMovesHeld) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -828,7 +823,7 @@ TEST_P(WindowEventDispatcherTest, MouseMovesHeld) { root_window()->RemovePreTargetHandler(&recorder); } -TEST_P(WindowEventDispatcherTest, TouchMovesHeld) { +TEST_F(WindowEventDispatcherTest, TouchMovesHeld) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -892,7 +887,7 @@ TEST_P(WindowEventDispatcherTest, TouchMovesHeld) { // Tests that mouse move event has a right location // when there isn't the target window -TEST_P(WindowEventDispatcherTest, MouseEventWithoutTargetWindow) { +TEST_F(WindowEventDispatcherTest, MouseEventWithoutTargetWindow) { EventFilterRecorder recorder_first; EventFilterRecorder recorder_second; @@ -925,7 +920,7 @@ TEST_P(WindowEventDispatcherTest, MouseEventWithoutTargetWindow) { // Tests that a mouse exit is dispatched to the last mouse location when // the window is hiddden. -TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { +TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { EventFilterRecorder recorder; test::TestWindowDelegate delegate; @@ -953,7 +948,7 @@ TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenHidingWindow) { } // Tests that a mouse-exit event is not synthesized during shutdown. -TEST_P(WindowEventDispatcherTest, NoMouseExitInShutdown) { +TEST_F(WindowEventDispatcherTest, NoMouseExitInShutdown) { EventFilterRecorder recorder; test::TestWindowDelegate delegate; std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( @@ -979,7 +974,7 @@ TEST_P(WindowEventDispatcherTest, NoMouseExitInShutdown) { } // Verifies that a direct call to ProcessedTouchEvent() does not cause a crash. -TEST_P(WindowEventDispatcherTest, CallToProcessedTouchEvent) { +TEST_F(WindowEventDispatcherTest, CallToProcessedTouchEvent) { test::TestWindowDelegate delegate; std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( &delegate, 1, gfx::Rect(50, 50, 100, 100), root_window())); @@ -1022,7 +1017,7 @@ class HoldPointerOnScrollHandler : public ui::test::TestEventHandler { // Tests that touch-move events don't contribute to an in-progress scroll // gesture if touch-move events are being held by the dispatcher. -TEST_P(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { +TEST_F(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); test::TestWindowDelegate delegate; @@ -1057,7 +1052,7 @@ TEST_P(WindowEventDispatcherTest, TouchMovesHeldOnScroll) { // Tests that a 'held' touch-event does contribute to gesture event when it is // dispatched. -TEST_P(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) { +TEST_F(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -1092,7 +1087,7 @@ TEST_P(WindowEventDispatcherTest, HeldTouchMoveContributesToGesture) { // Tests that synthetic mouse events are ignored when mouse // events are disabled. -TEST_P(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { +TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -1127,7 +1122,7 @@ TEST_P(WindowEventDispatcherTest, DispatchSyntheticMouseEvents) { } // Tests that a mouse-move event is not synthesized when a mouse-button is down. -TEST_P(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { +TEST_F(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { EventFilterRecorder recorder; test::TestWindowDelegate delegate; std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( @@ -1155,7 +1150,7 @@ TEST_P(WindowEventDispatcherTest, DoNotSynthesizeWhileButtonDown) { } // Tests that a mouse-press event is not dispatched during shutdown. -TEST_P(WindowEventDispatcherTest, DoNotDispatchInShutdown) { +TEST_F(WindowEventDispatcherTest, DoNotDispatchInShutdown) { EventFilterRecorder recorder; test::TestWindowDelegate delegate; std::unique_ptr<aura::Window> window(CreateTestWindowWithDelegate( @@ -1188,7 +1183,7 @@ TEST_P(WindowEventDispatcherTest, DoNotDispatchInShutdown) { // the cursor previously outside the window becomes inside, or vice versa. // Do not synthesize events if the window ignores events or is invisible. // Flaky on 32-bit Windows bots. http://crbug.com/388272 -TEST_P(WindowEventDispatcherTest, +TEST_F(WindowEventDispatcherTest, MAYBE(SynthesizeMouseEventsOnWindowBoundsChanged)) { test::TestCursorClient cursor_client(root_window()); cursor_client.ShowCursor(); @@ -1221,7 +1216,7 @@ TEST_P(WindowEventDispatcherTest, recorder.Reset(); // Set window to ignore events. - window->SetEventTargetingPolicy(ws::mojom::EventTargetingPolicy::NONE); + window->SetEventTargetingPolicy(EventTargetingPolicy::kNone); // Update the window bounds so that cursor is back inside the window. // This should not trigger a synthetic event. @@ -1232,8 +1227,7 @@ TEST_P(WindowEventDispatcherTest, recorder.Reset(); // Set window to accept events but invisible. - window->SetEventTargetingPolicy( - ws::mojom::EventTargetingPolicy::TARGET_AND_DESCENDANTS); + window->SetEventTargetingPolicy(EventTargetingPolicy::kTargetAndDescendants); window->Hide(); recorder.Reset(); @@ -1272,7 +1266,7 @@ TEST_P(WindowEventDispatcherTest, // Tests that a mouse exit is dispatched to the last known cursor location // when the cursor becomes invisible. -TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenCursorHidden) { +TEST_F(WindowEventDispatcherTest, DispatchMouseExitWhenCursorHidden) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -1311,7 +1305,7 @@ TEST_P(WindowEventDispatcherTest, DispatchMouseExitWhenCursorHidden) { // Tests that a synthetic mouse exit is dispatched to the last known cursor // location after mouse events are disabled on the cursor client. -TEST_P(WindowEventDispatcherTest, +TEST_F(WindowEventDispatcherTest, DispatchSyntheticMouseExitAfterMouseEventsDisabled) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -1418,7 +1412,7 @@ class DeletingWindowDelegate : public test::TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(DeletingWindowDelegate); }; -TEST_P(WindowEventDispatcherTest, DeleteWindowDuringDispatch) { +TEST_F(WindowEventDispatcherTest, DeleteWindowDuringDispatch) { // Verifies that we can delete a window during each phase of event handling. // Deleting the window should not cause a crash, only prevent further // processing from occurring. @@ -1490,7 +1484,7 @@ class DetachesParentOnTapDelegate : public test::TestWindowDelegate { // Tests that the gesture recognizer is reset for all child windows when a // window hides. No expectations, just checks that the test does not crash. -TEST_P(WindowEventDispatcherTest, +TEST_F(WindowEventDispatcherTest, GestureRecognizerResetsTargetWhenParentHides) { std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); DetachesParentOnTapDelegate delegate; @@ -1542,7 +1536,7 @@ class NestedGestureDelegate : public test::TestWindowDelegate { } // namespace // Tests that gesture end is delivered after nested gesture processing. -TEST_P(WindowEventDispatcherTest, GestureEndDeliveredAfterNestedGestures) { +TEST_F(WindowEventDispatcherTest, GestureEndDeliveredAfterNestedGestures) { NestedGestureDelegate d1(NULL, gfx::Point()); std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &d1)); w1->SetBounds(gfx::Rect(0, 0, 100, 100)); @@ -1562,7 +1556,7 @@ TEST_P(WindowEventDispatcherTest, GestureEndDeliveredAfterNestedGestures) { } // Tests whether we can repost the Tap down gesture event. -TEST_P(WindowEventDispatcherTest, RepostTapdownGestureTest) { +TEST_F(WindowEventDispatcherTest, RepostTapdownGestureTest) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -1642,7 +1636,7 @@ class RepostGestureEventRecorder : public EventFilterRecorder { // Tests whether events which are generated after the reposted gesture event // are received after that. In this case the scroll sequence events should // be received after the reposted gesture event. -TEST_P(WindowEventDispatcherTest, GestureRepostEventOrder) { +TEST_F(WindowEventDispatcherTest, GestureRepostEventOrder) { // Expected events at the end for the repost_target window defined below. const char kExpectedTargetEvents[] = // TODO)(rbyers): Gesture event reposting is disabled - crbug.com/279039. @@ -1738,7 +1732,7 @@ class OnMouseExitDeletingEventFilter : public EventFilterRecorder { // Tests that RootWindow drops mouse-moved event that is supposed to be sent to // a child, but the child is destroyed because of the synthesized mouse-exit // event generated on the previous mouse_moved_handler_. -TEST_P(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { +TEST_F(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { // Create window 1 and set its event filter. Window 1 will take ownership of // the event filter. std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), NULL)); @@ -1777,7 +1771,7 @@ TEST_P(WindowEventDispatcherTest, DeleteWindowDuringMouseMovedDispatch) { // Tests the case where the event dispatcher is deleted during the pre-dispatch // phase of dispatching and event. -TEST_P(WindowEventDispatcherTest, DeleteDispatcherDuringPreDispatch) { +TEST_F(WindowEventDispatcherTest, DeleteDispatcherDuringPreDispatch) { // Create a host for the window hierarchy. This host will be destroyed later // on. WindowTreeHost* host = @@ -1860,7 +1854,7 @@ class ValidRootDuringDestructionWindowObserver : public aura::WindowObserver { } // namespace // Verifies GetRootWindow() from ~Window returns a valid root. -TEST_P(WindowEventDispatcherTest, ValidRootDuringDestruction) { +TEST_F(WindowEventDispatcherTest, ValidRootDuringDestruction) { bool got_destroying = false; bool has_valid_root = false; ValidRootDuringDestructionWindowObserver observer(&got_destroying, @@ -1915,7 +1909,7 @@ class DontResetHeldEventWindowDelegate : public test::TestWindowDelegate { // tracks the number of events with ui::EF_SHIFT_DOWN set (all reposted events // have EF_SHIFT_DOWN). When the first event is seen RepostEvent() is used to // schedule another reposted event. -TEST_P(WindowEventDispatcherTest, DontResetHeldEvent) { +TEST_F(WindowEventDispatcherTest, DontResetHeldEvent) { DontResetHeldEventWindowDelegate delegate(root_window()); std::unique_ptr<Window> w1(CreateNormalWindow(1, root_window(), &delegate)); w1->SetBounds(gfx::Rect(0, 0, 40, 40)); @@ -1972,7 +1966,7 @@ class DeleteHostFromHeldMouseEventDelegate // Verifies if a WindowTreeHost is deleted from dispatching a held mouse event // we don't crash. -TEST_P(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { +TEST_F(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { // Should be deleted by |delegate|. WindowTreeHost* h2 = WindowTreeHost::Create(ui::PlatformWindowInitProperties{ gfx::Rect(0, 0, 100, 100)}) @@ -1993,7 +1987,7 @@ TEST_P(WindowEventDispatcherTest, DeleteHostFromHeldMouseEvent) { EXPECT_TRUE(delegate.got_destroy()); } -TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { +TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -2019,7 +2013,7 @@ TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveTouches) { root_window()->RemovePreTargetHandler(&recorder); } -TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { +TEST_F(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -2077,7 +2071,7 @@ TEST_P(WindowEventDispatcherTest, WindowHideCancelsActiveGestures) { // Places two windows side by side. Starts a pinch in one window, then sets // capture to the other window. Ensures that subsequent pinch events are // sent to the window which gained capture. -TEST_P(WindowEventDispatcherTest, TouchpadPinchEventsRetargetOnCapture) { +TEST_F(WindowEventDispatcherTest, TouchpadPinchEventsRetargetOnCapture) { EventFilterRecorder recorder1; EventFilterRecorder recorder2; std::unique_ptr<Window> window1( @@ -2124,7 +2118,7 @@ TEST_P(WindowEventDispatcherTest, TouchpadPinchEventsRetargetOnCapture) { // Places two windows side by side. Presses down on one window, and starts a // scroll. Sets capture on the other window and ensures that the "ending" events // aren't sent to the window which gained capture. -TEST_P(WindowEventDispatcherTest, EndingEventDoesntRetarget) { +TEST_F(WindowEventDispatcherTest, EndingEventDoesntRetarget) { EventFilterRecorder recorder1; EventFilterRecorder recorder2; std::unique_ptr<Window> window1(CreateNormalWindow(1, root_window(), NULL)); @@ -2198,7 +2192,7 @@ class CaptureWindowTracker : public test::TestWindowDelegate { } // Verifies handling loss of capture by the capture window being hidden. -TEST_P(WindowEventDispatcherTest, CaptureWindowHidden) { +TEST_F(WindowEventDispatcherTest, CaptureWindowHidden) { CaptureWindowTracker capture_window_tracker; capture_window_tracker.CreateCaptureWindow(root_window()); capture_window_tracker.capture_window()->Hide(); @@ -2206,7 +2200,7 @@ TEST_P(WindowEventDispatcherTest, CaptureWindowHidden) { } // Verifies handling loss of capture by the capture window being destroyed. -TEST_P(WindowEventDispatcherTest, CaptureWindowDestroyed) { +TEST_F(WindowEventDispatcherTest, CaptureWindowDestroyed) { CaptureWindowTracker capture_window_tracker; capture_window_tracker.CreateCaptureWindow(root_window()); capture_window_tracker.reset(); @@ -2249,7 +2243,7 @@ class RunLoopHandler : public ui::EventHandler { } // namespace -TEST_P(WindowEventDispatcherTest, HeldTouchMoveWithRunLoop) { +TEST_F(WindowEventDispatcherTest, HeldTouchMoveWithRunLoop) { RunLoopHandler handler(root_window()); host()->dispatcher()->HoldPointerMoves(); @@ -2360,7 +2354,7 @@ class WindowEventDispatcherTestWithMessageLoop DISALLOW_COPY_AND_ASSIGN(WindowEventDispatcherTestWithMessageLoop); }; -TEST_P(WindowEventDispatcherTestWithMessageLoop, EventRepostedInNonNestedLoop) { +TEST_F(WindowEventDispatcherTestWithMessageLoop, EventRepostedInNonNestedLoop) { ASSERT_FALSE(base::RunLoop::IsRunningOnCurrentThread()); // Perform the test in a callback, so that it runs after the message-loop // starts. @@ -2387,13 +2381,7 @@ class WindowEventDispatcherTestInHighDPI : public WindowEventDispatcherTest { } }; -TEST_P(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { - // This test is only applicable to LOCAL mode as it's setting a device scale - // factor and expecting events to be transformed while routing the event - // directly through host(). In MUS mode the window-service does the scaling. - if (GetParam() == Env::Mode::MUS) - return; - +TEST_F(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { test::TestWindowDelegate delegate; std::unique_ptr<aura::Window> child(test::CreateTestWindowWithDelegate( &delegate, 1234, gfx::Rect(20, 20, 100, 100), root_window())); @@ -2429,13 +2417,7 @@ TEST_P(WindowEventDispatcherTestInHighDPI, EventLocationTransform) { root_window()->RemovePreTargetHandler(&handler_root); } -TEST_P(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) { - // This test is only applicable to LOCAL mode as it's setting a device scale - // factor and expecting events to be transformed while routing the event - // directly through host(). In MUS mode the window-service does the scaling. - if (GetParam() == Env::Mode::MUS) - return; - +TEST_F(WindowEventDispatcherTestInHighDPI, TouchMovesHeldOnScroll) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); test::TestWindowDelegate delegate; @@ -2504,14 +2486,8 @@ class TriggerNestedLoopOnRightMousePress : public ui::test::TestEventHandler { // Tests that if dispatching a 'held' event triggers a nested run loop, then // the events that are dispatched from the nested run loop are transformed // correctly. -TEST_P(WindowEventDispatcherTestInHighDPI, +TEST_F(WindowEventDispatcherTestInHighDPI, EventsTransformedInRepostedEventTriggeredNestedLoop) { - // This test is only applicable to LOCAL mode as it's setting a device scale - // factor and expecting events to be transformed while routing the event - // directly through host(). In MUS mode the window-service does the scaling. - if (GetParam() == Env::Mode::MUS) - return; - std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), NULL)); // Make sure the window is visible. RunAllPendingInMessageLoop(); @@ -2562,7 +2538,7 @@ class SelfDestructDelegate : public test::TestWindowDelegate { DISALLOW_COPY_AND_ASSIGN(SelfDestructDelegate); }; -TEST_P(WindowEventDispatcherTest, SynthesizedLocatedEvent) { +TEST_F(WindowEventDispatcherTest, SynthesizedLocatedEvent) { ui::test::EventGenerator generator(root_window()); generator.MoveMouseTo(10, 10); EXPECT_EQ("10,10", @@ -2596,7 +2572,7 @@ TEST_P(WindowEventDispatcherTest, SynthesizedLocatedEvent) { // Tests that the window which has capture can get destroyed as a result of // ui::ET_MOUSE_CAPTURE_CHANGED event dispatched in // WindowEventDispatcher::UpdateCapture without causing a "use after free". -TEST_P(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { +TEST_F(WindowEventDispatcherTest, DestroyWindowOnCaptureChanged) { SelfDestructDelegate delegate; std::unique_ptr<aura::Window> window_first(CreateTestWindowWithDelegate( &delegate, 1, gfx::Rect(20, 10, 10, 20), root_window())); @@ -2636,7 +2612,7 @@ class StaticFocusClient : public client::FocusClient { // Tests that host-cancel-mode event can be dispatched to a dispatcher safely // when the focused window does not live in the dispatcher's tree. -TEST_P(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { +TEST_F(WindowEventDispatcherTest, HostCancelModeWithFocusedWindowOutside) { test::TestWindowDelegate delegate; std::unique_ptr<Window> focused(CreateTestWindowWithDelegate( &delegate, 123, gfx::Rect(20, 30, 100, 50), NULL)); @@ -2709,7 +2685,7 @@ class MoveWindowHandler : public ui::EventHandler { // Tests that nested event dispatch works correctly if the target of the older // event being dispatched is moved to a different dispatcher in response to an // event in the inner loop. -TEST_P(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { +TEST_F(WindowEventDispatcherTest, NestedEventDispatchTargetMoved) { std::unique_ptr<WindowTreeHost> second_host = WindowTreeHost::Create( ui::PlatformWindowInitProperties{gfx::Rect(20, 30, 100, 50)}); second_host->InitHost(); @@ -2766,7 +2742,7 @@ class AlwaysMouseDownInputStateLookup : public InputStateLookup { DISALLOW_COPY_AND_ASSIGN(AlwaysMouseDownInputStateLookup); }; -TEST_P(WindowEventDispatcherTest, +TEST_F(WindowEventDispatcherTest, CursorVisibilityChangedWhileCaptureWindowInAnotherDispatcher) { test::EventCountDelegate delegate; std::unique_ptr<Window> window(CreateTestWindowWithDelegate( @@ -2812,7 +2788,7 @@ TEST_P(WindowEventDispatcherTest, EXPECT_EQ("0 0 1", delegate.GetMouseMotionCountsAndReset()); } -TEST_P(WindowEventDispatcherTest, +TEST_F(WindowEventDispatcherTest, RedirectedEventToDifferentDispatcherLocation) { std::unique_ptr<WindowTreeHost> second_host = WindowTreeHost::Create( ui::PlatformWindowInitProperties{gfx::Rect(20, 30, 100, 50)}); @@ -2881,7 +2857,7 @@ class AsyncWindowDelegate : public test::TestWindowDelegate { // Tests that gesture events dispatched through the asynchronous flow have // co-ordinates in the right co-ordinate space. -TEST_P(WindowEventDispatcherTest, GestureEventCoordinates) { +TEST_F(WindowEventDispatcherTest, GestureEventCoordinates) { const float kX = 67.3f; const float kY = 97.8f; @@ -2917,7 +2893,7 @@ TEST_P(WindowEventDispatcherTest, GestureEventCoordinates) { } // Tests that a scroll-generating touch-event is marked as such. -TEST_P(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { +TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { EventFilterRecorder recorder; root_window()->AddPreTargetHandler(&recorder); @@ -2968,13 +2944,7 @@ TEST_P(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { // WindowTreeHost::MoveCursorTo() when the cursor did not move but the // cursor's position in root coordinates has changed (e.g. when the displays's // scale factor changed). Test that hover effects are properly updated. -TEST_P(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { - // This test is only applicable to LOCAL mode as it's setting a device scale - // factor and expecting events to be transformed while routing the event - // directly through host(). In MUS mode the window-service does the scaling. - if (GetParam() == Env::Mode::MUS) - return; - +TEST_F(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { WindowEventDispatcher* dispatcher = host()->dispatcher(); test::TestCursorClient cursor_client(root_window()); cursor_client.ShowCursor(); @@ -3019,7 +2989,7 @@ TEST_P(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) { // Tests that we correctly report the fraction of time without user input via // UMA. -TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { +TEST_F(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { const char* kHistogram = "Event.FractionOfTimeWithoutUserInput"; base::HistogramTester tester; @@ -3048,7 +3018,7 @@ TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { tester.ExpectTotalCount(kHistogram, 1); } -TEST_P(WindowEventDispatcherTest, TouchEventWithScaledWindow) { +TEST_F(WindowEventDispatcherTest, TouchEventWithScaledWindow) { WindowEventDispatcher* dispatcher = host()->dispatcher(); EventFilterRecorder root_recorder; @@ -3109,343 +3079,8 @@ TEST_P(WindowEventDispatcherTest, TouchEventWithScaledWindow) { child_recorder.Reset(); } - // Classic backend cannot dispatch events with non-null target. - if (GetParam() != Env::Mode::LOCAL) { - // |touch_position| value isn't in the bounds of root window, but it is in - // the bounds of the child window. - const gfx::Point touch_position = - root_bounds.bottom_right() + gfx::Vector2d(20, 20); - ui::TouchEvent pressed_event( - ui::ET_TOUCH_PRESSED, touch_position, ui::EventTimeForNow(), - ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); - ui::TouchEvent released_event( - ui::ET_TOUCH_RELEASED, touch_position, ui::EventTimeForNow(), - ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 0)); - - gfx::Point touch_root_position = touch_position; - aura::Window::ConvertPointToTarget(child.get(), root_window(), - &touch_root_position); - ui::Event::DispatcherApi(&pressed_event).set_target(child.get()); - pressed_event.set_root_location(touch_root_position); - ui::Event::DispatcherApi(&released_event).set_target(child.get()); - released_event.set_root_location(touch_position); - dispatcher->OnEventFromSource(&pressed_event); - dispatcher->OnEventFromSource(&released_event); - - EXPECT_TRUE(child->bounds().Contains(touch_position)); - EXPECT_FALSE(root_window()->bounds().Contains(touch_position)); - EXPECT_TRUE(root_window()->bounds().Contains(touch_root_position)); - EXPECT_EQ(expected_events, EventTypesToString(root_recorder.events())); - EXPECT_EQ(expected_events, EventTypesToString(child_recorder.events())); - root_recorder.Reset(); - child_recorder.Reset(); - } - child->RemovePreTargetHandler(&child_recorder); root_window()->RemovePreTargetHandler(&root_recorder); } -INSTANTIATE_TEST_SUITE_P(/* no prefix */, - WindowEventDispatcherTest, - ::testing::Values(Env::Mode::LOCAL, Env::Mode::MUS)); - -INSTANTIATE_TEST_SUITE_P(/* no prefix */, - WindowEventDispatcherTestWithMessageLoop, - ::testing::Values(Env::Mode::LOCAL, Env::Mode::MUS)); - -INSTANTIATE_TEST_SUITE_P(/* no prefix */, - WindowEventDispatcherTestInHighDPI, - ::testing::Values(Env::Mode::LOCAL, Env::Mode::MUS)); - -using WindowEventDispatcherMusTest = test::AuraTestBaseMus; - -class LastEventLocationDelegate : public test::TestWindowDelegate { - public: - LastEventLocationDelegate() {} - ~LastEventLocationDelegate() override {} - - int mouse_event_count() const { return mouse_event_count_; } - const gfx::Point& last_mouse_location() const { return last_mouse_location_; } - - // TestWindowDelegate: - void OnMouseEvent(ui::MouseEvent* event) override { - ++mouse_event_count_; - last_mouse_location_ = event->root_location(); - EXPECT_EQ(last_mouse_location_, Env::GetInstance()->last_mouse_location()); - } - - private: - int mouse_event_count_ = 0; - gfx::Point last_mouse_location_; - - DISALLOW_COPY_AND_ASSIGN(LastEventLocationDelegate); -}; - -TEST_F(WindowEventDispatcherMusTest, LastEventLocation) { - LastEventLocationDelegate last_event_location_delegate; - std::unique_ptr<Window> window( - CreateTestWindowWithDelegate(&last_event_location_delegate, 123, - gfx::Rect(0, 0, 10, 20), root_window())); - - // Enable fetching mouse location from mouse. - test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); - EXPECT_EQ(gfx::Point(0, 0), - window_tree_client_impl()->GetCursorScreenPoint()); - EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); - - // Dispatch an event to |mouse_location|. While dispatching the event - // Env::last_mouse_location() should return |mouse_location|. - const gfx::Point mouse_location(1, 2); - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); - EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); - - // After dispatch the location should fallback to that of the - // WindowTreeClient, which defaults to 0,0. - EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); -} - -TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget) { - LastEventLocationDelegate last_event_location_delegate1; - std::unique_ptr<Window> child1( - CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, - gfx::Rect(10, 10, 100, 100), root_window())); - LastEventLocationDelegate last_event_location_delegate2; - std::unique_ptr<Window> child2( - CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, - gfx::Rect(20, 30, 100, 100), child1.get())); - - const gfx::Point mouse_location(30, 40); - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(0, last_event_location_delegate1.mouse_event_count()); - EXPECT_EQ(1, last_event_location_delegate2.mouse_event_count()); - EXPECT_EQ(gfx::Point(), last_event_location_delegate1.last_mouse_location()); - EXPECT_EQ(mouse_location, - last_event_location_delegate2.last_mouse_location()); -} - -TEST_F(WindowEventDispatcherMusTest, UseDefaultTargeterToFindTarget2) { - LastEventLocationDelegate last_event_location_delegate1; - std::unique_ptr<Window> child1( - CreateTestWindowWithDelegate(&last_event_location_delegate1, 123, - gfx::Rect(10, 10, 100, 100), root_window())); - LastEventLocationDelegate last_event_location_delegate2; - std::unique_ptr<Window> child2( - CreateTestWindowWithDelegate(&last_event_location_delegate2, 124, - gfx::Rect(20, 30, 100, 100), child1.get())); - - const gfx::Point mouse_location(15, 25); - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(1, last_event_location_delegate1.mouse_event_count()); - EXPECT_EQ(0, last_event_location_delegate2.mouse_event_count()); - EXPECT_EQ(mouse_location, - last_event_location_delegate1.last_mouse_location()); - EXPECT_EQ(gfx::Point(), last_event_location_delegate2.last_mouse_location()); -} - -namespace { - -class ExplicitWindowTargeter : public WindowTargeter { - public: - explicit ExplicitWindowTargeter(Window* target) : target_(target) {} - ~ExplicitWindowTargeter() override = default; - - // WindowTargeter: - ui::EventTarget* FindTargetForEvent(ui::EventTarget* root, - ui::Event* event) override { - return target_; - } - ui::EventTarget* FindNextBestTarget(ui::EventTarget* previous_target, - ui::Event* event) override { - return nullptr; - } - - private: - Window* target_; - - DISALLOW_COPY_AND_ASSIGN(ExplicitWindowTargeter); -}; - -} // namespace - -TEST_F(WindowEventDispatcherMusTest, TargetCaptureWindow) { - NonClientDelegate w1_delegate; - NonClientDelegate w2_delegate; - std::unique_ptr<Window> w1( - CreateNormalWindow(-1, root_window(), &w1_delegate)); - std::unique_ptr<Window> w2( - CreateNormalWindow(-1, root_window(), &w2_delegate)); - const gfx::Point w2_origin(10, 11); - w2->SetBounds(gfx::Rect(w2_origin, gfx::Size(100, 100))); - NonClientDelegate w2_child_delegate; - std::unique_ptr<Window> w2_child( - CreateNormalWindow(-1, w2.get(), &w2_child_delegate)); - w2->SetEventTargeter( - std::make_unique<ExplicitWindowTargeter>(w2_child.get())); - w2->SetCapture(); - ASSERT_TRUE(w2->HasCapture()); - const gfx::Point root_location(100, 200); - const gfx::Point mouse_location(15, 25); - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, root_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - ui::Event::DispatcherApi(&mouse).set_target(w1.get()); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(0, w1_delegate.mouse_event_count()); - EXPECT_EQ(1, w2_delegate.mouse_event_count()); - EXPECT_EQ(0, w2_child_delegate.mouse_event_count()); - EXPECT_EQ(mouse_location - w2_origin.OffsetFromOrigin(), - w2_delegate.mouse_event_location()); -} - -namespace { - -class LocationRecordingEventHandler : public ui::EventHandler { - public: - LocationRecordingEventHandler() = default; - ~LocationRecordingEventHandler() override = default; - - const gfx::Point& event_root_location() const { return event_root_location_; } - - const gfx::Point& env_root_location() const { return env_root_location_; } - - int mouse_event_count() const { return mouse_event_count_; } - - // ui::EventHandler: - void OnMouseEvent(ui::MouseEvent* event) override { - ++mouse_event_count_; - event_root_location_ = event->root_location(); - env_root_location_ = Env::GetInstance()->last_mouse_location(); - } - - private: - int mouse_event_count_ = 0; - gfx::Point event_root_location_; - gfx::Point env_root_location_; - - DISALLOW_COPY_AND_ASSIGN(LocationRecordingEventHandler); -}; - -} // namespace - -TEST_F(WindowEventDispatcherMusTest, RootLocationDoesntChange) { - std::unique_ptr<Window> window( - test::CreateTestWindowWithBounds(gfx::Rect(0, 0, 10, 20), root_window())); - std::unique_ptr<Window> child_window( - CreateNormalWindow(-1, window.get(), nullptr)); - - test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); - - LocationRecordingEventHandler event_handler; - child_window->AddPreTargetHandler(&event_handler); - - const gfx::Point mouse_location(1, 2); - gfx::Point root_location(mouse_location); - - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, root_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - ui::Event::DispatcherApi(&mouse).set_target(child_window.get()); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(1, event_handler.mouse_event_count()); - - // The root location during dispatch of the event and Env should match the - // one that was dispatched. - EXPECT_EQ(root_location, event_handler.event_root_location()); - EXPECT_EQ(root_location, event_handler.env_root_location()); - - child_window->RemovePreTargetHandler(&event_handler); -} - -class NestedLocationDelegate : public test::TestWindowDelegate { - public: - NestedLocationDelegate() {} - ~NestedLocationDelegate() override {} - - int mouse_event_count() const { return mouse_event_count_; } - int nested_message_loop_count() const { return nested_message_loop_count_; } - const gfx::Point& last_mouse_location() const { return last_mouse_location_; } - - // TestWindowDelegate: - void OnMouseEvent(ui::MouseEvent* event) override { - ++mouse_event_count_; - last_mouse_location_ = event->root_location(); - EXPECT_EQ(last_mouse_location_, Env::GetInstance()->last_mouse_location()); - - // Start a RunLoop that in turn starts a RunLoop. We have to do this as the - // first RunLoop doesn't triggering nesting (the MessageLoop isn't running - // at this point). The second RunLoop (created in InInitialMessageLoop()) - // is considered the first nested loop. - base::RunLoop run_loop; - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(&NestedLocationDelegate::InInitialMessageLoop, - base::Unretained(this), &run_loop)); - run_loop.Run(); - } - - private: - void InInitialMessageLoop(base::RunLoop* initial_run_loop) { - // See comments in OnMouseEvent() for details on which this creates another - // RunLoop. - base::RunLoop run_loop(base::RunLoop::Type::kNestableTasksAllowed); - base::ThreadTaskRunnerHandle::Get()->PostTask( - FROM_HERE, base::BindOnce(&NestedLocationDelegate::InRunMessageLoop, - base::Unretained(this), &run_loop)); - run_loop.Run(); - initial_run_loop->Quit(); - } - - void InRunMessageLoop(base::RunLoop* run_loop) { - ++nested_message_loop_count_; - // nested run loops trigger falling back to using the location from - // WindowTreeClient, which is 0,0. - EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); - run_loop->Quit(); - } - - int mouse_event_count_ = 0; - // Incremented when the deepest message loop is encountered. - int nested_message_loop_count_ = 0; - gfx::Point last_mouse_location_; - - DISALLOW_COPY_AND_ASSIGN(NestedLocationDelegate); -}; - -TEST_F(WindowEventDispatcherMusTest, EventDispatchTriggersNestedMessageLoop) { - NestedLocationDelegate last_event_location_delegate; - std::unique_ptr<Window> window( - CreateTestWindowWithDelegate(&last_event_location_delegate, 123, - gfx::Rect(0, 0, 10, 20), root_window())); - - // Enable fetching mouse location from mouse. - test::EnvTestHelper().SetAlwaysUseLastMouseLocation(false); - EXPECT_EQ(gfx::Point(0, 0), - window_tree_client_impl()->GetCursorScreenPoint()); - EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); - - // Dispatch an event to |mouse_location|. While dispatching the event - // Env::last_mouse_location() should return |mouse_location|. - const gfx::Point mouse_location(1, 2); - ui::MouseEvent mouse(ui::ET_MOUSE_PRESSED, mouse_location, mouse_location, - ui::EventTimeForNow(), ui::EF_LEFT_MOUSE_BUTTON, - ui::EF_LEFT_MOUSE_BUTTON); - DispatchEventUsingWindowDispatcher(&mouse); - EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); - EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); - EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); - - // After dispatch the location should fallback to that of the - // WindowTreeClient, which defaults to 0,0. - EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); -} - } // namespace aura |