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