Commit 1aecdebf authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

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

Fixed ASAN issue where an animation sequence was being used after it was
scheduled. In a test, the sequence is destroyed immediately after scheduling.
This was a pre-existing issue exposed by the new test.

Bug: 855725
Change-Id: I07a475374df775465e4a9f110df6d2759fdf38d6
Reviewed-on: https://chromium-review.googlesource.com/1113997Reviewed-by: default avatarXiaoyin Hu <xiaoyinh@chromium.org>
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570178}
parent 1be23e1d
......@@ -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:
......@@ -529,8 +549,8 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
base::TimeDelta::FromMilliseconds(
login_constants::kChangeUserAnimationDurationMs));
transition->set_tween_type(gfx::Tween::Type::FAST_OUT_SLOW_IN);
auto* sequence = new ui::LayerAnimationSequence(std::move(transition));
layer()->GetAnimator()->StartAnimation(sequence);
layer()->GetAnimator()->StartAnimation(
new ui::LayerAnimationSequence(std::move(transition)));
////////
// Fade the password view if it is being hidden or shown.
......@@ -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);
}
......@@ -577,7 +601,6 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
login_constants::kChangeUserAnimationDurationMs),
gfx::Tween::FAST_OUT_SLOW_IN);
auto* sequence = new ui::LayerAnimationSequence(std::move(transition));
pin_view_->layer()->GetAnimator()->ScheduleAnimation(sequence);
// Hide the PIN keyboard after animation if needed.
if (!has_pin) {
......@@ -585,6 +608,8 @@ void LoginAuthUserView::ApplyAnimationPostLayout() {
sequence->AddObserver(observer);
observer->SetActive();
}
pin_view_->layer()->GetAnimator()->ScheduleAnimation(sequence);
}
cached_animation_state_.reset();
......
......@@ -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