OLD | NEW |
| (Empty) |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/common/metrics/pointer_metrics_recorder.h" | |
6 | |
7 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | |
8 #include "ash/common/wm_shell.h" | |
9 #include "ash/common/wm_window.h" | |
10 #include "ash/public/cpp/shell_window_ids.h" | |
11 #include "ash/shared/app_types.h" | |
12 #include "ash/test/ash_test_base.h" | |
13 #include "base/test/histogram_tester.h" | |
14 #include "ui/events/event.h" | |
15 #include "ui/views/pointer_watcher.h" | |
16 #include "ui/views/widget/widget.h" | |
17 | |
18 using views::PointerWatcher; | |
19 | |
20 namespace ash { | |
21 namespace { | |
22 | |
23 const char kFormFactorHistogramName[] = "Event.DownEventCount.PerFormFactor"; | |
24 const char kInputHistogramName[] = "Event.DownEventCount.PerInput"; | |
25 const char kDestinationHistogramName[] = "Event.DownEventCount.PerDestination"; | |
26 | |
27 // Test fixture for the PointerMetricsRecorder class. | |
28 class PointerMetricsRecorderTest : public test::AshTestBase { | |
29 public: | |
30 PointerMetricsRecorderTest(); | |
31 ~PointerMetricsRecorderTest() override; | |
32 | |
33 // test::AshTestBase: | |
34 void SetUp() override; | |
35 void TearDown() override; | |
36 | |
37 protected: | |
38 // The test target. | |
39 std::unique_ptr<PointerMetricsRecorder> pointer_metrics_recorder_; | |
40 | |
41 // Used to verify recorded data. | |
42 std::unique_ptr<base::HistogramTester> histogram_tester_; | |
43 | |
44 private: | |
45 DISALLOW_COPY_AND_ASSIGN(PointerMetricsRecorderTest); | |
46 }; | |
47 | |
48 PointerMetricsRecorderTest::PointerMetricsRecorderTest() {} | |
49 | |
50 PointerMetricsRecorderTest::~PointerMetricsRecorderTest() {} | |
51 | |
52 void PointerMetricsRecorderTest::SetUp() { | |
53 test::AshTestBase::SetUp(); | |
54 pointer_metrics_recorder_.reset(new PointerMetricsRecorder()); | |
55 histogram_tester_.reset(new base::HistogramTester()); | |
56 } | |
57 | |
58 void PointerMetricsRecorderTest::TearDown() { | |
59 pointer_metrics_recorder_.reset(); | |
60 test::AshTestBase::TearDown(); | |
61 } | |
62 | |
63 } // namespace | |
64 | |
65 // Verifies that histogram is not recorded when receiving events that are not | |
66 // down events. | |
67 TEST_F(PointerMetricsRecorderTest, NonDownEventsInAllPointerHistogram) { | |
68 std::unique_ptr<views::Widget> target = | |
69 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
70 const ui::PointerEvent pointer_event( | |
71 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), 0, 0, 0, | |
72 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
73 base::TimeTicks()); | |
74 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
75 target.get()); | |
76 | |
77 histogram_tester_->ExpectTotalCount(kFormFactorHistogramName, 0); | |
78 histogram_tester_->ExpectTotalCount(kInputHistogramName, 0); | |
79 histogram_tester_->ExpectTotalCount(kDestinationHistogramName, 0); | |
80 } | |
81 | |
82 // Verifies that down events from different inputs are recorded. | |
83 TEST_F(PointerMetricsRecorderTest, DownEventPerInput) { | |
84 std::unique_ptr<views::Widget> target = | |
85 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
86 | |
87 const ui::PointerEvent unknown_event( | |
88 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
89 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_UNKNOWN), | |
90 base::TimeTicks()); | |
91 pointer_metrics_recorder_->OnPointerEventObserved(unknown_event, gfx::Point(), | |
92 target.get()); | |
93 histogram_tester_->ExpectBucketCount(kInputHistogramName, 0, 1); | |
94 | |
95 const ui::PointerEvent mouse_event( | |
96 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
97 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
98 base::TimeTicks()); | |
99 pointer_metrics_recorder_->OnPointerEventObserved(mouse_event, gfx::Point(), | |
100 target.get()); | |
101 histogram_tester_->ExpectBucketCount(kInputHistogramName, 1, 1); | |
102 | |
103 const ui::PointerEvent stylus_event( | |
104 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
105 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_PEN), | |
106 base::TimeTicks()); | |
107 pointer_metrics_recorder_->OnPointerEventObserved(stylus_event, gfx::Point(), | |
108 target.get()); | |
109 histogram_tester_->ExpectBucketCount(kInputHistogramName, 2, 1); | |
110 | |
111 const ui::PointerEvent stylus_event2( | |
112 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
113 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_ERASER), | |
114 base::TimeTicks()); | |
115 pointer_metrics_recorder_->OnPointerEventObserved(stylus_event2, gfx::Point(), | |
116 target.get()); | |
117 histogram_tester_->ExpectBucketCount(kInputHistogramName, 2, 2); | |
118 | |
119 const ui::PointerEvent touch_event( | |
120 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
121 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | |
122 base::TimeTicks()); | |
123 pointer_metrics_recorder_->OnPointerEventObserved(touch_event, gfx::Point(), | |
124 target.get()); | |
125 histogram_tester_->ExpectBucketCount(kInputHistogramName, 3, 1); | |
126 } | |
127 | |
128 // Verifies that down events in different form factors are recorded. | |
129 TEST_F(PointerMetricsRecorderTest, DownEventPerFormFactor) { | |
130 std::unique_ptr<views::Widget> target = | |
131 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
132 const ui::PointerEvent pointer_event( | |
133 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
134 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
135 base::TimeTicks()); | |
136 | |
137 // Enable maximize mode | |
138 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
139 true); | |
140 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
141 target.get()); | |
142 histogram_tester_->ExpectBucketCount(kFormFactorHistogramName, 1, 1); | |
143 | |
144 // Disable maximize mode | |
145 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
146 false); | |
147 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
148 target.get()); | |
149 histogram_tester_->ExpectBucketCount(kFormFactorHistogramName, 0, 1); | |
150 } | |
151 | |
152 // Verifies that down events dispatched to different destinations are recorded. | |
153 TEST_F(PointerMetricsRecorderTest, DownEventPerDestination) { | |
154 std::unique_ptr<views::Widget> target = | |
155 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
156 const ui::PointerEvent pointer_event( | |
157 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
158 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
159 base::TimeTicks()); | |
160 | |
161 WmWindow* window = WmWindow::Get(target->GetNativeWindow()); | |
162 CHECK(window); | |
163 | |
164 window->SetAppType(static_cast<int>(AppType::OTHERS)); | |
165 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
166 target.get()); | |
167 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 0, 1); | |
168 | |
169 window->SetAppType(static_cast<int>(AppType::BROWSER)); | |
170 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
171 target.get()); | |
172 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 1, 1); | |
173 | |
174 window->SetAppType(static_cast<int>(AppType::CHROME_APP)); | |
175 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
176 target.get()); | |
177 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 2, 1); | |
178 | |
179 window->SetAppType(static_cast<int>(AppType::ARC_APP)); | |
180 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
181 target.get()); | |
182 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 3, 1); | |
183 } | |
184 | |
185 } // namespace ash | |
OLD | NEW |