Index: content/browser/payments/payment_manager_unittest.cc |
diff --git a/content/browser/payments/payment_manager_unittest.cc b/content/browser/payments/payment_manager_unittest.cc |
index fd01718ba2d5ee3f3644a57be89d6a79b43d4ec9..1806b5d72599513b7094e81ad13ef21679796e37 100644 |
--- a/content/browser/payments/payment_manager_unittest.cc |
+++ b/content/browser/payments/payment_manager_unittest.cc |
@@ -5,17 +5,21 @@ |
#include <utility> |
#include "base/macros.h" |
+#include "base/run_loop.h" |
#include "components/payments/mojom/payment_app.mojom.h" |
#include "content/browser/payments/payment_app_content_unittest_base.h" |
#include "testing/gtest/include/gtest/gtest.h" |
#include "url/gurl.h" |
-using payments::mojom::PaymentAppManifestError; |
-using payments::mojom::PaymentAppManifestPtr; |
- |
namespace content { |
namespace { |
+using ::payments::mojom::PaymentAppManifestError; |
+using ::payments::mojom::PaymentAppManifestPtr; |
+using ::payments::mojom::PaymentHandlerStatus; |
+using ::payments::mojom::PaymentInstrument; |
+using ::payments::mojom::PaymentInstrumentPtr; |
+ |
const char kServiceWorkerPattern[] = "https://example.com/a"; |
const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
@@ -36,6 +40,19 @@ void GetManifestCallback(bool* called, |
*out_error = error; |
} |
+void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
+ PaymentHandlerStatus status) { |
+ *out_status = status; |
+} |
+ |
+void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, |
+ PaymentHandlerStatus* out_status, |
+ PaymentInstrumentPtr instrument, |
+ PaymentHandlerStatus status) { |
+ *out_instrument = std::move(instrument); |
+ *out_status = status; |
+} |
+ |
} // namespace |
class PaymentManagerTest : public PaymentAppContentUnitTestBase { |
@@ -48,6 +65,24 @@ class PaymentManagerTest : public PaymentAppContentUnitTestBase { |
PaymentManager* payment_manager() const { return manager_; } |
+ void SetPaymentInstrument(const std::string& instrumentKey, |
+ PaymentInstrumentPtr instrument, |
+ PaymentHandlerStatus* out_status) { |
+ manager_->SetPaymentInstrument( |
+ instrumentKey, std::move(instrument), |
+ base::Bind(&SetPaymentInstrumentCallback, out_status)); |
+ base::RunLoop().RunUntilIdle(); |
+ } |
+ |
+ void GetPaymentInstrument(const std::string& instrumentKey, |
+ PaymentInstrumentPtr* out_instrument, |
+ PaymentHandlerStatus* out_status) { |
+ manager_->GetPaymentInstrument( |
+ instrumentKey, |
+ base::Bind(&GetPaymentInstrumentCallback, out_instrument, out_status)); |
+ base::RunLoop().RunUntilIdle(); |
+ } |
+ |
private: |
// Owned by payment_app_context_. |
PaymentManager* manager_; |
@@ -121,4 +156,33 @@ TEST_F(PaymentManagerTest, GetManifestWithNoSavedManifest) { |
read_error); |
} |
+TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { |
+ PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
+ PaymentInstrumentPtr write_details = PaymentInstrument::New(); |
+ write_details->name = "Visa ending ****4756", |
+ write_details->enabled_methods.push_back("visa"); |
+ write_details->stringified_capabilities = "{}"; |
+ ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, write_status); |
+ SetPaymentInstrument("test_key", std::move(write_details), &write_status); |
+ ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
+ |
+ PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; |
+ PaymentInstrumentPtr read_details; |
+ ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); |
+ GetPaymentInstrument("test_key", &read_details, &read_status); |
+ ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); |
+ EXPECT_EQ("Visa ending ****4756", read_details->name); |
+ ASSERT_EQ(1U, read_details->enabled_methods.size()); |
+ EXPECT_EQ("visa", read_details->enabled_methods[0]); |
+ EXPECT_EQ("{}", read_details->stringified_capabilities); |
+} |
+ |
+TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) { |
+ PaymentHandlerStatus read_status = PaymentHandlerStatus::SUCCESS; |
+ PaymentInstrumentPtr read_details; |
+ ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); |
+ GetPaymentInstrument("test_key", &read_details, &read_status); |
+ ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); |
+} |
+ |
} // namespace content |