Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(505)

Unified Diff: content/browser/payments/payment_app_provider_impl_unittest.cc

Issue 2873683002: PaymentHandler: Implement GetAllPaymentApps(). (Closed)
Patch Set: PaymentHandler: Implement GetAllPaymentApps(). Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/payments/payment_app_provider_impl_unittest.cc
diff --git a/content/browser/payments/payment_app_provider_impl_unittest.cc b/content/browser/payments/payment_app_provider_impl_unittest.cc
index 5ced822c8637c82def4bbd58569ce6f279c21d8c..1cbfc4b111cc7aa35751e008d155e293a89438ea 100644
--- a/content/browser/payments/payment_app_provider_impl_unittest.cc
+++ b/content/browser/payments/payment_app_provider_impl_unittest.cc
@@ -23,6 +23,9 @@ class PaymentManager;
namespace {
+using ::payments::mojom::PaymentHandlerStatus;
+using ::payments::mojom::PaymentInstrumentPtr;
+
void SetManifestCallback(bool* called,
PaymentAppManifestError* out_error,
PaymentAppManifestError error) {
@@ -37,6 +40,16 @@ void GetAllManifestsCallback(bool* called,
*out_manifests = std::move(manifests);
}
+void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status,
+ PaymentHandlerStatus status) {
+ *out_status = status;
+}
+
+void GetAllPaymentAppsCallback(PaymentAppProvider::PaymentApps* out_apps,
+ PaymentAppProvider::PaymentApps apps) {
+ *out_apps = std::move(apps);
+}
+
void InvokePaymentAppCallback(bool* called,
payments::mojom::PaymentAppResponsePtr response) {
*called = true;
@@ -55,6 +68,24 @@ class PaymentAppProviderTest : public PaymentAppContentUnitTestBase {
base::RunLoop().RunUntilIdle();
}
+ void SetPaymentInstrument(
+ PaymentManager* manager,
+ const std::string& instrument_key,
+ PaymentInstrumentPtr instrument,
+ const PaymentManager::SetPaymentInstrumentCallback& callback) {
+ ASSERT_NE(nullptr, manager);
+ manager->SetPaymentInstrument(instrument_key, std::move(instrument),
+ callback);
+ base::RunLoop().RunUntilIdle();
+ }
+
+ void GetAllPaymentApps(
+ PaymentAppProvider::GetAllPaymentAppsCallback callback) {
+ PaymentAppProviderImpl::GetInstance()->GetAllPaymentApps(
+ browser_context(), std::move(callback));
+ base::RunLoop().RunUntilIdle();
+ }
+
void InvokePaymentApp(int64_t registration_id,
payments::mojom::PaymentAppRequestPtr app_request,
PaymentAppProvider::InvokePaymentAppCallback callback) {
@@ -148,4 +179,29 @@ TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) {
EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url());
}
+TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) {
+ PaymentManager* manager1 = CreatePaymentManager(
+ GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js"));
+ PaymentManager* manager2 = CreatePaymentManager(
+ GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js"));
+
+ PaymentHandlerStatus status;
+ SetPaymentInstrument(manager1, "test_key1",
+ payments::mojom::PaymentInstrument::New(),
+ base::Bind(&SetPaymentInstrumentCallback, &status));
+ SetPaymentInstrument(manager2, "test_key2",
+ payments::mojom::PaymentInstrument::New(),
+ base::Bind(&SetPaymentInstrumentCallback, &status));
+ SetPaymentInstrument(manager2, "test_key3",
+ payments::mojom::PaymentInstrument::New(),
+ base::Bind(&SetPaymentInstrumentCallback, &status));
+
+ PaymentAppProvider::PaymentApps apps;
+ GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps));
+
+ ASSERT_EQ(2U, apps.size());
+ ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size());
+ ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size());
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698