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

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

Issue 2751403002: Record the fraction of the time without user input - Aura only (Closed)
Patch Set: Update test. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/aura/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 2621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2669 // The cursor should not be over |w| after changing the device scale factor to 2671 // The cursor should not be over |w| after changing the device scale factor to
2670 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|. 2672 // 2x. A ET_MOUSE_EXITED event should have been sent to |w|.
2671 test_screen()->SetDeviceScaleFactor(2.f); 2673 test_screen()->SetDeviceScaleFactor(2.f);
2672 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11)); 2674 dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11));
2673 RunAllPendingInMessageLoop(); 2675 RunAllPendingInMessageLoop();
2674 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED)); 2676 EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED));
2675 2677
2676 w->RemovePreTargetHandler(&recorder); 2678 w->RemovePreTargetHandler(&recorder);
2677 } 2679 }
2678 2680
2681 // Tests that we correctly report the fraction of time without user input via
2682 // UMA.
2683 TEST_P(WindowEventDispatcherTest, FractionOfTimeWithoutUserInputRecorded) {
2684 const char* kHistogram = "Event.FractionOfTimeWithoutUserInput";
2685 base::HistogramTester tester;
2686
2687 std::unique_ptr<aura::Window> window(
2688 test::CreateTestWindowWithId(1234, root_window()));
2689
2690 ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
2691 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(4), 0,
2692 0);
2693
2694 // To flush the idle fraction reporter, we need to dispatch two events. The
2695 // first event causes us to record the previous active period, and the second
2696 // flushes the previous active period.
2697 ui::MouseEvent mouse2(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
2698 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(16),
2699 0, 0);
2700
2701 ui::MouseEvent mouse3(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
2702 gfx::Point(10, 10), ui::EventTimeStampFromSeconds(30),
2703 0, 0);
2704
2705 DispatchEventUsingWindowDispatcher(&mouse1);
2706 DispatchEventUsingWindowDispatcher(&mouse2);
2707 DispatchEventUsingWindowDispatcher(&mouse3);
2708
2709 tester.ExpectTotalCount(kHistogram, 1);
2710 }
2711
2679 INSTANTIATE_TEST_CASE_P(/* no prefix */, 2712 INSTANTIATE_TEST_CASE_P(/* no prefix */,
2680 WindowEventDispatcherTest, 2713 WindowEventDispatcherTest,
2681 ::testing::Values(test::BackendType::CLASSIC, 2714 ::testing::Values(test::BackendType::CLASSIC,
2682 test::BackendType::MUS)); 2715 test::BackendType::MUS));
2683 2716
2684 INSTANTIATE_TEST_CASE_P(/* no prefix */, 2717 INSTANTIATE_TEST_CASE_P(/* no prefix */,
2685 WindowEventDispatcherTestWithMessageLoop, 2718 WindowEventDispatcherTestWithMessageLoop,
2686 ::testing::Values(test::BackendType::CLASSIC, 2719 ::testing::Values(test::BackendType::CLASSIC,
2687 test::BackendType::MUS)); 2720 test::BackendType::MUS));
2688 2721
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
2864 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count()); 2897 EXPECT_EQ(1, last_event_location_delegate.mouse_event_count());
2865 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count()); 2898 EXPECT_EQ(1, last_event_location_delegate.nested_message_loop_count());
2866 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location()); 2899 EXPECT_EQ(mouse_location, last_event_location_delegate.last_mouse_location());
2867 2900
2868 // After dispatch the location should fallback to that of the 2901 // After dispatch the location should fallback to that of the
2869 // WindowTreeClient, which defaults to 0,0. 2902 // WindowTreeClient, which defaults to 0,0.
2870 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location()); 2903 EXPECT_EQ(gfx::Point(0, 0), Env::GetInstance()->last_mouse_location());
2871 } 2904 }
2872 2905
2873 } // namespace aura 2906 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698