Commit 3b7b85c2 authored by Sahel Sharify's avatar Sahel Sharify Committed by Commit Bot

[Payment] Test coverage for refetching the missing PH icon.

Bug: 1069010
Change-Id: I27b59f6abb61d81aeb368e183b934394a415e9bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2276406
Commit-Queue: Sahel Sharify <sahel@chromium.org>
Reviewed-by: default avatarLiquan (Max) Gu <maxlg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785814}
parent 5194845a
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/test/scoped_feature_list.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 "components/payments/content/service_worker_payment_app_finder.h"
#include "components/payments/core/features.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 "content/public/test/browser_test.h"
#include "net/dns/mock_host_resolver.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace payments {
class PaymentHandlerIconRefetchTest : public PaymentRequestBrowserTestBase {
protected:
PaymentHandlerIconRefetchTest() {
scoped_feature_list_.InitAndEnableFeature(
features::kAllowJITInstallationWhenAppIconIsMissing);
}
~PaymentHandlerIconRefetchTest() override = default;
void SetUpOnMainThread() override {
PaymentRequestBrowserTestBase::SetUpOnMainThread();
host_resolver()->AddRule("*", "127.0.0.1");
// Setup Kylepay server.
kylepay_server_.ServeFilesFromSourceDirectory(
"components/test/data/payments/kylepay.com/");
ASSERT_TRUE(kylepay_server_.Start());
}
// Sets a TestDownloader for ServiceWorkerPaymentAppFinder and ignores port in
// app scope. Must be called while on the page that will invoke the
// PaymentRequest API, because ServiceWorkerPaymentAppFinder is owned by the
// page.
void SetDownloaderAndIgnorePortInOriginComparisonForTesting() {
content::BrowserContext* context =
GetActiveWebContents()->GetBrowserContext();
auto downloader = std::make_unique<TestDownloader>(
content::BrowserContext::GetDefaultStoragePartition(context)
->GetURLLoaderFactoryForBrowserProcess());
downloader->AddTestServerURL("https://kylepay.com/",
kylepay_server_.GetURL("kylepay.com", "/"));
ServiceWorkerPaymentAppFinder::GetOrCreateForCurrentDocument(
GetActiveWebContents()->GetMainFrame())
->SetDownloaderAndIgnorePortInOriginComparisonForTesting(
std::move(downloader));
}
private:
net::EmbeddedTestServer kylepay_server_{net::EmbeddedTestServer::TYPE_HTTPS};
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(PaymentHandlerIconRefetchTest, RefechMissingIcon) {
// Navigate to a page with strict CSP so that Kylepay's icon fetch fails.
NavigateTo("/csp_prevent_icon_download.html");
SetDownloaderAndIgnorePortInOriginComparisonForTesting();
// Create a payment request for Kylepay.
ResetEventWaiterForDialogOpened();
EXPECT_TRUE(content::ExecJs(
GetActiveWebContents(),
"testPaymentMethods([{supportedMethods: 'https://kylepay.com/webpay'}], "
"/* requestShippingContact= */ true);"));
WaitForObservedEvent();
// App with missing icon is not preselectable.
EXPECT_FALSE(IsPayButtonEnabled());
// Open payment method section to explicitly choose Kylepay
OpenPaymentMethodScreen();
ResetEventWaiter(DialogEvent::BACK_NAVIGATION);
views::View* list_view = dialog_view()->GetViewByID(
static_cast<int>(DialogViewID::PAYMENT_METHOD_SHEET_LIST_VIEW));
EXPECT_TRUE(list_view);
EXPECT_EQ(1u, list_view->children().size());
ClickOnDialogViewAndWait(list_view->children()[0]);
// Pay button should be enabled now.
EXPECT_TRUE(IsPayButtonEnabled());
// Click on Pay to install Kylepay and complete the payment.
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON, dialog_view());
ExpectBodyContains({"kylepay.com/webpay"});
// Navigate to a page where refetching Kylepay's missing icon succeeds.
NavigateTo("/payment_request_bobpay_and_cards_test.html");
SetDownloaderAndIgnorePortInOriginComparisonForTesting();
// Create a payment request for Kylepay; One step flow (skip the sheet) should
// get triggered since the missing icon is refetched.
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN, DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
EXPECT_TRUE(content::ExecJs(
GetActiveWebContents(),
"testPaymentMethods([{supportedMethods: 'https://kylepay.com/webpay'}], "
"/* requestShippingContact= */ true);"));
WaitForObservedEvent();
ExpectBodyContains({"kylepay.com/webpay"});
// Navigate to the first merchant again and confirm that skip the sheet flow
// works there as well (i.e. The refetched icon is written to the payment app
// database.).
NavigateTo("/csp_prevent_icon_download.html");
SetDownloaderAndIgnorePortInOriginComparisonForTesting();
ResetEventWaiterForSequence(
{DialogEvent::PROCESSING_SPINNER_SHOWN,
DialogEvent::PROCESSING_SPINNER_HIDDEN, DialogEvent::DIALOG_OPENED,
DialogEvent::PROCESSING_SPINNER_SHOWN, DialogEvent::DIALOG_CLOSED});
EXPECT_TRUE(content::ExecJs(
GetActiveWebContents(),
"testPaymentMethods([{supportedMethods: 'https://kylepay.com/webpay'}], "
"/* requestShippingContact= */ true);"));
WaitForObservedEvent();
ExpectBodyContains({"kylepay.com/webpay"});
}
} // namespace payments
......@@ -2009,6 +2009,7 @@ if (!is_android) {
"../browser/ui/views/payments/modifiers_browsertest.cc",
"../browser/ui/views/payments/order_summary_view_controller_browsertest.cc",
"../browser/ui/views/payments/payment_handler_change_payment_method_browsertest.cc",
"../browser/ui/views/payments/payment_handler_icon_refetch_browsertest.cc",
"../browser/ui/views/payments/payment_handler_window_size_browsertest.cc",
"../browser/ui/views/payments/payment_method_view_controller_browsertest.cc",
"../browser/ui/views/payments/payment_request_blob_url_browsertest.cc",
......
......@@ -93,6 +93,7 @@ class ServiceWorkerPaymentAppFinder
friend class ServiceWorkerPaymentAppFinderBrowserTest;
friend class PaymentRequestPlatformBrowserTestBase;
friend class PaymentMethodViewControllerTest;
friend class PaymentHandlerIconRefetchTest;
explicit ServiceWorkerPaymentAppFinder(content::RenderFrameHost* rfh);
......
<!DOCTYPE html>
<!--
Copyright 2020 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<html>
<head>
<title>Icon refetch Test</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<meta http-equiv="Content-Security-Policy" content="img-src 'none'">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<pre id="result"></pre>
<script src="util.js"></script>
<script src="bobpay_and_cards.js"></script>
</body>
</html>
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