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" |
11 #include "components/payments/mojom/payment_app.mojom.h" | 11 #include "components/payments/mojom/payment_app.mojom.h" |
12 #include "content/browser/payments/payment_app_content_unittest_base.h" | 12 #include "content/browser/payments/payment_app_content_unittest_base.h" |
13 #include "content/browser/payments/payment_app_provider_impl.h" | 13 #include "content/browser/payments/payment_app_provider_impl.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "url/gurl.h" | 15 #include "url/gurl.h" |
16 | 16 |
17 using payments::mojom::PaymentAppManifestError; | 17 using payments::mojom::PaymentAppManifestError; |
18 using payments::mojom::PaymentAppManifestPtr; | 18 using payments::mojom::PaymentAppManifestPtr; |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 | 21 |
22 class PaymentManager; | 22 class PaymentManager; |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
| 26 using ::payments::mojom::PaymentHandlerStatus; |
| 27 using ::payments::mojom::PaymentInstrumentPtr; |
| 28 |
26 void SetManifestCallback(bool* called, | 29 void SetManifestCallback(bool* called, |
27 PaymentAppManifestError* out_error, | 30 PaymentAppManifestError* out_error, |
28 PaymentAppManifestError error) { | 31 PaymentAppManifestError error) { |
29 *called = true; | 32 *called = true; |
30 *out_error = error; | 33 *out_error = error; |
31 } | 34 } |
32 | 35 |
33 void GetAllManifestsCallback(bool* called, | 36 void GetAllManifestsCallback(bool* called, |
34 PaymentAppProvider::Manifests* out_manifests, | 37 PaymentAppProvider::Manifests* out_manifests, |
35 PaymentAppProvider::Manifests manifests) { | 38 PaymentAppProvider::Manifests manifests) { |
36 *called = true; | 39 *called = true; |
37 *out_manifests = std::move(manifests); | 40 *out_manifests = std::move(manifests); |
38 } | 41 } |
39 | 42 |
| 43 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
| 44 PaymentHandlerStatus status) { |
| 45 *out_status = status; |
| 46 } |
| 47 |
| 48 void GetAllPaymentAppsCallback(PaymentAppProvider::PaymentApps* out_apps, |
| 49 PaymentAppProvider::PaymentApps apps) { |
| 50 *out_apps = std::move(apps); |
| 51 } |
| 52 |
40 void InvokePaymentAppCallback(bool* called, | 53 void InvokePaymentAppCallback(bool* called, |
41 payments::mojom::PaymentAppResponsePtr response) { | 54 payments::mojom::PaymentAppResponsePtr response) { |
42 *called = true; | 55 *called = true; |
43 } | 56 } |
44 | 57 |
45 } // namespace | 58 } // namespace |
46 | 59 |
47 class PaymentAppProviderTest : public PaymentAppContentUnitTestBase { | 60 class PaymentAppProviderTest : public PaymentAppContentUnitTestBase { |
48 public: | 61 public: |
49 PaymentAppProviderTest() {} | 62 PaymentAppProviderTest() {} |
50 ~PaymentAppProviderTest() override {} | 63 ~PaymentAppProviderTest() override {} |
51 | 64 |
52 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { | 65 void GetAllManifests(PaymentAppProvider::GetAllManifestsCallback callback) { |
53 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), | 66 PaymentAppProviderImpl::GetInstance()->GetAllManifests(browser_context(), |
54 callback); | 67 callback); |
55 base::RunLoop().RunUntilIdle(); | 68 base::RunLoop().RunUntilIdle(); |
56 } | 69 } |
57 | 70 |
| 71 void SetPaymentInstrument( |
| 72 PaymentManager* manager, |
| 73 const std::string& instrument_key, |
| 74 PaymentInstrumentPtr instrument, |
| 75 PaymentManager::SetPaymentInstrumentCallback callback) { |
| 76 ASSERT_NE(nullptr, manager); |
| 77 manager->SetPaymentInstrument(instrument_key, std::move(instrument), |
| 78 std::move(callback)); |
| 79 base::RunLoop().RunUntilIdle(); |
| 80 } |
| 81 |
| 82 void GetAllPaymentApps( |
| 83 PaymentAppProvider::GetAllPaymentAppsCallback callback) { |
| 84 PaymentAppProviderImpl::GetInstance()->GetAllPaymentApps( |
| 85 browser_context(), std::move(callback)); |
| 86 base::RunLoop().RunUntilIdle(); |
| 87 } |
| 88 |
58 void InvokePaymentApp(int64_t registration_id, | 89 void InvokePaymentApp(int64_t registration_id, |
59 payments::mojom::PaymentAppRequestPtr app_request, | 90 payments::mojom::PaymentAppRequestPtr app_request, |
60 PaymentAppProvider::InvokePaymentAppCallback callback) { | 91 PaymentAppProvider::InvokePaymentAppCallback callback) { |
61 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( | 92 PaymentAppProviderImpl::GetInstance()->InvokePaymentApp( |
62 browser_context(), registration_id, std::move(app_request), callback); | 93 browser_context(), registration_id, std::move(app_request), callback); |
63 base::RunLoop().RunUntilIdle(); | 94 base::RunLoop().RunUntilIdle(); |
64 } | 95 } |
65 | 96 |
66 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { | 97 void CreatePaymentApp(const GURL& scope_url, const GURL& sw_script_url) { |
67 PaymentManager* manager = CreatePaymentManager(scope_url, sw_script_url); | 98 PaymentManager* manager = CreatePaymentManager(scope_url, sw_script_url); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 | 172 |
142 called = false; | 173 called = false; |
143 InvokePaymentApp(manifests[1].first, std::move(app_request), | 174 InvokePaymentApp(manifests[1].first, std::move(app_request), |
144 base::Bind(&InvokePaymentAppCallback, &called)); | 175 base::Bind(&InvokePaymentAppCallback, &called)); |
145 ASSERT_TRUE(called); | 176 ASSERT_TRUE(called); |
146 | 177 |
147 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); | 178 EXPECT_EQ(manifests[1].first, last_sw_registration_id()); |
148 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); | 179 EXPECT_EQ(GURL(kPaymentAppInfo[1].scopeUrl), last_sw_scope_url()); |
149 } | 180 } |
150 | 181 |
| 182 TEST_F(PaymentAppProviderTest, GetAllPaymentAppsTest) { |
| 183 PaymentManager* manager1 = CreatePaymentManager( |
| 184 GURL("https://hellopay.com/a"), GURL("https://hellopay.com/a/script.js")); |
| 185 PaymentManager* manager2 = CreatePaymentManager( |
| 186 GURL("https://bobpay.com/b"), GURL("https://bobpay.com/b/script.js")); |
| 187 |
| 188 PaymentHandlerStatus status; |
| 189 SetPaymentInstrument(manager1, "test_key1", |
| 190 payments::mojom::PaymentInstrument::New(), |
| 191 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 192 SetPaymentInstrument(manager2, "test_key2", |
| 193 payments::mojom::PaymentInstrument::New(), |
| 194 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 195 SetPaymentInstrument(manager2, "test_key3", |
| 196 payments::mojom::PaymentInstrument::New(), |
| 197 base::Bind(&SetPaymentInstrumentCallback, &status)); |
| 198 |
| 199 PaymentAppProvider::PaymentApps apps; |
| 200 GetAllPaymentApps(base::Bind(&GetAllPaymentAppsCallback, &apps)); |
| 201 |
| 202 ASSERT_EQ(2U, apps.size()); |
| 203 ASSERT_EQ(1U, apps[GURL("https://hellopay.com/")].size()); |
| 204 ASSERT_EQ(2U, apps[GURL("https://bobpay.com/")].size()); |
| 205 } |
| 206 |
151 } // namespace content | 207 } // namespace content |
OLD | NEW |