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/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_shell.h" | |
| 10 #include "ash/shared/app_types.h" | |
| 11 #include "ash/test/ash_test_base.h" | |
| 12 #include "base/test/histogram_tester.h" | |
| 13 #include "ui/aura/client/aura_constants.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 // Used to verify recorded data. | |
| 39 std::unique_ptr<base::HistogramTester> histogram_tester_; | |
| 40 | |
| 41 // The test target. | |
| 42 std::unique_ptr<PointerMetricsRecorder> pointer_metrics_recorder_; | |
| 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 histogram_tester_.reset(); | |
| 60 pointer_metrics_recorder_.reset(); | |
| 61 test::AshTestBase::TearDown(); | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 66 // Verifies that histogram is not recorded when receiving events that are not | |
| 67 // down events. | |
| 68 TEST_F(PointerMetricsRecorderTest, NonDownEventsInAllPointerHistogram) { | |
| 69 std::unique_ptr<views::Widget> target = | |
| 70 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
| 71 const ui::PointerEvent pointer_event( | |
| 72 ui::ET_POINTER_UP, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 73 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
| 74 base::TimeTicks()); | |
| 75 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 76 target.get()); | |
| 77 | |
| 78 histogram_tester_->ExpectTotalCount(kFormFactorHistogramName, 0); | |
| 79 histogram_tester_->ExpectTotalCount(kInputHistogramName, 0); | |
| 80 histogram_tester_->ExpectTotalCount(kDestinationHistogramName, 0); | |
| 81 } | |
| 82 | |
| 83 // Verifies that down events from diffent input are recorded. | |
|
Daniel Erat
2016/09/27 19:15:10
nit: "different", s/input/inputs/
xiaoyinh(OOO Sep 11-29)
2016/09/29 20:37:43
Done.
| |
| 84 TEST_F(PointerMetricsRecorderTest, DownEventPerInput) { | |
| 85 std::unique_ptr<views::Widget> target = | |
| 86 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
| 87 | |
| 88 const ui::PointerEvent unkown_event( | |
|
Daniel Erat
2016/09/27 19:15:10
nit: "unknown"
xiaoyinh(OOO Sep 11-29)
2016/09/29 20:37:43
Done.
| |
| 89 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 90 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_UNKNOWN), | |
| 91 base::TimeTicks()); | |
| 92 pointer_metrics_recorder_->OnPointerEventObserved(unkown_event, gfx::Point(), | |
| 93 target.get()); | |
| 94 histogram_tester_->ExpectBucketCount(kInputHistogramName, 0, 1); | |
| 95 | |
| 96 const ui::PointerEvent mouse_event( | |
| 97 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 98 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
| 99 base::TimeTicks()); | |
| 100 pointer_metrics_recorder_->OnPointerEventObserved(mouse_event, gfx::Point(), | |
| 101 target.get()); | |
| 102 histogram_tester_->ExpectBucketCount(kInputHistogramName, 1, 1); | |
| 103 | |
| 104 const ui::PointerEvent stylus_event( | |
| 105 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 106 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_PEN), | |
| 107 base::TimeTicks()); | |
| 108 pointer_metrics_recorder_->OnPointerEventObserved(stylus_event, gfx::Point(), | |
| 109 target.get()); | |
| 110 histogram_tester_->ExpectBucketCount(kInputHistogramName, 2, 1); | |
| 111 | |
| 112 const ui::PointerEvent stylus_event2( | |
| 113 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 114 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_ERASER), | |
| 115 base::TimeTicks()); | |
| 116 pointer_metrics_recorder_->OnPointerEventObserved(stylus_event2, gfx::Point(), | |
| 117 target.get()); | |
| 118 histogram_tester_->ExpectBucketCount(kInputHistogramName, 2, 2); | |
| 119 | |
| 120 const ui::PointerEvent touch_event( | |
| 121 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 122 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH), | |
| 123 base::TimeTicks()); | |
| 124 pointer_metrics_recorder_->OnPointerEventObserved(touch_event, gfx::Point(), | |
| 125 target.get()); | |
| 126 histogram_tester_->ExpectBucketCount(kInputHistogramName, 3, 1); | |
| 127 } | |
| 128 | |
| 129 // Verifies that down events in different form factor are recorded. | |
|
Daniel Erat
2016/09/27 19:15:10
nit: s/factor/factors/
xiaoyinh(OOO Sep 11-29)
2016/09/29 20:37:43
Done.
| |
| 130 TEST_F(PointerMetricsRecorderTest, DownEventPerFormFactor) { | |
| 131 std::unique_ptr<views::Widget> target = | |
| 132 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
| 133 const ui::PointerEvent pointer_event( | |
| 134 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 135 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
| 136 base::TimeTicks()); | |
| 137 | |
| 138 // Enable maximize mode | |
| 139 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 140 true); | |
| 141 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 142 target.get()); | |
| 143 histogram_tester_->ExpectBucketCount(kFormFactorHistogramName, 1, 1); | |
| 144 | |
| 145 // Disable maximize mode | |
| 146 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
| 147 false); | |
| 148 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 149 target.get()); | |
| 150 histogram_tester_->ExpectBucketCount(kFormFactorHistogramName, 0, 1); | |
| 151 } | |
| 152 | |
| 153 // Verifies that down events dispatched to different destination are recorded. | |
|
Daniel Erat
2016/09/27 19:15:10
nit: s/destination/destinations/
xiaoyinh(OOO Sep 11-29)
2016/09/29 20:37:43
Done.
| |
| 154 TEST_F(PointerMetricsRecorderTest, DownEventPerDestination) { | |
| 155 std::unique_ptr<views::Widget> target = | |
| 156 CreateTestWidget(nullptr, kShellWindowId_DefaultContainer, gfx::Rect()); | |
| 157 const ui::PointerEvent pointer_event( | |
| 158 ui::ET_POINTER_DOWN, gfx::Point(), gfx::Point(), 0, 0, 0, | |
| 159 ui::PointerDetails(ui::EventPointerType::POINTER_TYPE_MOUSE), | |
| 160 base::TimeTicks()); | |
| 161 aura::Window* window = target.get()->GetNativeWindow(); | |
| 162 DCHECK(window); | |
| 163 | |
| 164 window->SetProperty(aura::client::kAppType, | |
| 165 static_cast<int>(AppType::OTHERS)); | |
| 166 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 167 target.get()); | |
| 168 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 0, 1); | |
| 169 | |
| 170 window->SetProperty(aura::client::kAppType, | |
| 171 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->SetProperty(aura::client::kAppType, | |
| 177 static_cast<int>(AppType::CHROME_APP)); | |
| 178 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 179 target.get()); | |
| 180 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 2, 1); | |
| 181 | |
| 182 window->SetProperty(aura::client::kAppType, | |
| 183 static_cast<int>(AppType::ARC_APP)); | |
| 184 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 185 target.get()); | |
| 186 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 3, 1); | |
| 187 | |
| 188 window->SetProperty(aura::client::kAppType, | |
| 189 static_cast<int>(AppType::DEFAULT_NOTE_TAKING_APP)); | |
| 190 pointer_metrics_recorder_->OnPointerEventObserved(pointer_event, gfx::Point(), | |
| 191 target.get()); | |
| 192 histogram_tester_->ExpectBucketCount(kDestinationHistogramName, 4, 1); | |
| 193 } | |
| 194 | |
| 195 } // namespace ash | |
| OLD | NEW |