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

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 4. 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
« no previous file with comments | « ash/metrics/user_metrics_recorder.cc ('k') | ash/test/user_metrics_recorder_test_api.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/shell.h"
8 #include "ash/system/user/login_status.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/test_system_tray_delegate.h"
11 #include "ash/test/user_metrics_recorder_test_api.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/test/histogram_tester.h"
14 #include "ui/aura/window.h"
15
16 namespace ash {
17 namespace {
18
19 const char kAsh_NumberOfVisibleWindowsInPrimaryDisplay[] =
20 "Ash.NumberOfVisibleWindowsInPrimaryDisplay";
21
22 const char kAsh_ActiveWindowShowTypeOverTime[] =
23 "Ash.ActiveWindowShowTypeOverTime";
24
25 } // namespace
26
27 // Test fixture for the UserMetricsRecorder class.
28 class UserMetricsRecorderTest : public test::AshTestBase {
29 public:
30 UserMetricsRecorderTest();
31 ~UserMetricsRecorderTest() override;
32
33 // test::AshTestBase:
34 void SetUp() override;
35 void TearDown() override;
36
37 // Sets the user login status.
38 void SetLoginStatus(user::LoginStatus login_status);
39
40 // Sets the current user session to be active or inactive in a desktop
41 // environment.
42 void SetUserInActiveDesktopEnvironment(bool is_active);
43
44 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() {
45 return user_metrics_recorder_test_api_.get();
46 }
47
48 base::HistogramTester& histograms() { return histograms_; }
49
50 private:
51 // Test API to access private members of the test target.
52 scoped_ptr<test::UserMetricsRecorderTestAPI> user_metrics_recorder_test_api_;
53
54 // Histogram value verifier.
55 base::HistogramTester histograms_;
56
57 // The active SystemTrayDelegate. Not owned.
58 test::TestSystemTrayDelegate* test_system_tray_delegate_;
59
60 DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorderTest);
61 };
62
63 UserMetricsRecorderTest::UserMetricsRecorderTest() {
64 }
65
66 UserMetricsRecorderTest::~UserMetricsRecorderTest() {
67 }
68
69 void UserMetricsRecorderTest::SetUp() {
70 test::AshTestBase::SetUp();
71 user_metrics_recorder_test_api_.reset(new test::UserMetricsRecorderTestAPI());
72 test_system_tray_delegate_ = GetSystemTrayDelegate();
73 }
74
75 void UserMetricsRecorderTest::TearDown() {
76 test_system_tray_delegate_ = nullptr;
77 test::AshTestBase::TearDown();
78 }
79
80 void UserMetricsRecorderTest::SetLoginStatus(user::LoginStatus login_status) {
81 test_system_tray_delegate_->SetLoginStatus(login_status);
82 }
83
84 void UserMetricsRecorderTest::SetUserInActiveDesktopEnvironment(
85 bool is_active) {
86 if (is_active) {
87 SetLoginStatus(user::LOGGED_IN_USER);
88 ASSERT_TRUE(
89 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
90 } else {
91 SetLoginStatus(user::LOGGED_IN_LOCKED);
92 ASSERT_FALSE(
93 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
94 }
95 }
96
97 // Verifies the return value of IsUserInActiveDesktopEnvironment() for the
98 // different login status values.
99 TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) {
100 SetLoginStatus(user::LOGGED_IN_NONE);
101 EXPECT_FALSE(
102 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
103
104 SetLoginStatus(user::LOGGED_IN_LOCKED);
105 EXPECT_FALSE(
106 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
107
108 SetLoginStatus(user::LOGGED_IN_USER);
109 EXPECT_TRUE(
110 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
111
112 SetLoginStatus(user::LOGGED_IN_OWNER);
113 EXPECT_TRUE(
114 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
115
116 SetLoginStatus(user::LOGGED_IN_GUEST);
117 EXPECT_TRUE(
118 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
119
120 SetLoginStatus(user::LOGGED_IN_PUBLIC);
121 EXPECT_TRUE(
122 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
123
124 SetLoginStatus(user::LOGGED_IN_SUPERVISED);
125 EXPECT_TRUE(
126 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
127
128 SetLoginStatus(user::LOGGED_IN_KIOSK_APP);
129 EXPECT_FALSE(
130 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
131 }
132
133 // Verifies that the IsUserInActiveDesktopEnvironment() dependent stats are not
134 // recorded when a user is not active in a desktop environment.
135 TEST_F(UserMetricsRecorderTest,
136 VerifyStatsRecordedWhenUserNotInActiveDesktopEnvironment) {
137 SetUserInActiveDesktopEnvironment(false);
138 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
139
140 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 0);
141 }
142
143 // Verifies that the IsUserInActiveDesktopEnvironment() dependent stats are
144 // recorded when a user is active in a desktop environment.
145 TEST_F(UserMetricsRecorderTest,
146 VerifyStatsRecordedWhenUserInActiveDesktopEnvironment) {
147 SetUserInActiveDesktopEnvironment(true);
148 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
149
150 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 1);
151 }
152
153 // Verifies recording of stats which are always recorded by
154 // RecordPeriodicMetrics.
155 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedByRecordPeriodicMetrics) {
156 SetUserInActiveDesktopEnvironment(true);
157 user_metrics_recorder_test_api()->RecordPeriodicMetrics();
158
159 histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1);
160 }
161
162 } // namespace ash
OLDNEW
« no previous file with comments | « ash/metrics/user_metrics_recorder.cc ('k') | ash/test/user_metrics_recorder_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698