Chromium Code Reviews| 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(); | |
|
please use gerrit instead
2017/05/02 20:08:12
Why twice?
zino
2017/05/03 14:50:00
My mistake. :P
Thanks.
| |
| 135 base::RunLoop().RunUntilIdle(); | |
| 136 } | |
| 137 | |
| 126 private: | 138 private: |
| 127 // Owned by payment_app_context_. | 139 // Owned by payment_app_context_. |
| 128 PaymentManager* manager_; | 140 PaymentManager* manager_; |
| 129 | 141 |
| 130 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); | 142 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
| 131 }; | 143 }; |
| 132 | 144 |
| 133 TEST_F(PaymentManagerTest, SetAndGetManifest) { | 145 TEST_F(PaymentManagerTest, SetAndGetManifest) { |
| 134 bool called = false; | 146 bool called = false; |
| 135 PaymentAppManifestError error = | 147 PaymentAppManifestError error = |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 | 299 |
| 288 keys_status = PaymentHandlerStatus::NOT_FOUND; | 300 keys_status = PaymentHandlerStatus::NOT_FOUND; |
| 289 KeysOfPaymentInstruments(&keys, &keys_status); | 301 KeysOfPaymentInstruments(&keys, &keys_status); |
| 290 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); | 302 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); |
| 291 ASSERT_EQ(3U, keys.size()); | 303 ASSERT_EQ(3U, keys.size()); |
| 292 ASSERT_EQ("test_key1", keys[0]); | 304 ASSERT_EQ("test_key1", keys[0]); |
| 293 ASSERT_EQ("test_key3", keys[1]); | 305 ASSERT_EQ("test_key3", keys[1]); |
| 294 ASSERT_EQ("test_key2", keys[2]); | 306 ASSERT_EQ("test_key2", keys[2]); |
| 295 } | 307 } |
| 296 | 308 |
| 309 TEST_F(PaymentManagerTest, ClearPaymentInstruments) { | |
| 310 PaymentHandlerStatus status = PaymentHandlerStatus::NOT_FOUND; | |
| 311 std::vector<std::string> keys; | |
| 312 KeysOfPaymentInstruments(&keys, &status); | |
| 313 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | |
| 314 ASSERT_EQ(0U, keys.size()); | |
| 315 | |
| 316 { | |
| 317 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
| 318 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); | |
| 319 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
| 320 } | |
| 321 { | |
| 322 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
| 323 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); | |
| 324 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
| 325 } | |
| 326 { | |
| 327 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | |
| 328 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); | |
| 329 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | |
| 330 } | |
| 331 | |
| 332 status = PaymentHandlerStatus::NOT_FOUND; | |
| 333 KeysOfPaymentInstruments(&keys, &status); | |
| 334 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | |
| 335 ASSERT_EQ(3U, keys.size()); | |
| 336 | |
| 337 status = PaymentHandlerStatus::NOT_FOUND; | |
| 338 ClearPaymentInstruments(&status); | |
| 339 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | |
| 340 | |
| 341 status = PaymentHandlerStatus::NOT_FOUND; | |
| 342 KeysOfPaymentInstruments(&keys, &status); | |
| 343 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | |
| 344 ASSERT_EQ(0U, keys.size()); | |
| 345 } | |
| 346 | |
| 297 } // namespace content | 347 } // namespace content |
| OLD | NEW |