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 |
53 void HasPaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 61 void HasPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
54 PaymentHandlerStatus status) { | 62 PaymentHandlerStatus status) { |
55 *out_status = status; | 63 *out_status = status; |
56 } | 64 } |
57 | 65 |
58 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, | 66 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, |
59 PaymentHandlerStatus* out_status, | 67 PaymentHandlerStatus* out_status, |
60 PaymentInstrumentPtr instrument, | 68 PaymentInstrumentPtr instrument, |
61 PaymentHandlerStatus status) { | 69 PaymentHandlerStatus status) { |
62 *out_instrument = std::move(instrument); | 70 *out_instrument = std::move(instrument); |
(...skipping 22 matching lines...) Expand all Loading... |
85 | 93 |
86 void SetPaymentInstrument(const std::string& instrument_key, | 94 void SetPaymentInstrument(const std::string& instrument_key, |
87 PaymentInstrumentPtr instrument, | 95 PaymentInstrumentPtr instrument, |
88 PaymentHandlerStatus* out_status) { | 96 PaymentHandlerStatus* out_status) { |
89 manager_->SetPaymentInstrument( | 97 manager_->SetPaymentInstrument( |
90 instrument_key, std::move(instrument), | 98 instrument_key, std::move(instrument), |
91 base::Bind(&SetPaymentInstrumentCallback, out_status)); | 99 base::Bind(&SetPaymentInstrumentCallback, out_status)); |
92 base::RunLoop().RunUntilIdle(); | 100 base::RunLoop().RunUntilIdle(); |
93 } | 101 } |
94 | 102 |
| 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 |
95 void HasPaymentInstrument(const std::string& instrument_key, | 110 void HasPaymentInstrument(const std::string& instrument_key, |
96 PaymentHandlerStatus* out_status) { | 111 PaymentHandlerStatus* out_status) { |
97 manager_->HasPaymentInstrument( | 112 manager_->HasPaymentInstrument( |
98 instrument_key, base::Bind(&HasPaymentInstrumentCallback, out_status)); | 113 instrument_key, base::Bind(&HasPaymentInstrumentCallback, out_status)); |
99 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
100 } | 115 } |
101 | 116 |
102 void GetPaymentInstrument(const std::string& instrument_key, | 117 void GetPaymentInstrument(const std::string& instrument_key, |
103 PaymentInstrumentPtr* out_instrument, | 118 PaymentInstrumentPtr* out_instrument, |
104 PaymentHandlerStatus* out_status) { | 119 PaymentHandlerStatus* out_status) { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 255 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
241 | 256 |
242 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; | 257 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; |
243 HasPaymentInstrument("test_key", &has_status); | 258 HasPaymentInstrument("test_key", &has_status); |
244 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); | 259 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); |
245 | 260 |
246 HasPaymentInstrument("unstored_test_key", &has_status); | 261 HasPaymentInstrument("unstored_test_key", &has_status); |
247 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); | 262 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); |
248 } | 263 } |
249 | 264 |
| 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 |
250 } // namespace content | 297 } // namespace content |
OLD | NEW |