| 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 "content/browser/payments/payment_app_content_unittest_base.h" | 9 #include "content/browser/payments/payment_app_content_unittest_base.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); | 122 DISALLOW_COPY_AND_ASSIGN(PaymentManagerTest); |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { | 125 TEST_F(PaymentManagerTest, SetAndGetPaymentInstrument) { |
| 126 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 126 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 127 PaymentInstrumentPtr write_details = PaymentInstrument::New(); | 127 PaymentInstrumentPtr write_details = PaymentInstrument::New(); |
| 128 write_details->name = "Visa ending ****4756", | 128 write_details->name = "Visa ending ****4756", |
| 129 write_details->enabled_methods.push_back("visa"); | 129 write_details->enabled_methods.push_back("visa"); |
| 130 write_details->stringified_capabilities = "{}"; | 130 write_details->stringified_capabilities = "{}"; |
| 131 SetPaymentInstrument("test_key", std::move(write_details), &write_status); | 131 SetPaymentInstrument("test_key", std::move(write_details), &write_status); |
| 132 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 132 // Write the first instrument of a web payment app will return |
| 133 // FETCH_PAYMENT_APP_INFO_FAILED since the web app's manifest is not |
| 134 // available, but the write of the instrument is succeed, othewise will return |
| 135 // the other errors. |
| 136 ASSERT_EQ(PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED, write_status); |
| 133 | 137 |
| 134 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; | 138 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; |
| 135 PaymentInstrumentPtr read_details; | 139 PaymentInstrumentPtr read_details; |
| 136 GetPaymentInstrument("test_key", &read_details, &read_status); | 140 GetPaymentInstrument("test_key", &read_details, &read_status); |
| 137 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); | 141 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); |
| 138 EXPECT_EQ("Visa ending ****4756", read_details->name); | 142 EXPECT_EQ("Visa ending ****4756", read_details->name); |
| 139 ASSERT_EQ(1U, read_details->enabled_methods.size()); | 143 ASSERT_EQ(1U, read_details->enabled_methods.size()); |
| 140 EXPECT_EQ("visa", read_details->enabled_methods[0]); | 144 EXPECT_EQ("visa", read_details->enabled_methods[0]); |
| 141 EXPECT_EQ("{}", read_details->stringified_capabilities); | 145 EXPECT_EQ("{}", read_details->stringified_capabilities); |
| 142 } | 146 } |
| 143 | 147 |
| 144 TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) { | 148 TEST_F(PaymentManagerTest, GetUnstoredPaymentInstrument) { |
| 145 PaymentHandlerStatus read_status = PaymentHandlerStatus::SUCCESS; | 149 PaymentHandlerStatus read_status = PaymentHandlerStatus::SUCCESS; |
| 146 PaymentInstrumentPtr read_details; | 150 PaymentInstrumentPtr read_details; |
| 147 GetPaymentInstrument("test_key", &read_details, &read_status); | 151 GetPaymentInstrument("test_key", &read_details, &read_status); |
| 148 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); | 152 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); |
| 149 } | 153 } |
| 150 | 154 |
| 151 TEST_F(PaymentManagerTest, DeletePaymentInstrument) { | 155 TEST_F(PaymentManagerTest, DeletePaymentInstrument) { |
| 152 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 156 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 153 PaymentInstrumentPtr write_details = PaymentInstrument::New(); | 157 PaymentInstrumentPtr write_details = PaymentInstrument::New(); |
| 154 write_details->name = "Visa ending ****4756", | 158 write_details->name = "Visa ending ****4756", |
| 155 write_details->enabled_methods.push_back("visa"); | 159 write_details->enabled_methods.push_back("visa"); |
| 156 write_details->stringified_capabilities = "{}"; | 160 write_details->stringified_capabilities = "{}"; |
| 157 SetPaymentInstrument("test_key", std::move(write_details), &write_status); | 161 SetPaymentInstrument("test_key", std::move(write_details), &write_status); |
| 158 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 162 // Write the first instrument of a web payment app will return |
| 163 // FETCH_PAYMENT_APP_INFO_FAILED since the web app's manifest is not |
| 164 // available, but the write of the instrument is succeed, othewise will return |
| 165 // the other errors. |
| 166 ASSERT_EQ(PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED, write_status); |
| 159 | 167 |
| 160 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; | 168 PaymentHandlerStatus read_status = PaymentHandlerStatus::NOT_FOUND; |
| 161 PaymentInstrumentPtr read_details; | 169 PaymentInstrumentPtr read_details; |
| 162 GetPaymentInstrument("test_key", &read_details, &read_status); | 170 GetPaymentInstrument("test_key", &read_details, &read_status); |
| 163 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); | 171 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, read_status); |
| 164 | 172 |
| 165 PaymentHandlerStatus delete_status = PaymentHandlerStatus::NOT_FOUND; | 173 PaymentHandlerStatus delete_status = PaymentHandlerStatus::NOT_FOUND; |
| 166 DeletePaymentInstrument("test_key", &delete_status); | 174 DeletePaymentInstrument("test_key", &delete_status); |
| 167 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, delete_status); | 175 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, delete_status); |
| 168 | 176 |
| 169 read_status = PaymentHandlerStatus::NOT_FOUND; | 177 read_status = PaymentHandlerStatus::NOT_FOUND; |
| 170 GetPaymentInstrument("test_key", &read_details, &read_status); | 178 GetPaymentInstrument("test_key", &read_details, &read_status); |
| 171 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); | 179 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, read_status); |
| 172 } | 180 } |
| 173 | 181 |
| 174 TEST_F(PaymentManagerTest, HasPaymentInstrument) { | 182 TEST_F(PaymentManagerTest, HasPaymentInstrument) { |
| 175 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 183 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 176 PaymentInstrumentPtr write_details = PaymentInstrument::New(); | 184 PaymentInstrumentPtr write_details = PaymentInstrument::New(); |
| 177 write_details->name = "Visa ending ****4756", | 185 write_details->name = "Visa ending ****4756", |
| 178 write_details->enabled_methods.push_back("visa"); | 186 write_details->enabled_methods.push_back("visa"); |
| 179 write_details->stringified_capabilities = "{}"; | 187 write_details->stringified_capabilities = "{}"; |
| 180 SetPaymentInstrument("test_key", std::move(write_details), &write_status); | 188 SetPaymentInstrument("test_key", std::move(write_details), &write_status); |
| 181 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 189 // Write the first instrument of a web payment app will return |
| 190 // FETCH_PAYMENT_APP_INFO_FAILED since the web app's manifest is not |
| 191 // available, but the write of the instrument is succeed, othewise will return |
| 192 // the other errors. |
| 193 ASSERT_EQ(PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED, write_status); |
| 182 | 194 |
| 183 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; | 195 PaymentHandlerStatus has_status = PaymentHandlerStatus::NOT_FOUND; |
| 184 HasPaymentInstrument("test_key", &has_status); | 196 HasPaymentInstrument("test_key", &has_status); |
| 185 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); | 197 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, has_status); |
| 186 | 198 |
| 187 HasPaymentInstrument("unstored_test_key", &has_status); | 199 HasPaymentInstrument("unstored_test_key", &has_status); |
| 188 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); | 200 ASSERT_EQ(PaymentHandlerStatus::NOT_FOUND, has_status); |
| 189 } | 201 } |
| 190 | 202 |
| 191 TEST_F(PaymentManagerTest, KeysOfPaymentInstruments) { | 203 TEST_F(PaymentManagerTest, KeysOfPaymentInstruments) { |
| 192 PaymentHandlerStatus keys_status = PaymentHandlerStatus::NOT_FOUND; | 204 PaymentHandlerStatus keys_status = PaymentHandlerStatus::NOT_FOUND; |
| 193 std::vector<std::string> keys; | 205 std::vector<std::string> keys; |
| 194 KeysOfPaymentInstruments(&keys, &keys_status); | 206 KeysOfPaymentInstruments(&keys, &keys_status); |
| 195 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); | 207 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, keys_status); |
| 196 ASSERT_EQ(0U, keys.size()); | 208 ASSERT_EQ(0U, keys.size()); |
| 197 | 209 |
| 198 { | 210 { |
| 199 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 211 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 200 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); | 212 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); |
| 201 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 213 // Write the first instrument of a web payment app will return |
| 214 // FETCH_PAYMENT_APP_INFO_FAILED since the web app's manifest is not |
| 215 // available, but the write of the instrument is succeed, othewise will |
| 216 // return the other errors. |
| 217 ASSERT_EQ(PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED, |
| 218 write_status); |
| 202 } | 219 } |
| 203 { | 220 { |
| 204 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 221 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 205 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); | 222 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); |
| 206 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 223 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 207 } | 224 } |
| 208 { | 225 { |
| 209 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 226 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 210 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); | 227 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); |
| 211 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 228 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 223 TEST_F(PaymentManagerTest, ClearPaymentInstruments) { | 240 TEST_F(PaymentManagerTest, ClearPaymentInstruments) { |
| 224 PaymentHandlerStatus status = PaymentHandlerStatus::NOT_FOUND; | 241 PaymentHandlerStatus status = PaymentHandlerStatus::NOT_FOUND; |
| 225 std::vector<std::string> keys; | 242 std::vector<std::string> keys; |
| 226 KeysOfPaymentInstruments(&keys, &status); | 243 KeysOfPaymentInstruments(&keys, &status); |
| 227 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 244 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 228 ASSERT_EQ(0U, keys.size()); | 245 ASSERT_EQ(0U, keys.size()); |
| 229 | 246 |
| 230 { | 247 { |
| 231 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 248 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 232 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); | 249 SetPaymentInstrument("test_key1", PaymentInstrument::New(), &write_status); |
| 233 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 250 // Write the first instrument of a web payment app will return |
| 251 // FETCH_PAYMENT_APP_INFO_FAILED since the web app's manifest is not |
| 252 // available, but the write of the instrument is succeed, othewise will |
| 253 // return the other errors. |
| 254 ASSERT_EQ(PaymentHandlerStatus::FETCH_PAYMENT_APP_INFO_FAILED, |
| 255 write_status); |
| 234 } | 256 } |
| 235 { | 257 { |
| 236 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 258 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 237 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); | 259 SetPaymentInstrument("test_key3", PaymentInstrument::New(), &write_status); |
| 238 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 260 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 239 } | 261 } |
| 240 { | 262 { |
| 241 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; | 263 PaymentHandlerStatus write_status = PaymentHandlerStatus::NOT_FOUND; |
| 242 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); | 264 SetPaymentInstrument("test_key2", PaymentInstrument::New(), &write_status); |
| 243 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); | 265 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, write_status); |
| 244 } | 266 } |
| 245 | 267 |
| 246 status = PaymentHandlerStatus::NOT_FOUND; | 268 status = PaymentHandlerStatus::NOT_FOUND; |
| 247 KeysOfPaymentInstruments(&keys, &status); | 269 KeysOfPaymentInstruments(&keys, &status); |
| 248 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 270 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 249 ASSERT_EQ(3U, keys.size()); | 271 ASSERT_EQ(3U, keys.size()); |
| 250 | 272 |
| 251 status = PaymentHandlerStatus::NOT_FOUND; | 273 status = PaymentHandlerStatus::NOT_FOUND; |
| 252 ClearPaymentInstruments(&status); | 274 ClearPaymentInstruments(&status); |
| 253 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 275 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 254 | 276 |
| 255 status = PaymentHandlerStatus::NOT_FOUND; | 277 status = PaymentHandlerStatus::NOT_FOUND; |
| 256 KeysOfPaymentInstruments(&keys, &status); | 278 KeysOfPaymentInstruments(&keys, &status); |
| 257 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); | 279 ASSERT_EQ(PaymentHandlerStatus::SUCCESS, status); |
| 258 ASSERT_EQ(0U, keys.size()); | 280 ASSERT_EQ(0U, keys.size()); |
| 259 } | 281 } |
| 260 | 282 |
| 261 } // namespace content | 283 } // namespace content |
| OLD | NEW |