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"
13 // Test fixture for the TaskSwitchMetricsRecorder class.
14 class TaskSwitchMetricsRecorderTest
: public testing::Test
{
16 TaskSwitchMetricsRecorderTest();
17 ~TaskSwitchMetricsRecorderTest() override
;
19 // Wrapper to the test targets OnTaskSwitch(TaskSwitchSource) method.
21 TaskSwitchMetricsRecorder::TaskSwitchSource task_switch_source
);
24 void SetUp() override
;
25 void TearDown() override
;
28 // Used to verify recorded data.
29 scoped_ptr
<base::HistogramTester
> histogram_tester_
;
32 scoped_ptr
<TaskSwitchMetricsRecorder
> task_switch_metrics_recorder_
;
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();
65 // Verifies that task switches from a non ANY source also add data to the
66 // Ash.TimeBetweenTaskSwitches histogram.
67 TEST_F(TaskSwitchMetricsRecorderTest
,
68 VerifyTaskSwitchesRecordInAllTaskSwitchHistogram
) {
69 const std::string kHistogramName
= "Ash.TimeBetweenTaskSwitches";
71 OnTaskSwitch(TaskSwitchMetricsRecorder::SHELF
);
72 OnTaskSwitch(TaskSwitchMetricsRecorder::SHELF
);
73 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
76 // Verifies that the TaskSwitchMetricsRecorder::DESKTOP source adds data to the
77 // Ash.Desktop.TimeBetweenNavigateToTaskSwitches histogram.
78 TEST_F(TaskSwitchMetricsRecorderTest
, VerifyTaskSwitchesForDesktopAreRecorded
) {
79 const std::string kHistogramName
=
80 "Ash.Desktop.TimeBetweenNavigateToTaskSwitches";
82 OnTaskSwitch(TaskSwitchMetricsRecorder::DESKTOP
);
83 OnTaskSwitch(TaskSwitchMetricsRecorder::DESKTOP
);
84 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
86 OnTaskSwitch(TaskSwitchMetricsRecorder::DESKTOP
);
87 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);
90 // Verifies that the TaskSwitchMetricsRecorder::WINDOW_CYCLE_CONTROLLER source
91 // adds data to the Ash.WindowCycleController.TimeBetweenTaskSwitches histogram.
92 TEST_F(TaskSwitchMetricsRecorderTest
,
93 VerifyTaskSwitchesForWindowCycleControllerAreRecorded
) {
94 const std::string kHistogramName
=
95 "Ash.WindowCycleController.TimeBetweenTaskSwitches";
97 OnTaskSwitch(TaskSwitchMetricsRecorder::WINDOW_CYCLE_CONTROLLER
);
98 OnTaskSwitch(TaskSwitchMetricsRecorder::WINDOW_CYCLE_CONTROLLER
);
99 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
101 OnTaskSwitch(TaskSwitchMetricsRecorder::WINDOW_CYCLE_CONTROLLER
);
102 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);
105 // Verifies that the TaskSwitchMetricsRecorder::SHELF source adds data to the
106 // Ash.Shelf.TimeBetweenNavigateToTaskSwitches histogram.
107 TEST_F(TaskSwitchMetricsRecorderTest
,
108 VerifyTaskSwitchesFromTheShelfAreRecorded
) {
109 const std::string kHistogramName
=
110 "Ash.Shelf.TimeBetweenNavigateToTaskSwitches";
112 OnTaskSwitch(TaskSwitchMetricsRecorder::SHELF
);
113 OnTaskSwitch(TaskSwitchMetricsRecorder::SHELF
);
114 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
116 OnTaskSwitch(TaskSwitchMetricsRecorder::SHELF
);
117 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);
120 // Verifies that the TaskSwitchMetricsRecorder::TAB_STRIP source adds data to
121 // the Ash.Tab.TimeBetweenSwitchToExistingTabUserActions histogram.
122 TEST_F(TaskSwitchMetricsRecorderTest
,
123 VerifyTaskSwitchesFromTheTabStripAreRecorded
) {
124 const std::string kHistogramName
=
125 "Ash.Tab.TimeBetweenSwitchToExistingTabUserActions";
127 OnTaskSwitch(TaskSwitchMetricsRecorder::TAB_STRIP
);
128 OnTaskSwitch(TaskSwitchMetricsRecorder::TAB_STRIP
);
129 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
131 OnTaskSwitch(TaskSwitchMetricsRecorder::TAB_STRIP
);
132 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);
135 // Verifies that the TaskSwitchMetricsRecorder::OVERVIEW_MODE source adds data
136 // to the Ash.WindowSelector.TimeBetweenActiveWindowChanges histogram.
137 TEST_F(TaskSwitchMetricsRecorderTest
,
138 VerifyTaskSwitchesFromOverviewModeAreRecorded
) {
139 const std::string kHistogramName
=
140 "Ash.WindowSelector.TimeBetweenActiveWindowChanges";
142 OnTaskSwitch(TaskSwitchMetricsRecorder::OVERVIEW_MODE
);
143 OnTaskSwitch(TaskSwitchMetricsRecorder::OVERVIEW_MODE
);
144 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
146 OnTaskSwitch(TaskSwitchMetricsRecorder::OVERVIEW_MODE
);
147 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);
150 // Verifies that the TaskSwitchMetricsRecorder::APP_LIST source adds data to the
151 // Ash.AppList.TimeBetweenTaskSwitches histogram.
152 TEST_F(TaskSwitchMetricsRecorderTest
,
153 VerifyTaskSwitchesFromApplistAreRecorded
) {
154 const std::string kHistogramName
= "Ash.AppList.TimeBetweenTaskSwitches";
156 OnTaskSwitch(TaskSwitchMetricsRecorder::APP_LIST
);
157 OnTaskSwitch(TaskSwitchMetricsRecorder::APP_LIST
);
158 histogram_tester_
->ExpectTotalCount(kHistogramName
, 1);
160 OnTaskSwitch(TaskSwitchMetricsRecorder::APP_LIST
);
161 histogram_tester_
->ExpectTotalCount(kHistogramName
, 2);