0

[High5] Show correct UI on login screen for PIN only

Bug: b:357606198, b:348326316
Change-Id: I19981eefc7e420c83ddcc1c6f80cb712336be6c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5762639
Reviewed-by: Elie Maamari <emaamari@google.com>
Reviewed-by: Denis Kuznetsov <antrim@chromium.org>
Commit-Queue: Yunke Zhou <yunkez@google.com>
Cr-Commit-Position: refs/heads/main@{#1342734}
This commit is contained in:
Yunke Zhou
2024-08-16 10:36:34 +00:00
committed by Chromium LUCI CQ
parent c33324ff2f
commit bc2a4a8e0e
5 changed files with 224 additions and 79 deletions

@ -4900,6 +4900,9 @@ No devices connected.
<message name="IDS_ASH_LOGIN_POD_PASSWORD_PLACEHOLDER" desc="Text to display as placeholder in the password field when password is the only auth method.">
Password
</message>
<message name="IDS_ASH_LOGIN_POD_PIN_PLACEHOLDER" desc="Text to display as placeholder in the password field when pin is the only auth method.">
PIN
</message>
<message name="IDS_ASH_LOGIN_POD_PASSWORD_PIN_PLACEHOLDER" desc="Text to display as placeholder in the password field when both password and pin are allowed.">
PIN or password
</message>

@ -0,0 +1 @@
e8f0dfc8f92efd4b6e7d612389d9480726a2124d

@ -1025,7 +1025,7 @@ const LoginUserInfo& LoginAuthUserView::current_user() const {
}
base::WeakPtr<views::View> LoginAuthUserView::GetActiveInputView() {
if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE) {
if (ShouldShowPinInputField()) {
return pin_input_view_ != nullptr ? pin_input_view_->AsWeakPtr() : nullptr;
}
@ -1042,7 +1042,7 @@ gfx::Size LoginAuthUserView::CalculatePreferredSize(
}
void LoginAuthUserView::RequestFocus() {
if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE) {
if (ShouldShowPinInputField()) {
pin_input_view_->RequestFocus();
} else if (password_view_->GetEnabled()) {
RequestFocusOnPasswordView();
@ -1237,7 +1237,7 @@ void LoginAuthUserView::OnOnlineSignInMessageTap() {
void LoginAuthUserView::OnPinPadBackspace() {
DCHECK(pin_input_view_);
DCHECK(password_view_);
if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE) {
if (ShouldShowPinInputField()) {
pin_input_view_->Backspace();
} else {
password_view_->Backspace();
@ -1247,7 +1247,7 @@ void LoginAuthUserView::OnPinPadBackspace() {
void LoginAuthUserView::OnPinPadInsertDigit(int digit) {
DCHECK(pin_input_view_);
DCHECK(password_view_);
if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE) {
if (ShouldShowPinInputField()) {
pin_input_view_->InsertDigit(digit);
} else {
password_view_->InsertNumber(digit);
@ -1256,14 +1256,14 @@ void LoginAuthUserView::OnPinPadInsertDigit(int digit) {
void LoginAuthUserView::OnPasswordTextChanged(bool is_empty) {
DCHECK(pin_view_);
if (input_field_mode_ != InputFieldMode::PIN_WITH_TOGGLE) {
if (!ShouldShowPinInputField()) {
pin_view_->OnPasswordTextChanged(is_empty);
}
}
void LoginAuthUserView::OnPinTextChanged(bool is_empty) {
DCHECK(pin_view_);
if (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE) {
if (ShouldShowPinInputField()) {
pin_view_->OnPasswordTextChanged(is_empty);
}
}
@ -1273,8 +1273,10 @@ bool LoginAuthUserView::HasAuthMethod(AuthMethods auth_method) const {
}
bool LoginAuthUserView::ShouldAuthenticateWithPin() const {
return input_field_mode_ == InputFieldMode::PIN_AND_PASSWORD ||
input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE;
return input_field_mode_ == InputFieldMode::kPinOnlyAutosubmitOn ||
input_field_mode_ == InputFieldMode::kPinOnlyAutosubmitOff ||
input_field_mode_ == InputFieldMode::kPasswordAndPin ||
input_field_mode_ == InputFieldMode::kPinWithToggle;
}
void LoginAuthUserView::AttemptAuthenticateWithChallengeResponse() {
@ -1330,8 +1332,8 @@ void LoginAuthUserView::UpdateFocus() {
void LoginAuthUserView::OnSwitchButtonClicked() {
// Ignore events from the switch button if no longer present.
if (input_field_mode_ != InputFieldMode::PIN_WITH_TOGGLE &&
input_field_mode_ != InputFieldMode::PWD_WITH_TOGGLE) {
if (input_field_mode_ != InputFieldMode::kPinWithToggle &&
input_field_mode_ != InputFieldMode::kPwdWithToggle) {
return;
}
@ -1341,9 +1343,9 @@ void LoginAuthUserView::OnSwitchButtonClicked() {
// Cache the current state of the UI.
CaptureStateForAnimationPreLayout();
// Same auth methods, but the input field mode has changed.
input_field_mode_ = (input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE)
? InputFieldMode::PWD_WITH_TOGGLE
: InputFieldMode::PIN_WITH_TOGGLE;
input_field_mode_ = (input_field_mode_ == InputFieldMode::kPinWithToggle)
? InputFieldMode::kPwdWithToggle
: InputFieldMode::kPinWithToggle;
SetAuthMethods(auth_methods_, auth_metadata_);
// Layout and animate.
DeprecatedLayoutImmediately();
@ -1355,34 +1357,66 @@ void LoginAuthUserView::UpdateInputFieldMode() {
// - Challenge response is active (Smart Card)
// - Online sign in message shown
// - Disabled message shown
// - No password auth available
// - Auth factors view is requesting to hide the password/PIN field
// - No password or pin auth available (only checking password auth before
// PIN-only auth is allowed)
if (HasAuthMethod(AUTH_CHALLENGE_RESPONSE) ||
HasAuthMethod(AUTH_ONLINE_SIGN_IN) || HasAuthMethod(AUTH_DISABLED) ||
!HasAuthMethod(AUTH_PASSWORD) ||
HasAuthMethod(AUTH_AUTH_FACTOR_IS_HIDING_PASSWORD)) {
input_field_mode_ = InputFieldMode::NONE;
input_field_mode_ = InputFieldMode::kNone;
return;
}
if (features::IsAllowPasswordlessSetupEnabled()) {
if (!HasAuthMethod(AUTH_PASSWORD) && !HasAuthMethod(AUTH_PIN)) {
input_field_mode_ = InputFieldMode::kNone;
return;
}
} else {
if (!HasAuthMethod(AUTH_PASSWORD)) {
input_field_mode_ = InputFieldMode::kNone;
return;
}
}
if (!HasAuthMethod(AUTH_PIN)) {
input_field_mode_ = InputFieldMode::PASSWORD_ONLY;
input_field_mode_ = InputFieldMode::kPasswordOnly;
return;
}
// Default to combined password/pin if autosubmit is disabled.
const int pin_length = auth_metadata_.autosubmit_pin_length;
if (!LoginPinInputView::IsAutosubmitSupported(pin_length)) {
input_field_mode_ = InputFieldMode::PIN_AND_PASSWORD;
const bool is_auto_submit_supported =
LoginPinInputView::IsAutosubmitSupported(pin_length);
if (features::IsAllowPasswordlessSetupEnabled()) {
CHECK(HasAuthMethod(AUTH_PASSWORD) || HasAuthMethod(AUTH_PIN));
if (!HasAuthMethod(AUTH_PASSWORD)) {
input_field_mode_ = is_auto_submit_supported
? InputFieldMode::kPinOnlyAutosubmitOn
: InputFieldMode::kPinOnlyAutosubmitOff;
return;
}
}
// Default to combined password/pin if autosubmit is disabled.
if (!is_auto_submit_supported) {
input_field_mode_ = InputFieldMode::kPasswordAndPin;
return;
}
// Defaults to PIN + switch button if not showing the switch button already.
if (input_field_mode_ != InputFieldMode::PIN_WITH_TOGGLE &&
input_field_mode_ != InputFieldMode::PWD_WITH_TOGGLE) {
input_field_mode_ = InputFieldMode::PIN_WITH_TOGGLE;
if (input_field_mode_ != InputFieldMode::kPinWithToggle &&
input_field_mode_ != InputFieldMode::kPwdWithToggle) {
input_field_mode_ = InputFieldMode::kPinWithToggle;
return;
}
// If none of the conditions above are met, it means the user has both
// password and PIN auth and is already in kPinWithToggle or kPwdWithToggle
// mode.
DCHECK(HasAuthMethod(AUTH_PASSWORD) && HasAuthMethod(AUTH_PIN));
DCHECK(input_field_mode_ == InputFieldMode::kPinWithToggle ||
input_field_mode_ == InputFieldMode::kPwdWithToggle);
}
bool LoginAuthUserView::ShouldShowPinPad() const {
@ -1390,30 +1424,34 @@ bool LoginAuthUserView::ShouldShowPinPad() const {
return false;
}
switch (input_field_mode_) {
case InputFieldMode::NONE:
case InputFieldMode::kNone:
return false;
case InputFieldMode::PASSWORD_ONLY:
case InputFieldMode::PWD_WITH_TOGGLE:
case InputFieldMode::kPasswordOnly:
case InputFieldMode::kPwdWithToggle:
return auth_metadata_.show_pinpad_for_pw;
case InputFieldMode::PIN_AND_PASSWORD:
case InputFieldMode::PIN_WITH_TOGGLE:
case InputFieldMode::kPinOnlyAutosubmitOn:
case InputFieldMode::kPinOnlyAutosubmitOff:
case InputFieldMode::kPasswordAndPin:
case InputFieldMode::kPinWithToggle:
return true;
}
}
bool LoginAuthUserView::ShouldShowPasswordField() const {
return input_field_mode_ == InputFieldMode::PASSWORD_ONLY ||
input_field_mode_ == InputFieldMode::PIN_AND_PASSWORD ||
input_field_mode_ == InputFieldMode::PWD_WITH_TOGGLE;
return input_field_mode_ == InputFieldMode::kPasswordOnly ||
input_field_mode_ == InputFieldMode::kPasswordAndPin ||
input_field_mode_ == InputFieldMode::kPinOnlyAutosubmitOff ||
input_field_mode_ == InputFieldMode::kPwdWithToggle;
}
bool LoginAuthUserView::ShouldShowPinInputField() const {
return input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE;
return input_field_mode_ == InputFieldMode::kPinOnlyAutosubmitOn ||
input_field_mode_ == InputFieldMode::kPinWithToggle;
}
bool LoginAuthUserView::ShouldShowToggle() const {
return input_field_mode_ == InputFieldMode::PIN_WITH_TOGGLE ||
input_field_mode_ == InputFieldMode::PWD_WITH_TOGGLE;
return input_field_mode_ == InputFieldMode::kPinWithToggle ||
input_field_mode_ == InputFieldMode::kPwdWithToggle;
}
gfx::Size LoginAuthUserView::GetPaddingBelowUserView() const {
@ -1453,7 +1491,7 @@ gfx::Size LoginAuthUserView::GetPaddingBelowPasswordView() const {
}
std::u16string LoginAuthUserView::GetPinPasswordToggleText() const {
if (input_field_mode_ == InputFieldMode::PWD_WITH_TOGGLE) {
if (input_field_mode_ == InputFieldMode::kPwdWithToggle) {
return l10n_util::GetStringUTF16(IDS_ASH_LOGIN_SWITCH_TO_PIN);
} else {
return l10n_util::GetStringUTF16(IDS_ASH_LOGIN_SWITCH_TO_PASSWORD);
@ -1461,11 +1499,13 @@ std::u16string LoginAuthUserView::GetPinPasswordToggleText() const {
}
std::u16string LoginAuthUserView::GetPasswordViewPlaceholder() const {
if (input_field_mode_ == InputFieldMode::PIN_AND_PASSWORD) {
if (input_field_mode_ == InputFieldMode::kPasswordAndPin) {
return l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_POD_PASSWORD_PIN_PLACEHOLDER);
}
if (input_field_mode_ == InputFieldMode::kPinOnlyAutosubmitOff) {
return l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PIN_PLACEHOLDER);
}
return l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PASSWORD_PLACEHOLDER);
}

@ -96,11 +96,19 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView {
// might be in. This is determined by the current authentication methods
// that a user has.
enum class InputFieldMode {
NONE, // Not showing any input field.
PASSWORD_ONLY, // No PIN set. Password only field.
PIN_AND_PASSWORD, // PIN set, but auto-submit feature disabled.
PIN_WITH_TOGGLE, // PIN field for auto submit.
PWD_WITH_TOGGLE // PWD field when auto submit enabled.
kNone, // Not showing any input field.
kPasswordOnly, // Password only field, no PIN set.
kPinOnlyAutosubmitOn, // PIN only field, auto-submit feature enabled, no
// password set.
kPinOnlyAutosubmitOff, // PIN only field, auto-submit feature disabled, no
// password set.
kPwdWithToggle, // Password field with toggle, PIN auto-submit
// feature enabled.
kPinWithToggle, // PIN field with toggle, auto-submit feature
// enabled.
// TODO(b/357606198): Separate password and PIN field.
kPasswordAndPin, // Both password and PIN are set, PIN auto-submit feature
// disabled.
};
// TestApi is used for tests to get internal implementation details.
@ -316,7 +324,7 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView {
AuthMethodsMetadata auth_metadata_ = AuthMethodsMetadata();
// Controls which input field is currently being shown.
InputFieldMode input_field_mode_ = InputFieldMode::NONE;
InputFieldMode input_field_mode_ = InputFieldMode::kNone;
raw_ptr<LoginUserView> user_view_ = nullptr;
raw_ptr<LoginPasswordView> password_view_ = nullptr;

@ -55,15 +55,19 @@ struct InputFieldVisibility {
};
const std::map<LoginAuthUserView::InputFieldMode, InputFieldVisibility>
expected_visibilities = {
{LoginAuthUserView::InputFieldMode::NONE,
{LoginAuthUserView::InputFieldMode::kNone,
{/*pwd*/ false, /*pin_input*/ false, /*toggle*/ false}},
{LoginAuthUserView::InputFieldMode::PASSWORD_ONLY,
{LoginAuthUserView::InputFieldMode::kPasswordOnly,
{/*pwd*/ true, /*pin_input*/ false, /*toggle*/ false}},
{LoginAuthUserView::InputFieldMode::PIN_AND_PASSWORD,
{LoginAuthUserView::InputFieldMode::kPinOnlyAutosubmitOn,
{/*pwd*/ false, /*pin_input*/ true, /*toggle*/ false}},
{LoginAuthUserView::InputFieldMode::kPinOnlyAutosubmitOff,
{/*pwd*/ true, /*pin_input*/ false, /*toggle*/ false}},
{LoginAuthUserView::InputFieldMode::PIN_WITH_TOGGLE,
{LoginAuthUserView::InputFieldMode::kPasswordAndPin,
{/*pwd*/ true, /*pin_input*/ false, /*toggle*/ false}},
{LoginAuthUserView::InputFieldMode::kPinWithToggle,
{/*pwd*/ false, /*pin_input*/ true, /*toggle*/ true}},
{LoginAuthUserView::InputFieldMode::PWD_WITH_TOGGLE,
{LoginAuthUserView::InputFieldMode::kPwdWithToggle,
{/*pwd*/ true, /*pin_input*/ false, /*toggle*/ true}},
};
@ -96,7 +100,7 @@ class LoginAuthUserViewTestBase : public LoginTestBase {
}
// Enables password and pin with the given length.
void SetAuthPin(int autosubmit_length) {
void SetAuthPasswordAndPin(int autosubmit_length) {
auto auth = LoginAuthUserView::AUTH_PASSWORD | LoginAuthUserView::AUTH_PIN;
SetAuthMethods(/*auth_methods*/ auth,
/*show_pinpad_for_pw*/ false,
@ -104,6 +108,14 @@ class LoginAuthUserViewTestBase : public LoginTestBase {
/*autosubmit_pin_length*/ autosubmit_length);
}
void SetAuthPin(int autosubmit_length) {
auto auth = LoginAuthUserView::AUTH_PIN;
SetAuthMethods(/*auth_methods*/ auth,
/*show_pinpad_for_pw*/ false,
/*virtual_keyboard_visible*/ false,
/*autosubmit_pin_length*/ autosubmit_length);
}
// Expects the given input field mode and the corresponding visibility.
void ExpectModeVisibility(LoginAuthUserView::InputFieldMode mode) {
EXPECT_EQ(view_->input_field_mode(), mode);
@ -162,6 +174,14 @@ class LoginAuthUserViewUnittest : public LoginAuthUserViewTestBase {
}
};
class LoginAuthUserViewPinOnlyUnittest : public LoginAuthUserViewUnittest {
public:
LoginAuthUserViewPinOnlyUnittest() {
feature_list_.Reset();
feature_list_.InitAndEnableFeature(features::kAllowPasswordlessSetup);
}
};
// Verifies showing the PIN keyboard makes the user view grow.
TEST_F(LoginAuthUserViewUnittest, ShowingPinExpandsView) {
gfx::Size start_size = view_->size();
@ -248,8 +268,8 @@ TEST_F(LoginAuthUserViewUnittest, ResetPinFieldOnUpdateUser) {
// Set up PIN with auto submit.
SetUserCount(1);
SetAuthPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_WITH_TOGGLE);
SetAuthPasswordAndPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPinWithToggle);
// Insert some random digits.
pin_input->InsertDigit(1);
@ -270,17 +290,17 @@ TEST_F(LoginAuthUserViewUnittest, CorrectFieldModeForExposedPinLength) {
SetUserCount(1);
for (int pin_length = 0; pin_length <= 64; pin_length++) {
SetAuthPin(/*autosubmit_length*/ pin_length);
SetAuthPasswordAndPin(/*autosubmit_length*/ pin_length);
if (LoginPinInputView::IsAutosubmitSupported(pin_length)) {
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_WITH_TOGGLE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPinWithToggle);
} else {
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_AND_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPasswordAndPin);
}
}
}
// Tests the correctness of InputFieldMode::NONE
// Tests the correctness of InputFieldMode::kNone
TEST_F(LoginAuthUserViewUnittest, ModesWithoutInputFields) {
LoginAuthUserView::TestApi auth_test(view_);
LoginAuthUserView::AuthMethods methods_without_input[] = {
@ -290,11 +310,11 @@ TEST_F(LoginAuthUserViewUnittest, ModesWithoutInputFields) {
for (auto method : methods_without_input) {
SetAuthMethods(method);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::NONE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kNone);
}
}
// Tests the correctness of InputFieldMode::PASSWORD_ONLY. With only the
// Tests the correctness of InputFieldMode::kPasswordOnly. With only the
// password field present and no PIN, the authentication call must
// have 'authenticated_by_pin' as false.
TEST_F(LoginAuthUserViewUnittest, PasswordOnlyFieldMode) {
@ -307,7 +327,7 @@ TEST_F(LoginAuthUserViewUnittest, PasswordOnlyFieldMode) {
// Only password, no PIN.
SetUserCount(1);
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PASSWORD_ONLY);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPasswordOnly);
password_test.textfield()->SetText(u"test_password");
@ -321,14 +341,43 @@ TEST_F(LoginAuthUserViewUnittest, PasswordOnlyFieldMode) {
base::RunLoop().RunUntilIdle();
}
/**
* Tests the correctness of InputFieldMode::PIN_AND_PASSWORD by ensuring the
* following:
* - Clicking on the pin pad inserts digits into the field
* - Digits are correctly ignored when the field is set to read-only
* - Submitting the credentials results in the correct auth call
*/
TEST_F(LoginAuthUserViewUnittest, PinAndPasswordFieldModeCorrectness) {
TEST_F(LoginAuthUserViewPinOnlyUnittest, PinOnlyModeWithAutosubmitEnabled) {
LoginAuthUserView::TestApi auth_test(view_);
auto client = std::make_unique<MockLoginScreenClient>();
LoginUserView* user_view(auth_test.user_view());
LoginPinInputView::TestApi pin_input_test{auth_test.pin_input_view()};
LoginPinView::TestApi pin_pad_api{auth_test.pin_view()};
// Set up PIN with auto submit.
SetUserCount(1);
SetAuthPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPinOnlyAutosubmitOn);
const auto pin = std::string("123456");
EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin_(
user_view->current_user().basic_user_info.account_id,
/*password=*/pin,
/*authenticated_by_pin=*/true,
/*callback=*/_));
// Inserting `1230456`.
pin_pad_api.ClickOnDigit(1);
pin_pad_api.ClickOnDigit(2);
pin_pad_api.ClickOnDigit(3);
// `0` must be ignored when the field is read only.
auth_test.pin_input_view()->SetReadOnly(true);
pin_pad_api.ClickOnDigit(0);
auth_test.pin_input_view()->SetReadOnly(false);
pin_pad_api.ClickOnDigit(4);
pin_pad_api.ClickOnDigit(5);
pin_pad_api.ClickOnDigit(6);
ASSERT_TRUE(pin_input_test.GetCode().has_value());
EXPECT_EQ(pin_input_test.GetCode().value(), pin);
base::RunLoop().RunUntilIdle();
}
TEST_F(LoginAuthUserViewPinOnlyUnittest, PinOnlyModeWithAutosubmitDisabled) {
LoginAuthUserView::TestApi auth_test(view_);
ui::test::EventGenerator* generator = GetEventGenerator();
auto client = std::make_unique<MockLoginScreenClient>();
@ -338,7 +387,8 @@ TEST_F(LoginAuthUserViewUnittest, PinAndPasswordFieldModeCorrectness) {
// PIN length not exposed and thus no auto submit.
SetUserCount(1);
SetAuthPin(/*autosubmit_length*/ 0);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_AND_PASSWORD);
ExpectModeVisibility(
LoginAuthUserView::InputFieldMode::kPinOnlyAutosubmitOff);
// Typing '123456789'.
pin_pad_api.ClickOnDigit(1);
@ -365,7 +415,50 @@ TEST_F(LoginAuthUserViewUnittest, PinAndPasswordFieldModeCorrectness) {
}
/**
* Tests the correctness of InputFieldMode::PIN_WITH_TOGGLE - the default
* Tests the correctness of InputFieldMode::kPasswordAndPin by ensuring the
* following:
* - Clicking on the pin pad inserts digits into the field
* - Digits are correctly ignored when the field is set to read-only
* - Submitting the credentials results in the correct auth call
*/
TEST_F(LoginAuthUserViewUnittest, PinAndPasswordFieldModeCorrectness) {
LoginAuthUserView::TestApi auth_test(view_);
ui::test::EventGenerator* generator = GetEventGenerator();
auto client = std::make_unique<MockLoginScreenClient>();
LoginUserView* user_view(auth_test.user_view());
LoginPinView::TestApi pin_pad_api{auth_test.pin_view()};
// PIN length not exposed and thus no auto submit.
SetUserCount(1);
SetAuthPasswordAndPin(/*autosubmit_length*/ 0);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPasswordAndPin);
// Typing '123456789'.
pin_pad_api.ClickOnDigit(1);
pin_pad_api.ClickOnDigit(2);
pin_pad_api.ClickOnDigit(3);
// '456' must be ignored.
auth_test.password_view()->SetReadOnly(true);
pin_pad_api.ClickOnDigit(4);
pin_pad_api.ClickOnDigit(5);
pin_pad_api.ClickOnDigit(6);
auth_test.password_view()->SetReadOnly(false);
pin_pad_api.ClickOnDigit(7);
pin_pad_api.ClickOnDigit(8);
pin_pad_api.ClickOnDigit(9);
EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin_(
user_view->current_user().basic_user_info.account_id,
/*password=*/"123789",
/*authenticated_by_pin=*/true,
/*callback=*/_));
generator->PressKey(ui::KeyboardCode::VKEY_RETURN, 0);
base::RunLoop().RunUntilIdle();
}
/**
* Tests the correctness of InputFieldMode::kPinWithToggle - the default
* input mode when using a PIN with auto submit enabled, by ensuring the
* following:
* - Clicking on the pin pad inserts digits into the field
@ -381,8 +474,8 @@ TEST_F(LoginAuthUserViewUnittest, PinWithToggleFieldModeCorrectness) {
// Set up PIN with auto submit.
SetUserCount(1);
SetAuthPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_WITH_TOGGLE);
SetAuthPasswordAndPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPinWithToggle);
const auto pin = std::string("123456");
EXPECT_CALL(*client, AuthenticateUserWithPasswordOrPin_(
@ -409,7 +502,7 @@ TEST_F(LoginAuthUserViewUnittest, PinWithToggleFieldModeCorrectness) {
}
/**
* Tests the correctness of InputFieldMode::PWD_WITH_TOGGLE. This is the
* Tests the correctness of InputFieldMode::kPwdWithToggle. This is the
* mode that shows just the password field with the option to switch to PIN.
* It is only available when the user has auto submit enabled.
*/
@ -422,14 +515,14 @@ TEST_F(LoginAuthUserViewUnittest, PwdWithToggleFieldModeCorrectness) {
// Set up PIN with auto submit and click on the toggle to switch to password.
SetUserCount(1);
SetAuthPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_WITH_TOGGLE);
SetAuthPasswordAndPin(/*autosubmit_length*/ 6);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPinWithToggle);
const ui::MouseEvent event(ui::EventType::kMousePressed, gfx::Point(),
gfx::Point(), ui::EventTimeForNow(), 0, 0);
views::test::ButtonTestApi(auth_test.pin_password_toggle())
.NotifyClick(event);
base::RunLoop().RunUntilIdle();
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PWD_WITH_TOGGLE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPwdWithToggle);
// Insert a password consisting of numbers only and expect it to be treated
// as a password, not a PIN. This means 'authenticated_by_pin' must be false.
@ -496,7 +589,7 @@ TEST_P(LoginAuthUserViewOnlineUnittest, OnlineSignInMessage) {
GetParam() ? IDS_ASH_LOCK_SCREEN_VERIFY_ACCOUNT_MESSAGE
: IDS_ASH_LOGIN_ONLINE_SIGN_IN_MESSAGE);
EXPECT_EQ(online_sign_in_message->GetText(), expected_text);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::NONE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kNone);
// Clicking the message triggers |ShowGaiaSignin|.
EXPECT_CALL(
@ -652,20 +745,20 @@ TEST_F(LoginAuthUserViewAuthFactorsUnittest,
InitializeViewForUser(user);
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PASSWORD_ONLY);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPasswordOnly);
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_AUTH_FACTOR_IS_HIDING_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::NONE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kNone);
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_PIN);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::PIN_AND_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kPasswordAndPin);
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_PIN |
LoginAuthUserView::AUTH_AUTH_FACTOR_IS_HIDING_PASSWORD);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::NONE);
ExpectModeVisibility(LoginAuthUserView::InputFieldMode::kNone);
}
// Regression test for b/217385675.