[Web Payment] Reduce number of test delegates.
This patch merges a couple of test implementations of
ChromePaymentRequestDelegate into a single
TestChromePaymentRequestDelegate and removes its constructor
parameters, so it can be used more easily in the next patches.
This is step 1 in multi-step patch to make
ServiceWorkerPaymentAppFactory (instead of RenderFrameHost) own
ServiceWorkerPaymentAppFinder, in order to simplify object ownership in
Web Payment code. Steps:
1) Reduce # of test implementations of ChromePaymentRequestDelegate.
2) Move PaymentRequest constructor parameters into the delegate.
3) Tests affect ServiceWorkerPaymentAppFinder through the delegate.
4) ServiceWorkerPaymentAppFactory owns ServiceWorkerPaymentAppFinder.
Bug: 1382826
Change-Id: I9801deda8cb1d6e5cbee58b8165b398c270af5d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4023844
Reviewed-by: Stephen McGruer <smcgruer@chromium.org>
Commit-Queue: Rouslan Solomakhin <rouslan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1072770}
diff --git a/chrome/browser/payments/chrome_payment_request_delegate.cc b/chrome/browser/payments/chrome_payment_request_delegate.cc
index 688bcc7..29b3048 100644
--- a/chrome/browser/payments/chrome_payment_request_delegate.cc
+++ b/chrome/browser/payments/chrome_payment_request_delegate.cc
@@ -252,6 +252,11 @@
std::move(opt_out_callback));
}
+content::RenderFrameHost* ChromePaymentRequestDelegate::GetRenderFrameHost()
+ const {
+ return content::RenderFrameHost::FromID(frame_routing_id_);
+}
+
std::unique_ptr<webauthn::InternalAuthenticator>
ChromePaymentRequestDelegate::CreateInternalAuthenticator() const {
// This authenticator can be used in a cross-origin iframe only if the
@@ -310,10 +315,6 @@
: "";
}
-bool ChromePaymentRequestDelegate::SkipUiForBasicCard() const {
- return false; // Only tests do this.
-}
-
std::string ChromePaymentRequestDelegate::GetTwaPackageName() const {
#if BUILDFLAG(IS_CHROMEOS_ASH)
auto* rfh = content::RenderFrameHost::FromID(frame_routing_id_);
diff --git a/chrome/browser/payments/chrome_payment_request_delegate.h b/chrome/browser/payments/chrome_payment_request_delegate.h
index f703a16..c484a0644 100644
--- a/chrome/browser/payments/chrome_payment_request_delegate.h
+++ b/chrome/browser/payments/chrome_payment_request_delegate.h
@@ -57,6 +57,7 @@
base::OnceClosure opt_out_callback) override;
// ContentPaymentRequestDelegate:
+ content::RenderFrameHost* GetRenderFrameHost() const override;
std::unique_ptr<webauthn::InternalAuthenticator> CreateInternalAuthenticator()
const override;
scoped_refptr<PaymentManifestWebDataService>
@@ -67,7 +68,6 @@
PaymentHandlerOpenWindowCallback callback) override;
bool IsInteractive() const override;
std::string GetInvalidSslCertificateErrorMessage() override;
- bool SkipUiForBasicCard() const override;
std::string GetTwaPackageName() const override;
PaymentRequestDialog* GetDialogForTesting() override;
SecurePaymentConfirmationNoCreds* GetNoMatchingCredentialsDialogForTesting()
@@ -90,7 +90,7 @@
std::unique_ptr<SecurePaymentConfirmationNoCreds> spc_no_creds_dialog_;
- content::GlobalRenderFrameHostId frame_routing_id_;
+ const content::GlobalRenderFrameHostId frame_routing_id_;
};
} // namespace payments
diff --git a/chrome/browser/ui/BUILD.gn b/chrome/browser/ui/BUILD.gn
index 48dfb2b..2029edbf 100644
--- a/chrome/browser/ui/BUILD.gn
+++ b/chrome/browser/ui/BUILD.gn
@@ -5915,6 +5915,7 @@
if (toolkit_views) {
deps += [
"//components/constrained_window:constrained_window",
+ "//components/webauthn/content/browser",
"//ui/views:test_support",
]
sources += [
diff --git a/chrome/browser/ui/views/payments/payment_request_browsertest_base.cc b/chrome/browser/ui/views/payments/payment_request_browsertest_base.cc
index 023f7a6..1987a94ae 100644
--- a/chrome/browser/ui/views/payments/payment_request_browsertest_base.cc
+++ b/chrome/browser/ui/views/payments/payment_request_browsertest_base.cc
@@ -140,10 +140,6 @@
is_browser_window_active_ = false;
}
-void PaymentRequestBrowserTestBase::SetSkipUiForForBasicCard() {
- skip_ui_for_basic_card_ = true;
-}
-
void PaymentRequestBrowserTestBase::OnCanMakePaymentCalled() {
if (event_waiter_)
event_waiter_->OnEvent(DialogEvent::CAN_MAKE_PAYMENT_CALLED);
@@ -551,11 +547,16 @@
content::RenderFrameHost* render_frame_host) {
DCHECK(render_frame_host);
DCHECK(render_frame_host->IsActive());
- std::unique_ptr<TestChromePaymentRequestDelegate> delegate =
- std::make_unique<TestChromePaymentRequestDelegate>(
- render_frame_host, /*observer=*/GetWeakPtr(), &prefs_, is_incognito_,
- is_valid_ssl_, is_browser_window_active_, skip_ui_for_basic_card_);
+
+ auto delegate =
+ std::make_unique<TestChromePaymentRequestDelegate>(render_frame_host);
+ delegate->set_payment_request_dialog_view_observer_for_test(GetWeakPtr());
+ delegate->OverridePrefService(&prefs_);
+ delegate->OverrideOffTheRecord(is_incognito_);
+ delegate->OverrideValidSSL(is_valid_ssl_);
+ delegate->OverrideBrowserWindowActive(is_browser_window_active_);
delegate_ = delegate.get();
+
auto display_manager = delegate->GetDisplayManager()->GetWeakPtr();
auto* request = new PaymentRequest(
*render_frame_host, std::move(delegate), std::move(display_manager),
diff --git a/chrome/browser/ui/views/payments/payment_request_browsertest_base.h b/chrome/browser/ui/views/payments/payment_request_browsertest_base.h
index ef6359b..2c2bc43 100644
--- a/chrome/browser/ui/views/payments/payment_request_browsertest_base.h
+++ b/chrome/browser/ui/views/payments/payment_request_browsertest_base.h
@@ -116,7 +116,6 @@
void SetIncognito();
void SetInvalidSsl();
void SetBrowserWindowInactive();
- void SetSkipUiForForBasicCard();
// PaymentRequest::ObserverForTest:
void OnCanMakePaymentCalled() override;
@@ -272,7 +271,7 @@
PaymentRequestDialogView* dialog_view() { return delegate_->dialog_view(); }
void SetRegionDataLoader(autofill::RegionDataLoader* region_data_loader) {
- delegate_->SetRegionDataLoader(region_data_loader);
+ delegate_->OverrideRegionDataLoader(region_data_loader);
}
// Sets the value of the payments.can_make_payment_enabled pref.
@@ -300,7 +299,6 @@
bool is_incognito_ = false;
bool is_valid_ssl_ = true;
bool is_browser_window_active_ = true;
- bool skip_ui_for_basic_card_ = false;
std::vector<base::WeakPtr<PaymentRequest>> requests_;
ConstCSPChecker const_csp_checker_{/*allow=*/true};
diff --git a/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.cc b/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.cc
index 549db70..86245df 100644
--- a/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.cc
+++ b/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.cc
@@ -4,61 +4,124 @@
#include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h"
-#include "content/public/browser/web_contents.h"
+#include <memory>
+
+#include "components/payments/core/error_logger.h"
+#include "components/webauthn/content/browser/internal_authenticator_impl.h"
+#include "content/public/browser/render_frame_host.h"
+#include "services/network/public/cpp/shared_url_loader_factory.h"
namespace payments {
+namespace {
+
+class TestAuthenticator : public content::InternalAuthenticatorImpl {
+ public:
+ TestAuthenticator(content::RenderFrameHost* rfh, bool has_authenticator)
+ : content::InternalAuthenticatorImpl(rfh),
+ has_authenticator_(has_authenticator) {}
+
+ ~TestAuthenticator() override = default;
+
+ // webauthn::InternalAuthenticator
+ void IsUserVerifyingPlatformAuthenticatorAvailable(
+ blink::mojom::Authenticator::
+ IsUserVerifyingPlatformAuthenticatorAvailableCallback callback)
+ override {
+ std::move(callback).Run(has_authenticator_);
+ }
+
+ private:
+ const bool has_authenticator_;
+};
+
+} // namespace
TestChromePaymentRequestDelegate::TestChromePaymentRequestDelegate(
- content::RenderFrameHost* render_frame_host,
- base::WeakPtr<PaymentRequestDialogView::ObserverForTest> observer,
- PrefService* pref_service,
- bool is_off_the_record,
- bool is_valid_ssl,
- bool is_browser_window_active,
- bool skip_ui_for_basic_card)
- : ChromePaymentRequestDelegate(render_frame_host),
- region_data_loader_(nullptr),
- observer_(observer),
- pref_service_(pref_service),
- is_off_the_record_(is_off_the_record),
- is_valid_ssl_(is_valid_ssl),
- is_browser_window_active_(is_browser_window_active),
- skip_ui_for_basic_card_(skip_ui_for_basic_card) {}
+ content::RenderFrameHost* render_frame_host)
+ : ChromePaymentRequestDelegate(render_frame_host) {}
TestChromePaymentRequestDelegate::~TestChromePaymentRequestDelegate() = default;
+void TestChromePaymentRequestDelegate::OverrideRegionDataLoader(
+ autofill::RegionDataLoader* region_data_loader) {
+ region_data_loader_ = region_data_loader;
+}
+
+void TestChromePaymentRequestDelegate::OverridePrefService(
+ PrefService* pref_service) {
+ pref_service_ = pref_service;
+}
+
+void TestChromePaymentRequestDelegate::OverrideOffTheRecord(
+ bool is_off_the_record) {
+ is_off_the_record_ = is_off_the_record;
+}
+
+void TestChromePaymentRequestDelegate::OverrideValidSSL(bool is_valid_ssl) {
+ is_valid_ssl_ = is_valid_ssl;
+}
+
+void TestChromePaymentRequestDelegate::OverrideBrowserWindowActive(
+ bool is_browser_window_active) {
+ is_browser_window_active_ = is_browser_window_active;
+}
+
void TestChromePaymentRequestDelegate::ShowDialog(
base::WeakPtr<PaymentRequest> request) {
- shown_dialog_ = PaymentRequestDialogView::Create(request, observer_);
- shown_dialog_->ShowDialog();
+ if (dialog_type_ == DialogType::PAYMENT_REQUEST) {
+ shown_dialog_ = PaymentRequestDialogView::Create(request, observer_);
+ shown_dialog_->ShowDialog();
+ } else {
+ ChromePaymentRequestDelegate::ShowDialog(request);
+ }
}
bool TestChromePaymentRequestDelegate::IsOffTheRecord() const {
- return is_off_the_record_;
+ return is_off_the_record_.has_value()
+ ? *is_off_the_record_
+ : ChromePaymentRequestDelegate::IsOffTheRecord();
}
autofill::RegionDataLoader*
TestChromePaymentRequestDelegate::GetRegionDataLoader() {
- if (region_data_loader_)
- return region_data_loader_;
- return ChromePaymentRequestDelegate::GetRegionDataLoader();
+ return region_data_loader_
+ ? region_data_loader_.get()
+ : ChromePaymentRequestDelegate::GetRegionDataLoader();
}
PrefService* TestChromePaymentRequestDelegate::GetPrefService() {
- return pref_service_;
+ return pref_service_ ? pref_service_.get()
+ : ChromePaymentRequestDelegate::GetPrefService();
}
bool TestChromePaymentRequestDelegate::IsBrowserWindowActive() const {
- return is_browser_window_active_;
+ return is_browser_window_active_.has_value()
+ ? *is_browser_window_active_
+ : ChromePaymentRequestDelegate::IsBrowserWindowActive();
+}
+
+std::unique_ptr<webauthn::InternalAuthenticator>
+TestChromePaymentRequestDelegate::CreateInternalAuthenticator() const {
+ content::RenderFrameHost* rfh = GetRenderFrameHost();
+ return rfh ? std::make_unique<TestAuthenticator>(rfh, has_authenticator_)
+ : nullptr;
}
std::string
TestChromePaymentRequestDelegate::GetInvalidSslCertificateErrorMessage() {
- return is_valid_ssl_ ? "" : "Invalid SSL certificate";
+ if (is_valid_ssl_.has_value())
+ return *is_valid_ssl_ ? "" : "Invalid SSL certificate";
+
+ return ChromePaymentRequestDelegate::GetInvalidSslCertificateErrorMessage();
}
-bool TestChromePaymentRequestDelegate::SkipUiForBasicCard() const {
- return skip_ui_for_basic_card_;
+std::string TestChromePaymentRequestDelegate::GetTwaPackageName() const {
+ return twa_package_name_;
+}
+
+const base::WeakPtr<PaymentUIObserver>
+TestChromePaymentRequestDelegate::GetPaymentUIObserver() const {
+ return payment_ui_observer_;
}
} // namespace payments
diff --git a/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h b/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h
index 3ea51e3..2c1b0e7 100644
--- a/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h
+++ b/chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h
@@ -5,69 +5,96 @@
#ifndef CHROME_BROWSER_UI_VIEWS_PAYMENTS_TEST_CHROME_PAYMENT_REQUEST_DELEGATE_H_
#define CHROME_BROWSER_UI_VIEWS_PAYMENTS_TEST_CHROME_PAYMENT_REQUEST_DELEGATE_H_
-#include <memory>
+#include <string>
#include "base/memory/raw_ptr.h"
+#include "base/memory/weak_ptr.h"
#include "chrome/browser/payments/chrome_payment_request_delegate.h"
#include "chrome/browser/ui/views/payments/payment_request_dialog_view.h"
+#include "third_party/abseil-cpp/absl/types/optional.h"
class PrefService;
-namespace payments {
+namespace autofill {
+class RegionDataLoader;
+} // namespace autofill
+
+namespace content {
class RenderFrameHost;
-} // namespace payments
+} // namespace content
namespace payments {
-class PaymentRequest;
-
// Implementation of the Payment Request delegate used in tests.
class TestChromePaymentRequestDelegate : public ChromePaymentRequestDelegate {
public:
// This delegate does not own things passed as pointers.
- TestChromePaymentRequestDelegate(
- content::RenderFrameHost* render_frame_host,
- base::WeakPtr<PaymentRequestDialogView::ObserverForTest> observer,
- PrefService* pref_service,
- bool is_off_the_record,
- bool is_valid_ssl,
- bool is_browser_window_active,
- bool skip_ui_for_basic_card);
+ explicit TestChromePaymentRequestDelegate(
+ content::RenderFrameHost* render_frame_host);
+ ~TestChromePaymentRequestDelegate() override;
TestChromePaymentRequestDelegate(const TestChromePaymentRequestDelegate&) =
delete;
TestChromePaymentRequestDelegate& operator=(
const TestChromePaymentRequestDelegate&) = delete;
- ~TestChromePaymentRequestDelegate() override;
+ // If an Override* method is not called, then the default implementation from
+ // ChromePaymentRequestDelegate is used.
+ void OverrideRegionDataLoader(autofill::RegionDataLoader* region_data_loader);
+ void OverridePrefService(PrefService* pref_service);
+ void OverrideOffTheRecord(bool is_off_the_record);
+ void OverrideValidSSL(bool is_valid_ssl);
+ void OverrideBrowserWindowActive(bool is_browser_window_active);
- void SetRegionDataLoader(autofill::RegionDataLoader* region_data_loader) {
- region_data_loader_ = region_data_loader;
+ void set_payment_ui_observer(
+ base::WeakPtr<PaymentUIObserver> payment_ui_observer) {
+ payment_ui_observer_ = payment_ui_observer;
}
- // ChromePaymentRequestDelegate.
- void ShowDialog(base::WeakPtr<PaymentRequest> request) override;
- bool IsOffTheRecord() const override;
- autofill::RegionDataLoader* GetRegionDataLoader() override;
- PrefService* GetPrefService() override;
- bool IsBrowserWindowActive() const override;
- std::string GetInvalidSslCertificateErrorMessage() override;
- bool SkipUiForBasicCard() const override;
+ void set_payment_request_dialog_view_observer_for_test(
+ base::WeakPtr<PaymentRequestDialogView::ObserverForTest> observer) {
+ observer_ = observer;
+ }
+
+ void set_twa_package_name(const std::string& twa_package_name) {
+ twa_package_name_ = twa_package_name;
+ }
+
+ void set_has_authenticator(bool has_authenticator) {
+ has_authenticator_ = has_authenticator;
+ }
PaymentRequestDialogView* dialog_view() {
return static_cast<PaymentRequestDialogView*>(shown_dialog_.get());
}
private:
- // Not owned so must outlive the PaymentRequest object;
- raw_ptr<autofill::RegionDataLoader> region_data_loader_;
+ // ChromePaymentRequestDelegate:
+ void ShowDialog(base::WeakPtr<PaymentRequest> request) override;
+ bool IsOffTheRecord() const override;
+ autofill::RegionDataLoader* GetRegionDataLoader() override;
+ PrefService* GetPrefService() override;
+ bool IsBrowserWindowActive() const override;
+ std::unique_ptr<webauthn::InternalAuthenticator> CreateInternalAuthenticator()
+ const override;
+ std::string GetInvalidSslCertificateErrorMessage() override;
+ std::string GetTwaPackageName() const override;
+ const base::WeakPtr<PaymentUIObserver> GetPaymentUIObserver() const override;
+ // Not owned so must outlive the PaymentRequest object;
+ raw_ptr<autofill::RegionDataLoader> region_data_loader_ = nullptr;
+ raw_ptr<PrefService> pref_service_ = nullptr;
+
+ base::WeakPtr<PaymentUIObserver> payment_ui_observer_;
base::WeakPtr<PaymentRequestDialogView::ObserverForTest> observer_;
- raw_ptr<PrefService> pref_service_;
- const bool is_off_the_record_;
- const bool is_valid_ssl_;
- const bool is_browser_window_active_;
- const bool skip_ui_for_basic_card_;
+
+ std::string twa_package_name_;
+
+ bool has_authenticator_ = true;
+
+ absl::optional<bool> is_off_the_record_;
+ absl::optional<bool> is_valid_ssl_;
+ absl::optional<bool> is_browser_window_active_;
};
} // namespace payments
diff --git a/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.cc b/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.cc
index 8c3bd08..d1f2091 100644
--- a/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.cc
+++ b/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.cc
@@ -18,9 +18,6 @@
base::WeakPtr<SecurePaymentConfirmationDialogView::ObserverForTest>
observer)
: ChromePaymentRequestDelegate(render_frame_host),
- frame_routing_id_(content::GlobalRenderFrameHostId(
- render_frame_host->GetProcess()->GetID(),
- render_frame_host->GetRoutingID())),
model_(model),
dialog_view_((new SecurePaymentConfirmationDialogView(
observer,
@@ -32,7 +29,7 @@
void TestSecurePaymentConfirmationPaymentRequestDelegate::ShowDialog(
base::WeakPtr<PaymentRequest> request) {
- auto* rfh = content::RenderFrameHost::FromID(frame_routing_id_);
+ content::RenderFrameHost* rfh = GetRenderFrameHost();
if (rfh && rfh->IsActive()) {
dialog_view_->ShowDialog(content::WebContents::FromRenderFrameHost(rfh),
model_->GetWeakPtr(), base::DoNothing(),
diff --git a/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.h b/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.h
index 1b00c2c..78253bf 100644
--- a/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.h
+++ b/chrome/browser/ui/views/payments/test_secure_payment_confirmation_payment_request_delegate.h
@@ -7,7 +7,6 @@
#include "chrome/browser/payments/chrome_payment_request_delegate.h"
#include "chrome/browser/ui/views/payments/secure_payment_confirmation_dialog_view.h"
-#include "content/public/browser/global_routing_id.h"
namespace content {
class RenderFrameHost;
@@ -38,7 +37,6 @@
}
private:
- const content::GlobalRenderFrameHostId frame_routing_id_;
base::WeakPtr<SecurePaymentConfirmationModel> model_;
base::WeakPtr<SecurePaymentConfirmationDialogView> dialog_view_;
};
diff --git a/chrome/test/payments/payment_request_test_controller_desktop.cc b/chrome/test/payments/payment_request_test_controller_desktop.cc
index 58b9f8c..382c222e 100644
--- a/chrome/test/payments/payment_request_test_controller_desktop.cc
+++ b/chrome/test/payments/payment_request_test_controller_desktop.cc
@@ -2,24 +2,21 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/memory/raw_ptr.h"
#include "chrome/test/payments/payment_request_test_controller.h"
#include "base/check.h"
#include "base/location.h"
+#include "base/memory/raw_ptr.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
-#include "chrome/browser/payments/chrome_payment_request_delegate.h"
#include "chrome/browser/payments/payment_request_factory.h"
+#include "chrome/browser/ui/views/payments/test_chrome_payment_request_delegate.h"
#include "components/payments/content/android_app_communication.h"
#include "components/payments/content/payment_request.h"
#include "components/payments/content/payment_request_web_contents_manager.h"
#include "components/payments/content/payment_ui_observer.h"
#include "components/payments/core/payment_prefs.h"
-#include "components/payments/core/payment_request_delegate.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
-#include "components/webauthn/content/browser/internal_authenticator_impl.h"
-#include "components/webauthn/core/browser/internal_authenticator.h"
#include "content/public/browser/global_routing_id.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
@@ -28,78 +25,6 @@
#include "third_party/blink/public/mojom/webauthn/authenticator.mojom.h"
namespace payments {
-namespace {
-
-class TestAuthenticator : public content::InternalAuthenticatorImpl {
- public:
- explicit TestAuthenticator(content::RenderFrameHost* rfh,
- bool has_authenticator)
- : content::InternalAuthenticatorImpl(rfh),
- has_authenticator_(has_authenticator) {}
-
- ~TestAuthenticator() override = default;
-
- // webauthn::InternalAuthenticator
- void IsUserVerifyingPlatformAuthenticatorAvailable(
- blink::mojom::Authenticator::
- IsUserVerifyingPlatformAuthenticatorAvailableCallback callback)
- override {
- std::move(callback).Run(has_authenticator_);
- }
-
- private:
- const bool has_authenticator_;
-};
-
-class ChromePaymentRequestTestDelegate : public ChromePaymentRequestDelegate {
- public:
- ChromePaymentRequestTestDelegate(
- content::RenderFrameHost* render_frame_host,
- bool is_off_the_record,
- bool valid_ssl,
- PrefService* prefs,
- const std::string& twa_package_name,
- bool has_authenticator,
- base::WeakPtr<PaymentUIObserver> ui_observer_for_test)
- : ChromePaymentRequestDelegate(render_frame_host),
- frame_routing_id_(content::GlobalRenderFrameHostId(
- render_frame_host->GetProcess()->GetID(),
- render_frame_host->GetRoutingID())),
- is_off_the_record_(is_off_the_record),
- valid_ssl_(valid_ssl),
- prefs_(prefs),
- twa_package_name_(twa_package_name),
- has_authenticator_(has_authenticator),
- ui_observer_for_test_(ui_observer_for_test) {}
-
- bool IsOffTheRecord() const override { return is_off_the_record_; }
- std::string GetInvalidSslCertificateErrorMessage() override {
- return valid_ssl_ ? "" : "Invalid SSL certificate";
- }
- PrefService* GetPrefService() override { return prefs_; }
- bool IsBrowserWindowActive() const override { return true; }
- std::string GetTwaPackageName() const override { return twa_package_name_; }
- std::unique_ptr<webauthn::InternalAuthenticator> CreateInternalAuthenticator()
- const override {
- auto* rfh = content::RenderFrameHost::FromID(frame_routing_id_);
- return rfh ? std::make_unique<TestAuthenticator>(rfh, has_authenticator_)
- : nullptr;
- }
- const base::WeakPtr<PaymentUIObserver> GetPaymentUIObserver() const override {
- return ui_observer_for_test_;
- }
-
- private:
- content::GlobalRenderFrameHostId frame_routing_id_;
- const bool is_off_the_record_;
- const bool valid_ssl_;
- const raw_ptr<PrefService> prefs_;
- const std::string twa_package_name_;
- const bool has_authenticator_;
- base::WeakPtr<PaymentUIObserver> ui_observer_for_test_;
-};
-
-} // namespace
class PaymentRequestTestController::ObserverConverter
: public PaymentRequest::ObserverForTest,
@@ -296,10 +221,18 @@
auto* manager =
PaymentRequestWebContentsManager::GetOrCreateForWebContents(
*web_contents);
- auto delegate = std::make_unique<ChromePaymentRequestTestDelegate>(
- render_frame_host, is_off_the_record, valid_ssl, prefs,
- twa_package_name, has_authenticator, observer_for_test);
+
+ auto delegate = std::make_unique<TestChromePaymentRequestDelegate>(
+ render_frame_host);
+ delegate->OverrideBrowserWindowActive(true);
+ delegate->OverrideOffTheRecord(is_off_the_record);
+ delegate->OverrideValidSSL(valid_ssl);
+ delegate->OverridePrefService(prefs);
+ delegate->set_twa_package_name(twa_package_name);
+ delegate->set_has_authenticator(has_authenticator);
+ delegate->set_payment_ui_observer(observer_for_test);
*delegate_weakptr = delegate->GetContentWeakPtr();
+
if (!twa_payment_app_method_name.empty()) {
AndroidAppCommunication::GetForBrowserContext(
render_frame_host->GetBrowserContext())
diff --git a/components/payments/content/content_payment_request_delegate.h b/components/payments/content/content_payment_request_delegate.h
index 471a303..88af46a 100644
--- a/components/payments/content/content_payment_request_delegate.h
+++ b/components/payments/content/content_payment_request_delegate.h
@@ -15,6 +15,10 @@
template <class T>
class scoped_refptr;
+namespace content {
+class RenderFrameHost;
+} // namespace content
+
namespace webauthn {
class InternalAuthenticator;
} // namespace webauthn
@@ -32,6 +36,10 @@
public:
~ContentPaymentRequestDelegate() override;
+ // Returns the RenderFrameHost for the frame that initiated the
+ // PaymentRequest.
+ virtual content::RenderFrameHost* GetRenderFrameHost() const = 0;
+
// Creates and returns an instance of the InternalAuthenticator interface for
// communication with WebAuthn.
virtual std::unique_ptr<webauthn::InternalAuthenticator>
@@ -66,10 +74,6 @@
// parameter will return an "Invalid certificate" error message.
virtual std::string GetInvalidSslCertificateErrorMessage() = 0;
- // Returns whether the UI should be skipped for a "basic-card" scenario. This
- // will only be true in tests.
- virtual bool SkipUiForBasicCard() const = 0;
-
// Returns the Android package name of the Trusted Web Activity that invoked
// this browser, if any. Otherwise, an empty string.
virtual std::string GetTwaPackageName() const = 0;
diff --git a/components/payments/content/payment_request.cc b/components/payments/content/payment_request.cc
index baad22c..05ab578 100644
--- a/components/payments/content/payment_request.cc
+++ b/components/payments/content/payment_request.cc
@@ -740,8 +740,7 @@
// Only allowing URL based payment apps to skip the payment sheet.
skipped_payment_request_ui_ =
!spec()->IsSecurePaymentConfirmationRequested() &&
- (spec()->url_payment_method_identifiers().size() > 0 ||
- delegate_->SkipUiForBasicCard()) &&
+ spec()->url_payment_method_identifiers().size() > 0 &&
base::FeatureList::IsEnabled(features::kWebPaymentsSingleAppUiSkip) &&
base::FeatureList::IsEnabled(::features::kServiceWorkerPaymentApps) &&
state()->IsInitialized() && spec()->IsInitialized() &&
diff --git a/components/payments/content/test_content_payment_request_delegate.cc b/components/payments/content/test_content_payment_request_delegate.cc
index 4ac54f8..df24ce8 100644
--- a/components/payments/content/test_content_payment_request_delegate.cc
+++ b/components/payments/content/test_content_payment_request_delegate.cc
@@ -16,7 +16,13 @@
autofill::PersonalDataManager* pdm)
: core_delegate_(std::move(task_executor), pdm) {}
-TestContentPaymentRequestDelegate::~TestContentPaymentRequestDelegate() {}
+TestContentPaymentRequestDelegate::~TestContentPaymentRequestDelegate() =
+ default;
+
+content::RenderFrameHost*
+TestContentPaymentRequestDelegate::GetRenderFrameHost() const {
+ return nullptr;
+}
std::unique_ptr<webauthn::InternalAuthenticator>
TestContentPaymentRequestDelegate::CreateInternalAuthenticator() const {
@@ -58,10 +64,6 @@
return core_delegate_.IsBrowserWindowActive();
}
-bool TestContentPaymentRequestDelegate::SkipUiForBasicCard() const {
- return false;
-}
-
std::string TestContentPaymentRequestDelegate::GetTwaPackageName() const {
return "";
}
diff --git a/components/payments/content/test_content_payment_request_delegate.h b/components/payments/content/test_content_payment_request_delegate.h
index fe27fb9a..f3c7a0f 100644
--- a/components/payments/content/test_content_payment_request_delegate.h
+++ b/components/payments/content/test_content_payment_request_delegate.h
@@ -37,6 +37,7 @@
~TestContentPaymentRequestDelegate() override;
// ContentPaymentRequestDelegate:
+ content::RenderFrameHost* GetRenderFrameHost() const override;
std::unique_ptr<webauthn::InternalAuthenticator> CreateInternalAuthenticator()
const override;
scoped_refptr<PaymentManifestWebDataService>
@@ -48,7 +49,6 @@
void ShowErrorMessage() override;
void ShowProcessingSpinner() override;
bool IsBrowserWindowActive() const override;
- bool SkipUiForBasicCard() const override;
std::string GetTwaPackageName() const override;
PaymentRequestDialog* GetDialogForTesting() override;
SecurePaymentConfirmationNoCreds* GetNoMatchingCredentialsDialogForTesting()