Commit 86a87223 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Views login/lock clear password when switching active auth user.

Bug: 855725
Change-Id: I91f6bab46701c9d66bc8b497661c460a7968619f
Reviewed-on: https://chromium-review.googlesource.com/1112075
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarXiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569802}
parent fa187881
......@@ -101,6 +101,26 @@ ui::CallbackLayerAnimationObserver* BuildObserverToHideView(views::View* view) {
view));
}
// Clears the password for the given |LoginPasswordView| instance and then
// deletes itself.
class ClearPasswordAnimationObserver : public ui::ImplicitAnimationObserver {
public:
explicit ClearPasswordAnimationObserver(LoginPasswordView* view)
: view_(view) {}
~ClearPasswordAnimationObserver() override = default;
// ui::ImplicitAnimationObserver:
void OnImplicitAnimationsCompleted() override {
view_->Clear();
delete this;
}
private:
LoginPasswordView* view_;
DISALLOW_COPY_AND_ASSIGN(ClearPasswordAnimationObserver);
};
// A view which has a round border and a fingerprint icon at the center.
class FingerprintIconView : public views::View {
public:
......@@ -548,6 +568,10 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
login_constants::kChangeUserAnimationDurationMs));
settings.SetTweenType(gfx::Tween::Type::FAST_OUT_SLOW_IN);
if (cached_animation_state_->had_password && !has_password) {
settings.AddObserver(
new ClearPasswordAnimationObserver(password_view_));
}
password_view_->layer()->SetOpacity(opacity_end);
}
......
......@@ -12,6 +12,7 @@
#include "ash/strings/grit/ash_strings.h"
#include "base/bind_helpers.h"
#include "base/run_loop.h"
#include "base/strings/utf_string_conversions.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event_utils.h"
......@@ -163,4 +164,32 @@ TEST_F(LoginAuthUserViewUnittest, OnlineSignInMessage) {
EXPECT_FALSE(online_sign_in_message->visible());
}
// Verifies that password is cleared after AUTH_PASSWORD is disabled.
TEST_F(LoginAuthUserViewUnittest,
PasswordClearedAfterAnimationIfPasswordDisabled) {
LoginPasswordView::TestApi password_test(view_->password_view());
auto has_password = [&]() {
return !password_test.textfield()->text().empty();
};
// Set a password.
view_->SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD);
password_test.textfield()->SetText(base::ASCIIToUTF16("Hello"));
// Enable some other auth method (PIN), password is not cleared.
view_->CaptureStateForAnimationPreLayout();
view_->SetAuthMethods(LoginAuthUserView::AUTH_PASSWORD |
LoginAuthUserView::AUTH_PIN);
EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout();
EXPECT_TRUE(has_password());
// Disable password, password is cleared.
view_->CaptureStateForAnimationPreLayout();
view_->SetAuthMethods(LoginAuthUserView::AUTH_NONE);
EXPECT_TRUE(has_password());
view_->ApplyAnimationPostLayout();
EXPECT_FALSE(has_password());
}
} // 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