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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 } | 64 } |
65 | 65 |
66 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, | 66 void GetPaymentInstrumentCallback(PaymentInstrumentPtr* out_instrument, |
67 PaymentHandlerStatus* out_status, | 67 PaymentHandlerStatus* out_status, |
68 PaymentInstrumentPtr instrument, | 68 PaymentInstrumentPtr instrument, |
69 PaymentHandlerStatus status) { | 69 PaymentHandlerStatus status) { |
70 *out_instrument = std::move(instrument); | 70 *out_instrument = std::move(instrument); |
71 *out_status = status; | 71 *out_status = status; |
72 } | 72 } |
73 | 73 |
| 74 void ClearPaymentInstrumentsCallback(PaymentHandlerStatus* out_status, |
| 75 PaymentHandlerStatus status) { |
| 76 *out_status = status; |
| 77 } |
| 78 |
74 } // namespace | 79 } // namespace |
75 | 80 |
76 class PaymentManagerTest : public PaymentAppContentUnitTestBase { | 81 class PaymentManagerTest : public PaymentAppContentUnitTestBase { |
77 public: | 82 public: |
78 PaymentManagerTest() { | 83 PaymentManagerTest() { |
79 manager_ = CreatePaymentManager(GURL(kServiceWorkerPattern), | 84 manager_ = CreatePaymentManager(GURL(kServiceWorkerPattern), |
80 GURL(kServiceWorkerScript)); | 85 GURL(kServiceWorkerScript)); |
81 EXPECT_NE(nullptr, manager_); | 86 EXPECT_NE(nullptr, manager_); |
82 } | 87 } |
83 | 88 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 121 |
117 void GetPaymentInstrument(const std::string& instrument_key, | 122 void GetPaymentInstrument(const std::string& instrument_key, |
118 PaymentInstrumentPtr* out_instrument, | 123 PaymentInstrumentPtr* out_instrument, |
119 PaymentHandlerStatus* out_status) { | 124 PaymentHandlerStatus* out_status) { |
120 manager_->GetPaymentInstrument( | 125 manager_->GetPaymentInstrument( |
121 instrument_key, | 126 instrument_key, |
122 base::Bind(&GetPaymentInstrumentCallback, out_instrument, out_status)); | 127 base::Bind(&GetPaymentInstrumentCallback, out_instrument, out_status)); |
123 base::RunLoop().RunUntilIdle(); | 128 base::RunLoop().RunUntilIdle(); |
124 } | 129 } |
125 | 130 |
| 131 void ClearPaymentInstruments(PaymentHandlerStatus* out_status) { |
| 132 manager_->ClearPaymentInstruments( |
| 133 base::Bind(&ClearPaymentInstrumentsCallback, out_status)); |
| 134 base::RunLoop().RunUntilIdle(); |
| 135 } |
| 136 |
126 private: | 137 private: |
127 // Owned by payment_app_context_. | 138 // Owned by payment_app_context_. |
128 PaymentManager* manager_; | 139 PaymentManager* manager_; |
129 | 140 |
130 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); | 141 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
131 }; | 142 }; |
132 | 143 |
133 TEST_F(PaymentManagerTest, SetAndGetManifest) { | 144 TEST_F(PaymentManagerTest, SetAndGetManifest) { |
134 bool called = false; | 145 bool called = false; |
135 PaymentAppManifestError error = | 146 PaymentAppManifestError error = |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 | 298 |
288 keys_status = PaymentHandlerStatus::NOT_FOUND; | 299 keys_status = PaymentHandlerStatus::NOT_FOUND; |
289 KeysOfPaymentInstruments(&keys, &keys_status); | 300 KeysOfPaymentInstruments(&keys, &keys_status); |
290 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); | 301 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); |
291 ASSERT_EQ(3U, keys.size()); | 302 ASSERT_EQ(3U, keys.size()); |
292 ASSERT_EQ("test_key1", keys[0]); | 303 ASSERT_EQ("test_key1", keys[0]); |
293 ASSERT_EQ("test_key3", keys[1]); | 304 ASSERT_EQ("test_key3", keys[1]); |
294 ASSERT_EQ("test_key2", keys[2]); | 305 ASSERT_EQ("test_key2", keys[2]); |
295 } | 306 } |
296 | 307 |
| 308 TEST_F(PaymentManagerTest, ClearPaymentInstruments) { |
| 309 PaymentHandlerStatus status = PaymentHandlerStatus::NOT_FOUND; |
| 310 std::vector<std::string> keys; |
| 311 KeysOfPaymentInstruments(&keys, &status); |
| 312 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 313 ASSERT_EQ(0U, keys.size()); |
| 314 |
| 315 { |
| 316 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 317 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); |
| 318 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 319 } |
| 320 { |
| 321 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 322 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); |
| 323 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 324 } |
| 325 { |
| 326 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 327 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); |
| 328 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 329 } |
| 330 |
| 331 status = PaymentHandlerStatus::NOT_FOUND; |
| 332 KeysOfPaymentInstruments(&keys, &status); |
| 333 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 334 ASSERT_EQ(3U, keys.size()); |
| 335 |
| 336 status = PaymentHandlerStatus::NOT_FOUND; |
| 337 ClearPaymentInstruments(&status); |
| 338 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 339 |
| 340 status = PaymentHandlerStatus::NOT_FOUND; |
| 341 KeysOfPaymentInstruments(&keys, &status); |
| 342 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 343 ASSERT_EQ(0U, keys.size()); |
| 344 } |
| 345 |
297 } // namespace content | 346 } // namespace content |
OLD | NEW |