Commit c49b346d authored by Lloyd Pique's avatar Lloyd Pique Committed by Commit Bot

Register for overlays when handling Android payments

Test: Test Payment app shows the Play Store overlay
Bug: b:172592701

Change-Id: I540c4c91225aad0f3cca1c3bb66024a84cfa3deb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2519891Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarRouslan Solomakhin <rouslan@chromium.org>
Commit-Queue: Lloyd Pique <lpique@chromium.org>
Auto-Submit: Lloyd Pique <lpique@chromium.org>
Cr-Commit-Position: refs/heads/master@{#829481}
parent 64a654d0
...@@ -70,6 +70,10 @@ source_set("browsertests") { ...@@ -70,6 +70,10 @@ source_set("browsertests") {
"//components/permissions:permissions", "//components/permissions:permissions",
] ]
} }
if (is_chromeos) {
deps += [ "//ash/public/cpp/external_arc:external_arc" ]
}
} }
source_set("unittests") { source_set("unittests") {
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#if defined(OS_CHROMEOS)
#include "ash/public/cpp/external_arc/overlay/arc_overlay_manager.h"
#endif
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/test/payments/payment_request_platform_browsertest_base.h" #include "chrome/test/payments/payment_request_platform_browsertest_base.h"
#include "components/payments/core/features.h" #include "components/payments/core/features.h"
...@@ -45,6 +48,10 @@ IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest, ...@@ -45,6 +48,10 @@ IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
// goods purchase. // goods purchase.
IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest, IN_PROC_BROWSER_TEST_F(AndroidPaymentAppFactoryTest,
IgnoreOtherPaymentAppsInTwaWhenHaveAppStoreBilling) { IgnoreOtherPaymentAppsInTwaWhenHaveAppStoreBilling) {
#if defined(OS_CHROMEOS)
ash::ArcOverlayManager overlay_manager_;
#endif
std::string method_name = https_server()->GetURL("a.com", "/").spec(); std::string method_name = https_server()->GetURL("a.com", "/").spec();
method_name = method_name.substr(0, method_name.length() - 1); method_name = method_name.substr(0, method_name.length() - 1);
ASSERT_NE('/', method_name[method_name.length() - 1]); ASSERT_NE('/', method_name[method_name.length() - 1]);
......
include_rules = [ include_rules = [
"+ash/public/cpp/external_arc/overlay",
"+components/network_session_configurator/common", "+components/network_session_configurator/common",
"+components/payments", "+components/payments",
"+third_party/blink/public/mojom/webauthn", "+third_party/blink/public/mojom/webauthn",
......
...@@ -75,6 +75,7 @@ static_library("content") { ...@@ -75,6 +75,7 @@ static_library("content") {
sources += [ "android_app_communication_chrome_os.cc" ] sources += [ "android_app_communication_chrome_os.cc" ]
deps += [ deps += [
"//ash/public/cpp/external_arc:external_arc",
"//components/arc", "//components/arc",
"//components/arc/mojom", "//components/arc/mojom",
] ]
...@@ -220,6 +221,7 @@ source_set("unit_tests") { ...@@ -220,6 +221,7 @@ source_set("unit_tests") {
sources += [ "android_app_communication_test_support_chrome_os.cc" ] sources += [ "android_app_communication_test_support_chrome_os.cc" ]
deps += [ deps += [
"//ash/public/cpp/external_arc:external_arc",
"//components/arc", "//components/arc",
"//components/arc:arc_test_support", "//components/arc:arc_test_support",
"//components/arc/mojom", "//components/arc/mojom",
......
include_rules = [ include_rules = [
"-components/payments/content/android", "-components/payments/content/android",
"+ash/public/cpp/external_arc/overlay",
"+components/arc", "+components/arc",
"+components/autofill", "+components/autofill",
"+components/keyed_service/content", "+components/keyed_service/content",
......
...@@ -21,6 +21,7 @@ class GURL; ...@@ -21,6 +21,7 @@ class GURL;
namespace content { namespace content {
class BrowserContext; class BrowserContext;
class WebContents;
} // namespace content } // namespace content
namespace payments { namespace payments {
...@@ -81,6 +82,7 @@ class AndroidAppCommunication : public base::SupportsUserData::Data { ...@@ -81,6 +82,7 @@ class AndroidAppCommunication : public base::SupportsUserData::Data {
const GURL& top_level_origin, const GURL& top_level_origin,
const GURL& payment_request_origin, const GURL& payment_request_origin,
const std::string& payment_request_id, const std::string& payment_request_id,
content::WebContents* web_contents,
InvokePaymentAppCallback callback) = 0; InvokePaymentAppCallback callback) = 0;
// Allows usage of a test browser context. // Allows usage of a test browser context.
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <utility> #include <utility>
#include "ash/public/cpp/external_arc/overlay/arc_overlay_manager.h"
#include "base/callback_helpers.h"
#include "components/arc/mojom/payment_app.mojom.h" #include "components/arc/mojom/payment_app.mojom.h"
#include "components/arc/pay/arc_payment_app_bridge.h" #include "components/arc/pay/arc_payment_app_bridge.h"
#include "components/payments/core/android_app_description.h" #include "components/payments/core/android_app_description.h"
...@@ -13,6 +15,7 @@ ...@@ -13,6 +15,7 @@
#include "components/payments/core/method_strings.h" #include "components/payments/core/method_strings.h"
#include "components/payments/core/native_error_strings.h" #include "components/payments/core/native_error_strings.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace payments { namespace payments {
...@@ -100,8 +103,13 @@ void OnIsReadyToPay(AndroidAppCommunication::IsReadyToPayCallback callback, ...@@ -100,8 +103,13 @@ void OnIsReadyToPay(AndroidAppCommunication::IsReadyToPayCallback callback,
void OnPaymentAppResponse( void OnPaymentAppResponse(
AndroidAppCommunication::InvokePaymentAppCallback callback, AndroidAppCommunication::InvokePaymentAppCallback callback,
base::ScopedClosureRunner overlay_state,
arc::mojom::InvokePaymentAppResultPtr response) { arc::mojom::InvokePaymentAppResultPtr response) {
// Dismiss and prevent any further overlays
overlay_state.RunAndReset();
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (response.is_null()) { if (response.is_null()) {
std::move(callback).Run(errors::kEmptyResponse, std::move(callback).Run(errors::kEmptyResponse,
/*is_activity_result_ok=*/false, /*is_activity_result_ok=*/false,
...@@ -271,9 +279,23 @@ class AndroidAppCommunicationChromeOS : public AndroidAppCommunication { ...@@ -271,9 +279,23 @@ class AndroidAppCommunicationChromeOS : public AndroidAppCommunication {
const GURL& top_level_origin, const GURL& top_level_origin,
const GURL& payment_request_origin, const GURL& payment_request_origin,
const std::string& payment_request_id, const std::string& payment_request_id,
content::WebContents* web_contents,
InvokePaymentAppCallback callback) override { InvokePaymentAppCallback callback) override {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// Create and register a token with ArcOverlayManager for the
// browser window. Doing so is required to allow the Android Play Billing
// interface to be overlaid on top of the browser window.
// TODO(b/172592701): Use base::UnguessableToken::Create().ToString() and
// send the same value to the Android service.
std::string billing_token =
payment_request_origin.spec() + "#" + payment_request_id;
ash::ArcOverlayManager* const overlay_manager =
ash::ArcOverlayManager::instance();
base::ScopedClosureRunner overlay_state =
overlay_manager->RegisterHostWindow(std::move(billing_token),
web_contents->GetNativeView());
base::Optional<std::string> error_message; base::Optional<std::string> error_message;
if (package_name_for_testing_ == package_name) { if (package_name_for_testing_ == package_name) {
std::move(callback).Run(error_message, std::move(callback).Run(error_message,
...@@ -304,7 +326,8 @@ class AndroidAppCommunicationChromeOS : public AndroidAppCommunication { ...@@ -304,7 +326,8 @@ class AndroidAppCommunicationChromeOS : public AndroidAppCommunication {
payment_app_service->InvokePaymentApp( payment_app_service->InvokePaymentApp(
std::move(parameters), std::move(parameters),
base::BindOnce(&OnPaymentAppResponse, std::move(callback))); base::BindOnce(&OnPaymentAppResponse, std::move(callback),
std::move(overlay_state)));
} }
// AndroidAppCommunication implementation. // AndroidAppCommunication implementation.
......
...@@ -48,6 +48,7 @@ class AndroidAppCommunicationStub : public AndroidAppCommunication { ...@@ -48,6 +48,7 @@ class AndroidAppCommunicationStub : public AndroidAppCommunication {
const GURL& top_level_origin, const GURL& top_level_origin,
const GURL& payment_request_origin, const GURL& payment_request_origin,
const std::string& payment_request_id, const std::string& payment_request_id,
content::WebContents* web_contents,
InvokePaymentAppCallback callback) override { InvokePaymentAppCallback callback) override {
std::move(callback).Run(errors::kUnableToInvokeAndroidPaymentApps, std::move(callback).Run(errors::kUnableToInvokeAndroidPaymentApps,
/*is_activity_result_ok=*/false, /*is_activity_result_ok=*/false,
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <utility> #include <utility>
#include "ash/public/cpp/external_arc/overlay/test/test_arc_overlay_manager.h"
#include "components/arc/mojom/payment_app.mojom.h" #include "components/arc/mojom/payment_app.mojom.h"
#include "components/arc/pay/arc_payment_app_bridge.h" #include "components/arc/pay/arc_payment_app_bridge.h"
#include "components/arc/test/arc_payment_app_bridge_test_support.h" #include "components/arc/test/arc_payment_app_bridge_test_support.h"
...@@ -145,6 +146,7 @@ class AndroidAppCommunicationTestSupportChromeOS ...@@ -145,6 +146,7 @@ class AndroidAppCommunicationTestSupportChromeOS
arc::ArcPaymentAppBridgeTestSupport support_; arc::ArcPaymentAppBridgeTestSupport support_;
std::vector<std::unique_ptr<AndroidAppDescription>> apps_; std::vector<std::unique_ptr<AndroidAppDescription>> apps_;
ash::TestArcOverlayManager overlay_manager_;
}; };
} // namespace } // namespace
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "base/optional.h" #include "base/optional.h"
#include "components/payments/content/android_app_communication_test_support.h" #include "components/payments/content/android_app_communication_test_support.h"
#include "components/payments/core/android_app_description.h" #include "components/payments/core/android_app_description.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_web_contents_factory.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -45,7 +47,9 @@ std::vector<std::unique_ptr<AndroidAppDescription>> createApp( ...@@ -45,7 +47,9 @@ std::vector<std::unique_ptr<AndroidAppDescription>> createApp(
class AndroidAppCommunicationTest : public testing::Test { class AndroidAppCommunicationTest : public testing::Test {
public: public:
AndroidAppCommunicationTest() AndroidAppCommunicationTest()
: support_(AndroidAppCommunicationTestSupport::Create()) {} : support_(AndroidAppCommunicationTestSupport::Create()),
web_contents_(
web_contents_factory_.CreateWebContents(support_->context())) {}
~AndroidAppCommunicationTest() override = default; ~AndroidAppCommunicationTest() override = default;
AndroidAppCommunicationTest(const AndroidAppCommunicationTest& other) = AndroidAppCommunicationTest(const AndroidAppCommunicationTest& other) =
...@@ -77,6 +81,8 @@ class AndroidAppCommunicationTest : public testing::Test { ...@@ -77,6 +81,8 @@ class AndroidAppCommunicationTest : public testing::Test {
} }
std::unique_ptr<AndroidAppCommunicationTestSupport> support_; std::unique_ptr<AndroidAppCommunicationTestSupport> support_;
content::TestWebContentsFactory web_contents_factory_;
content::WebContents* web_contents_;
base::Optional<std::string> error_; base::Optional<std::string> error_;
std::vector<std::unique_ptr<AndroidAppDescription>> apps_; std::vector<std::unique_ptr<AndroidAppDescription>> apps_;
bool is_ready_to_pay_ = false; bool is_ready_to_pay_ = false;
...@@ -466,6 +472,7 @@ TEST_F(AndroidAppCommunicationTest, NoArcForInvokePaymentApp) { ...@@ -466,6 +472,7 @@ TEST_F(AndroidAppCommunicationTest, NoArcForInvokePaymentApp) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
...@@ -490,6 +497,7 @@ TEST_F(AndroidAppCommunicationTest, TwaPaymentOnlyWithPlayBilling) { ...@@ -490,6 +497,7 @@ TEST_F(AndroidAppCommunicationTest, TwaPaymentOnlyWithPlayBilling) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
...@@ -522,6 +530,7 @@ TEST_F(AndroidAppCommunicationTest, NoPaymentWithMoreThanOnePaymentMethodData) { ...@@ -522,6 +530,7 @@ TEST_F(AndroidAppCommunicationTest, NoPaymentWithMoreThanOnePaymentMethodData) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
...@@ -557,6 +566,7 @@ TEST_F(AndroidAppCommunicationTest, PaymentWithEmptyMethodData) { ...@@ -557,6 +566,7 @@ TEST_F(AndroidAppCommunicationTest, PaymentWithEmptyMethodData) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
...@@ -589,6 +599,7 @@ TEST_F(AndroidAppCommunicationTest, UserCancelInvokePaymentApp) { ...@@ -589,6 +599,7 @@ TEST_F(AndroidAppCommunicationTest, UserCancelInvokePaymentApp) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
...@@ -621,6 +632,7 @@ TEST_F(AndroidAppCommunicationTest, UserConfirmInvokePaymentApp) { ...@@ -621,6 +632,7 @@ TEST_F(AndroidAppCommunicationTest, UserConfirmInvokePaymentApp) {
"com.example.app", "com.example.app.Activity", stringified_method_data, "com.example.app", "com.example.app.Activity", stringified_method_data,
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
web_contents_,
base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse, base::BindOnce(&AndroidAppCommunicationTest::OnPaymentAppResponse,
base::Unretained(this))); base::Unretained(this)));
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "components/payments/core/method_strings.h" #include "components/payments/core/method_strings.h"
#include "components/payments/core/native_error_strings.h" #include "components/payments/core/native_error_strings.h"
#include "components/payments/core/payer_data.h" #include "components/payments/core/payer_data.h"
#include "content/public/browser/web_contents.h"
namespace payments { namespace payments {
...@@ -21,14 +22,16 @@ AndroidPaymentApp::AndroidPaymentApp( ...@@ -21,14 +22,16 @@ AndroidPaymentApp::AndroidPaymentApp(
const GURL& payment_request_origin, const GURL& payment_request_origin,
const std::string& payment_request_id, const std::string& payment_request_id,
std::unique_ptr<AndroidAppDescription> description, std::unique_ptr<AndroidAppDescription> description,
base::WeakPtr<AndroidAppCommunication> communication) base::WeakPtr<AndroidAppCommunication> communication,
content::GlobalFrameRoutingId frame_routing_id)
: PaymentApp(/*icon_resource_id=*/0, PaymentApp::Type::NATIVE_MOBILE_APP), : PaymentApp(/*icon_resource_id=*/0, PaymentApp::Type::NATIVE_MOBILE_APP),
stringified_method_data_(std::move(stringified_method_data)), stringified_method_data_(std::move(stringified_method_data)),
top_level_origin_(top_level_origin), top_level_origin_(top_level_origin),
payment_request_origin_(payment_request_origin), payment_request_origin_(payment_request_origin),
payment_request_id_(payment_request_id), payment_request_id_(payment_request_id),
description_(std::move(description)), description_(std::move(description)),
communication_(communication) { communication_(communication),
frame_routing_id_(frame_routing_id) {
DCHECK(!payment_method_names.empty()); DCHECK(!payment_method_names.empty());
DCHECK_EQ(payment_method_names.size(), stringified_method_data_->size()); DCHECK_EQ(payment_method_names.size(), stringified_method_data_->size());
DCHECK_EQ(*payment_method_names.begin(), DCHECK_EQ(*payment_method_names.begin(),
...@@ -48,10 +51,19 @@ void AndroidPaymentApp::InvokePaymentApp(Delegate* delegate) { ...@@ -48,10 +51,19 @@ void AndroidPaymentApp::InvokePaymentApp(Delegate* delegate) {
if (!communication_) if (!communication_)
return; return;
content::RenderFrameHost* rfh =
content::RenderFrameHost::FromID(frame_routing_id_);
if (!rfh || !rfh->IsCurrent())
return;
content::WebContents* web_contents =
content::WebContents::FromRenderFrameHost(rfh);
if (!web_contents)
return;
communication_->InvokePaymentApp( communication_->InvokePaymentApp(
description_->package, description_->activities.front()->name, description_->package, description_->activities.front()->name,
*stringified_method_data_, top_level_origin_, payment_request_origin_, *stringified_method_data_, top_level_origin_, payment_request_origin_,
payment_request_id_, payment_request_id_, web_contents,
base::BindOnce(&AndroidPaymentApp::OnPaymentAppResponse, base::BindOnce(&AndroidPaymentApp::OnPaymentAppResponse,
weak_ptr_factory_.GetWeakPtr(), delegate)); weak_ptr_factory_.GetWeakPtr(), delegate));
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "components/payments/content/android_app_communication.h" #include "components/payments/content/android_app_communication.h"
#include "components/payments/content/payment_app.h" #include "components/payments/content/payment_app.h"
#include "components/payments/core/android_app_description.h" #include "components/payments/core/android_app_description.h"
#include "content/public/browser/global_routing_id.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace payments { namespace payments {
...@@ -40,7 +41,8 @@ class AndroidPaymentApp : public PaymentApp { ...@@ -40,7 +41,8 @@ class AndroidPaymentApp : public PaymentApp {
const GURL& payment_request_origin, const GURL& payment_request_origin,
const std::string& payment_request_id, const std::string& payment_request_id,
std::unique_ptr<AndroidAppDescription> description, std::unique_ptr<AndroidAppDescription> description,
base::WeakPtr<AndroidAppCommunication> communication); base::WeakPtr<AndroidAppCommunication> communication,
content::GlobalFrameRoutingId frame_routing_id);
~AndroidPaymentApp() override; ~AndroidPaymentApp() override;
AndroidPaymentApp(const AndroidPaymentApp& other) = delete; AndroidPaymentApp(const AndroidPaymentApp& other) = delete;
...@@ -88,6 +90,7 @@ class AndroidPaymentApp : public PaymentApp { ...@@ -88,6 +90,7 @@ class AndroidPaymentApp : public PaymentApp {
const std::string payment_request_id_; const std::string payment_request_id_;
const std::unique_ptr<AndroidAppDescription> description_; const std::unique_ptr<AndroidAppDescription> description_;
base::WeakPtr<AndroidAppCommunication> communication_; base::WeakPtr<AndroidAppCommunication> communication_;
content::GlobalFrameRoutingId frame_routing_id_;
base::WeakPtrFactory<AndroidPaymentApp> weak_ptr_factory_{this}; base::WeakPtrFactory<AndroidPaymentApp> weak_ptr_factory_{this};
}; };
......
...@@ -179,7 +179,8 @@ class AppFinder : public base::SupportsUserData::Data { ...@@ -179,7 +179,8 @@ class AppFinder : public base::SupportsUserData::Data {
DCHECK_LT(0U, number_of_pending_is_ready_to_pay_queries_); DCHECK_LT(0U, number_of_pending_is_ready_to_pay_queries_);
// The browser could be shutting down. // The browser could be shutting down.
if (!communication_ || !delegate_ || !delegate_->GetSpec()) { if (!communication_ || !delegate_ || !delegate_->GetSpec() ||
!delegate_->GetInitiatorRenderFrameHost()) {
OnDoneCreatingPaymentApps(); OnDoneCreatingPaymentApps();
return; return;
} }
...@@ -191,7 +192,8 @@ class AppFinder : public base::SupportsUserData::Data { ...@@ -191,7 +192,8 @@ class AppFinder : public base::SupportsUserData::Data {
payment_method_names, std::move(stringified_method_data), payment_method_names, std::move(stringified_method_data),
delegate_->GetTopOrigin(), delegate_->GetFrameOrigin(), delegate_->GetTopOrigin(), delegate_->GetFrameOrigin(),
delegate_->GetSpec()->details().id.value(), delegate_->GetSpec()->details().id.value(),
std::move(app_description), communication_)); std::move(app_description), communication_,
delegate_->GetInitiatorRenderFrameHost()->GetGlobalFrameRoutingId()));
} }
if (--number_of_pending_is_ready_to_pay_queries_ == 0) if (--number_of_pending_is_ready_to_pay_queries_ == 0)
......
...@@ -175,6 +175,9 @@ TEST_F(AndroidPaymentAppFactoryTest, FindAppsThatDoNotHaveReadyToPayService) { ...@@ -175,6 +175,9 @@ TEST_F(AndroidPaymentAppFactoryTest, FindAppsThatDoNotHaveReadyToPayService) {
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.example.app")); .WillRepeatedly(testing::Return("com.example.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
...@@ -214,6 +217,9 @@ TEST_F(AndroidPaymentAppFactoryTest, ...@@ -214,6 +217,9 @@ TEST_F(AndroidPaymentAppFactoryTest,
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.example.app")); .WillRepeatedly(testing::Return("com.example.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
...@@ -250,6 +256,9 @@ TEST_F(AndroidPaymentAppFactoryTest, ...@@ -250,6 +256,9 @@ TEST_F(AndroidPaymentAppFactoryTest,
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.twa.app")); .WillRepeatedly(testing::Return("com.twa.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
...@@ -282,6 +291,9 @@ TEST_F(AndroidPaymentAppFactoryTest, IgnoreAppsThatAreNotReadyToPay) { ...@@ -282,6 +291,9 @@ TEST_F(AndroidPaymentAppFactoryTest, IgnoreAppsThatAreNotReadyToPay) {
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.example.app")); .WillRepeatedly(testing::Return("com.example.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
EXPECT_CALL(delegate_, OnPaymentAppCreated(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreated(testing::_)).Times(0);
...@@ -309,6 +321,9 @@ TEST_F(AndroidPaymentAppFactoryTest, FindTheCorrectTwaAppInTwaMode) { ...@@ -309,6 +321,9 @@ TEST_F(AndroidPaymentAppFactoryTest, FindTheCorrectTwaAppInTwaMode) {
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.correct-twa.app")); .WillRepeatedly(testing::Return("com.correct-twa.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
...@@ -448,6 +463,9 @@ TEST_F(AndroidPaymentAppFactoryTest, ...@@ -448,6 +463,9 @@ TEST_F(AndroidPaymentAppFactoryTest,
EXPECT_CALL(delegate_, GetTwaPackageName()) EXPECT_CALL(delegate_, GetTwaPackageName())
.WillRepeatedly(testing::Return("com.twa.app")); .WillRepeatedly(testing::Return("com.twa.app"));
EXPECT_CALL(delegate_, GetInitiatorRenderFrameHost())
.WillRepeatedly(
testing::Return(delegate_.GetWebContents()->GetMainFrame()));
EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps()); EXPECT_CALL(delegate_, OnDoneCreatingPaymentApps());
EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0); EXPECT_CALL(delegate_, OnPaymentAppCreationError(testing::_)).Times(0);
EXPECT_CALL(delegate_, OnPaymentAppCreated(PaymentAppMatches( EXPECT_CALL(delegate_, OnPaymentAppCreated(PaymentAppMatches(
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
#include "components/payments/content/android_app_communication_test_support.h" #include "components/payments/content/android_app_communication_test_support.h"
#include "components/payments/core/android_app_description.h" #include "components/payments/core/android_app_description.h"
#include "components/payments/core/method_strings.h" #include "components/payments/core/method_strings.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_web_contents_factory.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -28,7 +31,8 @@ class AndroidPaymentAppTest : public testing::Test, ...@@ -28,7 +31,8 @@ class AndroidPaymentAppTest : public testing::Test,
public PaymentApp::Delegate { public PaymentApp::Delegate {
public: public:
static std::unique_ptr<AndroidPaymentApp> CreateAndroidPaymentApp( static std::unique_ptr<AndroidPaymentApp> CreateAndroidPaymentApp(
base::WeakPtr<AndroidAppCommunication> communication) { base::WeakPtr<AndroidAppCommunication> communication,
content::WebContents* web_contents) {
std::set<std::string> payment_method_names; std::set<std::string> payment_method_names;
payment_method_names.insert(methods::kGooglePlayBilling); payment_method_names.insert(methods::kGooglePlayBilling);
auto stringified_method_data = auto stringified_method_data =
...@@ -47,11 +51,14 @@ class AndroidPaymentAppTest : public testing::Test, ...@@ -47,11 +51,14 @@ class AndroidPaymentAppTest : public testing::Test,
payment_method_names, std::move(stringified_method_data), payment_method_names, std::move(stringified_method_data),
GURL("https://top-level-origin.com"), GURL("https://top-level-origin.com"),
GURL("https://payment-request-origin.com"), "payment-request-id", GURL("https://payment-request-origin.com"), "payment-request-id",
std::move(description), communication); std::move(description), communication,
web_contents->GetMainFrame()->GetGlobalFrameRoutingId());
} }
AndroidPaymentAppTest() AndroidPaymentAppTest()
: support_(AndroidAppCommunicationTestSupport::Create()) {} : support_(AndroidAppCommunicationTestSupport::Create()),
web_contents_(
web_contents_factory_.CreateWebContents(support_->context())) {}
~AndroidPaymentAppTest() override = default; ~AndroidPaymentAppTest() override = default;
...@@ -72,6 +79,8 @@ class AndroidPaymentAppTest : public testing::Test, ...@@ -72,6 +79,8 @@ class AndroidPaymentAppTest : public testing::Test,
} }
std::unique_ptr<AndroidAppCommunicationTestSupport> support_; std::unique_ptr<AndroidAppCommunicationTestSupport> support_;
content::TestWebContentsFactory web_contents_factory_;
content::WebContents* web_contents_;
std::unique_ptr<AndroidAppCommunicationTestSupport::ScopedInitialization> std::unique_ptr<AndroidAppCommunicationTestSupport::ScopedInitialization>
scoped_initialization_; scoped_initialization_;
base::WeakPtr<AndroidAppCommunication> communication_; base::WeakPtr<AndroidAppCommunication> communication_;
...@@ -87,7 +96,7 @@ TEST_F(AndroidPaymentAppTest, BrowserShutdown) { ...@@ -87,7 +96,7 @@ TEST_F(AndroidPaymentAppTest, BrowserShutdown) {
support_->ExpectNoPaymentAppInvoke(); support_->ExpectNoPaymentAppInvoke();
auto app = CreateAndroidPaymentApp(communication_); auto app = CreateAndroidPaymentApp(communication_, web_contents_);
app->InvokePaymentApp(/*delegate=*/this); app->InvokePaymentApp(/*delegate=*/this);
EXPECT_TRUE(error_message_.empty()); EXPECT_TRUE(error_message_.empty());
...@@ -103,7 +112,7 @@ TEST_F(AndroidPaymentAppTest, UnableToCommunicateToAndroidApps) { ...@@ -103,7 +112,7 @@ TEST_F(AndroidPaymentAppTest, UnableToCommunicateToAndroidApps) {
support_->ExpectNoPaymentAppInvoke(); support_->ExpectNoPaymentAppInvoke();
auto app = CreateAndroidPaymentApp(communication_); auto app = CreateAndroidPaymentApp(communication_, web_contents_);
app->InvokePaymentApp(/*delegate=*/this); app->InvokePaymentApp(/*delegate=*/this);
EXPECT_EQ("Unable to invoke Android apps.", error_message_); EXPECT_EQ("Unable to invoke Android apps.", error_message_);
...@@ -122,7 +131,7 @@ TEST_F(AndroidPaymentAppTest, OnInstrumentDetailsError) { ...@@ -122,7 +131,7 @@ TEST_F(AndroidPaymentAppTest, OnInstrumentDetailsError) {
/*payment_method_identifier=*/methods::kGooglePlayBilling, /*payment_method_identifier=*/methods::kGooglePlayBilling,
/*stringified_details=*/"{}"); /*stringified_details=*/"{}");
auto app = CreateAndroidPaymentApp(communication_); auto app = CreateAndroidPaymentApp(communication_, web_contents_);
app->InvokePaymentApp(/*delegate=*/this); app->InvokePaymentApp(/*delegate=*/this);
if (support_->AreAndroidAppsSupportedOnThisPlatform()) { if (support_->AreAndroidAppsSupportedOnThisPlatform()) {
...@@ -146,7 +155,7 @@ TEST_F(AndroidPaymentAppTest, OnInstrumentDetailsReady) { ...@@ -146,7 +155,7 @@ TEST_F(AndroidPaymentAppTest, OnInstrumentDetailsReady) {
/*payment_method_identifier=*/methods::kGooglePlayBilling, /*payment_method_identifier=*/methods::kGooglePlayBilling,
/*stringified_details=*/"{\"status\": \"ok\"}"); /*stringified_details=*/"{\"status\": \"ok\"}");
auto app = CreateAndroidPaymentApp(communication_); auto app = CreateAndroidPaymentApp(communication_, web_contents_);
app->InvokePaymentApp(/*delegate=*/this); app->InvokePaymentApp(/*delegate=*/this);
if (support_->AreAndroidAppsSupportedOnThisPlatform()) { if (support_->AreAndroidAppsSupportedOnThisPlatform()) {
......
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