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 <utility> | 5 #include <utility> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "components/payments/mojom/payment_app.mojom.h" | 9 #include "components/payments/mojom/payment_app.mojom.h" |
10 #include "content/browser/payments/payment_app_content_unittest_base.h" | 10 #include "content/browser/payments/payment_app_content_unittest_base.h" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 void DeletePaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 43 void DeletePaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
44 PaymentHandlerStatus status) { | 44 PaymentHandlerStatus status) { |
45 *out_status = status; | 45 *out_status = status; |
46 } | 46 } |
47 | 47 |
48 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 48 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
49 PaymentHandlerStatus status) { | 49 PaymentHandlerStatus status) { |
50 *out_status = status; | 50 *out_status = status; |
51 } | 51 } |
52 | 52 |
53 void KeysOfPaymentInstrumentsCallback(std::vector<std::string>* out_keys, | |
54 PaymentHandlerStatus* out_status, | |
55 const std::vector<std::string>& keys, | |
56 PaymentHandlerStatus status) { | |
57 *out_keys = keys; | |
58 *out_status = status; | |
59 } | |
60 | |
61 void HasPaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 53 void HasPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
62 PaymentHandlerStatus status) { | 54 PaymentHandlerStatus status) { |
63 *out_status = status; | 55 *out_status = status; |
64 } | 56 } |
65 | 57 |
66 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, | 58 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, |
67 PaymentHandlerStatus* out_status, | 59 PaymentHandlerStatus* out_status, |
68 PaymentInstrumentPtr instrument, | 60 PaymentInstrumentPtr instrument, |
69 PaymentHandlerStatus status) { | 61 PaymentHandlerStatus status) { |
70 *out_instrument = std::move(instrument); | 62 *out_instrument = std::move(instrument); |
(...skipping 22 matching lines...) Expand all Loading... |
93 | 85 |
94 void SetPaymentInstrument(const std::string& instrument_key, | 86 void SetPaymentInstrument(const std::string& instrument_key, |
95 PaymentInstrumentPtr instrument, | 87 PaymentInstrumentPtr instrument, |
96 PaymentHandlerStatus* out_status) { | 88 PaymentHandlerStatus* out_status) { |
97 manager_->SetPaymentInstrument( | 89 manager_->SetPaymentInstrument( |
98 instrument_key, std::move(instrument), | 90 instrument_key, std::move(instrument), |
99 base::Bind(&SetPaymentInstrumentCallback, out_status)); | 91 base::Bind(&SetPaymentInstrumentCallback, out_status)); |
100 base::RunLoop().RunUntilIdle(); | 92 base::RunLoop().RunUntilIdle(); |
101 } | 93 } |
102 | 94 |
103 void KeysOfPaymentInstruments(std::vector<std::string>* out_keys, | |
104 PaymentHandlerStatus* out_status) { | |
105 manager_->KeysOfPaymentInstruments( | |
106 base::Bind(&KeysOfPaymentInstrumentsCallback, out_keys, out_status)); | |
107 base::RunLoop().RunUntilIdle(); | |
108 } | |
109 | |
110 void HasPaymentInstrument(const std::string& instrument_key, | 95 void HasPaymentInstrument(const std::string& instrument_key, |
111 PaymentHandlerStatus* out_status) { | 96 PaymentHandlerStatus* out_status) { |
112 manager_->HasPaymentInstrument( | 97 manager_->HasPaymentInstrument( |
113 instrument_key, base::Bind(&HasPaymentInstrumentCallback, out_status)); | 98 instrument_key, base::Bind(&HasPaymentInstrumentCallback, out_status)); |
114 base::RunLoop().RunUntilIdle(); | 99 base::RunLoop().RunUntilIdle(); |
115 } | 100 } |
116 | 101 |
117 void GetPaymentInstrument(const std::string& instrument_key, | 102 void GetPaymentInstrument(const std::string& instrument_key, |
118 PaymentInstrumentPtr* out_instrument, | 103 PaymentInstrumentPtr* out_instrument, |
119 PaymentHandlerStatus* out_status) { | 104 PaymentHandlerStatus* out_status) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 240 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
256 | 241 |
257 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; | 242 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; |
258 HasPaymentInstrument("test_key", &has_status); | 243 HasPaymentInstrument("test_key", &has_status); |
259 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); | 244 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); |
260 | 245 |
261 HasPaymentInstrument("unstored_test_key", &has_status); | 246 HasPaymentInstrument("unstored_test_key", &has_status); |
262 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); | 247 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); |
263 } | 248 } |
264 | 249 |
265 TEST_F(PaymentManagerTest, KeysOfPaymentInstruments) { | |
266 PaymentHandlerStatus keys_status = PaymentHandlerStatus::NOT_FOUND; | |
267 std::vector<std::string> keys; | |
268 KeysOfPaymentInstruments(&keys, &keys_status); | |
269 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); | |
270 ASSERT_EQ(0U, keys.size()); | |
271 | |
272 { | |
273 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
274 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); | |
275 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
276 } | |
277 { | |
278 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
279 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); | |
280 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
281 } | |
282 { | |
283 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
284 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); | |
285 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
286 } | |
287 | |
288 keys_status = PaymentHandlerStatus::NOT_FOUND; | |
289 KeysOfPaymentInstruments(&keys, &keys_status); | |
290 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); | |
291 ASSERT_EQ(3U, keys.size()); | |
292 ASSERT_EQ("test_key1", keys[0]); | |
293 ASSERT_EQ("test_key3", keys[1]); | |
294 ASSERT_EQ("test_key2", keys[2]); | |
295 } | |
296 | |
297 } // namespace content | 250 } // namespace content |
OLD | NEW |