Commit 8cb43c2a authored by xiyuan's avatar xiyuan Committed by Commit bot

cros: Fix inconsistent SessionController state for tests

- Do not set ACTIVE state in StartRestoreAfterCrashSession and
  StartStubLoginSession. SessionStarted() call will do that. Setting
  it explicitly breaks tests such as AccessibilityManagerTest that
  has "--login-manager" but goes through StartRestoreAfterCrashSession
  code to initialize;
- CrashRestoreComplexTest should use GetLRULoggedInUsers instead
  of GetLoggedInUsers since it tests the user session order;
- Fix UserManagerBase to cover tests that add a non-existent user;
  - Make sure |logged_in_user_| preserves the order since its index is
    used as fake session id ATM;
  - Fire UserAddedToSession for such users;

BUG=648964
TEST=Existing tests.

Review-Url: https://codereview.chromium.org/2577903002
Cr-Commit-Position: refs/heads/master@{#438944}
parent c06c52ea
...@@ -157,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(CrashRestoreComplexTest, RestoreSessionForThreeUsers) { ...@@ -157,7 +157,7 @@ IN_PROC_BROWSER_TEST_F(CrashRestoreComplexTest, RestoreSessionForThreeUsers) {
EXPECT_EQ(account_id3_, user->GetAccountId()); EXPECT_EQ(account_id3_, user->GetAccountId());
EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id3_), EXPECT_EQ(CryptohomeClient::GetStubSanitizedUsername(cryptohome_id3_),
user->username_hash()); user->username_hash());
const user_manager::UserList& users = user_manager->GetLoggedInUsers(); const user_manager::UserList& users = user_manager->GetLRULoggedInUsers();
ASSERT_EQ(3UL, users.size()); ASSERT_EQ(3UL, users.size());
// User that becomes active moves to the beginning of the list. // User that becomes active moves to the beginning of the list.
......
...@@ -90,9 +90,6 @@ void StartRestoreAfterCrashSession(Profile* user_profile, ...@@ -90,9 +90,6 @@ void StartRestoreAfterCrashSession(Profile* user_profile,
const std::string& login_user_id) { const std::string& login_user_id) {
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
session_manager::SessionManager::Get()->SetSessionState(
session_manager::SessionState::ACTIVE);
// TODO(xiyuan): Identify tests that do not set this kLoginUser flag but // TODO(xiyuan): Identify tests that do not set this kLoginUser flag but
// still rely on "stub user" session. Keeping existing behavior to avoid // still rely on "stub user" session. Keeping existing behavior to avoid
// breaking tests. // breaking tests.
...@@ -152,9 +149,6 @@ void StartRestoreAfterCrashSession(Profile* user_profile, ...@@ -152,9 +149,6 @@ void StartRestoreAfterCrashSession(Profile* user_profile,
// Starts a user session with stub user. // Starts a user session with stub user.
void StartStubLoginSession(Profile* user_profile, void StartStubLoginSession(Profile* user_profile,
const std::string& login_user_id) { const std::string& login_user_id) {
session_manager::SessionManager::Get()->SetSessionState(
session_manager::SessionState::ACTIVE);
// For dev machines and stub user emulate as if sync has been initialized. // For dev machines and stub user emulate as if sync has been initialized.
SigninManagerFactory::GetForProfile(user_profile) SigninManagerFactory::GetForProfile(user_profile)
->SetAuthenticatedAccountInfo(login_user_id, login_user_id); ->SetAuthenticatedAccountInfo(login_user_id, login_user_id);
......
...@@ -182,14 +182,18 @@ void UserManagerBase::UserLoggedIn(const AccountId& account_id, ...@@ -182,14 +182,18 @@ void UserManagerBase::UserLoggedIn(const AccountId& account_id,
active_user_->set_is_active(true); active_user_->set_is_active(true);
active_user_->set_username_hash(username_hash); active_user_->set_username_hash(username_hash);
// Place user who just signed in to the top of the logged in users. logged_in_users_.push_back(active_user_);
logged_in_users_.insert(logged_in_users_.begin(), active_user_);
SetLRUUser(active_user_); SetLRUUser(active_user_);
if (!primary_user_) { if (!primary_user_) {
primary_user_ = active_user_; primary_user_ = active_user_;
if (primary_user_->HasGaiaAccount()) if (primary_user_->HasGaiaAccount())
SendGaiaUserLoginMetrics(account_id); SendGaiaUserLoginMetrics(account_id);
} else if (primary_user_ != active_user_) {
// This is only needed for tests where a new user session is created
// for non-existent user.
SetIsCurrentUserNew(true);
NotifyUserAddedToSession(active_user_, true /* user switch pending */);
} }
UMA_HISTOGRAM_ENUMERATION( UMA_HISTOGRAM_ENUMERATION(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment