| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ash/common/shelf/shelf_button_pressed_metric_tracker.h" | 5 #include "ash/common/shelf/shelf_button_pressed_metric_tracker.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // AshTestBase: | 68 // AshTestBase: |
| 69 void SetUp() override; | 69 void SetUp() override; |
| 70 void TearDown() override; | 70 void TearDown() override; |
| 71 | 71 |
| 72 // Calls ButtonPressed on the test target with the given |event| | 72 // Calls ButtonPressed on the test target with the given |event| |
| 73 // and dummy values for the |sender| and |performed_action| parameters. | 73 // and dummy values for the |sender| and |performed_action| parameters. |
| 74 void ButtonPressed(const ui::Event& event); | 74 void ButtonPressed(const ui::Event& event); |
| 75 | 75 |
| 76 // Calls ButtonPressed on the test target with the given |performed_action| | 76 // Calls ButtonPressed on the test target with the given |performed_action| |
| 77 // and dummy values for the |event| and |sender| parameters. | 77 // and dummy values for the |event| and |sender| parameters. |
| 78 void ButtonPressed(ShelfItemDelegate::PerformedAction performed_action); | 78 void ButtonPressed(ShelfAction performed_action); |
| 79 | 79 |
| 80 // Calls ButtonPressed on the test target with the given |sender| and | 80 // Calls ButtonPressed on the test target with the given |sender| and |
| 81 // |performed_action| and a dummy value for the |event| parameter. | 81 // |performed_action| and a dummy value for the |event| parameter. |
| 82 void ButtonPressed(const views::Button* sender, | 82 void ButtonPressed(const views::Button* sender, ShelfAction performed_action); |
| 83 ShelfItemDelegate::PerformedAction performed_action); | |
| 84 | 83 |
| 85 protected: | 84 protected: |
| 86 // The test target. Not owned. | 85 // The test target. Not owned. |
| 87 ShelfButtonPressedMetricTracker* metric_tracker_; | 86 ShelfButtonPressedMetricTracker* metric_tracker_; |
| 88 | 87 |
| 89 // The TickClock injected in to the test target. | 88 // The TickClock injected in to the test target. |
| 90 base::SimpleTestTickClock* tick_clock_; | 89 base::SimpleTestTickClock* tick_clock_; |
| 91 | 90 |
| 92 private: | 91 private: |
| 93 DISALLOW_COPY_AND_ASSIGN(ShelfButtonPressedMetricTrackerTest); | 92 DISALLOW_COPY_AND_ASSIGN(ShelfButtonPressedMetricTrackerTest); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 124 | 123 |
| 125 void ShelfButtonPressedMetricTrackerTest::TearDown() { | 124 void ShelfButtonPressedMetricTrackerTest::TearDown() { |
| 126 tick_clock_ = nullptr; | 125 tick_clock_ = nullptr; |
| 127 | 126 |
| 128 AshTestBase::TearDown(); | 127 AshTestBase::TearDown(); |
| 129 } | 128 } |
| 130 | 129 |
| 131 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( | 130 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( |
| 132 const ui::Event& event) { | 131 const ui::Event& event) { |
| 133 const DummyButton kDummyButton; | 132 const DummyButton kDummyButton; |
| 134 metric_tracker_->ButtonPressed(event, &kDummyButton, | 133 metric_tracker_->ButtonPressed(event, &kDummyButton, kNoAction); |
| 135 ShelfItemDelegate::kNoAction); | |
| 136 } | 134 } |
| 137 | 135 |
| 138 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( | 136 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( |
| 139 ShelfItemDelegate::PerformedAction performed_action) { | 137 ShelfAction performed_action) { |
| 140 const DummyEvent kDummyEvent; | 138 const DummyEvent kDummyEvent; |
| 141 const DummyButton kDummyButton; | 139 const DummyButton kDummyButton; |
| 142 metric_tracker_->ButtonPressed(kDummyEvent, &kDummyButton, performed_action); | 140 metric_tracker_->ButtonPressed(kDummyEvent, &kDummyButton, performed_action); |
| 143 } | 141 } |
| 144 | 142 |
| 145 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( | 143 void ShelfButtonPressedMetricTrackerTest::ButtonPressed( |
| 146 const views::Button* sender, | 144 const views::Button* sender, |
| 147 ShelfItemDelegate::PerformedAction performed_action) { | 145 ShelfAction performed_action) { |
| 148 const DummyEvent kDummyEvent; | 146 const DummyEvent kDummyEvent; |
| 149 metric_tracker_->ButtonPressed(kDummyEvent, sender, performed_action); | 147 metric_tracker_->ButtonPressed(kDummyEvent, sender, performed_action); |
| 150 } | 148 } |
| 151 | 149 |
| 152 } // namespace | 150 } // namespace |
| 153 | 151 |
| 154 // Verifies that a Launcher_ButtonPressed_Mouse UMA user action is recorded when | 152 // Verifies that a Launcher_ButtonPressed_Mouse UMA user action is recorded when |
| 155 // a button is pressed by a mouse event. | 153 // a button is pressed by a mouse event. |
| 156 TEST_F(ShelfButtonPressedMetricTrackerTest, | 154 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 157 Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByMouse) { | 155 Launcher_ButtonPressed_MouseIsRecordedWhenIconActivatedByMouse) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 175 ButtonPressed(touch_event); | 173 ButtonPressed(touch_event); |
| 176 EXPECT_EQ(1, | 174 EXPECT_EQ(1, |
| 177 user_action_tester.GetActionCount("Launcher_ButtonPressed_Touch")); | 175 user_action_tester.GetActionCount("Launcher_ButtonPressed_Touch")); |
| 178 } | 176 } |
| 179 | 177 |
| 180 // Verifies that a Launcher_LaunchTask UMA user action is recorded when | 178 // Verifies that a Launcher_LaunchTask UMA user action is recorded when |
| 181 // pressing a button causes a new window to be created. | 179 // pressing a button causes a new window to be created. |
| 182 TEST_F(ShelfButtonPressedMetricTrackerTest, | 180 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 183 Launcher_LaunchTaskIsRecordedWhenNewWindowIsCreated) { | 181 Launcher_LaunchTaskIsRecordedWhenNewWindowIsCreated) { |
| 184 base::UserActionTester user_action_tester; | 182 base::UserActionTester user_action_tester; |
| 185 ButtonPressed(ShelfItemDelegate::kNewWindowCreated); | 183 ButtonPressed(kNewWindowCreated); |
| 186 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask")); | 184 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_LaunchTask")); |
| 187 } | 185 } |
| 188 | 186 |
| 189 // Verifies that a Launcher_MinimizeTask UMA user action is recorded when | 187 // Verifies that a Launcher_MinimizeTask UMA user action is recorded when |
| 190 // pressing a button causes an existing window to be minimized. | 188 // pressing a button causes an existing window to be minimized. |
| 191 TEST_F(ShelfButtonPressedMetricTrackerTest, | 189 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 192 Launcher_MinimizeTaskIsRecordedWhenWindowIsMinimized) { | 190 Launcher_MinimizeTaskIsRecordedWhenWindowIsMinimized) { |
| 193 base::UserActionTester user_action_tester; | 191 base::UserActionTester user_action_tester; |
| 194 ButtonPressed(ShelfItemDelegate::kExistingWindowMinimized); | 192 ButtonPressed(kExistingWindowMinimized); |
| 195 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_MinimizeTask")); | 193 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_MinimizeTask")); |
| 196 } | 194 } |
| 197 | 195 |
| 198 // Verifies that a Launcher_SwitchTask UMA user action is recorded when | 196 // Verifies that a Launcher_SwitchTask UMA user action is recorded when |
| 199 // pressing a button causes an existing window to be activated. | 197 // pressing a button causes an existing window to be activated. |
| 200 TEST_F(ShelfButtonPressedMetricTrackerTest, | 198 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 201 Launcher_SwitchTaskIsRecordedWhenExistingWindowIsActivated) { | 199 Launcher_SwitchTaskIsRecordedWhenExistingWindowIsActivated) { |
| 202 base::UserActionTester user_action_tester; | 200 base::UserActionTester user_action_tester; |
| 203 ButtonPressed(ShelfItemDelegate::kExistingWindowActivated); | 201 ButtonPressed(kExistingWindowActivated); |
| 204 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_SwitchTask")); | 202 EXPECT_EQ(1, user_action_tester.GetActionCount("Launcher_SwitchTask")); |
| 205 } | 203 } |
| 206 | 204 |
| 207 // Verify that a window activation action will record a data point if it was | 205 // Verify that a window activation action will record a data point if it was |
| 208 // subsequent to a minimize action. | 206 // subsequent to a minimize action. |
| 209 TEST_F(ShelfButtonPressedMetricTrackerTest, | 207 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 210 VerifyDataRecordedAfterMinimizedAndSubsequentActivatedAction) { | 208 VerifyDataRecordedAfterMinimizedAndSubsequentActivatedAction) { |
| 211 const DummyButton kDummyButton; | 209 const DummyButton kDummyButton; |
| 212 | 210 |
| 213 base::HistogramTester histogram_tester; | 211 base::HistogramTester histogram_tester; |
| 214 | 212 |
| 215 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowMinimized); | 213 ButtonPressed(&kDummyButton, kExistingWindowMinimized); |
| 216 histogram_tester.ExpectTotalCount( | 214 histogram_tester.ExpectTotalCount( |
| 217 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); | 215 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); |
| 218 | 216 |
| 219 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | 217 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 220 histogram_tester.ExpectTotalCount( | 218 histogram_tester.ExpectTotalCount( |
| 221 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); | 219 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); |
| 222 } | 220 } |
| 223 | 221 |
| 224 // Verify that a multiple window activation actions will record a single data | 222 // Verify that a multiple window activation actions will record a single data |
| 225 // point if they are subsequent to a minimize action. | 223 // point if they are subsequent to a minimize action. |
| 226 TEST_F(ShelfButtonPressedMetricTrackerTest, | 224 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 227 VerifyDataRecordedAfterMinimizedAndMultipleSubsequentActivatedActions) { | 225 VerifyDataRecordedAfterMinimizedAndMultipleSubsequentActivatedActions) { |
| 228 const DummyButton kDummyButton; | 226 const DummyButton kDummyButton; |
| 229 | 227 |
| 230 base::HistogramTester histogram_tester; | 228 base::HistogramTester histogram_tester; |
| 231 | 229 |
| 232 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowMinimized); | 230 ButtonPressed(&kDummyButton, kExistingWindowMinimized); |
| 233 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | 231 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 234 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | 232 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 235 | 233 |
| 236 histogram_tester.ExpectTotalCount( | 234 histogram_tester.ExpectTotalCount( |
| 237 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); | 235 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); |
| 238 } | 236 } |
| 239 | 237 |
| 240 // Verify that a window activation action will not record a data point if it was | 238 // Verify that a window activation action will not record a data point if it was |
| 241 // not subsequent to a minimize action. | 239 // not subsequent to a minimize action. |
| 242 TEST_F(ShelfButtonPressedMetricTrackerTest, | 240 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 243 VerifyDataRecordedAfterMinimizedAndNonSubsequentActivatedAction) { | 241 VerifyDataRecordedAfterMinimizedAndNonSubsequentActivatedAction) { |
| 244 const DummyButton kDummyButton; | 242 const DummyButton kDummyButton; |
| 245 | 243 |
| 246 base::HistogramTester histogram_tester; | 244 base::HistogramTester histogram_tester; |
| 247 | 245 |
| 248 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowMinimized); | 246 ButtonPressed(&kDummyButton, kExistingWindowMinimized); |
| 249 ButtonPressed(&kDummyButton, ShelfItemDelegate::kAppListMenuShown); | 247 ButtonPressed(&kDummyButton, kAppListMenuShown); |
| 250 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | 248 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 251 | 249 |
| 252 histogram_tester.ExpectTotalCount( | 250 histogram_tester.ExpectTotalCount( |
| 253 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); | 251 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); |
| 254 } | 252 } |
| 255 | 253 |
| 256 // Verify no data is recorded if a second source button is pressed in between | 254 // Verify no data is recorded if a second source button is pressed in between |
| 257 // subsequent minimized and activated actions on the same source. | 255 // subsequent minimized and activated actions on the same source. |
| 258 TEST_F(ShelfButtonPressedMetricTrackerTest, | 256 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 259 VerifyDataRecordedAfterMinimizedButtonA) { | 257 VerifyDataRecordedAfterMinimizedButtonA) { |
| 260 const DummyButton kDummyButton; | 258 const DummyButton kDummyButton; |
| 261 const DummyButton kSecondDummyButton; | 259 const DummyButton kSecondDummyButton; |
| 262 | 260 |
| 263 base::HistogramTester histogram_tester; | 261 base::HistogramTester histogram_tester; |
| 264 | 262 |
| 265 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowMinimized); | 263 ButtonPressed(&kDummyButton, kExistingWindowMinimized); |
| 266 ButtonPressed(&kSecondDummyButton, | 264 ButtonPressed(&kSecondDummyButton, kExistingWindowMinimized); |
| 267 ShelfItemDelegate::kExistingWindowMinimized); | 265 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 268 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | |
| 269 | 266 |
| 270 histogram_tester.ExpectTotalCount( | 267 histogram_tester.ExpectTotalCount( |
| 271 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); | 268 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 0); |
| 272 } | 269 } |
| 273 | 270 |
| 274 // Verify the data value recorded when a window activation action is subsequent | 271 // Verify the data value recorded when a window activation action is subsequent |
| 275 // to a minimize action. | 272 // to a minimize action. |
| 276 TEST_F(ShelfButtonPressedMetricTrackerTest, | 273 TEST_F(ShelfButtonPressedMetricTrackerTest, |
| 277 VerifyTheValueRecordedBySubsequentMinimizedAndActivateActions) { | 274 VerifyTheValueRecordedBySubsequentMinimizedAndActivateActions) { |
| 278 const int kTimeDeltaInMilliseconds = 17; | 275 const int kTimeDeltaInMilliseconds = 17; |
| 279 const DummyButton kDummyButton; | 276 const DummyButton kDummyButton; |
| 280 | 277 |
| 281 base::HistogramTester histogram_tester; | 278 base::HistogramTester histogram_tester; |
| 282 | 279 |
| 283 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowMinimized); | 280 ButtonPressed(&kDummyButton, kExistingWindowMinimized); |
| 284 tick_clock_->Advance( | 281 tick_clock_->Advance( |
| 285 base::TimeDelta::FromMilliseconds(kTimeDeltaInMilliseconds)); | 282 base::TimeDelta::FromMilliseconds(kTimeDeltaInMilliseconds)); |
| 286 ButtonPressed(&kDummyButton, ShelfItemDelegate::kExistingWindowActivated); | 283 ButtonPressed(&kDummyButton, kExistingWindowActivated); |
| 287 | 284 |
| 288 histogram_tester.ExpectTotalCount( | 285 histogram_tester.ExpectTotalCount( |
| 289 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); | 286 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, 1); |
| 290 histogram_tester.ExpectBucketCount( | 287 histogram_tester.ExpectBucketCount( |
| 291 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, | 288 kTimeBetweenWindowMinimizedAndActivatedActionsHistogramName, |
| 292 kTimeDeltaInMilliseconds, 1); | 289 kTimeDeltaInMilliseconds, 1); |
| 293 } | 290 } |
| 294 | 291 |
| 295 } // namespace test | 292 } // namespace test |
| 296 } // namespace ash | 293 } // namespace ash |
| OLD | NEW |