| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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 "base/json/json_reader.h" | 5 #include "base/json/json_reader.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 "{" | 310 "{" |
| 311 "\"instrument_id\":\"instrument_id\"," | 311 "\"instrument_id\":\"instrument_id\"," |
| 312 "\"risk_params\":\"risky business\"" | 312 "\"risk_params\":\"risky business\"" |
| 313 "}"; | 313 "}"; |
| 314 | 314 |
| 315 const char kGetFullWalletValidRequest[] = | 315 const char kGetFullWalletValidRequest[] = |
| 316 "{" | 316 "{" |
| 317 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | 317 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," |
| 318 "\"google_transaction_id\":\"google_transaction_id\"," | 318 "\"google_transaction_id\":\"google_transaction_id\"," |
| 319 "\"merchant_domain\":\"https://example.com/\"," | 319 "\"merchant_domain\":\"https://example.com/\"," |
| 320 "\"phone_number_required\":true," |
| 320 "\"risk_params\":\"risky business\"," | 321 "\"risk_params\":\"risky business\"," |
| 321 "\"selected_address_id\":\"shipping_address_id\"," | 322 "\"selected_address_id\":\"shipping_address_id\"," |
| 322 "\"selected_instrument_id\":\"instrument_id\"," | 323 "\"selected_instrument_id\":\"instrument_id\"," |
| 323 "\"supported_risk_challenge\":" | 324 "\"supported_risk_challenge\":" |
| 324 "[" | 325 "[" |
| 325 "]" | 326 "]," |
| 327 "\"use_minimal_addresses\":false" |
| 326 "}"; | 328 "}"; |
| 327 | 329 |
| 328 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = | 330 const char kGetFullWalletWithRiskCapabilitesValidRequest[] = |
| 329 "{" | 331 "{" |
| 330 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," | 332 "\"feature\":\"REQUEST_AUTOCOMPLETE\"," |
| 331 "\"google_transaction_id\":\"google_transaction_id\"," | 333 "\"google_transaction_id\":\"google_transaction_id\"," |
| 332 "\"merchant_domain\":\"https://example.com/\"," | 334 "\"merchant_domain\":\"https://example.com/\"," |
| 335 "\"phone_number_required\":true," |
| 333 "\"risk_params\":\"risky business\"," | 336 "\"risk_params\":\"risky business\"," |
| 334 "\"selected_address_id\":\"shipping_address_id\"," | 337 "\"selected_address_id\":\"shipping_address_id\"," |
| 335 "\"selected_instrument_id\":\"instrument_id\"," | 338 "\"selected_instrument_id\":\"instrument_id\"," |
| 336 "\"supported_risk_challenge\":" | 339 "\"supported_risk_challenge\":" |
| 337 "[" | 340 "[" |
| 338 "\"VERIFY_CVC\"" | 341 "\"VERIFY_CVC\"" |
| 339 "]" | 342 "]," |
| 343 "\"use_minimal_addresses\":false" |
| 340 "}"; | 344 "}"; |
| 341 | 345 |
| 342 const char kGetWalletItemsValidRequest[] = | 346 const char kGetWalletItemsValidRequest[] = |
| 343 "{" | 347 "{" |
| 344 "\"merchant_domain\":\"https://example.com/\"" | 348 "\"merchant_domain\":\"https://example.com/\"," |
| 349 "\"phone_number_required\":true," |
| 350 "\"shipping_address_required\":true," |
| 351 "\"use_minimal_addresses\":false" |
| 352 "}"; |
| 353 |
| 354 const char kGetWalletItemsNoShippingRequest[] = |
| 355 "{" |
| 356 "\"merchant_domain\":\"https://example.com/\"," |
| 357 "\"phone_number_required\":true," |
| 358 "\"shipping_address_required\":false," |
| 359 "\"use_minimal_addresses\":false" |
| 345 "}"; | 360 "}"; |
| 346 | 361 |
| 347 const char kSaveAddressValidRequest[] = | 362 const char kSaveAddressValidRequest[] = |
| 348 "{" | 363 "{" |
| 349 "\"merchant_domain\":\"https://example.com/\"," | 364 "\"merchant_domain\":\"https://example.com/\"," |
| 365 "\"phone_number_required\":true," |
| 350 "\"risk_params\":\"risky business\"," | 366 "\"risk_params\":\"risky business\"," |
| 351 "\"shipping_address\":" | 367 "\"shipping_address\":" |
| 352 "{" | 368 "{" |
| 353 "\"phone_number\":\"save_phone_number\"," | 369 "\"phone_number\":\"save_phone_number\"," |
| 354 "\"postal_address\":" | 370 "\"postal_address\":" |
| 355 "{" | 371 "{" |
| 356 "\"address_line\":" | 372 "\"address_line\":" |
| 357 "[" | 373 "[" |
| 358 "\"save_address_line_1\"," | 374 "\"save_address_line_1\"," |
| 359 "\"save_address_line_2\"" | 375 "\"save_address_line_2\"" |
| 360 "]," | 376 "]," |
| 361 "\"administrative_area_name\":\"save_admin_area_name\"," | 377 "\"administrative_area_name\":\"save_admin_area_name\"," |
| 362 "\"country_name_code\":\"US\"," | 378 "\"country_name_code\":\"US\"," |
| 363 "\"locality_name\":\"save_locality_name\"," | 379 "\"locality_name\":\"save_locality_name\"," |
| 364 "\"postal_code_number\":\"save_postal_code_number\"," | 380 "\"postal_code_number\":\"save_postal_code_number\"," |
| 365 "\"recipient_name\":\"save_recipient_name\"" | 381 "\"recipient_name\":\"save_recipient_name\"" |
| 366 "}" | 382 "}" |
| 367 "}" | 383 "}," |
| 384 "\"use_minimal_addresses\":false" |
| 368 "}"; | 385 "}"; |
| 369 | 386 |
| 370 const char kSaveInstrumentValidRequest[] = | 387 const char kSaveInstrumentValidRequest[] = |
| 371 "{" | 388 "{" |
| 372 "\"instrument\":" | 389 "\"instrument\":" |
| 373 "{" | 390 "{" |
| 374 "\"credit_card\":" | 391 "\"credit_card\":" |
| 375 "{" | 392 "{" |
| 376 "\"address\":" | 393 "\"address\":" |
| 377 "{" | 394 "{" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 388 "}," | 405 "}," |
| 389 "\"exp_month\":12," | 406 "\"exp_month\":12," |
| 390 "\"exp_year\":3000," | 407 "\"exp_year\":3000," |
| 391 "\"fop_type\":\"VISA\"," | 408 "\"fop_type\":\"VISA\"," |
| 392 "\"last_4_digits\":\"4448\"" | 409 "\"last_4_digits\":\"4448\"" |
| 393 "}," | 410 "}," |
| 394 "\"type\":\"CREDIT_CARD\"" | 411 "\"type\":\"CREDIT_CARD\"" |
| 395 "}," | 412 "}," |
| 396 "\"instrument_phone_number\":\"phone_number\"," | 413 "\"instrument_phone_number\":\"phone_number\"," |
| 397 "\"merchant_domain\":\"https://example.com/\"," | 414 "\"merchant_domain\":\"https://example.com/\"," |
| 398 "\"risk_params\":\"risky business\"" | 415 "\"phone_number_required\":true," |
| 416 "\"risk_params\":\"risky business\"," |
| 417 "\"use_minimal_addresses\":false" |
| 399 "}"; | 418 "}"; |
| 400 | 419 |
| 401 const char kSaveInstrumentAndAddressValidRequest[] = | 420 const char kSaveInstrumentAndAddressValidRequest[] = |
| 402 "{" | 421 "{" |
| 403 "\"instrument\":" | 422 "\"instrument\":" |
| 404 "{" | 423 "{" |
| 405 "\"credit_card\":" | 424 "\"credit_card\":" |
| 406 "{" | 425 "{" |
| 407 "\"address\":" | 426 "\"address\":" |
| 408 "{" | 427 "{" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 419 "}," | 438 "}," |
| 420 "\"exp_month\":12," | 439 "\"exp_month\":12," |
| 421 "\"exp_year\":3000," | 440 "\"exp_year\":3000," |
| 422 "\"fop_type\":\"VISA\"," | 441 "\"fop_type\":\"VISA\"," |
| 423 "\"last_4_digits\":\"4448\"" | 442 "\"last_4_digits\":\"4448\"" |
| 424 "}," | 443 "}," |
| 425 "\"type\":\"CREDIT_CARD\"" | 444 "\"type\":\"CREDIT_CARD\"" |
| 426 "}," | 445 "}," |
| 427 "\"instrument_phone_number\":\"phone_number\"," | 446 "\"instrument_phone_number\":\"phone_number\"," |
| 428 "\"merchant_domain\":\"https://example.com/\"," | 447 "\"merchant_domain\":\"https://example.com/\"," |
| 448 "\"phone_number_required\":true," |
| 429 "\"risk_params\":\"risky business\"," | 449 "\"risk_params\":\"risky business\"," |
| 430 "\"shipping_address\":" | 450 "\"shipping_address\":" |
| 431 "{" | 451 "{" |
| 432 "\"phone_number\":\"save_phone_number\"," | 452 "\"phone_number\":\"save_phone_number\"," |
| 433 "\"postal_address\":" | 453 "\"postal_address\":" |
| 434 "{" | 454 "{" |
| 435 "\"address_line\":" | 455 "\"address_line\":" |
| 436 "[" | 456 "[" |
| 437 "\"save_address_line_1\"," | 457 "\"save_address_line_1\"," |
| 438 "\"save_address_line_2\"" | 458 "\"save_address_line_2\"" |
| 439 "]," | 459 "]," |
| 440 "\"administrative_area_name\":\"save_admin_area_name\"," | 460 "\"administrative_area_name\":\"save_admin_area_name\"," |
| 441 "\"country_name_code\":\"US\"," | 461 "\"country_name_code\":\"US\"," |
| 442 "\"locality_name\":\"save_locality_name\"," | 462 "\"locality_name\":\"save_locality_name\"," |
| 443 "\"postal_code_number\":\"save_postal_code_number\"," | 463 "\"postal_code_number\":\"save_postal_code_number\"," |
| 444 "\"recipient_name\":\"save_recipient_name\"" | 464 "\"recipient_name\":\"save_recipient_name\"" |
| 445 "}" | 465 "}" |
| 446 "}" | 466 "}," |
| 467 "\"use_minimal_addresses\":false" |
| 447 "}"; | 468 "}"; |
| 448 | 469 |
| 449 const char kSendAutocheckoutStatusOfSuccessValidRequest[] = | 470 const char kSendAutocheckoutStatusOfSuccessValidRequest[] = |
| 450 "{" | 471 "{" |
| 451 "\"google_transaction_id\":\"google_transaction_id\"," | 472 "\"google_transaction_id\":\"google_transaction_id\"," |
| 452 "\"merchant_domain\":\"https://example.com/\"," | 473 "\"merchant_domain\":\"https://example.com/\"," |
| 453 "\"success\":true" | 474 "\"success\":true" |
| 454 "}"; | 475 "}"; |
| 455 | 476 |
| 456 const char kSendAutocheckoutStatusWithStatisticsValidRequest[] = | 477 const char kSendAutocheckoutStatusWithStatisticsValidRequest[] = |
| 457 "{" | 478 "{" |
| 458 "\"google_transaction_id\":\"google_transaction_id\"," | 479 "\"google_transaction_id\":\"google_transaction_id\"," |
| 459 "\"merchant_domain\":\"https://example.com/\"," | 480 "\"merchant_domain\":\"https://example.com/\"," |
| 460 "\"steps\":[{\"step_description\":\"1_AUTOCHECKOUT_STEP_SHIPPING\"" | 481 "\"steps\":[{\"step_description\":\"1_AUTOCHECKOUT_STEP_SHIPPING\"" |
| 461 ",\"time_taken\":100}]," | 482 ",\"time_taken\":100}]," |
| 462 "\"success\":true" | 483 "\"success\":true" |
| 463 "}"; | 484 "}"; |
| 464 | 485 |
| 465 const char kSendAutocheckoutStatusOfFailureValidRequest[] = | 486 const char kSendAutocheckoutStatusOfFailureValidRequest[] = |
| 466 "{" | 487 "{" |
| 467 "\"google_transaction_id\":\"google_transaction_id\"," | 488 "\"google_transaction_id\":\"google_transaction_id\"," |
| 468 "\"merchant_domain\":\"https://example.com/\"," | 489 "\"merchant_domain\":\"https://example.com/\"," |
| 469 "\"reason\":\"CANNOT_PROCEED\"," | 490 "\"reason\":\"CANNOT_PROCEED\"," |
| 470 "\"success\":false" | 491 "\"success\":false" |
| 471 "}"; | 492 "}"; |
| 472 | 493 |
| 473 const char kUpdateAddressValidRequest[] = | 494 const char kUpdateAddressValidRequest[] = |
| 474 "{" | 495 "{" |
| 475 "\"merchant_domain\":\"https://example.com/\"," | 496 "\"merchant_domain\":\"https://example.com/\"," |
| 497 "\"phone_number_required\":true," |
| 476 "\"risk_params\":\"risky business\"," | 498 "\"risk_params\":\"risky business\"," |
| 477 "\"shipping_address\":" | 499 "\"shipping_address\":" |
| 478 "{" | 500 "{" |
| 479 "\"id\":\"shipping_address_id\"," | 501 "\"id\":\"shipping_address_id\"," |
| 480 "\"phone_number\":\"ship_phone_number\"," | 502 "\"phone_number\":\"ship_phone_number\"," |
| 481 "\"postal_address\":" | 503 "\"postal_address\":" |
| 482 "{" | 504 "{" |
| 483 "\"address_line\":" | 505 "\"address_line\":" |
| 484 "[" | 506 "[" |
| 485 "\"ship_address_line_1\"," | 507 "\"ship_address_line_1\"," |
| 486 "\"ship_address_line_2\"" | 508 "\"ship_address_line_2\"" |
| 487 "]," | 509 "]," |
| 488 "\"administrative_area_name\":\"ship_admin_area_name\"," | 510 "\"administrative_area_name\":\"ship_admin_area_name\"," |
| 489 "\"country_name_code\":\"US\"," | 511 "\"country_name_code\":\"US\"," |
| 490 "\"locality_name\":\"ship_locality_name\"," | 512 "\"locality_name\":\"ship_locality_name\"," |
| 491 "\"postal_code_number\":\"ship_postal_code_number\"," | 513 "\"postal_code_number\":\"ship_postal_code_number\"," |
| 492 "\"recipient_name\":\"ship_recipient_name\"" | 514 "\"recipient_name\":\"ship_recipient_name\"" |
| 493 "}" | 515 "}" |
| 494 "}" | 516 "}," |
| 517 "\"use_minimal_addresses\":false" |
| 495 "}"; | 518 "}"; |
| 496 | 519 |
| 497 const char kUpdateInstrumentAddressValidRequest[] = | 520 const char kUpdateInstrumentAddressValidRequest[] = |
| 498 "{" | 521 "{" |
| 499 "\"instrument_phone_number\":\"phone_number\"," | 522 "\"instrument_phone_number\":\"phone_number\"," |
| 500 "\"merchant_domain\":\"https://example.com/\"," | 523 "\"merchant_domain\":\"https://example.com/\"," |
| 524 "\"phone_number_required\":true," |
| 501 "\"risk_params\":\"risky business\"," | 525 "\"risk_params\":\"risky business\"," |
| 502 "\"upgraded_billing_address\":" | 526 "\"upgraded_billing_address\":" |
| 503 "{" | 527 "{" |
| 504 "\"address_line\":" | 528 "\"address_line\":" |
| 505 "[" | 529 "[" |
| 506 "\"address_line_1\"," | 530 "\"address_line_1\"," |
| 507 "\"address_line_2\"" | 531 "\"address_line_2\"" |
| 508 "]," | 532 "]," |
| 509 "\"administrative_area_name\":\"admin_area_name\"," | 533 "\"administrative_area_name\":\"admin_area_name\"," |
| 510 "\"country_name_code\":\"US\"," | 534 "\"country_name_code\":\"US\"," |
| 511 "\"locality_name\":\"locality_name\"," | 535 "\"locality_name\":\"locality_name\"," |
| 512 "\"postal_code_number\":\"postal_code_number\"," | 536 "\"postal_code_number\":\"postal_code_number\"," |
| 513 "\"recipient_name\":\"recipient_name\"" | 537 "\"recipient_name\":\"recipient_name\"" |
| 514 "}," | 538 "}," |
| 515 "\"upgraded_instrument_id\":\"instrument_id\"" | 539 "\"upgraded_instrument_id\":\"instrument_id\"," |
| 540 "\"use_minimal_addresses\":false" |
| 516 "}"; | 541 "}"; |
| 517 | 542 |
| 518 const char kUpdateInstrumentAddressWithNameChangeValidRequest[] = | 543 const char kUpdateInstrumentAddressWithNameChangeValidRequest[] = |
| 519 "{" | 544 "{" |
| 520 "\"instrument_phone_number\":\"phone_number\"," | 545 "\"instrument_phone_number\":\"phone_number\"," |
| 521 "\"merchant_domain\":\"https://example.com/\"," | 546 "\"merchant_domain\":\"https://example.com/\"," |
| 547 "\"phone_number_required\":true," |
| 522 "\"risk_params\":\"risky business\"," | 548 "\"risk_params\":\"risky business\"," |
| 523 "\"upgraded_billing_address\":" | 549 "\"upgraded_billing_address\":" |
| 524 "{" | 550 "{" |
| 525 "\"address_line\":" | 551 "\"address_line\":" |
| 526 "[" | 552 "[" |
| 527 "\"address_line_1\"," | 553 "\"address_line_1\"," |
| 528 "\"address_line_2\"" | 554 "\"address_line_2\"" |
| 529 "]," | 555 "]," |
| 530 "\"administrative_area_name\":\"admin_area_name\"," | 556 "\"administrative_area_name\":\"admin_area_name\"," |
| 531 "\"country_name_code\":\"US\"," | 557 "\"country_name_code\":\"US\"," |
| 532 "\"locality_name\":\"locality_name\"," | 558 "\"locality_name\":\"locality_name\"," |
| 533 "\"postal_code_number\":\"postal_code_number\"," | 559 "\"postal_code_number\":\"postal_code_number\"," |
| 534 "\"recipient_name\":\"recipient_name\"" | 560 "\"recipient_name\":\"recipient_name\"" |
| 535 "}," | 561 "}," |
| 536 "\"upgraded_instrument_id\":\"instrument_id\"" | 562 "\"upgraded_instrument_id\":\"instrument_id\"," |
| 563 "\"use_minimal_addresses\":false" |
| 537 "}"; | 564 "}"; |
| 538 | 565 |
| 539 const char kUpdateInstrumentExpirationDateValidRequest[] = | 566 const char kUpdateInstrumentExpirationDateValidRequest[] = |
| 540 "{" | 567 "{" |
| 541 "\"instrument\":" | 568 "\"instrument\":" |
| 542 "{" | 569 "{" |
| 543 "\"credit_card\":" | 570 "\"credit_card\":" |
| 544 "{" | 571 "{" |
| 545 "\"exp_month\":12," | 572 "\"exp_month\":12," |
| 546 "\"exp_year\":3000" | 573 "\"exp_year\":3000" |
| 547 "}," | 574 "}," |
| 548 "\"type\":\"CREDIT_CARD\"" | 575 "\"type\":\"CREDIT_CARD\"" |
| 549 "}," | 576 "}," |
| 550 "\"merchant_domain\":\"https://example.com/\"," | 577 "\"merchant_domain\":\"https://example.com/\"," |
| 578 "\"phone_number_required\":true," |
| 551 "\"risk_params\":\"risky business\"," | 579 "\"risk_params\":\"risky business\"," |
| 552 "\"upgraded_instrument_id\":\"instrument_id\"" | 580 "\"upgraded_instrument_id\":\"instrument_id\"," |
| 581 "\"use_minimal_addresses\":false" |
| 553 "}"; | 582 "}"; |
| 554 | 583 |
| 555 class MockAutofillMetrics : public AutofillMetrics { | 584 class MockAutofillMetrics : public AutofillMetrics { |
| 556 public: | 585 public: |
| 557 MockAutofillMetrics() {} | 586 MockAutofillMetrics() {} |
| 558 MOCK_CONST_METHOD2(LogWalletApiCallDuration, | 587 MOCK_CONST_METHOD2(LogWalletApiCallDuration, |
| 559 void(WalletApiCallMetric metric, | 588 void(WalletApiCallMetric metric, |
| 560 const base::TimeDelta& duration)); | 589 const base::TimeDelta& duration)); |
| 561 MOCK_CONST_METHOD2(LogWalletErrorMetric, | 590 MOCK_CONST_METHOD2(LogWalletErrorMetric, |
| 562 void(DialogType dialog_type, WalletErrorMetric metric)); | 591 void(DialogType dialog_type, WalletErrorMetric metric)); |
| 563 MOCK_CONST_METHOD2(LogWalletRequiredActionMetric, | 592 MOCK_CONST_METHOD2(LogWalletRequiredActionMetric, |
| 564 void(DialogType dialog_type, | 593 void(DialogType dialog_type, |
| 565 WalletRequiredActionMetric action)); | 594 WalletRequiredActionMetric action)); |
| 566 private: | 595 private: |
| 567 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); | 596 DISALLOW_COPY_AND_ASSIGN(MockAutofillMetrics); |
| 568 }; | 597 }; |
| 569 | 598 |
| 570 class MockWalletClientDelegate : public WalletClientDelegate { | 599 class MockWalletClientDelegate : public WalletClientDelegate { |
| 571 public: | 600 public: |
| 572 MockWalletClientDelegate() | 601 MockWalletClientDelegate() |
| 573 : full_wallets_received_(0), wallet_items_received_(0) {} | 602 : full_wallets_received_(0), |
| 603 wallet_items_received_(0), |
| 604 is_shipping_required_(true) {} |
| 574 ~MockWalletClientDelegate() {} | 605 ~MockWalletClientDelegate() {} |
| 575 | 606 |
| 576 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { | 607 virtual const AutofillMetrics& GetMetricLogger() const OVERRIDE { |
| 577 return metric_logger_; | 608 return metric_logger_; |
| 578 } | 609 } |
| 579 | 610 |
| 580 virtual DialogType GetDialogType() const OVERRIDE { | 611 virtual DialogType GetDialogType() const OVERRIDE { |
| 581 return DIALOG_TYPE_REQUEST_AUTOCOMPLETE; | 612 return DIALOG_TYPE_REQUEST_AUTOCOMPLETE; |
| 582 } | 613 } |
| 583 | 614 |
| 584 virtual std::string GetRiskData() const OVERRIDE { | 615 virtual std::string GetRiskData() const OVERRIDE { |
| 585 return "risky business"; | 616 return "risky business"; |
| 586 } | 617 } |
| 587 | 618 |
| 588 virtual std::string GetWalletCookieValue() const OVERRIDE { | 619 virtual std::string GetWalletCookieValue() const OVERRIDE { |
| 589 return "gdToken"; | 620 return "gdToken"; |
| 590 } | 621 } |
| 591 | 622 |
| 623 virtual bool IsShippingAddressRequired() const OVERRIDE { |
| 624 return is_shipping_required_; |
| 625 } |
| 626 |
| 627 void SetIsShippingAddressRequired(bool is_shipping_required) { |
| 628 is_shipping_required_ = is_shipping_required; |
| 629 } |
| 630 |
| 592 void ExpectLogWalletApiCallDuration( | 631 void ExpectLogWalletApiCallDuration( |
| 593 AutofillMetrics::WalletApiCallMetric metric, | 632 AutofillMetrics::WalletApiCallMetric metric, |
| 594 size_t times) { | 633 size_t times) { |
| 595 EXPECT_CALL(metric_logger_, | 634 EXPECT_CALL(metric_logger_, |
| 596 LogWalletApiCallDuration(metric, testing::_)).Times(times); | 635 LogWalletApiCallDuration(metric, testing::_)).Times(times); |
| 597 } | 636 } |
| 598 | 637 |
| 599 void ExpectWalletErrorMetric(AutofillMetrics::WalletErrorMetric metric) { | 638 void ExpectWalletErrorMetric(AutofillMetrics::WalletErrorMetric metric) { |
| 600 EXPECT_CALL( | 639 EXPECT_CALL( |
| 601 metric_logger_, | 640 metric_logger_, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 OVERRIDE { | 682 OVERRIDE { |
| 644 EXPECT_TRUE(wallet_items); | 683 EXPECT_TRUE(wallet_items); |
| 645 ++wallet_items_received_; | 684 ++wallet_items_received_; |
| 646 } | 685 } |
| 647 size_t full_wallets_received() const { return full_wallets_received_; } | 686 size_t full_wallets_received() const { return full_wallets_received_; } |
| 648 size_t wallet_items_received() const { return wallet_items_received_; } | 687 size_t wallet_items_received() const { return wallet_items_received_; } |
| 649 | 688 |
| 650 private: | 689 private: |
| 651 size_t full_wallets_received_; | 690 size_t full_wallets_received_; |
| 652 size_t wallet_items_received_; | 691 size_t wallet_items_received_; |
| 692 bool is_shipping_required_; |
| 653 | 693 |
| 654 testing::StrictMock<MockAutofillMetrics> metric_logger_; | 694 testing::StrictMock<MockAutofillMetrics> metric_logger_; |
| 655 }; | 695 }; |
| 656 | 696 |
| 657 } // namespace | 697 } // namespace |
| 658 | 698 |
| 659 class WalletClientTest : public testing::Test { | 699 class WalletClientTest : public testing::Test { |
| 660 public: | 700 public: |
| 661 virtual void SetUp() OVERRIDE { | 701 virtual void SetUp() OVERRIDE { |
| 662 wallet_client_.reset( | 702 wallet_client_.reset( |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 delegate_.ExpectBaselineMetrics(); | 1042 delegate_.ExpectBaselineMetrics(); |
| 1003 | 1043 |
| 1004 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1044 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
| 1005 | 1045 |
| 1006 VerifyAndFinishRequest(net::HTTP_OK, | 1046 VerifyAndFinishRequest(net::HTTP_OK, |
| 1007 kGetWalletItemsValidRequest, | 1047 kGetWalletItemsValidRequest, |
| 1008 kGetWalletItemsValidResponse); | 1048 kGetWalletItemsValidResponse); |
| 1009 EXPECT_EQ(1U, delegate_.wallet_items_received()); | 1049 EXPECT_EQ(1U, delegate_.wallet_items_received()); |
| 1010 } | 1050 } |
| 1011 | 1051 |
| 1052 TEST_F(WalletClientTest, GetWalletItemsRespectsDelegateForShippingRequired) { |
| 1053 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
| 1054 1); |
| 1055 delegate_.ExpectBaselineMetrics(); |
| 1056 delegate_.SetIsShippingAddressRequired(false); |
| 1057 |
| 1058 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
| 1059 |
| 1060 VerifyAndFinishRequest(net::HTTP_OK, |
| 1061 kGetWalletItemsNoShippingRequest, |
| 1062 kGetWalletItemsValidResponse); |
| 1063 EXPECT_EQ(1U, delegate_.wallet_items_received()); |
| 1064 } |
| 1065 |
| 1012 TEST_F(WalletClientTest, SaveAddressSucceeded) { | 1066 TEST_F(WalletClientTest, SaveAddressSucceeded) { |
| 1013 EXPECT_CALL(delegate_, | 1067 EXPECT_CALL(delegate_, |
| 1014 OnDidSaveToWallet(std::string(), | 1068 OnDidSaveToWallet(std::string(), |
| 1015 "saved_address_id", | 1069 "saved_address_id", |
| 1016 std::vector<RequiredAction>(), | 1070 std::vector<RequiredAction>(), |
| 1017 std::vector<FormFieldError>())).Times(1); | 1071 std::vector<FormFieldError>())).Times(1); |
| 1018 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1); | 1072 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SAVE_TO_WALLET, 1); |
| 1019 delegate_.ExpectBaselineMetrics(); | 1073 delegate_.ExpectBaselineMetrics(); |
| 1020 | 1074 |
| 1021 scoped_ptr<Address> address = GetTestSaveableAddress(); | 1075 scoped_ptr<Address> address = GetTestSaveableAddress(); |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1569 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1623 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
| 1570 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1624 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
| 1571 | 1625 |
| 1572 wallet_client_->CancelRequests(); | 1626 wallet_client_->CancelRequests(); |
| 1573 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1627 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
| 1574 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1628 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1575 } | 1629 } |
| 1576 | 1630 |
| 1577 } // namespace wallet | 1631 } // namespace wallet |
| 1578 } // namespace autofill | 1632 } // namespace autofill |
| OLD | NEW |