OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/metrics/user_metrics_recorder.h" | 5 #include "ash/metrics/user_metrics_recorder.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
10 #include "ash/shelf/shelf_util.h" | 10 #include "ash/shelf/shelf_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 class UserMetricsRecorderTest : public test::AshTestBase { | 39 class UserMetricsRecorderTest : public test::AshTestBase { |
40 public: | 40 public: |
41 UserMetricsRecorderTest(); | 41 UserMetricsRecorderTest(); |
42 ~UserMetricsRecorderTest() override; | 42 ~UserMetricsRecorderTest() override; |
43 | 43 |
44 // test::AshTestBase: | 44 // test::AshTestBase: |
45 void SetUp() override; | 45 void SetUp() override; |
46 void TearDown() override; | 46 void TearDown() override; |
47 | 47 |
48 // Sets the user login status. | 48 // Sets the user login status. |
49 void SetLoginStatus(user::LoginStatus login_status); | 49 void SetLoginStatus(LoginStatus login_status); |
50 | 50 |
51 // Sets the current user session to be active or inactive in a desktop | 51 // Sets the current user session to be active or inactive in a desktop |
52 // environment. | 52 // environment. |
53 void SetUserInActiveDesktopEnvironment(bool is_active); | 53 void SetUserInActiveDesktopEnvironment(bool is_active); |
54 | 54 |
55 // Creates an aura::Window. | 55 // Creates an aura::Window. |
56 aura::Window* CreateTestWindow(); | 56 aura::Window* CreateTestWindow(); |
57 | 57 |
58 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() { | 58 test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() { |
59 return user_metrics_recorder_test_api_.get(); | 59 return user_metrics_recorder_test_api_.get(); |
(...skipping 25 matching lines...) Expand all Loading... |
85 test::AshTestBase::SetUp(); | 85 test::AshTestBase::SetUp(); |
86 user_metrics_recorder_test_api_.reset(new test::UserMetricsRecorderTestAPI()); | 86 user_metrics_recorder_test_api_.reset(new test::UserMetricsRecorderTestAPI()); |
87 test_system_tray_delegate_ = GetSystemTrayDelegate(); | 87 test_system_tray_delegate_ = GetSystemTrayDelegate(); |
88 } | 88 } |
89 | 89 |
90 void UserMetricsRecorderTest::TearDown() { | 90 void UserMetricsRecorderTest::TearDown() { |
91 test_system_tray_delegate_ = nullptr; | 91 test_system_tray_delegate_ = nullptr; |
92 test::AshTestBase::TearDown(); | 92 test::AshTestBase::TearDown(); |
93 } | 93 } |
94 | 94 |
95 void UserMetricsRecorderTest::SetLoginStatus(user::LoginStatus login_status) { | 95 void UserMetricsRecorderTest::SetLoginStatus(LoginStatus login_status) { |
96 test_system_tray_delegate_->SetLoginStatus(login_status); | 96 test_system_tray_delegate_->SetLoginStatus(login_status); |
97 } | 97 } |
98 | 98 |
99 void UserMetricsRecorderTest::SetUserInActiveDesktopEnvironment( | 99 void UserMetricsRecorderTest::SetUserInActiveDesktopEnvironment( |
100 bool is_active) { | 100 bool is_active) { |
101 if (is_active) { | 101 if (is_active) { |
102 SetLoginStatus(user::LOGGED_IN_USER); | 102 SetLoginStatus(LoginStatus::USER); |
103 ASSERT_TRUE( | 103 ASSERT_TRUE( |
104 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 104 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
105 } else { | 105 } else { |
106 SetLoginStatus(user::LOGGED_IN_LOCKED); | 106 SetLoginStatus(LoginStatus::LOCKED); |
107 ASSERT_FALSE( | 107 ASSERT_FALSE( |
108 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 108 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 aura::Window* UserMetricsRecorderTest::CreateTestWindow() { | 112 aura::Window* UserMetricsRecorderTest::CreateTestWindow() { |
113 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( | 113 aura::Window* window = CreateTestWindowInShellWithDelegateAndType( |
114 nullptr, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect()); | 114 nullptr, ui::wm::WINDOW_TYPE_NORMAL, 0, gfx::Rect()); |
115 return window; | 115 return window; |
116 } | 116 } |
117 | 117 |
118 // Verifies the return value of IsUserInActiveDesktopEnvironment() for the | 118 // Verifies the return value of IsUserInActiveDesktopEnvironment() for the |
119 // different login status values. | 119 // different login status values. |
120 TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) { | 120 TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) { |
121 SetLoginStatus(user::LOGGED_IN_NONE); | 121 SetLoginStatus(LoginStatus::NOT_LOGGED_IN); |
122 EXPECT_FALSE( | 122 EXPECT_FALSE( |
123 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 123 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
124 | 124 |
125 SetLoginStatus(user::LOGGED_IN_LOCKED); | 125 SetLoginStatus(LoginStatus::LOCKED); |
126 EXPECT_FALSE( | 126 EXPECT_FALSE( |
127 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 127 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
128 | 128 |
129 SetLoginStatus(user::LOGGED_IN_USER); | 129 SetLoginStatus(LoginStatus::USER); |
130 EXPECT_TRUE( | 130 EXPECT_TRUE( |
131 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 131 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
132 | 132 |
133 SetLoginStatus(user::LOGGED_IN_OWNER); | 133 SetLoginStatus(LoginStatus::OWNER); |
134 EXPECT_TRUE( | 134 EXPECT_TRUE( |
135 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 135 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
136 | 136 |
137 SetLoginStatus(user::LOGGED_IN_GUEST); | 137 SetLoginStatus(LoginStatus::GUEST); |
138 EXPECT_TRUE( | 138 EXPECT_TRUE( |
139 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 139 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
140 | 140 |
141 SetLoginStatus(user::LOGGED_IN_PUBLIC); | 141 SetLoginStatus(LoginStatus::PUBLIC); |
142 EXPECT_TRUE( | 142 EXPECT_TRUE( |
143 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 143 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
144 | 144 |
145 SetLoginStatus(user::LOGGED_IN_SUPERVISED); | 145 SetLoginStatus(LoginStatus::SUPERVISED); |
146 EXPECT_TRUE( | 146 EXPECT_TRUE( |
147 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 147 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
148 | 148 |
149 SetLoginStatus(user::LOGGED_IN_KIOSK_APP); | 149 SetLoginStatus(LoginStatus::KIOSK_APP); |
150 EXPECT_FALSE( | 150 EXPECT_FALSE( |
151 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); | 151 user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment()); |
152 } | 152 } |
153 | 153 |
154 // Verifies that the IsUserInActiveDesktopEnvironment() dependent stats are not | 154 // Verifies that the IsUserInActiveDesktopEnvironment() dependent stats are not |
155 // recorded when a user is not active in a desktop environment. | 155 // recorded when a user is not active in a desktop environment. |
156 TEST_F(UserMetricsRecorderTest, | 156 TEST_F(UserMetricsRecorderTest, |
157 VerifyStatsRecordedWhenUserNotInActiveDesktopEnvironment) { | 157 VerifyStatsRecordedWhenUserNotInActiveDesktopEnvironment) { |
158 SetUserInActiveDesktopEnvironment(false); | 158 SetUserInActiveDesktopEnvironment(false); |
159 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); | 159 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 aura::Window* unpinned_window_5 = CreateTestWindow(); | 215 aura::Window* unpinned_window_5 = CreateTestWindow(); |
216 test_shelf_delegate->AddShelfItem(unpinned_window_5); | 216 test_shelf_delegate->AddShelfItem(unpinned_window_5); |
217 | 217 |
218 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); | 218 user_metrics_recorder_test_api()->RecordPeriodicMetrics(); |
219 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfItems, 5, 1); | 219 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfItems, 5, 1); |
220 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfPinnedItems, 2, 1); | 220 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfPinnedItems, 2, 1); |
221 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfUnpinnedItems, 3, 1); | 221 histograms().ExpectBucketCount(kAsh_Shelf_NumberOfUnpinnedItems, 3, 1); |
222 } | 222 } |
223 | 223 |
224 } // namespace ash | 224 } // namespace ash |
OLD | NEW |