Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(523)

Side by Side Diff: ash/metrics/user_metrics_recorder_unittest.cc

Issue 1093483002: Changed when the UMA metric Ash.NumberOfVisibleWindowsInPrimaryDisplay is recorded. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments from patch set 2. Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "ash/metrics/user_metrics_recorder.h"
6
7 #include "ash/shelf/shelf_layout_manager.h"
8 #include "ash/shell.h"
9 #include "ash/system/user/login_status.h"
10 #include "ash/test/ash_test_base.h"
11 #include "ash/test/test_system_tray_delegate.h"
12 #include "ash/test/user_metrics_recorder_test_api.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/test/histogram_tester.h"
15 #include "ui/aura/window.h"
16
17 namespace ash {
18 namespace {
19
20 const char kAsh_ShelfAlignmentOverTime[] = "Ash.ShelfAlignmentOverTime";
21
22 const char kAsh_NumberOfVisibleWindowsInPrimaryDisplay[] =
23 "Ash.NumberOfVisibleWindowsInPrimaryDisplay";
24
25 const char kAsh_ActiveWindowShowTypeOverTime[] =
26 "Ash.ActiveWindowShowTypeOverTime";
27
28 } // namespace
29
30 // Test fixture for the UserMetricsRecorder class.
31 class UserMetricsRecorderTest : public test::AshTestBase {
32 public:
33 UserMetricsRecorderTest();
34 ~UserMetricsRecorderTest() override;
35
36 void SetUp() override;
37 void TearDown() override;
38
39 // Sets the user login status.
40 void SetLoginStatus(user::LoginStatus login_status);
41
42 // Sets the current user session to be active in a multi window environment.
43 void SetUserActiveInMultiWindowEnvironment();
44
45 // Sets the current user session to be inactive in a multi window environment.
46 void SetUserNotActiveInMultiWindowEnvironment();
47
48 UserMetricsRecorder* user_metrics_recorder() {
49 return user_metrics_recorder_.get();
50 }
51
52 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() {
53 return user_metrics_recorder_test_api_.get();
54 }
55
56 base::HistogramTester& histograms() { return histograms_; }
57
58 private:
59 // The test target.
60 scoped_ptr<UserMetricsRecorder> user_metrics_recorder_;
61
62 // Test API to access private members of the test target.
63 scoped_ptr<test::UserMetricsRecorderTestAPI> user_metrics_recorder_test_api_;
64
65 // Histogram value verifier.
66 base::HistogramTester histograms_;
67
68 // The active SystemTrayDelegate. Not owned.
69 test::TestSystemTrayDelegate* test_system_tray_delegate_;
70
71 DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorderTest);
72 };
73
74 UserMetricsRecorderTest::UserMetricsRecorderTest() {
75 }
76
77 UserMetricsRecorderTest::~UserMetricsRecorderTest() {
78 }
79
80 void UserMetricsRecorderTest::SetUp() {
81 test::AshTestBase::SetUp();
82
83 user_metrics_recorder_.reset(
84 test::UserMetricsRecorderTestAPI::CreateUserMetricsRecorder(false)
85 .release());
86
87 user_metrics_recorder_test_api_.reset(
88 new test::UserMetricsRecorderTestAPI(user_metrics_recorder_.get()));
89
90 test_system_tray_delegate_ = GetSystemTrayDelegate();
91 }
92
93 void UserMetricsRecorderTest::TearDown() {
94 test_system_tray_delegate_ = nullptr;
95
96 // Make sure |user_metrics_recorder_test_api_| doesn't access
97 // |user_metrics_recorder_| after it's destructed.
98 user_metrics_recorder_test_api_.reset();
99 user_metrics_recorder_.reset();
100
101 test::AshTestBase::TearDown();
102 }
103
104 void UserMetricsRecorderTest::SetLoginStatus(user::LoginStatus login_status) {
105 test_system_tray_delegate_->SetLoginStatus(login_status);
106 }
107
108 void UserMetricsRecorderTest::SetUserActiveInMultiWindowEnvironment() {
pkotwicz 2015/04/21 16:15:17 Nit: I would make the method take a boolean.
bruthig 2015/04/24 20:00:11 Done.
109 SetLoginStatus(user::LOGGED_IN_USER);
110 ASSERT_TRUE(
111 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
112 }
113
114 void UserMetricsRecorderTest::SetUserNotActiveInMultiWindowEnvironment() {
115 SetLoginStatus(user::LOGGED_IN_LOCKED);
116 ASSERT_FALSE(
117 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
118 }
119
120 TEST_F(UserMetricsRecorderTest,
121 VerifyIsUserActiveInMultiWindowEnvironmentValues) {
122 SetLoginStatus(user::LOGGED_IN_NONE);
123 EXPECT_FALSE(
124 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
125
126 SetLoginStatus(user::LOGGED_IN_LOCKED);
127 EXPECT_FALSE(
128 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
129
130 SetLoginStatus(user::LOGGED_IN_USER);
131 EXPECT_TRUE(
132 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
133
134 SetLoginStatus(user::LOGGED_IN_OWNER);
135 EXPECT_TRUE(
136 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
137
138 SetLoginStatus(user::LOGGED_IN_GUEST);
139 EXPECT_TRUE(
140 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
141
142 SetLoginStatus(user::LOGGED_IN_PUBLIC);
143 EXPECT_TRUE(
144 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
145
146 SetLoginStatus(user::LOGGED_IN_SUPERVISED);
147 EXPECT_TRUE(
148 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
149
150 SetLoginStatus(user::LOGGED_IN_KIOSK_APP);
151 EXPECT_FALSE(
152 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment());
153 }
154
155 // Verifies that the stats dependent on the presence of a ShelfLayoutManager
156 // are recorded when a ShelfLayoutManager exists.
157 // TODO(bruthig): Add a test to verify the stats are not recorded when a
158 // ShelfLayoutManager does not exist. Consider investigating whether the
159 // conditional is necessary.
pkotwicz 2015/04/21 16:15:17 Remove the test given that we are unsure whether t
bruthig 2015/04/24 20:00:11 Done.
160 TEST_F(UserMetricsRecorderTest,
161 VerifyStatsRecordedWhenAShelfLayoutManagerExists) {
162 SetUserActiveInMultiWindowEnvironment();
163 ASSERT_TRUE(ShelfLayoutManager::ForShelf(Shell::GetPrimaryRootWindow()));
164 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
165
166 histograms().ExpectTotalCount(kAsh_ShelfAlignmentOverTime, 1);
167 }
168
169 // Verifies that the IsUserActive() dependent stats are not recorded when a
170 // user is not active.
pkotwicz 2015/04/21 16:15:17 Nit: Please update the test comment
bruthig 2015/04/24 20:00:11 Done.
171 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedWhenUserIsNotActive) {
172 SetUserNotActiveInMultiWindowEnvironment();
173 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
174
175 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 0);
176 }
177
178 // Verifies that the IsUserActive() dependent stats are recorded when a user
179 // is active.
pkotwicz 2015/04/21 16:15:17 Nit: Please update the test comment
bruthig 2015/04/24 20:00:12 Done.
180 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedWhenIsUserActive) {
181 SetUserActiveInMultiWindowEnvironment();
182 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
183
184 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 1);
185 }
186
187 // Verifies which stats are always recorded and are not dependent on conditional
188 // logic for when they are recorded.
pkotwicz 2015/04/21 16:15:17 How about: "Verifies recording of stats which are
bruthig 2015/04/24 20:00:11 Done.
189 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedByRecordPeriodicMetrics) {
190 SetUserActiveInMultiWindowEnvironment();
191 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
192
193 histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1);
194 }
195
196 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698