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