Commit 06873472 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Fix crash in LockContentsView::FocusNextUser

- Also fixed in FocusPreviousUser
- Add unit test to validate crash does not regress

Bug: 895589
Change-Id: Ibb436d95b558089d36a8b10f33fab2bc88568214
Reviewed-on: https://chromium-review.googlesource.com/c/1320212Reviewed-by: default avatarQuan Nguyen <qnnguyen@chromium.org>
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605811}
parent 216f8a0a
...@@ -418,6 +418,9 @@ LockContentsView::~LockContentsView() { ...@@ -418,6 +418,9 @@ LockContentsView::~LockContentsView() {
} }
void LockContentsView::FocusNextUser() { void LockContentsView::FocusNextUser() {
if (users_.empty())
return;
if (login_views_utils::HasFocusInAnyChildView(primary_big_view_)) { if (login_views_utils::HasFocusInAnyChildView(primary_big_view_)) {
if (opt_secondary_big_view_) { if (opt_secondary_big_view_) {
SwapActiveAuthBetweenPrimaryAndSecondary(false /*is_primary*/); SwapActiveAuthBetweenPrimaryAndSecondary(false /*is_primary*/);
...@@ -454,6 +457,9 @@ void LockContentsView::FocusNextUser() { ...@@ -454,6 +457,9 @@ void LockContentsView::FocusNextUser() {
} }
void LockContentsView::FocusPreviousUser() { void LockContentsView::FocusPreviousUser() {
if (users_.empty())
return;
if (login_views_utils::HasFocusInAnyChildView(primary_big_view_)) { if (login_views_utils::HasFocusInAnyChildView(primary_big_view_)) {
if (users_list_) { if (users_list_) {
users_list_->user_view_at(users_list_->user_count() - 1)->RequestFocus(); users_list_->user_view_at(users_list_->user_count() - 1)->RequestFocus();
......
...@@ -2138,4 +2138,17 @@ TEST_F(LockContentsViewUnitTest, ...@@ -2138,4 +2138,17 @@ TEST_F(LockContentsViewUnitTest,
Shell::Get()->power_button_controller()->OnTabletModeEnded(); Shell::Get()->power_button_controller()->OnTabletModeEnded();
} }
TEST_F(LockContentsViewUnitTest, RightAndLeftAcceleratorsWithNoUser) {
// Show lock screen but do *not* initialize any users.
auto* lock = new LockContentsView(
mojom::TrayActionState::kNotAvailable, LockScreen::ScreenType::kLock,
data_dispatcher(),
std::make_unique<FakeLoginDetachableBaseModel>(data_dispatcher()));
SetWidget(CreateWidgetWithContent(lock));
// Nothing to validate except that there is no crash.
lock->AcceleratorPressed(ui::Accelerator(ui::VKEY_RIGHT, 0));
lock->AcceleratorPressed(ui::Accelerator(ui::VKEY_LEFT, 0));
}
} // namespace ash } // namespace ash
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