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

Unified Diff: ash/metrics/user_metrics_recorder_unittest.cc

Issue 2826313002: cros: Use SessionController in UserMetricsRecorder to get login status (Closed)
Patch Set: review comments Created 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/metrics/user_metrics_recorder.cc ('k') | ash/test/test_system_tray_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/metrics/user_metrics_recorder_unittest.cc
diff --git a/ash/metrics/user_metrics_recorder_unittest.cc b/ash/metrics/user_metrics_recorder_unittest.cc
index e9f323c16927f8ecef0f9d49c705106bc2d28951..4effbd16b720e0c4039a2e126b84f2c242a340b8 100644
--- a/ash/metrics/user_metrics_recorder_unittest.cc
+++ b/ash/metrics/user_metrics_recorder_unittest.cc
@@ -8,15 +8,18 @@
#include "ash/login_status.h"
#include "ash/public/cpp/config.h"
+#include "ash/session/session_controller.h"
#include "ash/shelf/shelf_model.h"
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/test/ash_test_base.h"
-#include "ash/test/test_system_tray_delegate.h"
+#include "ash/test/test_session_controller_client.h"
#include "ash/test/user_metrics_recorder_test_api.h"
#include "ash/wm_window.h"
#include "base/test/histogram_tester.h"
+using session_manager::SessionState;
+
namespace ash {
namespace {
@@ -35,117 +38,68 @@ const char kAsh_Shelf_NumberOfUnpinnedItems[] =
} // namespace
-// Test fixture for the UserMetricsRecorder class.
-class UserMetricsRecorderTest : public test::AshTestBase {
+// Test fixture for the UserMetricsRecorder class. The tests manage their own
+// session state.
+class UserMetricsRecorderTest : public test::NoSessionAshTestBase {
public:
- UserMetricsRecorderTest();
- ~UserMetricsRecorderTest() override;
-
- // test::AshTestBase:
- void SetUp() override;
- void TearDown() override;
-
- // Sets the user login status.
- void SetLoginStatus(LoginStatus login_status);
+ UserMetricsRecorderTest() = default;
+ ~UserMetricsRecorderTest() override = default;
- // Sets the current user session to be active or inactive in a desktop
- // environment.
- void SetUserInActiveDesktopEnvironment(bool is_active);
-
- test::UserMetricsRecorderTestAPI* user_metrics_recorder_test_api() {
- return user_metrics_recorder_test_api_.get();
- }
+ test::UserMetricsRecorderTestAPI& test_api() { return test_api_; }
base::HistogramTester& histograms() { return histograms_; }
private:
// Test API to access private members of the test target.
- std::unique_ptr<test::UserMetricsRecorderTestAPI>
- user_metrics_recorder_test_api_;
+ test::UserMetricsRecorderTestAPI test_api_;
// Histogram value verifier.
base::HistogramTester histograms_;
- // The active SystemTrayDelegate. Not owned.
- test::TestSystemTrayDelegate* test_system_tray_delegate_;
-
DISALLOW_COPY_AND_ASSIGN(UserMetricsRecorderTest);
};
-UserMetricsRecorderTest::UserMetricsRecorderTest() {}
-
-UserMetricsRecorderTest::~UserMetricsRecorderTest() {}
-
-void UserMetricsRecorderTest::SetUp() {
- test::AshTestBase::SetUp();
- user_metrics_recorder_test_api_.reset(new test::UserMetricsRecorderTestAPI());
- test_system_tray_delegate_ = GetSystemTrayDelegate();
-}
-
-void UserMetricsRecorderTest::TearDown() {
- test_system_tray_delegate_ = nullptr;
- test::AshTestBase::TearDown();
-}
-
-void UserMetricsRecorderTest::SetLoginStatus(LoginStatus login_status) {
- test_system_tray_delegate_->SetLoginStatus(login_status);
-}
-
-void UserMetricsRecorderTest::SetUserInActiveDesktopEnvironment(
- bool is_active) {
- if (is_active) {
- SetLoginStatus(LoginStatus::USER);
- ASSERT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
- } else {
- SetLoginStatus(LoginStatus::LOCKED);
- ASSERT_FALSE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
- }
-}
-
// Verifies the return value of IsUserInActiveDesktopEnvironment() for the
// different login status values.
TEST_F(UserMetricsRecorderTest, VerifyIsUserInActiveDesktopEnvironmentValues) {
- SetLoginStatus(LoginStatus::NOT_LOGGED_IN);
- EXPECT_FALSE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::LOCKED);
- EXPECT_FALSE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::USER);
- EXPECT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::OWNER);
- EXPECT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::GUEST);
- EXPECT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::PUBLIC);
- EXPECT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::SUPERVISED);
- EXPECT_TRUE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
-
- SetLoginStatus(LoginStatus::KIOSK_APP);
- EXPECT_FALSE(
- user_metrics_recorder_test_api()->IsUserInActiveDesktopEnvironment());
+ SessionController* session = Shell::Get()->session_controller();
+
+ // Environment is not active before login.
+ ASSERT_FALSE(session->IsActiveUserSessionStarted());
+ EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
+
+ // Environment is active after login.
+ SetSessionStarted(true);
+ ASSERT_TRUE(session->IsActiveUserSessionStarted());
+ EXPECT_TRUE(test_api().IsUserInActiveDesktopEnvironment());
+
+ // Environment is not active when screen is locked.
+ test::TestSessionControllerClient* client = GetSessionControllerClient();
+ client->SetSessionState(SessionState::LOCKED);
+ ASSERT_TRUE(session->IsScreenLocked());
+ EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
+
+ // Kiosk logins are not considered active.
+ client->Reset();
+ client->AddUserSession("app@kiosk-apps.device-local.localhost",
+ user_manager::USER_TYPE_KIOSK_APP);
+ client->SetSessionState(session_manager::SessionState::ACTIVE);
+ EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
+
+ // Arc kiosk logins are not considered active.
+ client->Reset();
+ client->AddUserSession("app@arc-kiosk-apps.device-local.localhost",
+ user_manager::USER_TYPE_ARC_KIOSK_APP);
+ client->SetSessionState(session_manager::SessionState::ACTIVE);
+ EXPECT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
}
// Verifies that the IsUserInActiveDesktopEnvironment() dependent stats are not
// recorded when a user is not active in a desktop environment.
TEST_F(UserMetricsRecorderTest,
VerifyStatsRecordedWhenUserNotInActiveDesktopEnvironment) {
- SetUserInActiveDesktopEnvironment(false);
- user_metrics_recorder_test_api()->RecordPeriodicMetrics();
+ ASSERT_FALSE(test_api().IsUserInActiveDesktopEnvironment());
+ test_api().RecordPeriodicMetrics();
histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 0);
histograms().ExpectTotalCount(kAsh_Shelf_NumberOfItems, 0);
@@ -157,8 +111,9 @@ TEST_F(UserMetricsRecorderTest,
// recorded when a user is active in a desktop environment.
TEST_F(UserMetricsRecorderTest,
VerifyStatsRecordedWhenUserInActiveDesktopEnvironment) {
- SetUserInActiveDesktopEnvironment(true);
- user_metrics_recorder_test_api()->RecordPeriodicMetrics();
+ SetSessionStarted(true);
+ ASSERT_TRUE(test_api().IsUserInActiveDesktopEnvironment());
+ test_api().RecordPeriodicMetrics();
histograms().ExpectTotalCount(kAsh_NumberOfVisibleWindowsInPrimaryDisplay, 1);
histograms().ExpectTotalCount(kAsh_Shelf_NumberOfItems, 1);
@@ -169,8 +124,8 @@ TEST_F(UserMetricsRecorderTest,
// Verifies recording of stats which are always recorded by
// RecordPeriodicMetrics.
TEST_F(UserMetricsRecorderTest, VerifyStatsRecordedByRecordPeriodicMetrics) {
- SetUserInActiveDesktopEnvironment(true);
- user_metrics_recorder_test_api()->RecordPeriodicMetrics();
+ SetSessionStarted(true);
+ test_api().RecordPeriodicMetrics();
histograms().ExpectTotalCount(kAsh_ActiveWindowShowTypeOverTime, 1);
}
@@ -182,7 +137,7 @@ TEST_F(UserMetricsRecorderTest, ValuesRecordedByRecordShelfItemCounts) {
if (Shell::GetAshConfig() == Config::MASH)
return;
- SetUserInActiveDesktopEnvironment(true);
+ SetSessionStarted(true);
// Make sure the shelf contains the app list launcher button.
ShelfModel* shelf_model = Shell::Get()->shelf_model();
@@ -204,7 +159,7 @@ TEST_F(UserMetricsRecorderTest, ValuesRecordedByRecordShelfItemCounts) {
shelf_item.app_launch_id = AppLaunchId("app_id_5");
shelf_model->Add(shelf_item);
- user_metrics_recorder_test_api()->RecordPeriodicMetrics();
+ test_api().RecordPeriodicMetrics();
histograms().ExpectBucketCount(kAsh_Shelf_NumberOfItems, 5, 1);
histograms().ExpectBucketCount(kAsh_Shelf_NumberOfPinnedItems, 2, 1);
histograms().ExpectBucketCount(kAsh_Shelf_NumberOfUnpinnedItems, 3, 1);
« no previous file with comments | « ash/metrics/user_metrics_recorder.cc ('k') | ash/test/test_system_tray_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698