| 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" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "url/gurl.h" | 12 #include "url/gurl.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 using ::payments::mojom::PaymentAppManifestError; | |
| 18 using ::payments::mojom::PaymentAppManifestPtr; | |
| 19 using ::payments::mojom::PaymentHandlerStatus; | 17 using ::payments::mojom::PaymentHandlerStatus; |
| 20 using ::payments::mojom::PaymentInstrument; | 18 using ::payments::mojom::PaymentInstrument; |
| 21 using ::payments::mojom::PaymentInstrumentPtr; | 19 using ::payments::mojom::PaymentInstrumentPtr; |
| 22 | 20 |
| 23 const char kServiceWorkerPattern[] = "https://example.com/a"; | 21 const char kServiceWorkerPattern[] = "https://example.com/a"; |
| 24 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; | 22 const char kServiceWorkerScript[] = "https://example.com/a/script.js"; |
| 25 | 23 |
| 26 void SetManifestCallback(bool* called, | |
| 27 PaymentAppManifestError* out_error, | |
| 28 PaymentAppManifestError error) { | |
| 29 *called = true; | |
| 30 *out_error = error; | |
| 31 } | |
| 32 | |
| 33 void GetManifestCallback(bool* called, | |
| 34 PaymentAppManifestPtr* out_manifest, | |
| 35 PaymentAppManifestError* out_error, | |
| 36 PaymentAppManifestPtr manifest, | |
| 37 PaymentAppManifestError error) { | |
| 38 *called = true; | |
| 39 *out_manifest = std::move(manifest); | |
| 40 *out_error = error; | |
| 41 } | |
| 42 | |
| 43 void DeletePaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 24 void DeletePaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
| 44 PaymentHandlerStatus status) { | 25 PaymentHandlerStatus status) { |
| 45 *out_status = status; | 26 *out_status = status; |
| 46 } | 27 } |
| 47 | 28 |
| 48 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, | 29 void SetPaymentInstrumentCallback(PaymentHandlerStatus* out_status, |
| 49 PaymentHandlerStatus status) { | 30 PaymentHandlerStatus status) { |
| 50 *out_status = status; | 31 *out_status = status; |
| 51 } | 32 } |
| 52 | 33 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 base::RunLoop().RunUntilIdle(); | 115 base::RunLoop().RunUntilIdle(); |
| 135 } | 116 } |
| 136 | 117 |
| 137 private: | 118 private: |
| 138 // Owned by payment_app_context_. | 119 // Owned by payment_app_context_. |
| 139 PaymentManager* manager_; | 120 PaymentManager* manager_; |
| 140 | 121 |
| 141 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); | 122 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
| 142 }; | 123 }; |
| 143 | 124 |
| 144 TEST_F(PaymentManagerTest, SetAndGetManifest) { | |
| 145 bool called = false; | |
| 146 PaymentAppManifestError error = | |
| 147 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | |
| 148 SetManifest(payment_manager(), | |
| 149 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | |
| 150 base::Bind(&SetManifestCallback, &called, &error)); | |
| 151 ASSERT_TRUE(called); | |
| 152 | |
| 153 ASSERT_EQ(PaymentAppManifestError::NONE, error); | |
| 154 | |
| 155 called = false; | |
| 156 PaymentAppManifestPtr read_manifest; | |
| 157 PaymentAppManifestError read_error = | |
| 158 PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED; | |
| 159 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, | |
| 160 &read_manifest, &read_error)); | |
| 161 ASSERT_TRUE(called); | |
| 162 | |
| 163 ASSERT_EQ(payments::mojom::PaymentAppManifestError::NONE, read_error); | |
| 164 EXPECT_EQ("payment-app-icon", read_manifest->icon.value()); | |
| 165 EXPECT_EQ(kServiceWorkerPattern, read_manifest->name); | |
| 166 ASSERT_EQ(1U, read_manifest->options.size()); | |
| 167 EXPECT_EQ("payment-app-icon", read_manifest->options[0]->icon.value()); | |
| 168 EXPECT_EQ("Visa ****", read_manifest->options[0]->name); | |
| 169 EXPECT_EQ("payment-app-id", read_manifest->options[0]->id); | |
| 170 ASSERT_EQ(1U, read_manifest->options[0]->enabled_methods.size()); | |
| 171 EXPECT_EQ("visa", read_manifest->options[0]->enabled_methods[0]); | |
| 172 } | |
| 173 | |
| 174 TEST_F(PaymentManagerTest, SetManifestWithoutAssociatedServiceWorker) { | |
| 175 bool called = false; | |
| 176 PaymentAppManifestError error = PaymentAppManifestError::NONE; | |
| 177 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); | |
| 178 SetManifest(payment_manager(), | |
| 179 CreatePaymentAppManifestForTest(kServiceWorkerPattern), | |
| 180 base::Bind(&SetManifestCallback, &called, &error)); | |
| 181 ASSERT_TRUE(called); | |
| 182 | |
| 183 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, error); | |
| 184 } | |
| 185 | |
| 186 TEST_F(PaymentManagerTest, GetManifestWithoutAssociatedServiceWorker) { | |
| 187 bool called = false; | |
| 188 PaymentAppManifestPtr read_manifest; | |
| 189 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | |
| 190 UnregisterServiceWorker(GURL(kServiceWorkerPattern)); | |
| 191 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, | |
| 192 &read_manifest, &read_error)); | |
| 193 ASSERT_TRUE(called); | |
| 194 | |
| 195 EXPECT_EQ(PaymentAppManifestError::NO_ACTIVE_WORKER, read_error); | |
| 196 } | |
| 197 | |
| 198 TEST_F(PaymentManagerTest, GetManifestWithNoSavedManifest) { | |
| 199 bool called = false; | |
| 200 PaymentAppManifestPtr read_manifest; | |
| 201 PaymentAppManifestError read_error = PaymentAppManifestError::NONE; | |
| 202 GetManifest(payment_manager(), base::Bind(&GetManifestCallback, &called, | |
| 203 &read_manifest, &read_error)); | |
| 204 ASSERT_TRUE(called); | |
| 205 | |
| 206 EXPECT_EQ(PaymentAppManifestError::MANIFEST_STORAGE_OPERATION_FAILED, | |
| 207 read_error); | |
| 208 } | |
| 209 | |
| 210 TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { | 125 TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { |
| 211 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 126 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 212 PaymentInstrumentPtr write_details = PaymentInstrument::New(); | 127 PaymentInstrumentPtr write_details = PaymentInstrument::New(); |
| 213 write_details->name = "Visa ending ****4756", | 128 write_details->name = "Visa ending ****4756", |
| 214 write_details->enabled_methods.push_back("visa"); | 129 write_details->enabled_methods.push_back("visa"); |
| 215 write_details->stringified_capabilities = "{}"; | 130 write_details->stringified_capabilities = "{}"; |
| 216 SetPaymentInstrument("test_key", std::move(write_details), &write_status); | 131 SetPaymentInstrument("test_key", std::move(write_details), &write_status); |
| 217 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 132 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 218 | 133 |
| 219 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; | 134 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 ClearPaymentInstruments(&status); | 252 ClearPaymentInstruments(&status); |
| 338 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 253 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 339 | 254 |
| 340 status = PaymentHandlerStatus::NOT_FOUND; | 255 status = PaymentHandlerStatus::NOT_FOUND; |
| 341 KeysOfPaymentInstruments(&keys, &status); | 256 KeysOfPaymentInstruments(&keys, &status); |
| 342 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 257 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 343 ASSERT_EQ(0U, keys.size()); | 258 ASSERT_EQ(0U, keys.size()); |
| 344 } | 259 } |
| 345 | 260 |
| 346 } // namespace content | 261 } // namespace content |
| OLD | NEW |