OLD | NEW |
---|---|
(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" | |
pkotwicz
2015/04/25 00:16:53
Nit: You can remove this include?
bruthig
2015/04/27 15:22:21
Done.
| |
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_NumberOfVisibleWindowsInPrimaryDisplay[] = | |
21 "Ash.NumberOfVisibleWindowsInPrimaryDisplay"; | |
22 | |
23 const char kAsh_ActiveWindowShowTypeOverTime[] = | |
24 "Ash.ActiveWindowShowTypeOverTime"; | |
25 | |
26 } // namespace | |
27 | |
28 // Test fixture for the UserMetricsRecorder class. | |
29 class UserMetricsRecorderTest : public test::AshTestBase { | |
30 public: | |
31 UserMetricsRecorderTest(); | |
32 ~UserMetricsRecorderTest() override; | |
33 | |
oshima
2015/04/25 01:06:58
nit: // test::AshTestBase:
bruthig
2015/04/27 15:22:21
Done.
| |
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 (in)active in a multi window | |
pkotwicz
2015/04/25 00:16:53
Nit: I think that "active or inactive" is clearer
bruthig
2015/04/27 15:22:21
Done.
| |
41 // environment. | |
42 void SetUserActiveInMultiWindowEnvironment(bool is_active); | |
43 | |
pkotwicz
2015/04/25 00:16:53
I don't think that you use this method
bruthig
2015/04/27 15:22:21
Done.
| |
44 UserMetricsRecorder* user_metrics_recorder() { | |
45 return user_metrics_recorder_.get(); | |
46 } | |
oshima
2015/04/25 01:06:58
This seems to be unused?
bruthig
2015/04/27 15:22:21
Done.
| |
47 | |
48 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() { | |
49 return user_metrics_recorder_test_api_.get(); | |
50 } | |
51 | |
52 base::HistogramTester& histograms() { return histograms_; } | |
53 | |
54 private: | |
55 // The test target. | |
56 scoped_ptr<UserMetricsRecorder> user_metrics_recorder_; | |
57 | |
58 // Test API to access private members of the test target. | |
59 scoped_ptr<test::UserMetricsRecorderTestAPI> user_metrics_recorder_test_api_; | |
60 | |
61 // Histogram value verifier. | |
62 base::HistogramTester histograms_; | |
63 | |
64 // The active SystemTrayDelegate. Not owned. | |
65 test::TestSystemTrayDelegate* test_system_tray_delegate_; | |
66 | |
67 DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorderTest); | |
68 }; | |
69 | |
70 UserMetricsRecorderTest::UserMetricsRecorderTest() { | |
71 } | |
72 | |
73 UserMetricsRecorderTest::~UserMetricsRecorderTest() { | |
74 } | |
75 | |
76 void UserMetricsRecorderTest::SetUp() { | |
77 test::AshTestBase::SetUp(); | |
78 | |
79 user_metrics_recorder_.reset( | |
80 test::UserMetricsRecorderTestAPI::CreateUserMetricsRecorder(false) | |
81 .release()); | |
82 | |
83 user_metrics_recorder_test_api_.reset( | |
84 new test::UserMetricsRecorderTestAPI(user_metrics_recorder_.get())); | |
oshima
2015/04/25 01:06:58
what's the benefit of creating recorder, then crea
bruthig
2015/04/27 15:22:21
Done.
| |
85 | |
86 test_system_tray_delegate_ = GetSystemTrayDelegate(); | |
87 } | |
88 | |
89 void UserMetricsRecorderTest::TearDown() { | |
90 test_system_tray_delegate_ = nullptr; | |
91 | |
92 // Make sure |user_metrics_recorder_test_api_| doesn't access | |
93 // |user_metrics_recorder_| after it's destructed. | |
94 user_metrics_recorder_test_api_.reset(); | |
95 user_metrics_recorder_.reset(); | |
96 | |
97 test::AshTestBase::TearDown(); | |
98 } | |
99 | |
100 void UserMetricsRecorderTest::SetLoginStatus(user::LoginStatus login_status) { | |
101 test_system_tray_delegate_->SetLoginStatus(login_status); | |
102 } | |
103 | |
104 void UserMetricsRecorderTest::SetUserActiveInMultiWindowEnvironment( | |
105 bool is_active) { | |
106 if (is_active) { | |
107 SetLoginStatus(user::LOGGED_IN_USER); | |
108 ASSERT_TRUE(user_metrics_recorder_test_api() | |
109 ->IsUserActiveInMultiWindowEnvironment()); | |
110 } else { | |
111 SetLoginStatus(user::LOGGED_IN_LOCKED); | |
112 ASSERT_FALSE(user_metrics_recorder_test_api() | |
113 ->IsUserActiveInMultiWindowEnvironment()); | |
114 } | |
115 } | |
116 | |
117 TEST_F(UserMetricsRecorderTest, | |
118 VerifyIsUserActiveInMultiWindowEnvironmentValues) { | |
119 SetLoginStatus(user::LOGGED_IN_NONE); | |
120 EXPECT_FALSE( | |
121 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
122 | |
123 SetLoginStatus(user::LOGGED_IN_LOCKED); | |
124 EXPECT_FALSE( | |
125 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
126 | |
127 SetLoginStatus(user::LOGGED_IN_USER); | |
128 EXPECT_TRUE( | |
129 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
130 | |
131 SetLoginStatus(user::LOGGED_IN_OWNER); | |
132 EXPECT_TRUE( | |
133 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
134 | |
135 SetLoginStatus(user::LOGGED_IN_GUEST); | |
136 EXPECT_TRUE( | |
137 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
138 | |
139 SetLoginStatus(user::LOGGED_IN_PUBLIC); | |
140 EXPECT_TRUE( | |
141 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
142 | |
143 SetLoginStatus(user::LOGGED_IN_SUPERVISED); | |
144 EXPECT_TRUE( | |
145 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
146 | |
147 SetLoginStatus(user::LOGGED_IN_KIOSK_APP); | |
148 EXPECT_FALSE( | |
149 user_metrics_recorder_test_api()->IsUserActiveInMultiWindowEnvironment()); | |
150 } | |
151 | |
152 // Verifies that the IsUserActive() dependent stats are not recorded when a | |
153 // user is not active. | |
154 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedWhenUserIsNotActive) { | |
155 SetUserActiveInMultiWindowEnvironment(false); | |
156 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); | |
157 | |
158 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 0); | |
159 } | |
160 | |
161 // Verifies that the IsUserActive() dependent stats are recorded when a user | |
162 // is active. | |
163 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedWhenIsUserActive) { | |
164 SetUserActiveInMultiWindowEnvironment(true); | |
165 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); | |
166 | |
167 histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 1); | |
168 } | |
169 | |
170 // Verifies recording of stats which are always recorded by | |
171 // RecordPeriodicMetrics. | |
172 TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedByRecordPeriodicMetrics) { | |
173 SetUserActiveInMultiWindowEnvironment(true); | |
174 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); | |
175 | |
176 histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1); | |
177 } | |
178 | |
179 } // namespace ash | |
OLD | NEW |