Commit 08e5b730 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payments]Don't show "add card" button when basic card is not requested.

This is a Desktop only change to ensure that the "add card" button is
shown in payment method window only when the "basic card" method is
supported.

Change-Id: Ibfc31141cf45595c0db216d017b5c8c484094424
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2024923
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#735978}
parent 3e2c5b11
......@@ -180,7 +180,8 @@ PaymentMethodViewController::PaymentMethodViewController(
PaymentRequestDialogView* dialog)
: PaymentRequestSheetController(spec, state, dialog),
payment_method_list_(dialog),
enable_add_card_(!state->is_retry_called()) {
enable_add_card_(!state->is_retry_called() &&
spec->supports_basic_card()) {
const std::vector<std::unique_ptr<PaymentApp>>& available_apps =
state->available_apps();
for (const auto& app : available_apps) {
......
......@@ -5,19 +5,74 @@
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/personal_data_manager.h"
#include "components/payments/content/payment_request.h"
#include "components/payments/content/payment_request_state.h"
#include "components/payments/content/service_worker_payment_app_finder.h"
#include "components/payments/core/test_payment_manifest_downloader.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/storage_partition.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
class PaymentMethodViewControllerTest : public PaymentRequestBrowserTestBase {
protected:
PaymentMethodViewControllerTest() {}
PaymentMethodViewControllerTest()
: bobpay_server_(std::make_unique<net::EmbeddedTestServer>(
net::EmbeddedTestServer::TYPE_HTTPS)),
alicepay_server_(std::make_unique<net::EmbeddedTestServer>(
net::EmbeddedTestServer::TYPE_HTTPS)) {}
void SetUpOnMainThread() override {
host_resolver()->AddRule("*", "127.0.0.1");
PaymentRequestBrowserTestBase::SetUpOnMainThread();
}
void StartServerAndInstallAppForMethod(net::EmbeddedTestServer* server,
const std::string& method_name) {
// Set up test server.
DCHECK(server->InitializeAndListen());
server->ServeFilesFromSourceDirectory(
"components/test/data/payments/bobpay.com");
server->StartAcceptingConnections();
// Install payment app.
ui_test_utils::NavigateToURL(browser(),
server->GetURL(method_name, "/app1/"));
EXPECT_EQ(
"instruments.set(): Payment app for \"https://" + method_name +
"\" method installed.",
content::EvalJsWithManualReply(
GetActiveWebContents(), "install('https://" + method_name + "')"));
}
void SetDownloaderAndIgnorePortInOriginComparisonForTesting() {
content::BrowserContext* context =
GetActiveWebContents()->GetBrowserContext();
auto downloader = std::make_unique<TestDownloader>(
content::BrowserContext::GetDefaultStoragePartition(context)
->GetURLLoaderFactoryForBrowserProcess());
downloader->AddTestServerURL("https://alicepay.com/",
alicepay_server_->GetURL("alicepay.com", "/"));
downloader->AddTestServerURL("https://bobpay.com/",
bobpay_server_->GetURL("bobpay.com", "/"));
ServiceWorkerPaymentAppFinder::GetInstance()
->SetDownloaderAndIgnorePortInOriginComparisonForTesting(
std::move(downloader));
}
net::EmbeddedTestServer* bobpay_server() { return bobpay_server_.get(); }
net::EmbeddedTestServer* alicepay_server() { return alicepay_server_.get(); }
private:
std::unique_ptr<net::EmbeddedTestServer> bobpay_server_;
std::unique_ptr<net::EmbeddedTestServer> alicepay_server_;
DISALLOW_COPY_AND_ASSIGN(PaymentMethodViewControllerTest);
};
......@@ -129,4 +184,20 @@ IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest, EditButtonOpensEditor) {
ClickOnDialogViewAndWait(edit_button);
}
IN_PROC_BROWSER_TEST_F(PaymentMethodViewControllerTest,
DoNotShowAddCardWhenBasicCardIsNotSupported) {
StartServerAndInstallAppForMethod(bobpay_server(), "bobpay.com");
StartServerAndInstallAppForMethod(alicepay_server(), "alicepay.com");
SetDownloaderAndIgnorePortInOriginComparisonForTesting();
NavigateTo("/payment_request_bobpay_test.html");
// Confirm that "Add card" button is not shown since "basic-card" is not
// requested.
InvokePaymentRequestUI();
OpenPaymentMethodScreen();
views::View* add_card_button = dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::PAYMENT_METHOD_ADD_CARD_BUTTON));
EXPECT_EQ(nullptr, add_card_button);
}
} // namespace payments
......@@ -81,6 +81,7 @@ class ServiceWorkerPaymentAppFinder {
friend class HybridRequestSkipUITest;
friend class JourneyLoggerTest;
friend class PaymentHandlerJustInTimeInstallationTest;
friend class PaymentMethodViewControllerTest;
ServiceWorkerPaymentAppFinder();
~ServiceWorkerPaymentAppFinder();
......
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