| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/json/json_reader.h" | |
| 6 #include "base/json/json_writer.h" | |
| 7 #include "base/logging.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/strings/string_split.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/strings/stringprintf.h" | |
| 14 #include "base/test/histogram_tester.h" | |
| 15 #include "base/thread_task_runner_handle.h" | |
| 16 #include "base/values.h" | |
| 17 #include "components/autofill/content/browser/wallet/full_wallet.h" | |
| 18 #include "components/autofill/content/browser/wallet/instrument.h" | |
| 19 #include "components/autofill/content/browser/wallet/wallet_client.h" | |
| 20 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" | |
| 21 #include "components/autofill/content/browser/wallet/wallet_items.h" | |
| 22 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | |
| 23 #include "components/autofill/core/browser/autofill_metrics.h" | |
| 24 #include "content/public/test/test_browser_thread_bundle.h" | |
| 25 #include "net/base/escape.h" | |
| 26 #include "net/base/net_errors.h" | |
| 27 #include "net/http/http_request_headers.h" | |
| 28 #include "net/http/http_status_code.h" | |
| 29 #include "net/url_request/test_url_fetcher_factory.h" | |
| 30 #include "net/url_request/url_fetcher_delegate.h" | |
| 31 #include "net/url_request/url_request_status.h" | |
| 32 #include "net/url_request/url_request_test_util.h" | |
| 33 #include "testing/gmock/include/gmock/gmock.h" | |
| 34 #include "testing/gtest/include/gtest/gtest.h" | |
| 35 #include "url/gurl.h" | |
| 36 | |
| 37 namespace autofill { | |
| 38 namespace wallet { | |
| 39 | |
| 40 namespace { | |
| 41 | |
| 42 const char kGoogleTransactionId[] = "google-transaction-id"; | |
| 43 const char kMerchantUrl[] = "https://example.com/path?key=value"; | |
| 44 | |
| 45 const char kGetFullWalletValidResponse[] = | |
| 46 "{" | |
| 47 " \"expiration_month\":12," | |
| 48 " \"expiration_year\":3000," | |
| 49 " \"iin\":\"iin\"," | |
| 50 " \"rest\":\"rest\"," | |
| 51 " \"billing_address\":" | |
| 52 " {" | |
| 53 " \"id\":\"id\"," | |
| 54 " \"phone_number\":\"phone_number\"," | |
| 55 " \"postal_address\":" | |
| 56 " {" | |
| 57 " \"recipient_name\":\"recipient_name\"," | |
| 58 " \"address_line\":" | |
| 59 " [" | |
| 60 " \"address_line_1\"," | |
| 61 " \"address_line_2\"" | |
| 62 " ]," | |
| 63 " \"locality_name\":\"locality_name\"," | |
| 64 " \"administrative_area_name\":\"administrative_area_name\"," | |
| 65 " \"postal_code_number\":\"postal_code_number\"," | |
| 66 " \"country_name_code\":\"US\"," | |
| 67 " \"language_code\":\"language_code\"" | |
| 68 " }" | |
| 69 " }," | |
| 70 " \"shipping_address\":" | |
| 71 " {" | |
| 72 " \"id\":\"ship_id\"," | |
| 73 " \"phone_number\":\"ship_phone_number\"," | |
| 74 " \"postal_address\":" | |
| 75 " {" | |
| 76 " \"recipient_name\":\"ship_recipient_name\"," | |
| 77 " \"address_line\":" | |
| 78 " [" | |
| 79 " \"ship_address_line_1\"," | |
| 80 " \"ship_address_line_2\"" | |
| 81 " ]," | |
| 82 " \"locality_name\":\"ship_locality_name\"," | |
| 83 " \"administrative_area_name\":\"ship_administrative_area_name\"," | |
| 84 " \"postal_code_number\":\"ship_postal_code_number\"," | |
| 85 " \"country_name_code\":\"US\"," | |
| 86 " \"language_code\":\"ship_language_code\"" | |
| 87 " }" | |
| 88 " }," | |
| 89 " \"required_action\":" | |
| 90 " [" | |
| 91 " ]" | |
| 92 "}"; | |
| 93 | |
| 94 const char kGetFullWalletInvalidResponse[] = | |
| 95 "{" | |
| 96 " \"garbage\":123" | |
| 97 "}"; | |
| 98 | |
| 99 const char kGetWalletItemsValidResponse[] = | |
| 100 "{" | |
| 101 " \"required_action\":" | |
| 102 " [" | |
| 103 " ]," | |
| 104 " \"google_transaction_id\":\"google_transaction_id\"," | |
| 105 " \"instrument\":" | |
| 106 " [" | |
| 107 " {" | |
| 108 " \"descriptive_name\":\"descriptive_name\"," | |
| 109 " \"type\":\"VISA\"," | |
| 110 " \"last_four_digits\":\"4111\"," | |
| 111 " \"expiration_month\":12," | |
| 112 " \"expiration_year\":3000," | |
| 113 " \"brand\":\"monkeys\"," | |
| 114 " \"billing_address\":" | |
| 115 " {" | |
| 116 " \"name\":\"name\"," | |
| 117 " \"address1\":\"address1\"," | |
| 118 " \"address2\":\"address2\"," | |
| 119 " \"city\":\"city\"," | |
| 120 " \"state\":\"state\"," | |
| 121 " \"postal_code\":\"postal_code\"," | |
| 122 " \"phone_number\":\"phone_number\"," | |
| 123 " \"country_code\":\"US\"," | |
| 124 " \"language_code\":\"language_code\"" | |
| 125 " }," | |
| 126 " \"status\":\"VALID\"," | |
| 127 " \"object_id\":\"default_instrument_id\"" | |
| 128 " }" | |
| 129 " ]," | |
| 130 " \"default_instrument_id\":\"default_instrument_id\"," | |
| 131 " \"obfuscated_gaia_id\":\"obfuscated_gaia_id\"," | |
| 132 " \"address\":" | |
| 133 " [" | |
| 134 " ]," | |
| 135 " \"default_address_id\":\"default_address_id\"," | |
| 136 " \"required_legal_document\":" | |
| 137 " [" | |
| 138 " ]" | |
| 139 "}"; | |
| 140 | |
| 141 const char kSaveAddressValidResponse[] = | |
| 142 "{" | |
| 143 " \"shipping_address_id\":\"saved_address_id\"" | |
| 144 "}"; | |
| 145 | |
| 146 const char kSaveAddressWithRequiredActionsValidResponse[] = | |
| 147 "{" | |
| 148 " \"form_field_error\":" | |
| 149 " [" | |
| 150 " {" | |
| 151 " \"location\":\"SHIPPING_ADDRESS\"," | |
| 152 " \"type\":\"INVALID_POSTAL_CODE\"" | |
| 153 " }" | |
| 154 " ]," | |
| 155 " \"required_action\":" | |
| 156 " [" | |
| 157 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 158 " \"INVALID_form_field\"" | |
| 159 " ]" | |
| 160 "}"; | |
| 161 | |
| 162 const char kSaveWithInvalidRequiredActionsResponse[] = | |
| 163 "{" | |
| 164 " \"required_action\":" | |
| 165 " [" | |
| 166 " \" setup_wallet\"," | |
| 167 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 168 " \"INVALID_form_field\"" | |
| 169 " ]" | |
| 170 "}"; | |
| 171 | |
| 172 const char kSaveInvalidResponse[] = | |
| 173 "{" | |
| 174 " \"garbage\":123" | |
| 175 "}"; | |
| 176 | |
| 177 const char kSaveInstrumentValidResponse[] = | |
| 178 "{" | |
| 179 " \"instrument_id\":\"instrument_id\"" | |
| 180 "}"; | |
| 181 | |
| 182 const char kSaveInstrumentWithRequiredActionsValidResponse[] = | |
| 183 "{" | |
| 184 " \"form_field_error\":" | |
| 185 " [" | |
| 186 " {" | |
| 187 " \"location\":\"SHIPPING_ADDRESS\"," | |
| 188 " \"type\":\"INVALID_POSTAL_CODE\"" | |
| 189 " }" | |
| 190 " ]," | |
| 191 " \"required_action\":" | |
| 192 " [" | |
| 193 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 194 " \"INVALID_form_field\"" | |
| 195 " ]" | |
| 196 "}"; | |
| 197 | |
| 198 const char kSaveInstrumentAndAddressValidResponse[] = | |
| 199 "{" | |
| 200 " \"shipping_address_id\":\"saved_address_id\"," | |
| 201 " \"instrument_id\":\"saved_instrument_id\"" | |
| 202 "}"; | |
| 203 | |
| 204 const char kSaveInstrumentAndAddressWithRequiredActionsValidResponse[] = | |
| 205 "{" | |
| 206 " \"form_field_error\":" | |
| 207 " [" | |
| 208 " {" | |
| 209 " \"location\":\"SHIPPING_ADDRESS\"," | |
| 210 " \"type\":\"INVALID_POSTAL_CODE\"" | |
| 211 " }" | |
| 212 " ]," | |
| 213 " \"required_action\":" | |
| 214 " [" | |
| 215 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 216 " \"INVALID_form_field\"" | |
| 217 " ]" | |
| 218 "}"; | |
| 219 | |
| 220 const char kUpdateInstrumentValidResponse[] = | |
| 221 "{" | |
| 222 " \"instrument_id\":\"instrument_id\"" | |
| 223 "}"; | |
| 224 | |
| 225 const char kUpdateAddressValidResponse[] = | |
| 226 "{" | |
| 227 " \"shipping_address_id\":\"shipping_address_id\"" | |
| 228 "}"; | |
| 229 | |
| 230 const char kUpdateWithRequiredActionsValidResponse[] = | |
| 231 "{" | |
| 232 " \"form_field_error\":" | |
| 233 " [" | |
| 234 " {" | |
| 235 " \"location\":\"SHIPPING_ADDRESS\"," | |
| 236 " \"type\":\"INVALID_POSTAL_CODE\"" | |
| 237 " }" | |
| 238 " ]," | |
| 239 " \"required_action\":" | |
| 240 " [" | |
| 241 " \" \\treqUIRE_PhOnE_number \\n\\r\"," | |
| 242 " \"INVALID_form_field\"" | |
| 243 " ]" | |
| 244 "}"; | |
| 245 | |
| 246 const char kUpdateMalformedResponse[] = | |
| 247 "{" | |
| 248 " \"cheese\":\"monkeys\"" | |
| 249 "}"; | |
| 250 | |
| 251 const char kAuthenticateInstrumentFailureResponse[] = | |
| 252 "{" | |
| 253 " \"auth_result\":\"anything else\"" | |
| 254 "}"; | |
| 255 | |
| 256 const char kAuthenticateInstrumentSuccessResponse[] = | |
| 257 "{" | |
| 258 " \"auth_result\":\"SUCCESS\"" | |
| 259 "}"; | |
| 260 | |
| 261 const char kErrorResponse[] = | |
| 262 "{" | |
| 263 " \"error_type\":\"APPLICATION_ERROR\"," | |
| 264 " \"error_detail\":\"error_detail\"," | |
| 265 " \"application_error\":\"application_error\"," | |
| 266 " \"debug_data\":" | |
| 267 " {" | |
| 268 " \"debug_message\":\"debug_message\"," | |
| 269 " \"stack_trace\":\"stack_trace\"" | |
| 270 " }," | |
| 271 " \"application_error_data\":\"application_error_data\"," | |
| 272 " \"wallet_error\":" | |
| 273 " {" | |
| 274 " \"error_type\":\"SERVICE_UNAVAILABLE\"," | |
| 275 " \"error_detail\":\"error_detail\"," | |
| 276 " \"message_for_user\":" | |
| 277 " {" | |
| 278 " \"text\":\"text\"," | |
| 279 " \"subtext\":\"subtext\"," | |
| 280 " \"details\":\"details\"" | |
| 281 " }" | |
| 282 " }" | |
| 283 "}"; | |
| 284 | |
| 285 const char kErrorResponseSpendingLimitExceeded[] = | |
| 286 "{" | |
| 287 " \"error_type\":\"APPLICATION_ERROR\"," | |
| 288 " \"error_detail\":\"error_detail\"," | |
| 289 " \"application_error\":\"application_error\"," | |
| 290 " \"debug_data\":" | |
| 291 " {" | |
| 292 " \"debug_message\":\"debug_message\"," | |
| 293 " \"stack_trace\":\"stack_trace\"" | |
| 294 " }," | |
| 295 " \"application_error_data\":\"application_error_data\"," | |
| 296 " \"wallet_error\":" | |
| 297 " {" | |
| 298 " \"error_type\":\"SPENDING_LIMIT_EXCEEDED\"," | |
| 299 " \"error_detail\":\"error_detail\"," | |
| 300 " \"message_for_user\":" | |
| 301 " {" | |
| 302 " \"text\":\"text\"," | |
| 303 " \"subtext\":\"subtext\"," | |
| 304 " \"details\":\"details\"" | |
| 305 " }" | |
| 306 " }" | |
| 307 "}"; | |
| 308 | |
| 309 const char kErrorTypeMissingInResponse[] = | |
| 310 "{" | |
| 311 " \"error_type\":\"Not APPLICATION_ERROR\"," | |
| 312 " \"error_detail\":\"error_detail\"," | |
| 313 " \"application_error\":\"application_error\"," | |
| 314 " \"debug_data\":" | |
| 315 " {" | |
| 316 " \"debug_message\":\"debug_message\"," | |
| 317 " \"stack_trace\":\"stack_trace\"" | |
| 318 " }," | |
| 319 " \"application_error_data\":\"application_error_data\"" | |
| 320 "}"; | |
| 321 | |
| 322 // The JSON below is used to test against the request payload being sent to | |
| 323 // Online Wallet. It's indented differently since JSONWriter creates compact | |
| 324 // JSON from DictionaryValues. NB: The values must be alphabetical to pass | |
| 325 // the tests. | |
| 326 | |
| 327 const char kAcceptLegalDocumentsValidRequest[] = | |
| 328 "{" | |
| 329 "\"accepted_legal_document\":" | |
| 330 "[" | |
| 331 "\"doc_id_1\"," | |
| 332 "\"doc_id_2\"" | |
| 333 "]," | |
| 334 "\"google_transaction_id\":\"google-transaction-id\"," | |
| 335 "\"merchant_domain\":\"https://example.com/\"" | |
| 336 "}"; | |
| 337 | |
| 338 const char kAuthenticateInstrumentValidRequest[] = | |
| 339 "{" | |
| 340 "\"instrument_id\":\"instrument_id\"," | |
| 341 "\"risk_params\":\"risky business\"" | |
| 342 "}"; | |
| 343 | |
| 344 const char kGetFullWalletValidRequest[] = | |
| 345 "{" | |
| 346 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | |
| 347 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 348 "\"merchant_domain\":\"https://example.com/\"," | |
| 349 "\"new_wallet_user\":false," | |
| 350 "\"phone_number_required\":true," | |
| 351 "\"risk_params\":\"risky business\"," | |
| 352 "\"selected_address_id\":\"shipping_address_id\"," | |
| 353 "\"selected_instrument_id\":\"instrument_id\"," | |
| 354 "\"supported_risk_challenge\":" | |
| 355 "[" | |
| 356 "]," | |
| 357 "\"use_minimal_addresses\":false" | |
| 358 "}"; | |
| 359 | |
| 360 const char kGetFullWalletValidRequestNewUser[] = | |
| 361 "{" | |
| 362 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | |
| 363 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 364 "\"merchant_domain\":\"https://example.com/\"," | |
| 365 "\"new_wallet_user\":true," | |
| 366 "\"phone_number_required\":true," | |
| 367 "\"risk_params\":\"risky business\"," | |
| 368 "\"selected_address_id\":\"shipping_address_id\"," | |
| 369 "\"selected_instrument_id\":\"instrument_id\"," | |
| 370 "\"supported_risk_challenge\":" | |
| 371 "[" | |
| 372 "]," | |
| 373 "\"use_minimal_addresses\":false" | |
| 374 "}"; | |
| 375 | |
| 376 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = | |
| 377 "{" | |
| 378 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | |
| 379 "\"google_transaction_id\":\"google_transaction_id\"," | |
| 380 "\"merchant_domain\":\"https://example.com/\"," | |
| 381 "\"new_wallet_user\":false," | |
| 382 "\"phone_number_required\":true," | |
| 383 "\"risk_params\":\"risky business\"," | |
| 384 "\"selected_address_id\":\"shipping_address_id\"," | |
| 385 "\"selected_instrument_id\":\"instrument_id\"," | |
| 386 "\"supported_risk_challenge\":" | |
| 387 "[" | |
| 388 "\"VERIFY_CVC\"" | |
| 389 "]," | |
| 390 "\"use_minimal_addresses\":false" | |
| 391 "}"; | |
| 392 | |
| 393 const char kGetWalletItemsValidRequest[] = | |
| 394 "{" | |
| 395 "\"merchant_domain\":\"https://example.com/\"," | |
| 396 "\"phone_number_required\":true," | |
| 397 "\"shipping_address_required\":true," | |
| 398 "\"use_minimal_addresses\":false" | |
| 399 "}"; | |
| 400 | |
| 401 const char kGetWalletItemsWithTransactionDetails[] = | |
| 402 "{" | |
| 403 "\"currency_code\":\"USD\"," | |
| 404 "\"estimated_total_price\":\"100.00\"," | |
| 405 "\"merchant_domain\":\"https://example.com/\"," | |
| 406 "\"phone_number_required\":true," | |
| 407 "\"shipping_address_required\":true," | |
| 408 "\"use_minimal_addresses\":false" | |
| 409 "}"; | |
| 410 | |
| 411 const char kGetWalletItemsNoShippingRequest[] = | |
| 412 "{" | |
| 413 "\"merchant_domain\":\"https://example.com/\"," | |
| 414 "\"phone_number_required\":true," | |
| 415 "\"shipping_address_required\":false," | |
| 416 "\"use_minimal_addresses\":false" | |
| 417 "}"; | |
| 418 | |
| 419 const char kSaveAddressValidRequest[] = | |
| 420 "{" | |
| 421 "\"merchant_domain\":\"https://example.com/\"," | |
| 422 "\"phone_number_required\":true," | |
| 423 "\"risk_params\":\"risky business\"," | |
| 424 "\"shipping_address\":" | |
| 425 "{" | |
| 426 "\"phone_number\":\"save_phone_number\"," | |
| 427 "\"postal_address\":" | |
| 428 "{" | |
| 429 "\"address_line\":" | |
| 430 "[" | |
| 431 "\"save_address_line_1\"," | |
| 432 "\"save_address_line_2\"" | |
| 433 "]," | |
| 434 "\"administrative_area_name\":\"save_admin_area_name\"," | |
| 435 "\"country_name_code\":\"US\"," | |
| 436 "\"dependent_locality_name\":\"save_dependent_locality_name\"," | |
| 437 "\"language_code\":\"save_language_code\"," | |
| 438 "\"locality_name\":\"save_locality_name\"," | |
| 439 "\"postal_code_number\":\"save_postal_code_number\"," | |
| 440 "\"recipient_name\":\"save_recipient_name\"," | |
| 441 "\"sorting_code\":\"save_sorting_code\"" | |
| 442 "}" | |
| 443 "}," | |
| 444 "\"use_minimal_addresses\":false" | |
| 445 "}"; | |
| 446 | |
| 447 const char kSaveInstrumentValidRequest[] = | |
| 448 "{" | |
| 449 "\"instrument\":" | |
| 450 "{" | |
| 451 "\"credit_card\":" | |
| 452 "{" | |
| 453 "\"address\":" | |
| 454 "{" | |
| 455 "\"address_line\":" | |
| 456 "[" | |
| 457 "\"address_line_1\"," | |
| 458 "\"address_line_2\"" | |
| 459 "]," | |
| 460 "\"administrative_area_name\":\"admin_area_name\"," | |
| 461 "\"country_name_code\":\"US\"," | |
| 462 "\"dependent_locality_name\":\"dependent_locality_name\"," | |
| 463 "\"language_code\":\"language_code\"," | |
| 464 "\"locality_name\":\"locality_name\"," | |
| 465 "\"postal_code_number\":\"postal_code_number\"," | |
| 466 "\"recipient_name\":\"recipient_name\"," | |
| 467 "\"sorting_code\":\"sorting_code\"" | |
| 468 "}," | |
| 469 "\"exp_month\":12," | |
| 470 "\"exp_year\":3000," | |
| 471 "\"fop_type\":\"VISA\"," | |
| 472 "\"last_4_digits\":\"4448\"" | |
| 473 "}," | |
| 474 "\"type\":\"CREDIT_CARD\"" | |
| 475 "}," | |
| 476 "\"instrument_phone_number\":\"phone_number\"," | |
| 477 "\"merchant_domain\":\"https://example.com/\"," | |
| 478 "\"phone_number_required\":true," | |
| 479 "\"risk_params\":\"risky business\"," | |
| 480 "\"use_minimal_addresses\":false" | |
| 481 "}"; | |
| 482 | |
| 483 const char kSaveInstrumentAndAddressValidRequest[] = | |
| 484 "{" | |
| 485 "\"instrument\":" | |
| 486 "{" | |
| 487 "\"credit_card\":" | |
| 488 "{" | |
| 489 "\"address\":" | |
| 490 "{" | |
| 491 "\"address_line\":" | |
| 492 "[" | |
| 493 "\"address_line_1\"," | |
| 494 "\"address_line_2\"" | |
| 495 "]," | |
| 496 "\"administrative_area_name\":\"admin_area_name\"," | |
| 497 "\"country_name_code\":\"US\"," | |
| 498 "\"dependent_locality_name\":\"dependent_locality_name\"," | |
| 499 "\"language_code\":\"language_code\"," | |
| 500 "\"locality_name\":\"locality_name\"," | |
| 501 "\"postal_code_number\":\"postal_code_number\"," | |
| 502 "\"recipient_name\":\"recipient_name\"," | |
| 503 "\"sorting_code\":\"sorting_code\"" | |
| 504 "}," | |
| 505 "\"exp_month\":12," | |
| 506 "\"exp_year\":3000," | |
| 507 "\"fop_type\":\"VISA\"," | |
| 508 "\"last_4_digits\":\"4448\"" | |
| 509 "}," | |
| 510 "\"type\":\"CREDIT_CARD\"" | |
| 511 "}," | |
| 512 "\"instrument_phone_number\":\"phone_number\"," | |
| 513 "\"merchant_domain\":\"https://example.com/\"," | |
| 514 "\"phone_number_required\":true," | |
| 515 "\"risk_params\":\"risky business\"," | |
| 516 "\"shipping_address\":" | |
| 517 "{" | |
| 518 "\"phone_number\":\"save_phone_number\"," | |
| 519 "\"postal_address\":" | |
| 520 "{" | |
| 521 "\"address_line\":" | |
| 522 "[" | |
| 523 "\"save_address_line_1\"," | |
| 524 "\"save_address_line_2\"" | |
| 525 "]," | |
| 526 "\"administrative_area_name\":\"save_admin_area_name\"," | |
| 527 "\"country_name_code\":\"US\"," | |
| 528 "\"dependent_locality_name\":\"save_dependent_locality_name\"," | |
| 529 "\"language_code\":\"save_language_code\"," | |
| 530 "\"locality_name\":\"save_locality_name\"," | |
| 531 "\"postal_code_number\":\"save_postal_code_number\"," | |
| 532 "\"recipient_name\":\"save_recipient_name\"," | |
| 533 "\"sorting_code\":\"save_sorting_code\"" | |
| 534 "}" | |
| 535 "}," | |
| 536 "\"use_minimal_addresses\":false" | |
| 537 "}"; | |
| 538 | |
| 539 const char kUpdateAddressValidRequest[] = | |
| 540 "{" | |
| 541 "\"merchant_domain\":\"https://example.com/\"," | |
| 542 "\"phone_number_required\":true," | |
| 543 "\"risk_params\":\"risky business\"," | |
| 544 "\"shipping_address\":" | |
| 545 "{" | |
| 546 "\"id\":\"address_id\"," | |
| 547 "\"phone_number\":\"ship_phone_number\"," | |
| 548 "\"postal_address\":" | |
| 549 "{" | |
| 550 "\"address_line\":" | |
| 551 "[" | |
| 552 "\"ship_address_line_1\"," | |
| 553 "\"ship_address_line_2\"" | |
| 554 "]," | |
| 555 "\"administrative_area_name\":\"ship_admin_area_name\"," | |
| 556 "\"country_name_code\":\"US\"," | |
| 557 "\"dependent_locality_name\":\"ship_dependent_locality_name\"," | |
| 558 "\"language_code\":\"ship_language_code\"," | |
| 559 "\"locality_name\":\"ship_locality_name\"," | |
| 560 "\"postal_code_number\":\"ship_postal_code_number\"," | |
| 561 "\"recipient_name\":\"ship_recipient_name\"," | |
| 562 "\"sorting_code\":\"ship_sorting_code\"" | |
| 563 "}" | |
| 564 "}," | |
| 565 "\"use_minimal_addresses\":false" | |
| 566 "}"; | |
| 567 | |
| 568 const char kUpdateInstrumentAddressValidRequest[] = | |
| 569 "{" | |
| 570 "\"instrument_phone_number\":\"phone_number\"," | |
| 571 "\"merchant_domain\":\"https://example.com/\"," | |
| 572 "\"phone_number_required\":true," | |
| 573 "\"risk_params\":\"risky business\"," | |
| 574 "\"upgraded_billing_address\":" | |
| 575 "{" | |
| 576 "\"address_line\":" | |
| 577 "[" | |
| 578 "\"address_line_1\"," | |
| 579 "\"address_line_2\"" | |
| 580 "]," | |
| 581 "\"administrative_area_name\":\"admin_area_name\"," | |
| 582 "\"country_name_code\":\"US\"," | |
| 583 "\"dependent_locality_name\":\"dependent_locality_name\"," | |
| 584 "\"language_code\":\"language_code\"," | |
| 585 "\"locality_name\":\"locality_name\"," | |
| 586 "\"postal_code_number\":\"postal_code_number\"," | |
| 587 "\"recipient_name\":\"recipient_name\"," | |
| 588 "\"sorting_code\":\"sorting_code\"" | |
| 589 "}," | |
| 590 "\"upgraded_instrument_id\":\"default_instrument_id\"," | |
| 591 "\"use_minimal_addresses\":false" | |
| 592 "}"; | |
| 593 | |
| 594 const char kUpdateInstrumentAddressWithNameChangeValidRequest[] = | |
| 595 "{" | |
| 596 "\"instrument_phone_number\":\"phone_number\"," | |
| 597 "\"merchant_domain\":\"https://example.com/\"," | |
| 598 "\"phone_number_required\":true," | |
| 599 "\"risk_params\":\"risky business\"," | |
| 600 "\"upgraded_billing_address\":" | |
| 601 "{" | |
| 602 "\"address_line\":" | |
| 603 "[" | |
| 604 "\"address_line_1\"," | |
| 605 "\"address_line_2\"" | |
| 606 "]," | |
| 607 "\"administrative_area_name\":\"admin_area_name\"," | |
| 608 "\"country_name_code\":\"US\"," | |
| 609 "\"dependent_locality_name\":\"dependent_locality_name\"," | |
| 610 "\"language_code\":\"language_code\"," | |
| 611 "\"locality_name\":\"locality_name\"," | |
| 612 "\"postal_code_number\":\"postal_code_number\"," | |
| 613 "\"recipient_name\":\"recipient_name\"," | |
| 614 "\"sorting_code\":\"sorting_code\"" | |
| 615 "}," | |
| 616 "\"upgraded_instrument_id\":\"default_instrument_id\"," | |
| 617 "\"use_minimal_addresses\":false" | |
| 618 "}"; | |
| 619 | |
| 620 const char kUpdateInstrumentExpirationDateValidRequest[] = | |
| 621 "{" | |
| 622 "\"instrument\":" | |
| 623 "{" | |
| 624 "\"credit_card\":" | |
| 625 "{" | |
| 626 "\"exp_month\":12," | |
| 627 "\"exp_year\":3001" | |
| 628 "}," | |
| 629 "\"type\":\"CREDIT_CARD\"" | |
| 630 "}," | |
| 631 "\"merchant_domain\":\"https://example.com/\"," | |
| 632 "\"phone_number_required\":true," | |
| 633 "\"risk_params\":\"risky business\"," | |
| 634 "\"upgraded_instrument_id\":\"instrument_id\"," | |
| 635 "\"use_minimal_addresses\":false" | |
| 636 "}"; | |
| 637 | |
| 638 void ExpectBaselineMetrics(const base::HistogramTester& histogram) { | |
| 639 histogram.ExpectBucketCount( | |
| 640 "RequestAutocomplete.WalletErrors", | |
| 641 AutofillMetrics::WALLET_ERROR_BASELINE_ISSUED_REQUEST, 1); | |
| 642 histogram.ExpectBucketCount( | |
| 643 "RequestAutocomplete.WalletRequiredActions", | |
| 644 AutofillMetrics::WALLET_REQUIRED_ACTION_BASELINE_ISSUED_REQUEST, 1); | |
| 645 } | |
| 646 | |
| 647 void ExpectCommonWalletRequiredActionMetrics( | |
| 648 const base::HistogramTester& histogram) { | |
| 649 histogram.ExpectBucketCount("RequestAutocomplete.WalletRequiredActions", | |
| 650 AutofillMetrics::REQUIRE_PHONE_NUMBER, 1); | |
| 651 histogram.ExpectBucketCount("RequestAutocomplete.WalletRequiredActions", | |
| 652 AutofillMetrics::INVALID_FORM_FIELD, 1); | |
| 653 } | |
| 654 | |
| 655 class MockWalletClientDelegate : public WalletClientDelegate { | |
| 656 public: | |
| 657 MockWalletClientDelegate() | |
| 658 : full_wallets_received_(0), | |
| 659 wallet_items_received_(0), | |
| 660 is_shipping_required_(true) {} | |
| 661 ~MockWalletClientDelegate() {} | |
| 662 | |
| 663 std::string GetRiskData() const override { | |
| 664 return "risky business"; | |
| 665 } | |
| 666 | |
| 667 std::string GetWalletCookieValue() const override { | |
| 668 return "gdToken"; | |
| 669 } | |
| 670 | |
| 671 bool IsShippingAddressRequired() const override { | |
| 672 return is_shipping_required_; | |
| 673 } | |
| 674 | |
| 675 void SetIsShippingAddressRequired(bool is_shipping_required) { | |
| 676 is_shipping_required_ = is_shipping_required; | |
| 677 } | |
| 678 | |
| 679 MOCK_METHOD0(OnDidAcceptLegalDocuments, void()); | |
| 680 MOCK_METHOD1(OnDidAuthenticateInstrument, void(bool success)); | |
| 681 MOCK_METHOD4(OnDidSaveToWallet, | |
| 682 void(const std::string& instrument_id, | |
| 683 const std::string& shipping_address_id, | |
| 684 const std::vector<RequiredAction>& required_actions, | |
| 685 const std::vector<FormFieldError>& form_field_errors)); | |
| 686 MOCK_METHOD1(OnWalletError, void(WalletClient::ErrorType error_type)); | |
| 687 | |
| 688 void OnDidGetFullWallet(scoped_ptr<FullWallet> full_wallet) override { | |
| 689 EXPECT_TRUE(full_wallet); | |
| 690 ++full_wallets_received_; | |
| 691 } | |
| 692 void OnDidGetWalletItems(scoped_ptr<WalletItems> wallet_items) override { | |
| 693 EXPECT_TRUE(wallet_items); | |
| 694 ++wallet_items_received_; | |
| 695 } | |
| 696 size_t full_wallets_received() const { return full_wallets_received_; } | |
| 697 size_t wallet_items_received() const { return wallet_items_received_; } | |
| 698 | |
| 699 private: | |
| 700 size_t full_wallets_received_; | |
| 701 size_t wallet_items_received_; | |
| 702 bool is_shipping_required_; | |
| 703 }; | |
| 704 | |
| 705 } // namespace | |
| 706 | |
| 707 class WalletClientTest : public testing::Test { | |
| 708 public: | |
| 709 WalletClientTest() | |
| 710 : request_context_(new net::TestURLRequestContextGetter( | |
| 711 base::ThreadTaskRunnerHandle::Get())) {} | |
| 712 ~WalletClientTest() override {} | |
| 713 | |
| 714 void SetUp() override { | |
| 715 wallet_client_.reset(new WalletClient( | |
| 716 request_context_.get(), &delegate_, GURL(kMerchantUrl))); | |
| 717 } | |
| 718 | |
| 719 void TearDown() override { wallet_client_.reset(); } | |
| 720 | |
| 721 void VerifyAndFinishRequest(net::HttpStatusCode response_code, | |
| 722 const std::string& request_body, | |
| 723 const std::string& response_body) { | |
| 724 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | |
| 725 ASSERT_TRUE(fetcher); | |
| 726 | |
| 727 const std::string& upload_data = fetcher->upload_data(); | |
| 728 EXPECT_EQ(request_body, GetData(upload_data)); | |
| 729 net::HttpRequestHeaders request_headers; | |
| 730 fetcher->GetExtraRequestHeaders(&request_headers); | |
| 731 std::string auth_header_value; | |
| 732 EXPECT_TRUE(request_headers.GetHeader( | |
| 733 net::HttpRequestHeaders::kAuthorization, | |
| 734 &auth_header_value)); | |
| 735 EXPECT_EQ("GoogleLogin auth=gdToken", auth_header_value); | |
| 736 | |
| 737 fetcher->set_response_code(response_code); | |
| 738 fetcher->SetResponseString(response_body); | |
| 739 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 740 | |
| 741 // Pump the message loop to catch up to any asynchronous tasks that might | |
| 742 // have been posted from OnURLFetchComplete(). | |
| 743 base::RunLoop().RunUntilIdle(); | |
| 744 } | |
| 745 | |
| 746 void VerifyAndFinishFormEncodedRequest(net::HttpStatusCode response_code, | |
| 747 const std::string& json_payload, | |
| 748 const std::string& response_body, | |
| 749 size_t expected_parameter_number) { | |
| 750 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | |
| 751 ASSERT_TRUE(fetcher); | |
| 752 | |
| 753 net::HttpRequestHeaders request_headers; | |
| 754 fetcher->GetExtraRequestHeaders(&request_headers); | |
| 755 std::string auth_header_value; | |
| 756 EXPECT_TRUE(request_headers.GetHeader( | |
| 757 net::HttpRequestHeaders::kAuthorization, | |
| 758 &auth_header_value)); | |
| 759 EXPECT_EQ("GoogleLogin auth=gdToken", auth_header_value); | |
| 760 | |
| 761 const std::string& upload_data = fetcher->upload_data(); | |
| 762 base::StringPairs tokens; | |
| 763 base::SplitStringIntoKeyValuePairs(upload_data, '=', '&', &tokens); | |
| 764 EXPECT_EQ(tokens.size(), expected_parameter_number); | |
| 765 | |
| 766 size_t num_params = 0U; | |
| 767 for (base::StringPairs::const_iterator iter = tokens.begin(); | |
| 768 iter != tokens.end(); | |
| 769 ++iter) { | |
| 770 const std::string& key = iter->first; | |
| 771 const std::string& value = iter->second; | |
| 772 | |
| 773 if (key == "request_content_type") { | |
| 774 EXPECT_EQ("application/json", value); | |
| 775 num_params++; | |
| 776 } | |
| 777 | |
| 778 if (key == "request") { | |
| 779 EXPECT_EQ(json_payload, | |
| 780 GetData( | |
| 781 net::UnescapeURLComponent( | |
| 782 value, net::UnescapeRule::URL_SPECIAL_CHARS | | |
| 783 net::UnescapeRule::REPLACE_PLUS_WITH_SPACE))); | |
| 784 num_params++; | |
| 785 } | |
| 786 | |
| 787 if (key == "cvn") { | |
| 788 EXPECT_EQ("123", value); | |
| 789 num_params++; | |
| 790 } | |
| 791 | |
| 792 if (key == "card_number") { | |
| 793 EXPECT_EQ("4444444444444448", value); | |
| 794 num_params++; | |
| 795 } | |
| 796 | |
| 797 if (key == "otp") { | |
| 798 EXPECT_FALSE(value.empty()); | |
| 799 num_params++; | |
| 800 } | |
| 801 } | |
| 802 EXPECT_EQ(expected_parameter_number, num_params); | |
| 803 | |
| 804 fetcher->set_response_code(response_code); | |
| 805 fetcher->SetResponseString(response_body); | |
| 806 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
| 807 } | |
| 808 | |
| 809 void TestWalletErrorCode( | |
| 810 const std::string& error_type_string, | |
| 811 const std::string& message_type_for_buyer_string, | |
| 812 WalletClient::ErrorType expected_error_type, | |
| 813 AutofillMetrics::WalletErrorMetric expected_autofill_metric) { | |
| 814 static const char kResponseTemplate[] = | |
| 815 "{" | |
| 816 " \"error_type\":\"APPLICATION_ERROR\"," | |
| 817 " \"error_detail\":\"error_detail\"," | |
| 818 " \"application_error\":\"application_error\"," | |
| 819 " \"debug_data\":" | |
| 820 " {" | |
| 821 " \"debug_message\":\"debug_message\"," | |
| 822 " \"stack_trace\":\"stack_trace\"" | |
| 823 " }," | |
| 824 " \"application_error_data\":\"application_error_data\"," | |
| 825 " \"wallet_error\":" | |
| 826 " {" | |
| 827 " \"error_type\":\"%s\"," | |
| 828 " %s" // Placeholder for |user_error_type|. | |
| 829 " \"error_detail\":\"error_detail\"," | |
| 830 " \"message_for_user\":" | |
| 831 " {" | |
| 832 " \"text\":\"text\"," | |
| 833 " \"subtext\":\"subtext\"," | |
| 834 " \"details\":\"details\"" | |
| 835 " }" | |
| 836 " }" | |
| 837 "}"; | |
| 838 EXPECT_CALL(delegate_, OnWalletError(expected_error_type)).Times(1); | |
| 839 base::HistogramTester histogram; | |
| 840 | |
| 841 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 842 std::string buyer_error; | |
| 843 if (!message_type_for_buyer_string.empty()) { | |
| 844 buyer_error = base::StringPrintf("\"message_type_for_buyer\":\"%s\",", | |
| 845 message_type_for_buyer_string.c_str()); | |
| 846 } | |
| 847 std::string response = base::StringPrintf(kResponseTemplate, | |
| 848 error_type_string.c_str(), | |
| 849 buyer_error.c_str()); | |
| 850 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | |
| 851 kGetWalletItemsValidRequest, | |
| 852 response); | |
| 853 | |
| 854 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 855 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 856 expected_autofill_metric, 1); | |
| 857 ExpectBaselineMetrics(histogram); | |
| 858 } | |
| 859 | |
| 860 protected: | |
| 861 content::TestBrowserThreadBundle thread_bundle_; | |
| 862 scoped_ptr<WalletClient> wallet_client_; | |
| 863 scoped_refptr<net::TestURLRequestContextGetter> request_context_; | |
| 864 MockWalletClientDelegate delegate_; | |
| 865 | |
| 866 private: | |
| 867 std::string GetData(const std::string& upload_data) { | |
| 868 scoped_ptr<base::Value> root = base::JSONReader::Read(upload_data); | |
| 869 | |
| 870 // If this is not a JSON dictionary, return plain text. | |
| 871 if (!root || !root->IsType(base::Value::TYPE_DICTIONARY)) | |
| 872 return upload_data; | |
| 873 | |
| 874 // Remove api_key entry (to prevent accidental leak), return JSON as text. | |
| 875 base::DictionaryValue* dict = | |
| 876 static_cast<base::DictionaryValue*>(root.get()); | |
| 877 dict->Remove("api_key", NULL); | |
| 878 std::string clean_upload_data; | |
| 879 base::JSONWriter::Write(*dict, &clean_upload_data); | |
| 880 return clean_upload_data; | |
| 881 } | |
| 882 | |
| 883 net::TestURLFetcherFactory factory_; | |
| 884 }; | |
| 885 | |
| 886 TEST_F(WalletClientTest, WalletErrorCodes) { | |
| 887 struct { | |
| 888 std::string error_type_string; | |
| 889 std::string message_type_for_buyer_string; | |
| 890 WalletClient::ErrorType expected_error_type; | |
| 891 AutofillMetrics::WalletErrorMetric expected_autofill_metric; | |
| 892 } test_cases[] = { | |
| 893 // General |BUYER_ACCOUNT_ERROR| with no |message_type_for_buyer_string|. | |
| 894 { | |
| 895 "buyer_account_error", | |
| 896 "", | |
| 897 WalletClient::BUYER_ACCOUNT_ERROR, | |
| 898 AutofillMetrics::WALLET_BUYER_ACCOUNT_ERROR | |
| 899 }, | |
| 900 // |BUYER_ACCOUNT_ERROR| with "buyer_legal_address_not_supported" in | |
| 901 // message_type_for_buyer field. | |
| 902 { | |
| 903 "buyer_account_error", | |
| 904 "bla_country_not_supported", | |
| 905 WalletClient::BUYER_LEGAL_ADDRESS_NOT_SUPPORTED, | |
| 906 AutofillMetrics::WALLET_BUYER_LEGAL_ADDRESS_NOT_SUPPORTED | |
| 907 }, | |
| 908 // |BUYER_ACCOUNT_ERROR| with KYC error code in message_type_for_buyer | |
| 909 // field. | |
| 910 { | |
| 911 "buyer_account_error", | |
| 912 "buyer_kyc_error", | |
| 913 WalletClient::UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS, | |
| 914 AutofillMetrics::WALLET_UNVERIFIED_KNOW_YOUR_CUSTOMER_STATUS | |
| 915 }, | |
| 916 // |BUYER_ACCOUNT_ERROR| with un-recognizable |message_type_for_buyer|. | |
| 917 { | |
| 918 "buyer_account_error", | |
| 919 "random_string", | |
| 920 WalletClient::BUYER_ACCOUNT_ERROR, | |
| 921 AutofillMetrics::WALLET_BUYER_ACCOUNT_ERROR | |
| 922 }, | |
| 923 // The following are other error types we could get from Wallet. | |
| 924 { | |
| 925 "unsupported_merchant", | |
| 926 "", | |
| 927 WalletClient::UNSUPPORTED_MERCHANT, | |
| 928 AutofillMetrics::WALLET_UNSUPPORTED_MERCHANT | |
| 929 }, | |
| 930 { | |
| 931 "internal_error", | |
| 932 "", | |
| 933 WalletClient::INTERNAL_ERROR, | |
| 934 AutofillMetrics::WALLET_INTERNAL_ERROR | |
| 935 }, | |
| 936 { | |
| 937 "invalid_params", | |
| 938 "", | |
| 939 WalletClient::INVALID_PARAMS, | |
| 940 AutofillMetrics::WALLET_INVALID_PARAMS | |
| 941 }, | |
| 942 { | |
| 943 "service_unavailable", | |
| 944 "", | |
| 945 WalletClient::SERVICE_UNAVAILABLE, | |
| 946 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE | |
| 947 }, | |
| 948 { | |
| 949 "unsupported_api_version", | |
| 950 "", | |
| 951 WalletClient::UNSUPPORTED_API_VERSION, | |
| 952 AutofillMetrics::WALLET_UNSUPPORTED_API_VERSION | |
| 953 }, | |
| 954 // Any un-recognizable |error_type| is a |UNKNOWN_ERROR|. | |
| 955 { | |
| 956 "random_string_1", | |
| 957 "", | |
| 958 WalletClient::UNKNOWN_ERROR, | |
| 959 AutofillMetrics::WALLET_UNKNOWN_ERROR | |
| 960 }, | |
| 961 { | |
| 962 "random_string_2", | |
| 963 "", | |
| 964 WalletClient::UNKNOWN_ERROR, | |
| 965 AutofillMetrics::WALLET_UNKNOWN_ERROR | |
| 966 }, | |
| 967 }; | |
| 968 | |
| 969 for (size_t i = 0; i < arraysize(test_cases); ++i) { | |
| 970 SCOPED_TRACE( | |
| 971 base::StringPrintf( | |
| 972 "%s - %s", | |
| 973 test_cases[i].error_type_string.c_str(), | |
| 974 test_cases[i].message_type_for_buyer_string.c_str())); | |
| 975 TestWalletErrorCode(test_cases[i].error_type_string, | |
| 976 test_cases[i].message_type_for_buyer_string, | |
| 977 test_cases[i].expected_error_type, | |
| 978 test_cases[i].expected_autofill_metric); | |
| 979 } | |
| 980 } | |
| 981 | |
| 982 | |
| 983 TEST_F(WalletClientTest, WalletErrorResponseMissing) { | |
| 984 EXPECT_CALL(delegate_, OnWalletError( | |
| 985 WalletClient::UNKNOWN_ERROR)).Times(1); | |
| 986 base::HistogramTester histogram; | |
| 987 | |
| 988 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 989 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | |
| 990 kGetWalletItemsValidRequest, | |
| 991 kErrorTypeMissingInResponse); | |
| 992 | |
| 993 ExpectBaselineMetrics(histogram); | |
| 994 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 995 AutofillMetrics::WALLET_UNKNOWN_ERROR, 1); | |
| 996 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 997 } | |
| 998 | |
| 999 TEST_F(WalletClientTest, NetworkFailureOnExpectedResponse) { | |
| 1000 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); | |
| 1001 base::HistogramTester histogram; | |
| 1002 | |
| 1003 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1004 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, | |
| 1005 kGetWalletItemsValidRequest, | |
| 1006 std::string()); | |
| 1007 | |
| 1008 ExpectBaselineMetrics(histogram); | |
| 1009 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1010 AutofillMetrics::WALLET_NETWORK_ERROR, 1); | |
| 1011 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1012 } | |
| 1013 | |
| 1014 TEST_F(WalletClientTest, RequestError) { | |
| 1015 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); | |
| 1016 base::HistogramTester histogram; | |
| 1017 | |
| 1018 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1019 VerifyAndFinishRequest(net::HTTP_BAD_REQUEST, | |
| 1020 kGetWalletItemsValidRequest, | |
| 1021 std::string()); | |
| 1022 | |
| 1023 ExpectBaselineMetrics(histogram); | |
| 1024 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1025 AutofillMetrics::WALLET_BAD_REQUEST, 1); | |
| 1026 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1027 } | |
| 1028 | |
| 1029 TEST_F(WalletClientTest, GetFullWalletSuccess) { | |
| 1030 base::HistogramTester histogram; | |
| 1031 | |
| 1032 WalletClient::FullWalletRequest full_wallet_request( | |
| 1033 "instrument_id", | |
| 1034 "shipping_address_id", | |
| 1035 "google_transaction_id", | |
| 1036 std::vector<WalletClient::RiskCapability>(), | |
| 1037 false); | |
| 1038 wallet_client_->GetFullWallet(full_wallet_request); | |
| 1039 | |
| 1040 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1041 kGetFullWalletValidRequest, | |
| 1042 kGetFullWalletValidResponse, | |
| 1043 3U); | |
| 1044 EXPECT_EQ(1U, delegate_.full_wallets_received()); | |
| 1045 | |
| 1046 ExpectBaselineMetrics(histogram); | |
| 1047 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetFullWallet", 1); | |
| 1048 } | |
| 1049 | |
| 1050 TEST_F(WalletClientTest, GetFullWalletSuccessNewuser) { | |
| 1051 base::HistogramTester histogram; | |
| 1052 | |
| 1053 WalletClient::FullWalletRequest full_wallet_request( | |
| 1054 "instrument_id", | |
| 1055 "shipping_address_id", | |
| 1056 "google_transaction_id", | |
| 1057 std::vector<WalletClient::RiskCapability>(), | |
| 1058 true); | |
| 1059 wallet_client_->GetFullWallet(full_wallet_request); | |
| 1060 | |
| 1061 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1062 kGetFullWalletValidRequestNewUser, | |
| 1063 kGetFullWalletValidResponse, | |
| 1064 3U); | |
| 1065 EXPECT_EQ(1U, delegate_.full_wallets_received()); | |
| 1066 | |
| 1067 ExpectBaselineMetrics(histogram); | |
| 1068 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetFullWallet", 1); | |
| 1069 } | |
| 1070 | |
| 1071 TEST_F(WalletClientTest, GetFullWalletWithRiskCapabilitesSuccess) { | |
| 1072 base::HistogramTester histogram; | |
| 1073 | |
| 1074 std::vector<WalletClient::RiskCapability> risk_capabilities; | |
| 1075 risk_capabilities.push_back(WalletClient::VERIFY_CVC); | |
| 1076 WalletClient::FullWalletRequest full_wallet_request( | |
| 1077 "instrument_id", | |
| 1078 "shipping_address_id", | |
| 1079 "google_transaction_id", | |
| 1080 risk_capabilities, | |
| 1081 false); | |
| 1082 wallet_client_->GetFullWallet(full_wallet_request); | |
| 1083 | |
| 1084 VerifyAndFinishFormEncodedRequest( | |
| 1085 net::HTTP_OK, | |
| 1086 kGetFullWalletWithRiskCapabilitesValidRequest, | |
| 1087 kGetFullWalletValidResponse, | |
| 1088 3U); | |
| 1089 EXPECT_EQ(1U, delegate_.full_wallets_received()); | |
| 1090 | |
| 1091 ExpectBaselineMetrics(histogram); | |
| 1092 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetFullWallet", 1); | |
| 1093 } | |
| 1094 | |
| 1095 TEST_F(WalletClientTest, GetFullWalletMalformedResponse) { | |
| 1096 EXPECT_CALL(delegate_, | |
| 1097 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1098 base::HistogramTester histogram; | |
| 1099 | |
| 1100 WalletClient::FullWalletRequest full_wallet_request( | |
| 1101 "instrument_id", | |
| 1102 "shipping_address_id", | |
| 1103 "google_transaction_id", | |
| 1104 std::vector<WalletClient::RiskCapability>(), | |
| 1105 false); | |
| 1106 wallet_client_->GetFullWallet(full_wallet_request); | |
| 1107 | |
| 1108 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1109 kGetFullWalletValidRequest, | |
| 1110 kGetFullWalletInvalidResponse, | |
| 1111 3U); | |
| 1112 EXPECT_EQ(0U, delegate_.full_wallets_received()); | |
| 1113 | |
| 1114 ExpectBaselineMetrics(histogram); | |
| 1115 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetFullWallet", 1); | |
| 1116 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1117 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1118 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1119 AutofillMetrics::GET_FULL_WALLET, 1); | |
| 1120 } | |
| 1121 | |
| 1122 TEST_F(WalletClientTest, AcceptLegalDocuments) { | |
| 1123 EXPECT_CALL(delegate_, OnDidAcceptLegalDocuments()).Times(1); | |
| 1124 base::HistogramTester histogram; | |
| 1125 | |
| 1126 ScopedVector<WalletItems::LegalDocument> docs; | |
| 1127 base::DictionaryValue document; | |
| 1128 document.SetString("legal_document_id", "doc_id_1"); | |
| 1129 document.SetString("url", "https://example.com"); | |
| 1130 document.SetString("display_name", "doc_1"); | |
| 1131 docs.push_back( | |
| 1132 WalletItems::LegalDocument::CreateLegalDocument(document).release()); | |
| 1133 document.SetString("legal_document_id", "doc_id_2"); | |
| 1134 document.SetString("display_name", "doc_2"); | |
| 1135 docs.push_back( | |
| 1136 WalletItems::LegalDocument::CreateLegalDocument(document).release()); | |
| 1137 ASSERT_TRUE(docs.back()); | |
| 1138 docs.push_back( | |
| 1139 WalletItems::LegalDocument::CreatePrivacyPolicyDocument().release()); | |
| 1140 ASSERT_TRUE(docs.back()); | |
| 1141 wallet_client_->AcceptLegalDocuments(docs.get(), | |
| 1142 kGoogleTransactionId); | |
| 1143 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1144 kAcceptLegalDocumentsValidRequest, | |
| 1145 ")}'"); // Invalid JSON. Should be ignored. | |
| 1146 | |
| 1147 ExpectBaselineMetrics(histogram); | |
| 1148 histogram.ExpectTotalCount("Wallet.ApiCallDuration.AcceptLegalDocuments", 1); | |
| 1149 } | |
| 1150 | |
| 1151 TEST_F(WalletClientTest, AuthenticateInstrumentSucceeded) { | |
| 1152 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(true)).Times(1); | |
| 1153 base::HistogramTester histogram; | |
| 1154 | |
| 1155 wallet_client_->AuthenticateInstrument("instrument_id", "123"); | |
| 1156 | |
| 1157 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1158 kAuthenticateInstrumentValidRequest, | |
| 1159 kAuthenticateInstrumentSuccessResponse, | |
| 1160 3U); | |
| 1161 | |
| 1162 ExpectBaselineMetrics(histogram); | |
| 1163 histogram.ExpectTotalCount("Wallet.ApiCallDuration.AuthenticateInstrument", | |
| 1164 1); | |
| 1165 } | |
| 1166 | |
| 1167 TEST_F(WalletClientTest, AuthenticateInstrumentFailed) { | |
| 1168 EXPECT_CALL(delegate_, OnDidAuthenticateInstrument(false)).Times(1); | |
| 1169 base::HistogramTester histogram; | |
| 1170 | |
| 1171 wallet_client_->AuthenticateInstrument("instrument_id", "123"); | |
| 1172 | |
| 1173 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1174 kAuthenticateInstrumentValidRequest, | |
| 1175 kAuthenticateInstrumentFailureResponse, | |
| 1176 3U); | |
| 1177 | |
| 1178 ExpectBaselineMetrics(histogram); | |
| 1179 histogram.ExpectTotalCount("Wallet.ApiCallDuration.AuthenticateInstrument", | |
| 1180 1); | |
| 1181 } | |
| 1182 | |
| 1183 TEST_F(WalletClientTest, AuthenticateInstrumentFailedMalformedResponse) { | |
| 1184 EXPECT_CALL(delegate_, | |
| 1185 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1186 base::HistogramTester histogram; | |
| 1187 | |
| 1188 wallet_client_->AuthenticateInstrument("instrument_id", "123"); | |
| 1189 | |
| 1190 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1191 kAuthenticateInstrumentValidRequest, | |
| 1192 kSaveInvalidResponse, | |
| 1193 3U); | |
| 1194 | |
| 1195 ExpectBaselineMetrics(histogram); | |
| 1196 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1197 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1198 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1199 AutofillMetrics::AUTHENTICATE_INSTRUMENT, 1); | |
| 1200 histogram.ExpectTotalCount("Wallet.ApiCallDuration.AuthenticateInstrument", | |
| 1201 1); | |
| 1202 } | |
| 1203 | |
| 1204 // TODO(ahutter): Add failure tests for GetWalletItems. | |
| 1205 | |
| 1206 TEST_F(WalletClientTest, GetWalletItems) { | |
| 1207 base::HistogramTester histogram; | |
| 1208 | |
| 1209 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1210 | |
| 1211 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1212 kGetWalletItemsValidRequest, | |
| 1213 kGetWalletItemsValidResponse); | |
| 1214 EXPECT_EQ(1U, delegate_.wallet_items_received()); | |
| 1215 | |
| 1216 ExpectBaselineMetrics(histogram); | |
| 1217 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1218 } | |
| 1219 | |
| 1220 TEST_F(WalletClientTest, GetWalletItemsWithTransactionDetails) { | |
| 1221 base::HistogramTester histogram; | |
| 1222 | |
| 1223 wallet_client_->GetWalletItems(base::ASCIIToUTF16("100.00"), | |
| 1224 base::ASCIIToUTF16("USD")); | |
| 1225 | |
| 1226 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1227 kGetWalletItemsWithTransactionDetails, | |
| 1228 kGetWalletItemsValidResponse); | |
| 1229 EXPECT_EQ(1U, delegate_.wallet_items_received()); | |
| 1230 | |
| 1231 ExpectBaselineMetrics(histogram); | |
| 1232 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1233 } | |
| 1234 | |
| 1235 TEST_F(WalletClientTest, GetWalletItemsRespectsDelegateForShippingRequired) { | |
| 1236 base::HistogramTester histogram; | |
| 1237 delegate_.SetIsShippingAddressRequired(false); | |
| 1238 | |
| 1239 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1240 | |
| 1241 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1242 kGetWalletItemsNoShippingRequest, | |
| 1243 kGetWalletItemsValidResponse); | |
| 1244 EXPECT_EQ(1U, delegate_.wallet_items_received()); | |
| 1245 | |
| 1246 ExpectBaselineMetrics(histogram); | |
| 1247 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1248 } | |
| 1249 | |
| 1250 TEST_F(WalletClientTest, SaveAddressSucceeded) { | |
| 1251 EXPECT_CALL(delegate_, | |
| 1252 OnDidSaveToWallet(std::string(), | |
| 1253 "saved_address_id", | |
| 1254 std::vector<RequiredAction>(), | |
| 1255 std::vector<FormFieldError>())).Times(1); | |
| 1256 base::HistogramTester histogram; | |
| 1257 | |
| 1258 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1259 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1260 address.Pass(), | |
| 1261 NULL, | |
| 1262 NULL); | |
| 1263 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1264 kSaveAddressValidRequest, | |
| 1265 kSaveAddressValidResponse); | |
| 1266 | |
| 1267 ExpectBaselineMetrics(histogram); | |
| 1268 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1269 } | |
| 1270 | |
| 1271 TEST_F(WalletClientTest, SaveAddressWithRequiredActionsSucceeded) { | |
| 1272 base::HistogramTester histogram; | |
| 1273 | |
| 1274 std::vector<RequiredAction> required_actions; | |
| 1275 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1276 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1277 | |
| 1278 std::vector<FormFieldError> form_errors; | |
| 1279 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, | |
| 1280 FormFieldError::SHIPPING_ADDRESS)); | |
| 1281 | |
| 1282 EXPECT_CALL(delegate_, | |
| 1283 OnDidSaveToWallet(std::string(), | |
| 1284 std::string(), | |
| 1285 required_actions, | |
| 1286 form_errors)).Times(1); | |
| 1287 | |
| 1288 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1289 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1290 address.Pass(), | |
| 1291 NULL, | |
| 1292 NULL); | |
| 1293 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1294 kSaveAddressValidRequest, | |
| 1295 kSaveAddressWithRequiredActionsValidResponse); | |
| 1296 | |
| 1297 ExpectBaselineMetrics(histogram); | |
| 1298 ExpectCommonWalletRequiredActionMetrics(histogram); | |
| 1299 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1300 } | |
| 1301 | |
| 1302 TEST_F(WalletClientTest, SaveAddressFailedInvalidRequiredAction) { | |
| 1303 EXPECT_CALL(delegate_, | |
| 1304 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1305 base::HistogramTester histogram; | |
| 1306 | |
| 1307 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1308 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1309 address.Pass(), | |
| 1310 NULL, | |
| 1311 NULL); | |
| 1312 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1313 kSaveAddressValidRequest, | |
| 1314 kSaveWithInvalidRequiredActionsResponse); | |
| 1315 | |
| 1316 ExpectBaselineMetrics(histogram); | |
| 1317 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1318 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1319 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1320 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1321 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1322 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1323 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1324 } | |
| 1325 | |
| 1326 TEST_F(WalletClientTest, SaveAddressFailedMalformedResponse) { | |
| 1327 EXPECT_CALL(delegate_, | |
| 1328 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1329 base::HistogramTester histogram; | |
| 1330 | |
| 1331 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1332 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1333 address.Pass(), | |
| 1334 NULL, | |
| 1335 NULL); | |
| 1336 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1337 kSaveAddressValidRequest, | |
| 1338 kSaveInvalidResponse); | |
| 1339 | |
| 1340 ExpectBaselineMetrics(histogram); | |
| 1341 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1342 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1343 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1344 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1345 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1346 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1347 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1348 } | |
| 1349 | |
| 1350 TEST_F(WalletClientTest, SaveInstrumentSucceeded) { | |
| 1351 EXPECT_CALL(delegate_, | |
| 1352 OnDidSaveToWallet("instrument_id", | |
| 1353 std::string(), | |
| 1354 std::vector<RequiredAction>(), | |
| 1355 std::vector<FormFieldError>())).Times(1); | |
| 1356 base::HistogramTester histogram; | |
| 1357 | |
| 1358 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1359 wallet_client_->SaveToWallet(instrument.Pass(), | |
| 1360 scoped_ptr<Address>(), | |
| 1361 NULL, | |
| 1362 NULL); | |
| 1363 | |
| 1364 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1365 kSaveInstrumentValidRequest, | |
| 1366 kSaveInstrumentValidResponse, | |
| 1367 4U); | |
| 1368 | |
| 1369 ExpectBaselineMetrics(histogram); | |
| 1370 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1371 } | |
| 1372 | |
| 1373 TEST_F(WalletClientTest, SaveInstrumentWithRequiredActionsSucceeded) { | |
| 1374 base::HistogramTester histogram; | |
| 1375 | |
| 1376 std::vector<RequiredAction> required_actions; | |
| 1377 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1378 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1379 | |
| 1380 std::vector<FormFieldError> form_errors; | |
| 1381 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, | |
| 1382 FormFieldError::SHIPPING_ADDRESS)); | |
| 1383 | |
| 1384 EXPECT_CALL(delegate_, | |
| 1385 OnDidSaveToWallet(std::string(), | |
| 1386 std::string(), | |
| 1387 required_actions, | |
| 1388 form_errors)).Times(1); | |
| 1389 | |
| 1390 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1391 wallet_client_->SaveToWallet(instrument.Pass(), | |
| 1392 scoped_ptr<Address>(), | |
| 1393 NULL, | |
| 1394 NULL); | |
| 1395 | |
| 1396 VerifyAndFinishFormEncodedRequest( | |
| 1397 net::HTTP_OK, | |
| 1398 kSaveInstrumentValidRequest, | |
| 1399 kSaveInstrumentWithRequiredActionsValidResponse, | |
| 1400 4U); | |
| 1401 | |
| 1402 ExpectBaselineMetrics(histogram); | |
| 1403 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1404 ExpectCommonWalletRequiredActionMetrics(histogram); | |
| 1405 } | |
| 1406 | |
| 1407 TEST_F(WalletClientTest, SaveInstrumentFailedInvalidRequiredActions) { | |
| 1408 base::HistogramTester histogram; | |
| 1409 | |
| 1410 EXPECT_CALL(delegate_, | |
| 1411 OnWalletError(WalletClient::MALFORMED_RESPONSE)); | |
| 1412 | |
| 1413 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1414 wallet_client_->SaveToWallet(instrument.Pass(), | |
| 1415 scoped_ptr<Address>(), | |
| 1416 NULL, | |
| 1417 NULL); | |
| 1418 | |
| 1419 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1420 kSaveInstrumentValidRequest, | |
| 1421 kSaveWithInvalidRequiredActionsResponse, | |
| 1422 4U); | |
| 1423 | |
| 1424 ExpectBaselineMetrics(histogram); | |
| 1425 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1426 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1427 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1428 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1429 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1430 } | |
| 1431 | |
| 1432 TEST_F(WalletClientTest, SaveInstrumentFailedMalformedResponse) { | |
| 1433 EXPECT_CALL(delegate_, | |
| 1434 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1435 base::HistogramTester histogram; | |
| 1436 | |
| 1437 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1438 wallet_client_->SaveToWallet(instrument.Pass(), | |
| 1439 scoped_ptr<Address>(), | |
| 1440 NULL, | |
| 1441 NULL); | |
| 1442 | |
| 1443 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1444 kSaveInstrumentValidRequest, | |
| 1445 kSaveInvalidResponse, | |
| 1446 4U); | |
| 1447 | |
| 1448 ExpectBaselineMetrics(histogram); | |
| 1449 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1450 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1451 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1452 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1453 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1454 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1455 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1456 } | |
| 1457 | |
| 1458 TEST_F(WalletClientTest, SaveInstrumentAndAddressSucceeded) { | |
| 1459 EXPECT_CALL(delegate_, | |
| 1460 OnDidSaveToWallet("saved_instrument_id", | |
| 1461 "saved_address_id", | |
| 1462 std::vector<RequiredAction>(), | |
| 1463 std::vector<FormFieldError>())).Times(1); | |
| 1464 base::HistogramTester histogram; | |
| 1465 | |
| 1466 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1467 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1468 wallet_client_->SaveToWallet(instrument.Pass(), address.Pass(), NULL, NULL); | |
| 1469 | |
| 1470 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1471 kSaveInstrumentAndAddressValidRequest, | |
| 1472 kSaveInstrumentAndAddressValidResponse, | |
| 1473 4U); | |
| 1474 | |
| 1475 ExpectBaselineMetrics(histogram); | |
| 1476 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1477 } | |
| 1478 | |
| 1479 TEST_F(WalletClientTest, SaveInstrumentAndAddressWithRequiredActionsSucceeded) { | |
| 1480 base::HistogramTester histogram; | |
| 1481 | |
| 1482 std::vector<RequiredAction> required_actions; | |
| 1483 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1484 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1485 | |
| 1486 std::vector<FormFieldError> form_errors; | |
| 1487 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, | |
| 1488 FormFieldError::SHIPPING_ADDRESS)); | |
| 1489 | |
| 1490 EXPECT_CALL(delegate_, | |
| 1491 OnDidSaveToWallet(std::string(), | |
| 1492 std::string(), | |
| 1493 required_actions, | |
| 1494 form_errors)).Times(1); | |
| 1495 | |
| 1496 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1497 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1498 wallet_client_->SaveToWallet(instrument.Pass(), address.Pass(), NULL, NULL); | |
| 1499 | |
| 1500 VerifyAndFinishFormEncodedRequest( | |
| 1501 net::HTTP_OK, | |
| 1502 kSaveInstrumentAndAddressValidRequest, | |
| 1503 kSaveInstrumentAndAddressWithRequiredActionsValidResponse, | |
| 1504 4U); | |
| 1505 | |
| 1506 ExpectBaselineMetrics(histogram); | |
| 1507 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1508 ExpectCommonWalletRequiredActionMetrics(histogram); | |
| 1509 } | |
| 1510 | |
| 1511 TEST_F(WalletClientTest, SaveInstrumentAndAddressFailedInvalidRequiredAction) { | |
| 1512 EXPECT_CALL(delegate_, | |
| 1513 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1514 base::HistogramTester histogram; | |
| 1515 | |
| 1516 scoped_ptr<Instrument> instrument = GetTestInstrument(); | |
| 1517 scoped_ptr<Address> address = GetTestSaveableAddress(); | |
| 1518 wallet_client_->SaveToWallet(instrument.Pass(), address.Pass(), NULL, NULL); | |
| 1519 | |
| 1520 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1521 kSaveInstrumentAndAddressValidRequest, | |
| 1522 kSaveWithInvalidRequiredActionsResponse, | |
| 1523 4U); | |
| 1524 | |
| 1525 ExpectBaselineMetrics(histogram); | |
| 1526 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1527 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1528 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1529 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1530 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1531 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1532 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1533 } | |
| 1534 | |
| 1535 TEST_F(WalletClientTest, UpdateAddressSucceeded) { | |
| 1536 EXPECT_CALL(delegate_, | |
| 1537 OnDidSaveToWallet(std::string(), | |
| 1538 "shipping_address_id", | |
| 1539 std::vector<RequiredAction>(), | |
| 1540 std::vector<FormFieldError>())).Times(1); | |
| 1541 base::HistogramTester histogram; | |
| 1542 | |
| 1543 scoped_ptr<Address> reference_address = GetTestNonDefaultShippingAddress(); | |
| 1544 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1545 GetTestShippingAddress(), | |
| 1546 NULL, | |
| 1547 reference_address.get()); | |
| 1548 | |
| 1549 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1550 kUpdateAddressValidRequest, | |
| 1551 kUpdateAddressValidResponse); | |
| 1552 | |
| 1553 ExpectBaselineMetrics(histogram); | |
| 1554 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1555 } | |
| 1556 | |
| 1557 TEST_F(WalletClientTest, UpdateAddressWithRequiredActionsSucceeded) { | |
| 1558 base::HistogramTester histogram; | |
| 1559 | |
| 1560 std::vector<RequiredAction> required_actions; | |
| 1561 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1562 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1563 | |
| 1564 std::vector<FormFieldError> form_errors; | |
| 1565 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, | |
| 1566 FormFieldError::SHIPPING_ADDRESS)); | |
| 1567 | |
| 1568 EXPECT_CALL(delegate_, OnDidSaveToWallet(std::string(), | |
| 1569 std::string(), | |
| 1570 required_actions, | |
| 1571 form_errors)).Times(1); | |
| 1572 | |
| 1573 scoped_ptr<Address> reference_address = GetTestNonDefaultShippingAddress(); | |
| 1574 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1575 GetTestShippingAddress(), | |
| 1576 NULL, | |
| 1577 reference_address.get()); | |
| 1578 | |
| 1579 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1580 kUpdateAddressValidRequest, | |
| 1581 kUpdateWithRequiredActionsValidResponse); | |
| 1582 | |
| 1583 ExpectBaselineMetrics(histogram); | |
| 1584 ExpectCommonWalletRequiredActionMetrics(histogram); | |
| 1585 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1586 } | |
| 1587 | |
| 1588 TEST_F(WalletClientTest, UpdateAddressFailedInvalidRequiredAction) { | |
| 1589 EXPECT_CALL(delegate_, | |
| 1590 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1591 base::HistogramTester histogram; | |
| 1592 | |
| 1593 scoped_ptr<Address> reference_address = GetTestNonDefaultShippingAddress(); | |
| 1594 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1595 GetTestShippingAddress(), | |
| 1596 NULL, | |
| 1597 reference_address.get()); | |
| 1598 | |
| 1599 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1600 kUpdateAddressValidRequest, | |
| 1601 kSaveWithInvalidRequiredActionsResponse); | |
| 1602 | |
| 1603 ExpectBaselineMetrics(histogram); | |
| 1604 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1605 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1606 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1607 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1608 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1609 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1610 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1611 } | |
| 1612 | |
| 1613 TEST_F(WalletClientTest, UpdateAddressMalformedResponse) { | |
| 1614 EXPECT_CALL(delegate_, | |
| 1615 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1616 base::HistogramTester histogram; | |
| 1617 | |
| 1618 scoped_ptr<Address> reference_address = GetTestNonDefaultShippingAddress(); | |
| 1619 wallet_client_->SaveToWallet(scoped_ptr<Instrument>(), | |
| 1620 GetTestShippingAddress(), | |
| 1621 NULL, | |
| 1622 reference_address.get()); | |
| 1623 | |
| 1624 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1625 kUpdateAddressValidRequest, | |
| 1626 kUpdateMalformedResponse); | |
| 1627 | |
| 1628 ExpectBaselineMetrics(histogram); | |
| 1629 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1630 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1631 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1632 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1633 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1634 } | |
| 1635 | |
| 1636 TEST_F(WalletClientTest, UpdateInstrumentAddressSucceeded) { | |
| 1637 EXPECT_CALL(delegate_, | |
| 1638 OnDidSaveToWallet("instrument_id", | |
| 1639 std::string(), | |
| 1640 std::vector<RequiredAction>(), | |
| 1641 std::vector<FormFieldError>())).Times(1); | |
| 1642 base::HistogramTester histogram; | |
| 1643 | |
| 1644 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1645 GetTestMaskedInstrument(); | |
| 1646 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(), | |
| 1647 scoped_ptr<Address>(), | |
| 1648 reference_instrument.get(), | |
| 1649 NULL); | |
| 1650 | |
| 1651 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1652 kUpdateInstrumentAddressValidRequest, | |
| 1653 kUpdateInstrumentValidResponse); | |
| 1654 | |
| 1655 ExpectBaselineMetrics(histogram); | |
| 1656 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1657 } | |
| 1658 | |
| 1659 TEST_F(WalletClientTest, UpdateInstrumentExpirationDateSuceeded) { | |
| 1660 EXPECT_CALL(delegate_, | |
| 1661 OnDidSaveToWallet("instrument_id", | |
| 1662 std::string(), | |
| 1663 std::vector<RequiredAction>(), | |
| 1664 std::vector<FormFieldError>())).Times(1); | |
| 1665 base::HistogramTester histogram; | |
| 1666 | |
| 1667 scoped_ptr<Instrument> instrument = GetTestExpirationDateChangeInstrument(); | |
| 1668 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1669 GetTestMaskedInstrumentWithId("instrument_id"); | |
| 1670 | |
| 1671 int new_month = instrument->expiration_month(); | |
| 1672 int new_year = instrument->expiration_year(); | |
| 1673 ASSERT_TRUE(new_month != reference_instrument->expiration_month() || | |
| 1674 new_year != reference_instrument->expiration_year()); | |
| 1675 | |
| 1676 wallet_client_->SaveToWallet(instrument.Pass(), | |
| 1677 scoped_ptr<Address>(), | |
| 1678 reference_instrument.get(), | |
| 1679 NULL); | |
| 1680 | |
| 1681 VerifyAndFinishFormEncodedRequest(net::HTTP_OK, | |
| 1682 kUpdateInstrumentExpirationDateValidRequest, | |
| 1683 kUpdateInstrumentValidResponse, | |
| 1684 3U); | |
| 1685 | |
| 1686 ExpectBaselineMetrics(histogram); | |
| 1687 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1688 } | |
| 1689 | |
| 1690 TEST_F(WalletClientTest, UpdateInstrumentAddressWithNameChangeSucceeded) { | |
| 1691 EXPECT_CALL(delegate_, | |
| 1692 OnDidSaveToWallet("instrument_id", | |
| 1693 std::string(), | |
| 1694 std::vector<RequiredAction>(), | |
| 1695 std::vector<FormFieldError>())).Times(1); | |
| 1696 base::HistogramTester histogram; | |
| 1697 | |
| 1698 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1699 GetTestMaskedInstrument(); | |
| 1700 wallet_client_->SaveToWallet(GetTestAddressNameChangeInstrument(), | |
| 1701 scoped_ptr<Address>(), | |
| 1702 reference_instrument.get(), | |
| 1703 NULL); | |
| 1704 | |
| 1705 VerifyAndFinishFormEncodedRequest( | |
| 1706 net::HTTP_OK, | |
| 1707 kUpdateInstrumentAddressWithNameChangeValidRequest, | |
| 1708 kUpdateInstrumentValidResponse, | |
| 1709 3U); | |
| 1710 | |
| 1711 ExpectBaselineMetrics(histogram); | |
| 1712 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1713 } | |
| 1714 | |
| 1715 TEST_F(WalletClientTest, UpdateInstrumentWithRequiredActionsSucceeded) { | |
| 1716 base::HistogramTester histogram; | |
| 1717 | |
| 1718 std::vector<RequiredAction> required_actions; | |
| 1719 required_actions.push_back(REQUIRE_PHONE_NUMBER); | |
| 1720 required_actions.push_back(INVALID_FORM_FIELD); | |
| 1721 | |
| 1722 std::vector<FormFieldError> form_errors; | |
| 1723 form_errors.push_back(FormFieldError(FormFieldError::INVALID_POSTAL_CODE, | |
| 1724 FormFieldError::SHIPPING_ADDRESS)); | |
| 1725 | |
| 1726 EXPECT_CALL(delegate_, | |
| 1727 OnDidSaveToWallet(std::string(), | |
| 1728 std::string(), | |
| 1729 required_actions, | |
| 1730 form_errors)).Times(1); | |
| 1731 | |
| 1732 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1733 GetTestMaskedInstrument(); | |
| 1734 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(), | |
| 1735 scoped_ptr<Address>(), | |
| 1736 reference_instrument.get(), | |
| 1737 NULL); | |
| 1738 | |
| 1739 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1740 kUpdateInstrumentAddressValidRequest, | |
| 1741 kUpdateWithRequiredActionsValidResponse); | |
| 1742 | |
| 1743 ExpectBaselineMetrics(histogram); | |
| 1744 ExpectCommonWalletRequiredActionMetrics(histogram); | |
| 1745 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1746 } | |
| 1747 | |
| 1748 TEST_F(WalletClientTest, UpdateInstrumentFailedInvalidRequiredAction) { | |
| 1749 EXPECT_CALL(delegate_, | |
| 1750 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1751 base::HistogramTester histogram; | |
| 1752 | |
| 1753 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1754 GetTestMaskedInstrument(); | |
| 1755 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(), | |
| 1756 scoped_ptr<Address>(), | |
| 1757 reference_instrument.get(), | |
| 1758 NULL); | |
| 1759 | |
| 1760 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1761 kUpdateInstrumentAddressValidRequest, | |
| 1762 kSaveWithInvalidRequiredActionsResponse); | |
| 1763 | |
| 1764 ExpectBaselineMetrics(histogram); | |
| 1765 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1766 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1767 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1768 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1769 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1770 } | |
| 1771 | |
| 1772 TEST_F(WalletClientTest, UpdateInstrumentMalformedResponse) { | |
| 1773 EXPECT_CALL(delegate_, | |
| 1774 OnWalletError(WalletClient::MALFORMED_RESPONSE)).Times(1); | |
| 1775 base::HistogramTester histogram; | |
| 1776 | |
| 1777 scoped_ptr<WalletItems::MaskedInstrument> reference_instrument = | |
| 1778 GetTestMaskedInstrument(); | |
| 1779 wallet_client_->SaveToWallet(GetTestAddressUpgradeInstrument(), | |
| 1780 scoped_ptr<Address>(), | |
| 1781 reference_instrument.get(), | |
| 1782 NULL); | |
| 1783 | |
| 1784 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1785 kUpdateInstrumentAddressValidRequest, | |
| 1786 kUpdateMalformedResponse); | |
| 1787 | |
| 1788 ExpectBaselineMetrics(histogram); | |
| 1789 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1790 AutofillMetrics::WALLET_MALFORMED_RESPONSE, 1); | |
| 1791 histogram.ExpectTotalCount("Wallet.ApiCallDuration.SaveToWallet", 1); | |
| 1792 histogram.ExpectUniqueSample("Wallet.MalformedResponse", | |
| 1793 AutofillMetrics::SAVE_TO_WALLET, 1); | |
| 1794 } | |
| 1795 | |
| 1796 TEST_F(WalletClientTest, HasRequestInProgress) { | |
| 1797 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1798 base::HistogramTester histogram; | |
| 1799 | |
| 1800 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1801 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1802 | |
| 1803 VerifyAndFinishRequest(net::HTTP_OK, | |
| 1804 kGetWalletItemsValidRequest, | |
| 1805 kGetWalletItemsValidResponse); | |
| 1806 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1807 | |
| 1808 ExpectBaselineMetrics(histogram); | |
| 1809 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1810 } | |
| 1811 | |
| 1812 // 500 (INTERNAL_SERVER_ERROR) - response json is parsed. | |
| 1813 TEST_F(WalletClientTest, ErrorResponse500) { | |
| 1814 base::HistogramTester histogram; | |
| 1815 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1816 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1817 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1818 | |
| 1819 EXPECT_CALL(delegate_, OnWalletError( | |
| 1820 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | |
| 1821 | |
| 1822 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | |
| 1823 kGetWalletItemsValidRequest, | |
| 1824 kErrorResponse); | |
| 1825 | |
| 1826 ExpectBaselineMetrics(histogram); | |
| 1827 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1828 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE, 1); | |
| 1829 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1830 } | |
| 1831 | |
| 1832 // 403 (FORBIDDEN) - response json is parsed. | |
| 1833 TEST_F(WalletClientTest, ErrorResponse403) { | |
| 1834 base::HistogramTester histogram; | |
| 1835 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1836 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1837 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1838 | |
| 1839 EXPECT_CALL(delegate_, OnWalletError(WalletClient::SPENDING_LIMIT_EXCEEDED)) | |
| 1840 .Times(1); | |
| 1841 | |
| 1842 VerifyAndFinishRequest(net::HTTP_FORBIDDEN, | |
| 1843 kGetWalletItemsValidRequest, | |
| 1844 kErrorResponseSpendingLimitExceeded); | |
| 1845 | |
| 1846 ExpectBaselineMetrics(histogram); | |
| 1847 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1848 AutofillMetrics::WALLET_SPENDING_LIMIT_EXCEEDED, | |
| 1849 1); | |
| 1850 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1851 } | |
| 1852 | |
| 1853 // 400 (BAD_REQUEST) - response json is ignored. | |
| 1854 TEST_F(WalletClientTest, ErrorResponse400) { | |
| 1855 base::HistogramTester histogram; | |
| 1856 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1857 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1858 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1859 | |
| 1860 EXPECT_CALL(delegate_, OnWalletError(WalletClient::BAD_REQUEST)).Times(1); | |
| 1861 | |
| 1862 VerifyAndFinishRequest( | |
| 1863 net::HTTP_BAD_REQUEST, kGetWalletItemsValidRequest, kErrorResponse); | |
| 1864 | |
| 1865 ExpectBaselineMetrics(histogram); | |
| 1866 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1867 AutofillMetrics::WALLET_BAD_REQUEST, 1); | |
| 1868 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1869 } | |
| 1870 | |
| 1871 // Anything else - response json is ignored. | |
| 1872 TEST_F(WalletClientTest, ErrorResponseOther) { | |
| 1873 base::HistogramTester histogram; | |
| 1874 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1875 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1876 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1877 | |
| 1878 EXPECT_CALL(delegate_, OnWalletError(WalletClient::NETWORK_ERROR)).Times(1); | |
| 1879 | |
| 1880 VerifyAndFinishRequest( | |
| 1881 net::HTTP_NOT_FOUND, kGetWalletItemsValidRequest, kErrorResponse); | |
| 1882 | |
| 1883 ExpectBaselineMetrics(histogram); | |
| 1884 histogram.ExpectBucketCount("RequestAutocomplete.WalletErrors", | |
| 1885 AutofillMetrics::WALLET_NETWORK_ERROR, 1); | |
| 1886 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 1); | |
| 1887 } | |
| 1888 | |
| 1889 TEST_F(WalletClientTest, CancelRequest) { | |
| 1890 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1891 base::HistogramTester histogram; | |
| 1892 | |
| 1893 wallet_client_->GetWalletItems(base::string16(), base::string16()); | |
| 1894 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | |
| 1895 wallet_client_->CancelRequest(); | |
| 1896 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | |
| 1897 | |
| 1898 ExpectBaselineMetrics(histogram); | |
| 1899 histogram.ExpectTotalCount("Wallet.ApiCallDuration.GetWalletItems", 0); | |
| 1900 } | |
| 1901 | |
| 1902 } // namespace wallet | |
| 1903 } // namespace autofill | |
| OLD | NEW |