| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cstddef> | 5 #include <cstddef> |
| 6 #include <string> | 6 #include <string> |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 58 } |
| 59 | 59 |
| 60 void GetAllPaymentApps( | 60 void GetAllPaymentApps( |
| 61 PaymentAppProvider::GetAllPaymentAppsCallback callback) { | 61 PaymentAppProvider::GetAllPaymentAppsCallback callback) { |
| 62 PaymentAppProviderImpl::GetInstance()->GetAllPaymentApps( | 62 PaymentAppProviderImpl::GetInstance()->GetAllPaymentApps( |
| 63 browser_context(), std::move(callback)); | 63 browser_context(), std::move(callback)); |
| 64 base::RunLoop().RunUntilIdle(); | 64 base::RunLoop().RunUntilIdle(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void InvokePaymentApp(int64_t registration_id, | 67 void InvokePaymentApp(int64_t registration_id, |
| 68 payments::mojom::PaymentAppRequestPtr app_request, | 68 payments::mojom::PaymentRequestEventDataPtr event_data, |
| 69 PaymentAppProvider::InvokePaymentAppCallback callback) { | 69 PaymentAppProvider::InvokePaymentAppCallback callback) { |
| 70 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( | 70 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( |
| 71 browser_context(), registration_id, std::move(app_request), callback); | 71 browser_context(), registration_id, std::move(event_data), callback); |
| 72 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest); | 76 DISALLOW_COPY_AND_ASSIGN(PaymentAppProviderTest); |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) { | 79 TEST_F(PaymentAppProviderTest, InvokePaymentAppTest) { |
| 80 PaymentManager* manager1 = CreatePaymentManager( | 80 PaymentManager* manager1 = CreatePaymentManager( |
| 81 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); | 81 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); |
| 82 PaymentManager* manager2 = CreatePaymentManager( | 82 PaymentManager* manager2 = CreatePaymentManager( |
| 83 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js")); | 83 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js")); |
| 84 | 84 |
| 85 PaymentHandlerStatus status; | 85 PaymentHandlerStatus status; |
| 86 SetPaymentInstrument(manager1, "test_key1", | 86 SetPaymentInstrument(manager1, "test_key1", |
| 87 payments::mojom::PaymentInstrument::New(), | 87 payments::mojom::PaymentInstrument::New(), |
| 88 base::Bind(&SetPaymentInstrumentCallback, &status)); | 88 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 89 SetPaymentInstrument(manager2, "test_key2", | 89 SetPaymentInstrument(manager2, "test_key2", |
| 90 payments::mojom::PaymentInstrument::New(), | 90 payments::mojom::PaymentInstrument::New(), |
| 91 base::Bind(&SetPaymentInstrumentCallback, &status)); | 91 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 92 SetPaymentInstrument(manager2, "test_key3", | 92 SetPaymentInstrument(manager2, "test_key3", |
| 93 payments::mojom::PaymentInstrument::New(), | 93 payments::mojom::PaymentInstrument::New(), |
| 94 base::Bind(&SetPaymentInstrumentCallback, &status)); | 94 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 95 | 95 |
| 96 PaymentAppProvider::PaymentApps apps; | 96 PaymentAppProvider::PaymentApps apps; |
| 97 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); | 97 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); |
| 98 ASSERT_EQ(2U, apps.size()); | 98 ASSERT_EQ(2U, apps.size()); |
| 99 | 99 |
| 100 payments::mojom::PaymentAppRequestPtr app_request = | 100 payments::mojom::PaymentRequestEventDataPtr event_data = |
| 101 payments::mojom::PaymentAppRequest::New(); | 101 payments::mojom::PaymentRequestEventData::New(); |
| 102 app_request->method_data.push_back(payments::mojom::PaymentMethodData::New()); | 102 event_data->method_data.push_back(payments::mojom::PaymentMethodData::New()); |
| 103 app_request->total = payments::mojom::PaymentItem::New(); | 103 event_data->total = payments::mojom::PaymentItem::New(); |
| 104 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); | 104 event_data->total->amount = payments::mojom::PaymentCurrencyAmount::New(); |
| 105 | 105 |
| 106 bool called = false; | 106 bool called = false; |
| 107 InvokePaymentApp(apps[GURL("https://hellopay.com/")][0]->registration_id, | 107 InvokePaymentApp(apps[GURL("https://hellopay.com/")][0]->registration_id, |
| 108 std::move(app_request), | 108 std::move(event_data), |
| 109 base::Bind(&InvokePaymentAppCallback, &called)); | 109 base::Bind(&InvokePaymentAppCallback, &called)); |
| 110 ASSERT_TRUE(called); | 110 ASSERT_TRUE(called); |
| 111 | 111 |
| 112 EXPECT_EQ(apps[GURL("https://hellopay.com/")][0]->registration_id, | 112 EXPECT_EQ(apps[GURL("https://hellopay.com/")][0]->registration_id, |
| 113 last_sw_registration_id()); | 113 last_sw_registration_id()); |
| 114 } | 114 } |
| 115 | 115 |
| 116 TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) { | 116 TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) { |
| 117 PaymentManager* manager1 = CreatePaymentManager( | 117 PaymentManager* manager1 = CreatePaymentManager( |
| 118 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); | 118 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 129 | 129 |
| 130 PaymentAppProvider::PaymentApps apps; | 130 PaymentAppProvider::PaymentApps apps; |
| 131 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); | 131 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); |
| 132 | 132 |
| 133 ASSERT_EQ(2U, apps.size()); | 133 ASSERT_EQ(2U, apps.size()); |
| 134 ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size()); | 134 ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size()); |
| 135 ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size()); | 135 ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size()); |
| 136 } | 136 } |
| 137 | 137 |
| 138 } // namespace content | 138 } // namespace content |
| OLD | NEW |