Commit 118efde1 authored by Hao Zhang's avatar Hao Zhang Committed by Commit Bot

[Exp date fix flow] Disable Save Button When selecting expired expiration date

Bug: 899057
Change-Id: I4d87ee3b3f12d0f76376976b0be0460b8b94c007
Reviewed-on: https://chromium-review.googlesource.com/c/1334228
Commit-Queue: Hao Zhang <hozhng@google.com>
Reviewed-by: default avatarJared Saul <jsaul@google.com>
Reviewed-by: default avatarEvan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608272}
parent e0cd20e8
......@@ -1358,4 +1358,52 @@ IN_PROC_BROWSER_TEST_F(
views::LabelButton::ButtonState::STATE_NORMAL);
}
// Tests the upload save bubble. Ensures that if the user is selecting an
// expired expiration date, it is not allowed to click [Save].
IN_PROC_BROWSER_TEST_F(
SaveCardBubbleViewsFullFormBrowserTest,
Upload_SaveButtonIsDisabledIfExpiredExpirationDateAndExpirationDateRequested) {
// Enable the EditableExpirationDate experiment.
scoped_feature_list_.InitAndEnableFeature(
features::kAutofillUpstreamEditableExpirationDate);
// Set up the Payments RPC.
SetUploadDetailsRpcPaymentsAccepts();
// Submitting the form should still show the upload save bubble and legal
// footer, along with a pair of dropdowns specifically requesting the
// expiration date. (Must wait for response from Payments before accessing
// the controller.)
ResetEventWaiterForSequence(
{DialogEvent::REQUESTED_UPLOAD_SAVE,
DialogEvent::RECEIVED_GET_UPLOAD_DETAILS_RESPONSE});
FillAndSubmitFormWithoutExpirationDate();
WaitForObservedEvent();
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::MAIN_CONTENT_VIEW_UPLOAD)->visible());
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::FOOTNOTE_VIEW)->visible());
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::EXPIRATION_DATE_VIEW));
EXPECT_TRUE(FindViewInBubbleById(DialogViewId::EXPIRATION_DATE_DROPBOX_YEAR));
EXPECT_TRUE(
FindViewInBubbleById(DialogViewId::EXPIRATION_DATE_DROPBOX_MONTH));
views::LabelButton* save_button = static_cast<views::LabelButton*>(
FindViewInBubbleById(DialogViewId::OK_BUTTON));
views::Combobox* year_input = static_cast<views::Combobox*>(
FindViewInBubbleById(DialogViewId::EXPIRATION_DATE_DROPBOX_YEAR));
views::Combobox* month_input = static_cast<views::Combobox*>(
FindViewInBubbleById(DialogViewId::EXPIRATION_DATE_DROPBOX_MONTH));
// Set now to next month. Setting test_clock will not affect the dropdown to
// be selected, so selecting the current January will always be expired.
autofill::TestAutofillClock test_clock;
test_clock.SetNow(base::Time::Now());
test_clock.Advance(base::TimeDelta::FromDays(40));
// Selecting expired date will disable [Save] button.
month_input->SetSelectedRow(1);
year_input->SetSelectedRow(1);
EXPECT_EQ(save_button->state(),
views::LabelButton::ButtonState::STATE_DISABLED);
}
} // namespace autofill
......@@ -6,6 +6,7 @@
#include <memory>
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h"
......@@ -19,6 +20,8 @@
#include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/legal_message_line.h"
#include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
#include "components/autofill/core/browser/validation.h"
#include "components/autofill/core/common/autofill_clock.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -103,13 +106,23 @@ bool SaveCardOfferBubbleViews::IsDialogButtonEnabled(
&trimmed_text);
return !trimmed_text.empty();
}
// If requesting the user select the expiration date, it cannot be unselected.
// If requesting the user select the expiration date, it cannot be unselected
// or expired.
if (month_input_dropdown_ || year_input_dropdown_) {
// Make sure we are not requesting cardholder name and expiration date at
// the same time.
DCHECK(!cardholder_name_textfield_);
return !(month_input_dropdown_->selected_index() == 0 ||
year_input_dropdown_->selected_index() == 0);
int month_value = 0, year_value = 0;
if (!base::StringToInt(month_input_dropdown_->GetTextForRow(
month_input_dropdown_->selected_index()),
&month_value) ||
!base::StringToInt(year_input_dropdown_->GetTextForRow(
year_input_dropdown_->selected_index()),
&year_value)) {
return false;
}
return IsValidCreditCardExpirationDate(year_value, month_value,
AutofillClock::Now());
}
return true;
......
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