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 19 matching lines...) Expand all Loading... |
30 *out_error = error; | 30 *out_error = error; |
31 } | 31 } |
32 | 32 |
33 void GetAllManifestsCallback(bool* called, | 33 void GetAllManifestsCallback(bool* called, |
34 PaymentAppProvider::Manifests* out_manifests, | 34 PaymentAppProvider::Manifests* out_manifests, |
35 PaymentAppProvider::Manifests manifests) { | 35 PaymentAppProvider::Manifests manifests) { |
36 *called = true; | 36 *called = true; |
37 *out_manifests = std::move(manifests); | 37 *out_manifests = std::move(manifests); |
38 } | 38 } |
39 | 39 |
| 40 void InvokePaymentAppCallback(bool* called, |
| 41 payments::mojom::PaymentAppResponsePtr response) { |
| 42 *called = true; |
| 43 } |
| 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 class PaymentAppProviderTest : public PaymentAppContentUnitTestBase { | 47 class PaymentAppProviderTest : public PaymentAppContentUnitTestBase { |
43 public: | 48 public: |
44 PaymentAppProviderTest() {} | 49 PaymentAppProviderTest() {} |
45 ~PaymentAppProviderTest() override {} | 50 ~PaymentAppProviderTest() override {} |
46 | 51 |
47 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { | 52 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { |
48 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), | 53 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), |
49 callback); | 54 callback); |
50 base::RunLoop().RunUntilIdle(); | 55 base::RunLoop().RunUntilIdle(); |
51 } | 56 } |
52 | 57 |
53 void InvokePaymentApp(int64_t registration_id, | 58 void InvokePaymentApp(int64_t registration_id, |
54 payments::mojom::PaymentAppRequestPtr app_request) { | 59 payments::mojom::PaymentAppRequestPtr app_request, |
| 60 PaymentAppProvider::InvokePaymentAppCallback callback) { |
55 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( | 61 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( |
56 browser_context(), registration_id, std::move(app_request)); | 62 browser_context(), registration_id, std::move(app_request), callback); |
57 base::RunLoop().RunUntilIdle(); | 63 base::RunLoop().RunUntilIdle(); |
58 } | 64 } |
59 | 65 |
60 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { | 66 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { |
61 PaymentAppManager* manager = | 67 PaymentAppManager* manager = |
62 CreatePaymentAppManager(scope_url, sw_script_url); | 68 CreatePaymentAppManager(scope_url, sw_script_url); |
63 | 69 |
64 PaymentAppManifestError error = | 70 PaymentAppManifestError error = |
65 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | 71 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; |
66 bool called = false; | 72 bool called = false; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); | 133 GetAllManifests(base::Bind(&GetAllManifestsCallback, &called, &manifests)); |
128 ASSERT_TRUE(called); | 134 ASSERT_TRUE(called); |
129 ASSERT_EQ(3U, manifests.size()); | 135 ASSERT_EQ(3U, manifests.size()); |
130 | 136 |
131 payments::mojom::PaymentAppRequestPtr app_request = | 137 payments::mojom::PaymentAppRequestPtr app_request = |
132 payments::mojom::PaymentAppRequest::New(); | 138 payments::mojom::PaymentAppRequest::New(); |
133 app_request->methodData.push_back(payments::mojom::PaymentMethodData::New()); | 139 app_request->methodData.push_back(payments::mojom::PaymentMethodData::New()); |
134 app_request->total = payments::mojom::PaymentItem::New(); | 140 app_request->total = payments::mojom::PaymentItem::New(); |
135 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); | 141 app_request->total->amount = payments::mojom::PaymentCurrencyAmount::New(); |
136 | 142 |
137 EXPECT_FALSE(payment_app_invoked()); | 143 called = false; |
138 InvokePaymentApp(manifests[1].first, std::move(app_request)); | 144 InvokePaymentApp(manifests[1].first, std::move(app_request), |
| 145 base::Bind(&InvokePaymentAppCallback, &called)); |
| 146 ASSERT_TRUE(called); |
139 | 147 |
140 ASSERT_TRUE(payment_app_invoked()); | |
141 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); | 148 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); |
142 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); | 149 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); |
143 } | 150 } |
144 | 151 |
145 } // namespace content | 152 } // namespace content |
OLD | NEW |