Commit 9a19742e authored by James Cook's avatar James Cook Committed by Commit Bot

chromeos: Fix SessionObserver::OnFirstSessionStarted() not firing

During OOBE and normal user login, when
SessionController::SetUserSessionOrder() is called there is an
existing user session, so last_active_account_id.is_valid() returns
true and the observer never fires.

I suspect this breaks some accessibility features in kiosk mode
(magnifier keyboard control) and for hotrod (long-press for
spoken feedback).

It's probably been broken since the observer was added in May:
https://chromium-review.googlesource.com/c/chromium/src/+/1070771

Bug: 884275
Test: added to ash_unittests
Change-Id: Idbe4f20b7426742703995a05c7ebb1c5c8f1a7c8
Reviewed-on: https://chromium-review.googlesource.com/1226876Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591450}
parent 7356748a
......@@ -341,9 +341,10 @@ void SessionController::SetUserSessionOrder(
// Check active user change and notifies observers.
if (user_sessions_[0]->session_id != active_session_id_) {
const bool is_first_session = active_session_id_ == 0u;
active_session_id_ = user_sessions_[0]->session_id;
if (!last_active_account_id.is_valid()) {
if (is_first_session) {
for (auto& observer : observers_)
observer.OnFirstSessionStarted();
}
......
......@@ -51,6 +51,8 @@ class TestSessionObserver : public SessionObserver {
user_session_account_ids_.push_back(account_id);
}
void OnFirstSessionStarted() override { first_session_started_ = true; }
void OnSessionStateChanged(SessionState state) override { state_ = state; }
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override {
......@@ -67,6 +69,7 @@ class TestSessionObserver : public SessionObserver {
SessionState state() const { return state_; }
const AccountId& active_account_id() const { return active_account_id_; }
bool first_session_started() const { return first_session_started_; }
const std::vector<AccountId>& user_session_account_ids() const {
return user_session_account_ids_;
}
......@@ -78,6 +81,7 @@ class TestSessionObserver : public SessionObserver {
private:
SessionState state_ = SessionState::UNKNOWN;
AccountId active_account_id_;
bool first_session_started_ = false;
std::vector<AccountId> user_session_account_ids_;
PrefService* last_user_pref_service_ = nullptr;
......@@ -172,6 +176,18 @@ TEST_F(SessionControllerTest, SimpleSessionInfo) {
EXPECT_TRUE(controller()->IsRunningInAppMode());
}
TEST_F(SessionControllerTest, OnFirstSessionStarted) {
// Simulate chrome starting a user session.
mojom::SessionInfo info;
FillDefaultSessionInfo(&info);
SetSessionInfo(info);
UpdateSession(1u, "user1@test.com");
controller()->SetUserSessionOrder({1u});
// Observer is notified.
EXPECT_TRUE(observer()->first_session_started());
}
// Tests that the CanLockScreen is only true with an active user session.
TEST_F(SessionControllerTest, CanLockScreen) {
mojom::SessionInfo info;
......
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