Commit 9be7b29d authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments] Primary button says "Continue" when 3rdy party app selected.

After this cl payment sheets on Desktop and Android will show "Continue"
rather than "Pay" when a 3rd party(i.e. non-autofill) payment app is
selected.

Bug: 1055557
Change-Id: I1717703d50e33df5cdc4a3f0e900b29072df19c4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101690
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750220}
parent e5ed14fd
...@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.autofill.prefeditor.EditableOption; ...@@ -41,6 +41,7 @@ import org.chromium.chrome.browser.autofill.prefeditor.EditableOption;
import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog; import org.chromium.chrome.browser.autofill.prefeditor.EditorDialog;
import org.chromium.chrome.browser.autofill.prefeditor.EditorObserverForTest; import org.chromium.chrome.browser.autofill.prefeditor.EditorObserverForTest;
import org.chromium.chrome.browser.flags.ChromeFeatureList; import org.chromium.chrome.browser.flags.ChromeFeatureList;
import org.chromium.chrome.browser.payments.PaymentApp;
import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentUisShowStateReconciler; import org.chromium.chrome.browser.payments.PaymentRequestImpl.PaymentUisShowStateReconciler;
import org.chromium.chrome.browser.payments.ShippingStrings; import org.chromium.chrome.browser.payments.ShippingStrings;
import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBreakdownSection; import org.chromium.chrome.browser.payments.ui.PaymentRequestSection.LineItemBreakdownSection;
...@@ -1022,6 +1023,13 @@ public class PaymentRequestUI implements DimmingDialog.OnDismissListener, View.O ...@@ -1022,6 +1023,13 @@ public class PaymentRequestUI implements DimmingDialog.OnDismissListener, View.O
&& mPaymentMethodSectionInformation != null && mPaymentMethodSectionInformation != null
&& mPaymentMethodSectionInformation.getSelectedItem() != null && mPaymentMethodSectionInformation.getSelectedItem() != null
&& !mIsClientCheckingSelection && !mIsEditingPaymentItem && !mIsClosing); && !mIsClientCheckingSelection && !mIsEditingPaymentItem && !mIsClosing);
PaymentApp selectedApp = mPaymentMethodSectionInformation == null
? null
: (PaymentApp) mPaymentMethodSectionInformation.getSelectedItem();
mPayButton.setText(selectedApp != null && !selectedApp.isAutofillInstrument()
? R.string.payments_continue_button
: R.string.payments_pay_button);
mReadyToPayNotifierForTest.run(); mReadyToPayNotifierForTest.run();
} }
......
...@@ -12,6 +12,7 @@ import android.graphics.Bitmap; ...@@ -12,6 +12,7 @@ import android.graphics.Bitmap;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.widget.Button;
import org.junit.Before; import org.junit.Before;
import org.junit.ClassRule; import org.junit.ClassRule;
...@@ -62,6 +63,13 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest { ...@@ -62,6 +63,13 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest {
"310-310-6000", "jon.doe@gmail.com", "en-US")); "310-310-6000", "jon.doe@gmail.com", "en-US"));
} }
protected String getPrimaryButtonLabel() {
Button primary = (Button) mPaymentRequestTestRule.getPaymentRequestUI()
.getDialogForTest()
.findViewById(R.id.button_primary);
return primary.getText().toString();
}
/** /**
* Verify modifier for Bobpay is only applied for Bobpay. * Verify modifier for Bobpay is only applied for Bobpay.
*/ */
...@@ -81,6 +89,9 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest { ...@@ -81,6 +89,9 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest {
assertTrue(mPaymentRequestTestRule.getSelectedPaymentAppLabel().startsWith( assertTrue(mPaymentRequestTestRule.getSelectedPaymentAppLabel().startsWith(
"https://bobpay.com")); "https://bobpay.com"));
assertEquals("USD $4.00", mPaymentRequestTestRule.getOrderSummaryTotal()); assertEquals("USD $4.00", mPaymentRequestTestRule.getOrderSummaryTotal());
assertEquals(mPaymentRequestTestRule.getActivity().getResources().getString(
R.string.payments_continue_button),
getPrimaryButtonLabel());
// select other payment method and verify modifier for bobpay is not applied // select other payment method and verify modifier for bobpay is not applied
mPaymentRequestTestRule.clickOnPaymentMethodSuggestionOptionAndWait( mPaymentRequestTestRule.clickOnPaymentMethodSuggestionOptionAndWait(
...@@ -88,6 +99,9 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest { ...@@ -88,6 +99,9 @@ public class PaymentRequestPaymentAppAndBasicCardWithModifiersTest {
assertFalse(mPaymentRequestTestRule.getSelectedPaymentAppLabel().startsWith( assertFalse(mPaymentRequestTestRule.getSelectedPaymentAppLabel().startsWith(
"https://bobpay.com")); "https://bobpay.com"));
assertEquals("USD $5.00", mPaymentRequestTestRule.getOrderSummaryTotal()); assertEquals("USD $5.00", mPaymentRequestTestRule.getOrderSummaryTotal());
assertEquals(mPaymentRequestTestRule.getActivity().getResources().getString(
R.string.payments_pay_button),
getPrimaryButtonLabel());
} }
/** /**
......
...@@ -143,7 +143,10 @@ std::unique_ptr<views::Button> ...@@ -143,7 +143,10 @@ std::unique_ptr<views::Button>
OrderSummaryViewController::CreatePrimaryButton() { OrderSummaryViewController::CreatePrimaryButton() {
std::unique_ptr<views::Button> button( std::unique_ptr<views::Button> button(
views::MdTextButton::CreateSecondaryUiBlueButton( views::MdTextButton::CreateSecondaryUiBlueButton(
this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); this, state()->selected_app() && state()->selected_app()->type() !=
PaymentApp::Type::AUTOFILL
? l10n_util::GetStringUTF16(IDS_PAYMENTS_CONTINUE_BUTTON)
: l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON)));
button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG));
button->SetID(static_cast<int>(DialogViewID::PAY_BUTTON)); button->SetID(static_cast<int>(DialogViewID::PAY_BUTTON));
pay_button_ = button.get(); pay_button_ = button.get();
......
...@@ -50,6 +50,7 @@ ...@@ -50,6 +50,7 @@
#include "ui/gfx/animation/test_animation_delegate.h" #include "ui/gfx/animation/test_animation_delegate.h"
#include "ui/gfx/geometry/point.h" #include "ui/gfx/geometry/point.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
#include "ui/views/controls/styled_label.h" #include "ui/views/controls/styled_label.h"
...@@ -767,6 +768,13 @@ bool PaymentRequestBrowserTestBase::IsPayButtonEnabled() { ...@@ -767,6 +768,13 @@ bool PaymentRequestBrowserTestBase::IsPayButtonEnabled() {
return button->GetEnabled(); return button->GetEnabled();
} }
base::string16 PaymentRequestBrowserTestBase::GetPrimaryButtonLabel() const {
return static_cast<views::MdTextButton*>(
delegate_->dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::PAY_BUTTON)))
->GetText();
}
void PaymentRequestBrowserTestBase::WaitForAnimation() { void PaymentRequestBrowserTestBase::WaitForAnimation() {
WaitForAnimation(delegate_->dialog_view()); WaitForAnimation(delegate_->dialog_view());
} }
......
...@@ -241,6 +241,8 @@ class PaymentRequestBrowserTestBase ...@@ -241,6 +241,8 @@ class PaymentRequestBrowserTestBase
bool IsPayButtonEnabled(); bool IsPayButtonEnabled();
base::string16 GetPrimaryButtonLabel() const;
// Sets proper animation delegates and waits for animation to finish. // Sets proper animation delegates and waits for animation to finish.
void WaitForAnimation(); void WaitForAnimation();
void WaitForAnimation(PaymentRequestDialogView* dialog_view); void WaitForAnimation(PaymentRequestDialogView* dialog_view);
......
...@@ -369,6 +369,15 @@ class PaymentSheetRowBuilder { ...@@ -369,6 +369,15 @@ class PaymentSheetRowBuilder {
DISALLOW_COPY_AND_ASSIGN(PaymentSheetRowBuilder); DISALLOW_COPY_AND_ASSIGN(PaymentSheetRowBuilder);
}; };
// The primary button should show "Continue" when the selected payment app is
// non-autofill.
base::string16 CalculatePrimaryButtonLabel(const PaymentRequestState* state) {
return state->selected_app() &&
state->selected_app()->type() != PaymentApp::Type::AUTOFILL
? l10n_util::GetStringUTF16(IDS_PAYMENTS_CONTINUE_BUTTON)
: l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON);
}
} // namespace } // namespace
PaymentSheetViewController::PaymentSheetViewController( PaymentSheetViewController::PaymentSheetViewController(
...@@ -398,7 +407,7 @@ std::unique_ptr<views::Button> ...@@ -398,7 +407,7 @@ std::unique_ptr<views::Button>
PaymentSheetViewController::CreatePrimaryButton() { PaymentSheetViewController::CreatePrimaryButton() {
std::unique_ptr<views::Button> button( std::unique_ptr<views::Button> button(
views::MdTextButton::CreateSecondaryUiBlueButton( views::MdTextButton::CreateSecondaryUiBlueButton(
this, l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON))); this, CalculatePrimaryButtonLabel(state())));
button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG)); button->set_tag(static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG));
button->SetID(static_cast<int>(DialogViewID::PAY_BUTTON)); button->SetID(static_cast<int>(DialogViewID::PAY_BUTTON));
button->SetEnabled(state()->is_ready_to_pay()); button->SetEnabled(state()->is_ready_to_pay());
...@@ -575,6 +584,8 @@ void PaymentSheetViewController::StyledLabelLinkClicked( ...@@ -575,6 +584,8 @@ void PaymentSheetViewController::StyledLabelLinkClicked(
void PaymentSheetViewController::UpdatePayButtonState(bool enabled) { void PaymentSheetViewController::UpdatePayButtonState(bool enabled) {
primary_button()->SetEnabled(enabled); primary_button()->SetEnabled(enabled);
static_cast<views::MdTextButton*>(primary_button())
->SetText(CalculatePrimaryButtonLabel(state()));
} }
// Creates the Order Summary row, which contains an "Order Summary" label, // Creates the Order Summary row, which contains an "Order Summary" label,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util.h"
namespace payments { namespace payments {
...@@ -22,7 +23,7 @@ namespace payments { ...@@ -22,7 +23,7 @@ namespace payments {
class PaymentSheetViewControllerNoShippingTest class PaymentSheetViewControllerNoShippingTest
: public PaymentRequestBrowserTestBase { : public PaymentRequestBrowserTestBase {
protected: protected:
PaymentSheetViewControllerNoShippingTest() {} PaymentSheetViewControllerNoShippingTest() = default;
private: private:
DISALLOW_COPY_AND_ASSIGN(PaymentSheetViewControllerNoShippingTest); DISALLOW_COPY_AND_ASSIGN(PaymentSheetViewControllerNoShippingTest);
...@@ -48,6 +49,11 @@ IN_PROC_BROWSER_TEST_F(PaymentSheetViewControllerNoShippingTest, ...@@ -48,6 +49,11 @@ IN_PROC_BROWSER_TEST_F(PaymentSheetViewControllerNoShippingTest,
InvokePaymentRequestUI(); InvokePaymentRequestUI();
EXPECT_TRUE(IsPayButtonEnabled()); EXPECT_TRUE(IsPayButtonEnabled());
// When an autofill payment app is selected the primary button should have
// "Pay" label.
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_PAY_BUTTON),
GetPrimaryButtonLabel());
} }
// With only an unsupported card (Amex) in the database, the pay button should // With only an unsupported card (Amex) in the database, the pay button should
...@@ -220,6 +226,11 @@ IN_PROC_BROWSER_TEST_F(PaymentSheetViewControllerContactDetailsTest, ...@@ -220,6 +226,11 @@ IN_PROC_BROWSER_TEST_F(PaymentSheetViewControllerContactDetailsTest,
// Payment button should be enabled with blank autofill profiles since the // Payment button should be enabled with blank autofill profiles since the
// payment handler supports shipping delegation. // payment handler supports shipping delegation.
EXPECT_TRUE(IsPayButtonEnabled()); EXPECT_TRUE(IsPayButtonEnabled());
// When a 3rd party payment app is selected the primary button should have
// "Continue" label.
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PAYMENTS_CONTINUE_BUTTON),
GetPrimaryButtonLabel());
} }
// Payment sheet view skips showing contact section when the selected instrument // Payment sheet view skips showing contact section when the selected instrument
......
...@@ -613,6 +613,7 @@ void PaymentRequestState::SetDefaultProfileSelections() { ...@@ -613,6 +613,7 @@ void PaymentRequestState::SetDefaultProfileSelections() {
selected_app_ = nullptr; selected_app_ = nullptr;
if (!available_apps_.empty() && available_apps_[0]->CanPreselect()) { if (!available_apps_.empty() && available_apps_[0]->CanPreselect()) {
selected_app_ = available_apps_[0].get(); selected_app_ = available_apps_[0].get();
UpdateIsReadyToPayAndNotifyObservers();
} }
// Record the missing required payment fields when no complete payment // Record the missing required payment fields when no complete payment
......
...@@ -208,6 +208,9 @@ ...@@ -208,6 +208,9 @@
<message name="IDS_PAYMENTS_PAY_BUTTON" desc="The label for the button that finishes the payment process. Sentence-cased." formatter_data="android_java"> <message name="IDS_PAYMENTS_PAY_BUTTON" desc="The label for the button that finishes the payment process. Sentence-cased." formatter_data="android_java">
Pay Pay
</message> </message>
<message name="IDS_PAYMENTS_CONTINUE_BUTTON" desc="The label for the button that continues to the payment handler window. Sentence-cased." formatter_data="android_java">
Continue
</message>
<message name="IDS_PAYMENTS_ADD_CONTACT" desc="Text on a button that lets a user add new contact details, like the user's full name, an email address or a phone number. Sentence-cased." formatter_data="android_java"> <message name="IDS_PAYMENTS_ADD_CONTACT" desc="Text on a button that lets a user add new contact details, like the user's full name, an email address or a phone number. Sentence-cased." formatter_data="android_java">
Add contact info Add contact info
</message> </message>
...@@ -232,6 +235,9 @@ ...@@ -232,6 +235,9 @@
<message name="IDS_PAYMENTS_PAY_BUTTON" desc="The label for the button that finishes the payment process. Title-Cased."> <message name="IDS_PAYMENTS_PAY_BUTTON" desc="The label for the button that finishes the payment process. Title-Cased.">
Pay Pay
</message> </message>
<message name="IDS_PAYMENTS_CONTINUE_BUTTON" desc="The label for the button that continues to the payment handler window. Title-Cased.">
Continue
</message>
<message name="IDS_PAYMENTS_ADD_CONTACT" desc="Text on a button that lets a user add new contact details, like the user's full name, an email address or a phone number. Title-Cased."> <message name="IDS_PAYMENTS_ADD_CONTACT" desc="Text on a button that lets a user add new contact details, like the user's full name, an email address or a phone number. Title-Cased.">
Add Contact Info Add Contact Info
</message> </message>
......
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