Include all dupe types (event when value is zero) in scan stats.
[chromium-blink-merge.git] / ash / metrics / task_switch_metrics_recorder_unittest.cc
blob90a0db1fe07d08d86bc45db92d135d167d433e16
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
3 // found in the LICENSE file.
5 #include "ash/metrics/task_switch_metrics_recorder.h"
7 #include "base/test/histogram_tester.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 namespace ash {
11 namespace {
13 // Test fixture for the TaskSwitchMetricsRecorder class.
14 class TaskSwitchMetricsRecorderTest : public testing::Test {
15 public:
16 TaskSwitchMetricsRecorderTest();
17 ~TaskSwitchMetricsRecorderTest() override;
19 // Wrapper to the test targets OnTaskSwitch(TaskSwitchSource) method.
20 void OnTaskSwitch(
21 TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source);
23 // testing::Test:
24 void SetUp() override;
25 void TearDown() override;
27 protected:
28 // Used to verify recorded data.
29 scoped_ptr<base::HistogramTester> histogram_tester_;
31 // The test target.
32 scoped_ptr<TaskSwitchMetricsRecorder> task_switch_metrics_recorder_;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(TaskSwitchMetricsRecorderTest);
38 TaskSwitchMetricsRecorderTest::TaskSwitchMetricsRecorderTest() {
41 TaskSwitchMetricsRecorderTest::~TaskSwitchMetricsRecorderTest() {
44 void TaskSwitchMetricsRecorderTest::OnTaskSwitch(
45 TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source) {
46 task_switch_metrics_recorder_->OnTaskSwitch(task_switch_source);
49 void TaskSwitchMetricsRecorderTest::SetUp() {
50 testing::Test::SetUp();
52 histogram_tester_.reset(new base::HistogramTester());
53 task_switch_metrics_recorder_.reset(new TaskSwitchMetricsRecorder());
56 void TaskSwitchMetricsRecorderTest::TearDown() {
57 testing::Test::TearDown();
59 histogram_tester_.reset();
60 task_switch_metrics_recorder_.reset();
63 } // namespace
65 // Verifies that the TaskSwitchMetricsRecorder::kWindowCycleController source
66 // adds data to the Ash.WindowCycleController.TimeBetweenTaskSwitches histogram.
67 TEST_F(TaskSwitchMetricsRecorderTest,
68 VerifyTaskSwitchesForWindowCycleControllerAreRecorded) {
69 const std::string kHistogramName =
70 "Ash.WindowCycleController.TimeBetweenTaskSwitches";
72 OnTaskSwitch(TaskSwitchMetricsRecorder::kWindowCycleController);
73 OnTaskSwitch(TaskSwitchMetricsRecorder::kWindowCycleController);
74 histogram_tester_->ExpectTotalCount(kHistogramName, 1);
76 OnTaskSwitch(TaskSwitchMetricsRecorder::kWindowCycleController);
77 histogram_tester_->ExpectTotalCount(kHistogramName, 2);
80 // Verifies that the TaskSwitchMetricsRecorder::kShelf source adds data to the
81 // Ash.Shelf.TimeBetweenNavigateToTaskSwitches histogram.
82 TEST_F(TaskSwitchMetricsRecorderTest,
83 VerifyTaskSwitchesFromTheShelfAreRecorded) {
84 const std::string kHistogramName =
85 "Ash.Shelf.TimeBetweenNavigateToTaskSwitches";
87 OnTaskSwitch(TaskSwitchMetricsRecorder::kShelf);
88 OnTaskSwitch(TaskSwitchMetricsRecorder::kShelf);
89 histogram_tester_->ExpectTotalCount(kHistogramName, 1);
91 OnTaskSwitch(TaskSwitchMetricsRecorder::kShelf);
92 histogram_tester_->ExpectTotalCount(kHistogramName, 2);
95 // Verifies that the TaskSwitchMetricsRecorder::kTabStrip source adds data to
96 // the Ash.Tab.TimeBetweenSwitchToExistingTabUserActions histogram.
97 TEST_F(TaskSwitchMetricsRecorderTest,
98 VerifyTaskSwitchesFromTheTabStripAreRecorded) {
99 const std::string kHistogramName =
100 "Ash.Tab.TimeBetweenSwitchToExistingTabUserActions";
102 OnTaskSwitch(TaskSwitchMetricsRecorder::kTabStrip);
103 OnTaskSwitch(TaskSwitchMetricsRecorder::kTabStrip);
104 histogram_tester_->ExpectTotalCount(kHistogramName, 1);
106 OnTaskSwitch(TaskSwitchMetricsRecorder::kTabStrip);
107 histogram_tester_->ExpectTotalCount(kHistogramName, 2);
110 // Verifies that the TaskSwitchMetricsRecorder::kOverviewMode source adds data
111 // to the Ash.WindowSelector.TimeBetweenActiveWindowChanges histogram.
112 TEST_F(TaskSwitchMetricsRecorderTest,
113 VerifyTaskSwitchesFromOverviewModeAreRecorded) {
114 const std::string kHistogramName =
115 "Ash.WindowSelector.TimeBetweenActiveWindowChanges";
117 OnTaskSwitch(TaskSwitchMetricsRecorder::kOverviewMode);
118 OnTaskSwitch(TaskSwitchMetricsRecorder::kOverviewMode);
119 histogram_tester_->ExpectTotalCount(kHistogramName, 1);
121 OnTaskSwitch(TaskSwitchMetricsRecorder::kOverviewMode);
122 histogram_tester_->ExpectTotalCount(kHistogramName, 2);
125 // Verifies that the TaskSwitchMetricsRecorder::kAppList source adds data to the
126 // Ash.AppList.TimeBetweenTaskSwitches histogram.
127 TEST_F(TaskSwitchMetricsRecorderTest,
128 VerifyTaskSwitchesFromApplistAreRecorded) {
129 const std::string kHistogramName = "Ash.AppList.TimeBetweenTaskSwitches";
131 OnTaskSwitch(TaskSwitchMetricsRecorder::kAppList);
132 OnTaskSwitch(TaskSwitchMetricsRecorder::kAppList);
133 histogram_tester_->ExpectTotalCount(kHistogramName, 1);
135 OnTaskSwitch(TaskSwitchMetricsRecorder::kAppList);
136 histogram_tester_->ExpectTotalCount(kHistogramName, 2);
139 } // namespace ash