| 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> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/test/histogram_tester.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/aura/client/capture_client.h" | 20 #include "ui/aura/client/capture_client.h" |
| 20 #include "ui/aura/client/event_client.h" | 21 #include "ui/aura/client/event_client.h" |
| 21 #include "ui/aura/client/focus_client.h" | 22 #include "ui/aura/client/focus_client.h" |
| 22 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
| 23 #include "ui/aura/mus/window_tree_client.h" | 24 #include "ui/aura/mus/window_tree_client.h" |
| 24 #include "ui/aura/test/aura_test_base.h" | 25 #include "ui/aura/test/aura_test_base.h" |
| 25 #include "ui/aura/test/env_test_helper.h" | 26 #include "ui/aura/test/env_test_helper.h" |
| 26 #include "ui/aura/test/test_cursor_client.h" | 27 #include "ui/aura/test/test_cursor_client.h" |
| 27 #include "ui/aura/test/test_screen.h" | 28 #include "ui/aura/test/test_screen.h" |
| 28 #include "ui/aura/test/test_window_delegate.h" | 29 #include "ui/aura/test/test_window_delegate.h" |
| 29 #include "ui/aura/test/test_windows.h" | 30 #include "ui/aura/test/test_windows.h" |
| 30 #include "ui/aura/window.h" | 31 #include "ui/aura/window.h" |
| 31 #include "ui/aura/window_tracker.h" | 32 #include "ui/aura/window_tracker.h" |
| 32 #include "ui/base/hit_test.h" | 33 #include "ui/base/hit_test.h" |
| 33 #include "ui/display/screen.h" | 34 #include "ui/display/screen.h" |
| 34 #include "ui/events/event.h" | 35 #include "ui/events/event.h" |
| 35 #include "ui/events/event_handler.h" | 36 #include "ui/events/event_handler.h" |
| 36 #include "ui/events/event_utils.h" | 37 #include "ui/events/event_utils.h" |
| 37 #include "ui/events/gesture_detection/gesture_configuration.h" | 38 #include "ui/events/gesture_detection/gesture_configuration.h" |
| 39 #include "ui/events/keycodes/dom/dom_code.h" |
| 38 #include "ui/events/keycodes/keyboard_codes.h" | 40 #include "ui/events/keycodes/keyboard_codes.h" |
| 39 #include "ui/events/test/event_generator.h" | 41 #include "ui/events/test/event_generator.h" |
| 40 #include "ui/events/test/test_event_handler.h" | 42 #include "ui/events/test/test_event_handler.h" |
| 41 #include "ui/gfx/geometry/point.h" | 43 #include "ui/gfx/geometry/point.h" |
| 42 #include "ui/gfx/geometry/rect.h" | 44 #include "ui/gfx/geometry/rect.h" |
| 43 #include "ui/gfx/transform.h" | 45 #include "ui/gfx/transform.h" |
| 44 | 46 |
| 45 namespace aura { | 47 namespace aura { |
| 46 namespace { | 48 namespace { |
| 47 | 49 |
| (...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2687 // The cursor should not be over |w| after changing the device scale factor to | 2689 // The cursor should not be over |w| after changing the device scale factor to |
| 2688 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. | 2690 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. |
| 2689 test_screen()->SetDeviceScaleFactor(2.f); | 2691 test_screen()->SetDeviceScaleFactor(2.f); |
| 2690 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); | 2692 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); |
| 2691 RunAllPendingInMessageLoop(); | 2693 RunAllPendingInMessageLoop(); |
| 2692 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); | 2694 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); |
| 2693 | 2695 |
| 2694 w->RemovePreTargetHandler(&recorder); | 2696 w->RemovePreTargetHandler(&recorder); |
| 2695 } | 2697 } |
| 2696 | 2698 |
| 2699 // Tests that we correctly report the fraction of time without user input via |
| 2700 // UMA. |
| 2701 TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) { |
| 2702 const char* kHistogram = "Event.FractionOfTimeWithoutUserInput"; |
| 2703 base::HistogramTester tester; |
| 2704 |
| 2705 std::unique_ptr<aura::Window> window( |
| 2706 test::CreateTestWindowWithId(1234, root_window())); |
| 2707 |
| 2708 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 2709 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(4), 0, |
| 2710 0); |
| 2711 |
| 2712 // To flush the idle fraction reporter, we need to dispatch two events. The |
| 2713 // first event causes us to record the previous active period, and the second |
| 2714 // flushes the previous active period. |
| 2715 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 2716 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(16), |
| 2717 0, 0); |
| 2718 |
| 2719 ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::Point(10, 10), |
| 2720 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(30), |
| 2721 0, 0); |
| 2722 |
| 2723 DispatchEventUsingWindowDispatcher(&mouse1); |
| 2724 DispatchEventUsingWindowDispatcher(&mouse2); |
| 2725 DispatchEventUsingWindowDispatcher(&mouse3); |
| 2726 |
| 2727 tester.ExpectTotalCount(kHistogram, 1); |
| 2728 } |
| 2729 |
| 2697 INSTANTIATE_TEST_CASE_P(/* no prefix */, | 2730 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2698 WindowEventDispatcherTest, | 2731 WindowEventDispatcherTest, |
| 2699 ::testing::Values(test::BackendType::CLASSIC, | 2732 ::testing::Values(test::BackendType::CLASSIC, |
| 2700 test::BackendType::MUS)); | 2733 test::BackendType::MUS)); |
| 2701 | 2734 |
| 2702 INSTANTIATE_TEST_CASE_P(/* no prefix */, | 2735 INSTANTIATE_TEST_CASE_P(/* no prefix */, |
| 2703 WindowEventDispatcherTestWithMessageLoop, | 2736 WindowEventDispatcherTestWithMessageLoop, |
| 2704 ::testing::Values(test::BackendType::CLASSIC, | 2737 ::testing::Values(test::BackendType::CLASSIC, |
| 2705 test::BackendType::MUS)); | 2738 test::BackendType::MUS)); |
| 2706 | 2739 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2882 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); | 2915 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); |
| 2883 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); | 2916 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); |
| 2884 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); | 2917 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); |
| 2885 | 2918 |
| 2886 // After dispatch the location should fallback to that of the | 2919 // After dispatch the location should fallback to that of the |
| 2887 // WindowTreeClient, which defaults to 0,0. | 2920 // WindowTreeClient, which defaults to 0,0. |
| 2888 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); | 2921 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); |
| 2889 } | 2922 } |
| 2890 | 2923 |
| 2891 } // namespace aura | 2924 } // namespace aura |
| OLD | NEW |