Commit bbd354e0 authored by Renato Silva's avatar Renato Silva Committed by Commit Bot

Chrome OS - Refactor LoginAuthUserView

The visibility of the elements within LoginAuthUserView (password
field, pin pad) are now being controlled based on the InputFieldMode,
which is determined by the authentication methods a user has.

Additionally, the user's PIN length is now being provided to this view
to use, if it is exposed.

Bug: 1075994
Change-Id: Iad0bbc793e52a790856ae0dde3aae7369c16b390
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332663
Commit-Queue: Renato Silva <rrsilva@google.com>
Reviewed-by: default avatarRoman Sorokin [CET] <rsorokin@chromium.org>
Reviewed-by: default avatarDenis Kuznetsov [CET] <antrim@chromium.org>
Reviewed-by: default avatarRoman Aleksandrov <raleksandrov@google.com>
Auto-Submit: Renato Silva <rrsilva@google.com>
Cr-Commit-Position: refs/heads/master@{#795023}
parent 0f15bf84
...@@ -55,6 +55,7 @@ ...@@ -55,6 +55,7 @@
#include "chromeos/components/proximity_auth/public/mojom/auth_type.mojom.h" #include "chromeos/components/proximity_auth/public/mojom/auth_type.mojom.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "chromeos/strings/grit/chromeos_strings.h" #include "chromeos/strings/grit/chromeos_strings.h"
#include "components/user_manager/known_user.h"
#include "components/user_manager/user_type.h" #include "components/user_manager/user_type.h"
#include "ui/accessibility/ax_node_data.h" #include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -932,6 +933,8 @@ void LockContentsView::OnPinEnabledForUserChanged(const AccountId& user, ...@@ -932,6 +933,8 @@ void LockContentsView::OnPinEnabledForUserChanged(const AccountId& user,
} }
state->show_pin = enabled; state->show_pin = enabled;
state->autosubmit_pin_length =
user_manager::known_user::GetUserPinLength(user);
LoginBigUserView* big_user = LoginBigUserView* big_user =
TryToFindBigUser(user, true /*require_auth_active*/); TryToFindBigUser(user, true /*require_auth_active*/);
...@@ -1773,7 +1776,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update, ...@@ -1773,7 +1776,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
UserState* state = FindStateForUser( UserState* state = FindStateForUser(
view->auth_user()->current_user().basic_user_info.account_id); view->auth_user()->current_user().basic_user_info.account_id);
uint32_t to_update_auth; uint32_t to_update_auth;
bool show_pinpad = false; LoginAuthUserView::AuthMethodsMetadata auth_metadata;
if (state->force_online_sign_in) { if (state->force_online_sign_in) {
to_update_auth = LoginAuthUserView::AUTH_ONLINE_SIGN_IN; to_update_auth = LoginAuthUserView::AUTH_ONLINE_SIGN_IN;
} else if (state->disable_auth) { } else if (state->disable_auth) {
...@@ -1788,10 +1791,10 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update, ...@@ -1788,10 +1791,10 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
// visible, but the keyboard is in a different root window or the view // visible, but the keyboard is in a different root window or the view
// has not been added to the widget. In these cases, the keyboard does // has not been added to the widget. In these cases, the keyboard does
// not interfere with PIN entry. // not interfere with PIN entry.
const bool is_keyboard_visible_for_view = auth_metadata.virtual_keyboard_visible =
GetKeyboardControllerForView() ? keyboard_shown_ : false; GetKeyboardControllerForView() ? keyboard_shown_ : false;
show_pinpad = !is_keyboard_visible_for_view && auth_metadata.show_pinpad_for_pw = state->show_pin_pad_for_password;
(state->show_pin || state->show_pin_pad_for_password); auth_metadata.autosubmit_pin_length = state->autosubmit_pin_length;
if (state->show_pin) if (state->show_pin)
to_update_auth |= LoginAuthUserView::AUTH_PIN; to_update_auth |= LoginAuthUserView::AUTH_PIN;
if (state->enable_tap_auth) if (state->enable_tap_auth)
...@@ -1799,7 +1802,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update, ...@@ -1799,7 +1802,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
if (state->fingerprint_state != FingerprintState::UNAVAILABLE) if (state->fingerprint_state != FingerprintState::UNAVAILABLE)
to_update_auth |= LoginAuthUserView::AUTH_FINGERPRINT; to_update_auth |= LoginAuthUserView::AUTH_FINGERPRINT;
} }
view->auth_user()->SetAuthMethods(to_update_auth, show_pinpad); view->auth_user()->SetAuthMethods(to_update_auth, auth_metadata);
} else if (view->public_account()) { } else if (view->public_account()) {
view->public_account()->SetAuthEnabled(true /*enabled*/, animate); view->public_account()->SetAuthEnabled(true /*enabled*/, animate);
} }
...@@ -1809,8 +1812,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update, ...@@ -1809,8 +1812,7 @@ void LockContentsView::LayoutAuth(LoginBigUserView* to_update,
if (!view) if (!view)
return; return;
if (view->auth_user()) { if (view->auth_user()) {
view->auth_user()->SetAuthMethods(LoginAuthUserView::AUTH_NONE, view->auth_user()->SetAuthMethods(LoginAuthUserView::AUTH_NONE);
false /*show_pinpad*/);
} else if (view->public_account()) { } else if (view->public_account()) {
view->public_account()->SetAuthEnabled(false /*enabled*/, animate); view->public_account()->SetAuthEnabled(false /*enabled*/, animate);
} }
......
...@@ -248,6 +248,7 @@ class ASH_EXPORT LockContentsView ...@@ -248,6 +248,7 @@ class ASH_EXPORT LockContentsView
bool force_online_sign_in = false; bool force_online_sign_in = false;
bool disable_auth = false; bool disable_auth = false;
bool show_pin_pad_for_password = false; bool show_pin_pad_for_password = false;
size_t autosubmit_pin_length = 0;
base::Optional<EasyUnlockIconOptions> easy_unlock_state; base::Optional<EasyUnlockIconOptions> easy_unlock_state;
FingerprintState fingerprint_state; FingerprintState fingerprint_state;
......
...@@ -745,8 +745,8 @@ struct LoginAuthUserView::AnimationState { ...@@ -745,8 +745,8 @@ struct LoginAuthUserView::AnimationState {
non_pin_y_start_in_screen = view->GetBoundsInScreen().y(); non_pin_y_start_in_screen = view->GetBoundsInScreen().y();
pin_start_in_screen = view->pin_view_->GetBoundsInScreen().origin(); pin_start_in_screen = view->pin_view_->GetBoundsInScreen().origin();
had_pinpad = view->show_pinpad_; had_pinpad = view->ShouldShowPinPad();
had_password = view->HasAuthMethod(LoginAuthUserView::AUTH_PASSWORD); had_password = view->ShouldShowPasswordField();
had_fingerprint = view->HasAuthMethod(LoginAuthUserView::AUTH_FINGERPRINT); had_fingerprint = view->HasAuthMethod(LoginAuthUserView::AUTH_FINGERPRINT);
} }
...@@ -978,21 +978,23 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user, ...@@ -978,21 +978,23 @@ LoginAuthUserView::LoginAuthUserView(const LoginUserInfo& user,
add_padding(kDistanceFromPinKeyboardToBigUserViewBottomDp); add_padding(kDistanceFromPinKeyboardToBigUserViewBottomDp);
// Update authentication UI. // Update authentication UI.
SetAuthMethods(auth_methods_, false /*show_pinpad*/); SetAuthMethods(auth_methods_);
user_view_->UpdateForUser(user, false /*animate*/); user_view_->UpdateForUser(user, false /*animate*/);
} }
LoginAuthUserView::~LoginAuthUserView() = default; LoginAuthUserView::~LoginAuthUserView() = default;
void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods, void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
bool show_pinpad) { AuthMethodsMetadata auth_metadata) {
show_pinpad_ = show_pinpad;
bool had_password = HasAuthMethod(AUTH_PASSWORD); bool had_password = HasAuthMethod(AUTH_PASSWORD);
// Apply changes and determine the new state of input fields.
auth_methods_ = static_cast<AuthMethods>(auth_methods); auth_methods_ = static_cast<AuthMethods>(auth_methods);
bool has_password = HasAuthMethod(AUTH_PASSWORD); auth_metadata_ = auth_metadata;
bool has_pin = HasAuthMethod(AUTH_PIN); UpdateInputFieldMode();
bool has_tap = HasAuthMethod(AUTH_TAP);
bool has_password = ShouldShowPasswordField();
bool has_pinpad = ShouldShowPinPad();
bool force_online_sign_in = HasAuthMethod(AUTH_ONLINE_SIGN_IN); bool force_online_sign_in = HasAuthMethod(AUTH_ONLINE_SIGN_IN);
bool has_fingerprint = HasAuthMethod(AUTH_FINGERPRINT); bool has_fingerprint = HasAuthMethod(AUTH_FINGERPRINT);
bool has_challenge_response = HasAuthMethod(AUTH_CHALLENGE_RESPONSE); bool has_challenge_response = HasAuthMethod(AUTH_CHALLENGE_RESPONSE);
...@@ -1008,10 +1010,10 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods, ...@@ -1008,10 +1010,10 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
// Adjust the PIN keyboard visibility before the password textfield's one, so // Adjust the PIN keyboard visibility before the password textfield's one, so
// that when both are about to be hidden the focus doesn't jump to the "1" // that when both are about to be hidden the focus doesn't jump to the "1"
// keyboard button, causing unexpected accessibility effects. // keyboard button, causing unexpected accessibility effects.
pin_view_->SetVisible(show_pinpad); pin_view_->SetVisible(has_pinpad);
password_view_->SetEnabled(has_password); password_view_->SetEnabled(has_password);
password_view_->SetEnabledOnEmptyPassword(has_tap); password_view_->SetEnabledOnEmptyPassword(HasAuthMethod(AUTH_TAP));
password_view_->SetFocusEnabledForChildViews(has_password); password_view_->SetFocusEnabledForChildViews(has_password);
password_view_->SetVisible(!hide_auth && has_password); password_view_->SetVisible(!hide_auth && has_password);
password_view_->layer()->SetOpacity(has_password ? 1 : 0); password_view_->layer()->SetOpacity(has_password ? 1 : 0);
...@@ -1021,31 +1023,20 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods, ...@@ -1021,31 +1023,20 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
password_view_->RequestFocus(); password_view_->RequestFocus();
fingerprint_view_->SetVisible(has_fingerprint); fingerprint_view_->SetVisible(has_fingerprint);
fingerprint_view_->SetCanUsePin(has_pin); fingerprint_view_->SetCanUsePin(HasAuthMethod(AUTH_PIN));
challenge_response_view_->SetVisible(has_challenge_response); challenge_response_view_->SetVisible(has_challenge_response);
int padding_view_height = kDistanceBetweenPasswordFieldAndPinKeyboardDp; int padding_view_height = kDistanceBetweenPasswordFieldAndPinKeyboardDp;
if (has_fingerprint && !show_pinpad) { if (has_fingerprint && !has_pinpad) {
padding_view_height = kDistanceBetweenPasswordFieldAndFingerprintViewDp; padding_view_height = kDistanceBetweenPasswordFieldAndFingerprintViewDp;
} else if (has_challenge_response && !show_pinpad) { } else if (has_challenge_response && !has_pinpad) {
padding_view_height = padding_view_height =
kDistanceBetweenPasswordFieldAndChallengeResponseViewDp; kDistanceBetweenPasswordFieldAndChallengeResponseViewDp;
} }
padding_below_password_view_->SetPreferredSize( padding_below_password_view_->SetPreferredSize(
gfx::Size(kNonEmptyWidthDp, padding_view_height)); gfx::Size(kNonEmptyWidthDp, padding_view_height));
// Note: |has_tap| must have higher priority than |has_pin| when password_view_->SetPlaceholderText(GetPasswordViewPlaceholder());
// determining the placeholder.
if (has_tap) {
password_view_->SetPlaceholderText(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PASSWORD_TAP_PLACEHOLDER));
} else if (has_pin) {
password_view_->SetPlaceholderText(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PASSWORD_PIN_PLACEHOLDER));
} else {
password_view_->SetPlaceholderText(
l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PASSWORD_PLACEHOLDER));
}
const std::string& user_display_email = const std::string& user_display_email =
current_user().basic_user_info.display_email; current_user().basic_user_info.display_email;
password_view_->SetAccessibleName(l10n_util::GetStringFUTF16( password_view_->SetAccessibleName(l10n_util::GetStringFUTF16(
...@@ -1055,8 +1046,8 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods, ...@@ -1055,8 +1046,8 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods,
// Only the active auth user view has a password displayed. If that is the // Only the active auth user view has a password displayed. If that is the
// case, then render the user view as if it was always focused, since clicking // case, then render the user view as if it was always focused, since clicking
// on it will not do anything (such as swapping users). // on it will not do anything (such as swapping users).
user_view_->SetForceOpaque(has_password || hide_auth); user_view_->SetForceOpaque(HasAuthMethod(AUTH_PASSWORD) || hide_auth);
user_view_->SetTapEnabled(!has_password); user_view_->SetTapEnabled(!HasAuthMethod(AUTH_PASSWORD));
// Tapping the user view will trigger the online sign-in flow when // Tapping the user view will trigger the online sign-in flow when
// |force_online_sign_in| is true. // |force_online_sign_in| is true.
if (force_online_sign_in) if (force_online_sign_in)
...@@ -1105,8 +1096,9 @@ void LoginAuthUserView::CaptureStateForAnimationPreLayout() { ...@@ -1105,8 +1096,9 @@ void LoginAuthUserView::CaptureStateForAnimationPreLayout() {
void LoginAuthUserView::ApplyAnimationPostLayout() { void LoginAuthUserView::ApplyAnimationPostLayout() {
DCHECK(cached_animation_state_); DCHECK(cached_animation_state_);
bool has_password = HasAuthMethod(AUTH_PASSWORD); bool has_password = ShouldShowPasswordField();
bool has_pinpad = show_pinpad_; bool had_password = cached_animation_state_->had_password;
bool has_pinpad = ShouldShowPinPad();
bool has_fingerprint = HasAuthMethod(AUTH_FINGERPRINT); bool has_fingerprint = HasAuthMethod(AUTH_FINGERPRINT);
//////// ////////
...@@ -1139,12 +1131,12 @@ void LoginAuthUserView::ApplyAnimationPostLayout() { ...@@ -1139,12 +1131,12 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
//////// ////////
// Fade the password view if it is being hidden or shown. // Fade the password view if it is being hidden or shown.
if (cached_animation_state_->had_password != has_password) { if (had_password != has_password) {
float opacity_start = 0, opacity_end = 1; float opacity_start = 0, opacity_end = 1;
if (!has_password) if (!has_password)
std::swap(opacity_start, opacity_end); std::swap(opacity_start, opacity_end);
if (cached_animation_state_->had_password) if (had_password)
password_view_->SetVisible(true); password_view_->SetVisible(true);
password_view_->layer()->SetOpacity(opacity_start); password_view_->layer()->SetOpacity(opacity_start);
...@@ -1155,7 +1147,7 @@ void LoginAuthUserView::ApplyAnimationPostLayout() { ...@@ -1155,7 +1147,7 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds( settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
login_constants::kChangeUserAnimationDurationMs)); login_constants::kChangeUserAnimationDurationMs));
settings.SetTweenType(gfx::Tween::Type::FAST_OUT_SLOW_IN); settings.SetTweenType(gfx::Tween::Type::FAST_OUT_SLOW_IN);
if (cached_animation_state_->had_password && !has_password) { if (had_password && !has_password) {
settings.AddObserver( settings.AddObserver(
new ClearPasswordAndHideAnimationObserver(password_view_)); new ClearPasswordAndHideAnimationObserver(password_view_));
} }
...@@ -1361,4 +1353,49 @@ void LoginAuthUserView::AttemptAuthenticateWithChallengeResponse() { ...@@ -1361,4 +1353,49 @@ void LoginAuthUserView::AttemptAuthenticateWithChallengeResponse() {
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
void LoginAuthUserView::UpdateInputFieldMode() {
if (!HasAuthMethod(AUTH_PASSWORD)) {
input_field_mode_ = InputFieldMode::DISABLED;
return;
}
if (!HasAuthMethod(AUTH_PIN)) {
input_field_mode_ = InputFieldMode::PASSWORD_ONLY;
return;
}
input_field_mode_ = InputFieldMode::PIN_AND_PASSWORD;
return;
}
bool LoginAuthUserView::ShouldShowPinPad() const {
if (auth_metadata_.virtual_keyboard_visible)
return false;
switch (input_field_mode_) {
case InputFieldMode::DISABLED:
return false;
case InputFieldMode::PASSWORD_ONLY:
return auth_metadata_.show_pinpad_for_pw;
case InputFieldMode::PIN_AND_PASSWORD:
return true;
}
}
bool LoginAuthUserView::ShouldShowPasswordField() const {
return input_field_mode_ == InputFieldMode::PASSWORD_ONLY ||
input_field_mode_ == InputFieldMode::PIN_AND_PASSWORD;
}
base::string16 LoginAuthUserView::GetPasswordViewPlaceholder() const {
// Note: |AUTH_TAP| must have higher priority than |AUTH_PIN| when
// determining the placeholder.
if (HasAuthMethod(AUTH_TAP))
return l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_POD_PASSWORD_TAP_PLACEHOLDER);
if (input_field_mode_ == InputFieldMode::PIN_AND_PASSWORD)
return l10n_util::GetStringUTF16(
IDS_ASH_LOGIN_POD_PASSWORD_PIN_PLACEHOLDER);
return l10n_util::GetStringUTF16(IDS_ASH_LOGIN_POD_PASSWORD_PLACEHOLDER);
}
} // namespace ash } // namespace ash
...@@ -53,6 +53,26 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -53,6 +53,26 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// message to user. // message to user.
}; };
// Extra control parameters to be passed when setting the auth methods.
struct AuthMethodsMetadata {
explicit AuthMethodsMetadata() {}
// If the virtual keyboard is visible, the pinpad is hidden.
bool virtual_keyboard_visible = false;
// Whether to show the pinpad for the password field.
bool show_pinpad_for_pw = false;
// User's pin length to use for autosubmit.
size_t autosubmit_pin_length = 0;
};
// Possible states that the input field might be in.
// This is determined by the current authentication methods
// that a user has.
enum class InputFieldMode {
DISABLED, // Not showing any input field.
PASSWORD_ONLY, // No PIN set. Password only field.
PIN_AND_PASSWORD, // PIN set.
};
// TestApi is used for tests to get internal implementation details. // TestApi is used for tests to get internal implementation details.
class ASH_EXPORT TestApi { class ASH_EXPORT TestApi {
public: public:
...@@ -104,10 +124,13 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -104,10 +124,13 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
~LoginAuthUserView() override; ~LoginAuthUserView() override;
// Set the displayed set of auth methods. |auth_methods| contains or-ed // Set the displayed set of auth methods. |auth_methods| contains or-ed
// together AuthMethod values. |show_pinpad| determines whether the pin pad // together AuthMethod values. |auth_metadata| provides additional control
// should be visible. // parameters for the view.
void SetAuthMethods(uint32_t auth_methods, bool show_pinpad); void SetAuthMethods(
uint32_t auth_methods,
AuthMethodsMetadata auth_metadata = AuthMethodsMetadata());
AuthMethods auth_methods() const { return auth_methods_; } AuthMethods auth_methods() const { return auth_methods_; }
InputFieldMode input_field_mode() const { return input_field_mode_; }
// Add an easy unlock icon. // Add an easy unlock icon.
void SetEasyUnlockIcon(EasyUnlockIconId id, void SetEasyUnlockIcon(EasyUnlockIconId id,
...@@ -183,10 +206,24 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView, ...@@ -183,10 +206,24 @@ class ASH_EXPORT LoginAuthUserView : public NonAccessibleView,
// starts the asynchronous authentication process against a security token. // starts the asynchronous authentication process against a security token.
void AttemptAuthenticateWithChallengeResponse(); void AttemptAuthenticateWithChallengeResponse();
// Determines the mode of the input field based on the available
// authentication methods.
void UpdateInputFieldMode();
// Convenience methods to determine element visibility.
bool ShouldShowPinPad() const;
bool ShouldShowPasswordField() const;
// Convenience methods to determine UI text based on the InputFieldMode.
base::string16 GetPasswordViewPlaceholder() const;
// Authentication methods available and extra parameters that control the UI.
AuthMethods auth_methods_ = AUTH_NONE; AuthMethods auth_methods_ = AUTH_NONE;
AuthMethodsMetadata auth_metadata_ = AuthMethodsMetadata();
// Controls which input field is currently being shown.
InputFieldMode input_field_mode_ = InputFieldMode::DISABLED;
// Whether to show the pinpad. Sometimes hidden by the on screen keyboard
bool show_pinpad_ = false;
LoginUserView* user_view_ = nullptr; LoginUserView* user_view_ = nullptr;
LoginPasswordView* password_view_ = nullptr; LoginPasswordView* password_view_ = nullptr;
NonAccessibleView* password_view_container_ = nullptr; NonAccessibleView* password_view_container_ = nullptr;
......
...@@ -57,8 +57,15 @@ class LoginAuthUserViewUnittest : public LoginTestBase { ...@@ -57,8 +57,15 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
SetWidget(CreateWidgetWithContent(container_)); SetWidget(CreateWidgetWithContent(container_));
} }
void SetAuthMethods(uint32_t auth_methods, bool show_pinpad) { void SetAuthMethods(uint32_t auth_methods,
view_->SetAuthMethods(auth_methods, show_pinpad); bool show_pinpad_for_pw = false,
bool virtual_keyboard_visible = false,
size_t autosubmit_pin_length = 0) {
LoginAuthUserView::AuthMethodsMetadata auth_metadata;
auth_metadata.show_pinpad_for_pw = show_pinpad_for_pw;
auth_metadata.virtual_keyboard_visible = virtual_keyboard_visible;
auth_metadata.autosubmit_pin_length = autosubmit_pin_length;
view_->SetAuthMethods(auth_methods, auth_metadata);
} }
LoginUserInfo user_; LoginUserInfo user_;
...@@ -74,7 +81,8 @@ class LoginAuthUserViewUnittest : public LoginTestBase { ...@@ -74,7 +81,8 @@ class LoginAuthUserViewUnittest : public LoginTestBase {
// Verifies showing the PIN keyboard makes the user view grow. // Verifies showing the PIN keyboard makes the user view grow.
TEST_F(LoginAuthUserViewUnittest, ShowingPinExpandsView) { TEST_F(LoginAuthUserViewUnittest, ShowingPinExpandsView) {
gfx::Size start_size = view_->size(); gfx::Size start_size = view_->size();
SetAuthMethods(LoginAuthUserView::AUTH_PIN, true /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_PIN);
container_->Layout(); container_->Layout();
gfx::Size expanded_size = view_->size(); gfx::Size expanded_size = view_->size();
EXPECT_GT(expanded_size.height(), start_size.height()); EXPECT_GT(expanded_size.height(), start_size.height());
...@@ -94,11 +102,11 @@ TEST_F(LoginAuthUserViewUnittest, ShowingPasswordForcesOpaque) { ...@@ -94,11 +102,11 @@ TEST_F(LoginAuthUserViewUnittest, ShowingPasswordForcesOpaque) {
EXPECT_FALSE(auth_test.user_view()->HasFocus()); EXPECT_FALSE(auth_test.user_view()->HasFocus());
// If the user view is showing a password it must be opaque. // If the user view is showing a password it must be opaque.
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
EXPECT_TRUE(user_test.is_opaque()); EXPECT_TRUE(user_test.is_opaque());
SetAuthMethods(LoginAuthUserView::AUTH_NONE, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_FALSE(user_test.is_opaque()); EXPECT_FALSE(user_test.is_opaque());
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
EXPECT_TRUE(user_test.is_opaque()); EXPECT_TRUE(user_test.is_opaque());
} }
...@@ -118,8 +126,8 @@ TEST_F(LoginAuthUserViewUnittest, PressReturnWithTapToUnlockEnabled) { ...@@ -118,8 +126,8 @@ TEST_F(LoginAuthUserViewUnittest, PressReturnWithTapToUnlockEnabled) {
EXPECT_CALL(*client, EXPECT_CALL(*client,
AuthenticateUserWithEasyUnlock( AuthenticateUserWithEasyUnlock(
user_view->current_user().basic_user_info.account_id)); user_view->current_user().basic_user_info.account_id));
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD | LoginAuthUserView::AUTH_TAP, SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
false /*show_pinpad*/); LoginAuthUserView::AUTH_TAP);
password_view->Clear(); password_view->Clear();
generator->PressKey(ui::KeyboardCode::VKEY_RETURN, 0); generator->PressKey(ui::KeyboardCode::VKEY_RETURN, 0);
...@@ -137,7 +145,7 @@ TEST_F(LoginAuthUserViewUnittest, OnlineSignInMessage) { ...@@ -137,7 +145,7 @@ TEST_F(LoginAuthUserViewUnittest, OnlineSignInMessage) {
// When auth method is |AUTH_ONLINE_SIGN_IN|, the online sign-in message is // When auth method is |AUTH_ONLINE_SIGN_IN|, the online sign-in message is
// visible. The password field and PIN keyboard are invisible. // visible. The password field and PIN keyboard are invisible.
SetAuthMethods(LoginAuthUserView::AUTH_ONLINE_SIGN_IN, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_ONLINE_SIGN_IN);
EXPECT_TRUE(online_sign_in_message->GetVisible()); EXPECT_TRUE(online_sign_in_message->GetVisible());
EXPECT_FALSE(password_view->GetVisible()); EXPECT_FALSE(password_view->GetVisible());
EXPECT_FALSE(pin_view->GetVisible()); EXPECT_FALSE(pin_view->GetVisible());
...@@ -152,13 +160,13 @@ TEST_F(LoginAuthUserViewUnittest, OnlineSignInMessage) { ...@@ -152,13 +160,13 @@ TEST_F(LoginAuthUserViewUnittest, OnlineSignInMessage) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
// The online sign-in message is invisible for all other auth methods. // The online sign-in message is invisible for all other auth methods.
SetAuthMethods(LoginAuthUserView::AUTH_NONE, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_FALSE(online_sign_in_message->GetVisible()); EXPECT_FALSE(online_sign_in_message->GetVisible());
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
EXPECT_FALSE(online_sign_in_message->GetVisible()); EXPECT_FALSE(online_sign_in_message->GetVisible());
SetAuthMethods(LoginAuthUserView::AUTH_PIN, true /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PIN);
EXPECT_FALSE(online_sign_in_message->GetVisible()); EXPECT_FALSE(online_sign_in_message->GetVisible());
SetAuthMethods(LoginAuthUserView::AUTH_TAP, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_TAP);
EXPECT_FALSE(online_sign_in_message->GetVisible()); EXPECT_FALSE(online_sign_in_message->GetVisible());
} }
...@@ -171,20 +179,20 @@ TEST_F(LoginAuthUserViewUnittest, ...@@ -171,20 +179,20 @@ TEST_F(LoginAuthUserViewUnittest,
}; };
// Set a password. // Set a password.
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
password_test.textfield()->SetText(base::ASCIIToUTF16("Hello")); password_test.textfield()->SetText(base::ASCIIToUTF16("Hello"));
// Enable some other auth method (PIN), password is not cleared. // Enable some other auth method (PIN), password is not cleared.
view_->CaptureStateForAnimationPreLayout(); view_->CaptureStateForAnimationPreLayout();
SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD | LoginAuthUserView::AUTH_PIN, SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
true /*show_pinpad*/); LoginAuthUserView::AUTH_PIN);
EXPECT_TRUE(has_password()); EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout(); view_->ApplyAnimationPostLayout();
EXPECT_TRUE(has_password()); EXPECT_TRUE(has_password());
// Disable password, password is cleared. // Disable password, password is cleared.
view_->CaptureStateForAnimationPreLayout(); view_->CaptureStateForAnimationPreLayout();
SetAuthMethods(LoginAuthUserView::AUTH_NONE, false /*show_pinpad*/); SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_TRUE(has_password()); EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout(); view_->ApplyAnimationPostLayout();
EXPECT_FALSE(has_password()); EXPECT_FALSE(has_password());
......
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