Commit c383b029 authored by Mathieu Perreault's avatar Mathieu Perreault Committed by Commit Bot

[Payments] Fix some issues around buttons for Card Unmask dialog

- The close button is the now the only button showing if there is
a permanent error or a network failure.
- State is reset appropriately between dialog shows.
- Layout is called on the whole widget when buttons change.

Bug: 850571
Change-Id: I1dfe792b49102d8a002d9bcf984e8c6c0844cc58
Reviewed-on: https://chromium-review.googlesource.com/1119164
Commit-Queue: Mathieu Perreault <mathp@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#572438}
parent e9a7dae9
......@@ -136,7 +136,10 @@ void CardUnmaskPromptViews::GotVerificationResult(
DialogModelChanged();
}
Layout();
// Since we may have affected the layout of the button row, we retrigger a
// layout of the whole dialog (contents and button row).
InvalidateLayout();
parent()->Layout();
}
void CardUnmaskPromptViews::LinkClicked(views::Link* source, int event_flags) {
......@@ -249,8 +252,12 @@ void CardUnmaskPromptViews::DeleteDelegate() {
int CardUnmaskPromptViews::GetDialogButtons() const {
// In permanent error state, only the "close" button is shown.
if (controller_->GetVerificationResult() == AutofillClient::PERMANENT_FAILURE)
AutofillClient::PaymentsRpcResult result =
controller_->GetVerificationResult();
if (result == AutofillClient::PERMANENT_FAILURE ||
result == AutofillClient::NETWORK_ERROR) {
return ui::DIALOG_BUTTON_CANCEL;
}
return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
}
......
......@@ -101,6 +101,7 @@ void CardUnmaskPromptControllerImpl::OnVerificationResult(
void CardUnmaskPromptControllerImpl::OnUnmaskDialogClosed() {
card_unmask_view_ = nullptr;
LogOnCloseEvents();
unmasking_result_ = AutofillClient::NONE;
if (delegate_)
delegate_->OnUnmaskPromptClosed();
}
......
......@@ -187,7 +187,11 @@ TEST_F(CardUnmaskPromptControllerImplTest, LogClosedFailedToUnmaskRetriable) {
controller_->OnVerificationResult(AutofillClient::TRY_AGAIN_FAILURE);
base::HistogramTester histogram_tester;
EXPECT_EQ(AutofillClient::TRY_AGAIN_FAILURE,
controller_->GetVerificationResult());
controller_->OnUnmaskDialogClosed();
// State should be cleared when the dialog is closed.
EXPECT_EQ(AutofillClient::NONE, controller_->GetVerificationResult());
histogram_tester.ExpectBucketCount(
"Autofill.UnmaskPrompt.Events",
......@@ -202,7 +206,11 @@ TEST_F(CardUnmaskPromptControllerImplTest,
controller_->OnVerificationResult(AutofillClient::PERMANENT_FAILURE);
base::HistogramTester histogram_tester;
EXPECT_EQ(AutofillClient::PERMANENT_FAILURE,
controller_->GetVerificationResult());
controller_->OnUnmaskDialogClosed();
// State should be cleared when the dialog is closed.
EXPECT_EQ(AutofillClient::NONE, controller_->GetVerificationResult());
histogram_tester.ExpectBucketCount(
"Autofill.UnmaskPrompt.Events",
......@@ -216,7 +224,11 @@ TEST_F(CardUnmaskPromptControllerImplTest, LogUnmaskedCardFirstAttempt) {
base::HistogramTester histogram_tester;
controller_->OnVerificationResult(AutofillClient::SUCCESS);
EXPECT_EQ(AutofillClient::SUCCESS, controller_->GetVerificationResult());
controller_->OnUnmaskDialogClosed();
// State should be cleared when the dialog is closed.
EXPECT_EQ(AutofillClient::NONE, controller_->GetVerificationResult());
histogram_tester.ExpectBucketCount(
"Autofill.UnmaskPrompt.Events",
......
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