OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 MOCK_METHOD2(OnDidSaveAddress, | 557 MOCK_METHOD2(OnDidSaveAddress, |
558 void(const std::string& address_id, | 558 void(const std::string& address_id, |
559 const std::vector<RequiredAction>& required_actions)); | 559 const std::vector<RequiredAction>& required_actions)); |
560 MOCK_METHOD2(OnDidSaveInstrument, | 560 MOCK_METHOD2(OnDidSaveInstrument, |
561 void(const std::string& instrument_id, | 561 void(const std::string& instrument_id, |
562 const std::vector<RequiredAction>& required_actions)); | 562 const std::vector<RequiredAction>& required_actions)); |
563 MOCK_METHOD3(OnDidSaveInstrumentAndAddress, | 563 MOCK_METHOD3(OnDidSaveInstrumentAndAddress, |
564 void(const std::string& instrument_id, | 564 void(const std::string& instrument_id, |
565 const std::string& shipping_address_id, | 565 const std::string& shipping_address_id, |
566 const std::vector<RequiredAction>& required_actions)); | 566 const std::vector<RequiredAction>& required_actions)); |
567 MOCK_METHOD0(OnDidSendAutocheckoutStatus, void()); | |
568 MOCK_METHOD2(OnDidUpdateAddress, | 567 MOCK_METHOD2(OnDidUpdateAddress, |
569 void(const std::string& address_id, | 568 void(const std::string& address_id, |
570 const std::vector<RequiredAction>& required_actions)); | 569 const std::vector<RequiredAction>& required_actions)); |
571 MOCK_METHOD2(OnDidUpdateInstrument, | 570 MOCK_METHOD2(OnDidUpdateInstrument, |
572 void(const std::string& instrument_id, | 571 void(const std::string& instrument_id, |
573 const std::vector<RequiredAction>& required_actions)); | 572 const std::vector<RequiredAction>& required_actions)); |
574 MOCK_METHOD1(OnWalletError, void(WalletClient::ErrorType error_type)); | 573 MOCK_METHOD1(OnWalletError, void(WalletClient::ErrorType error_type)); |
575 MOCK_METHOD0(OnMalformedResponse, void()); | 574 MOCK_METHOD0(OnMalformedResponse, void()); |
576 MOCK_METHOD1(OnNetworkError, void(int response_code)); | 575 MOCK_METHOD1(OnNetworkError, void(int response_code)); |
577 | 576 |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 scoped_ptr<Address> address = GetTestAddress(); | 1467 scoped_ptr<Address> address = GetTestAddress(); |
1469 wallet_client_->UpdateInstrument("instrument_id", | 1468 wallet_client_->UpdateInstrument("instrument_id", |
1470 *address, | 1469 *address, |
1471 GURL(kMerchantUrl)); | 1470 GURL(kMerchantUrl)); |
1472 VerifyAndFinishRequest(net::HTTP_OK, | 1471 VerifyAndFinishRequest(net::HTTP_OK, |
1473 kUpdateInstrumentValidRequest, | 1472 kUpdateInstrumentValidRequest, |
1474 kUpdateMalformedResponse); | 1473 kUpdateMalformedResponse); |
1475 } | 1474 } |
1476 | 1475 |
1477 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { | 1476 TEST_F(WalletClientTest, SendAutocheckoutOfStatusSuccess) { |
1478 EXPECT_CALL(delegate_, OnDidSendAutocheckoutStatus()).Times(1); | |
1479 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 1477 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
1480 | 1478 |
1481 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, | 1479 wallet_client_->SendAutocheckoutStatus(autofill::SUCCESS, |
1482 GURL(kMerchantUrl), | 1480 GURL(kMerchantUrl), |
1483 "google_transaction_id"); | 1481 "google_transaction_id"); |
1484 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 1482 VerifyAndFinishRequest(net::HTTP_OK, |
1485 ASSERT_TRUE(fetcher); | 1483 kSendAutocheckoutStatusOfSuccessValidRequest, |
1486 EXPECT_EQ(kSendAutocheckoutStatusOfSuccessValidRequest, GetData(fetcher)); | 1484 ")]}"); // Invalid JSON. Should be ignored. |
1487 fetcher->SetResponseString(")]}'"); // Invalid JSON. Should be ignored. | |
1488 fetcher->set_response_code(net::HTTP_OK); | |
1489 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
1490 } | 1485 } |
1491 | 1486 |
1492 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { | 1487 TEST_F(WalletClientTest, SendAutocheckoutStatusOfFailure) { |
1493 EXPECT_CALL(delegate_, OnDidSendAutocheckoutStatus()).Times(1); | |
1494 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 1488 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
1495 | 1489 |
1496 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, | 1490 wallet_client_->SendAutocheckoutStatus(autofill::CANNOT_PROCEED, |
1497 GURL(kMerchantUrl), | 1491 GURL(kMerchantUrl), |
1498 "google_transaction_id"); | 1492 "google_transaction_id"); |
1499 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 1493 VerifyAndFinishRequest(net::HTTP_OK, |
1500 ASSERT_TRUE(fetcher); | 1494 kSendAutocheckoutStatusOfFailureValidRequest, |
1501 EXPECT_EQ(kSendAutocheckoutStatusOfFailureValidRequest, GetData(fetcher)); | 1495 ")]}"); // Invalid JSON. Should be ignored. |
1502 fetcher->set_response_code(net::HTTP_OK); | |
1503 fetcher->SetResponseString(")]}'"); // Invalid JSON. Should be ignored. | |
1504 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
1505 } | 1496 } |
1506 | 1497 |
1507 TEST_F(WalletClientTest, HasRequestInProgress) { | 1498 TEST_F(WalletClientTest, HasRequestInProgress) { |
1508 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1499 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1509 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1500 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1510 1); | 1501 1); |
1511 | 1502 |
1512 wallet_client_->GetWalletItems(GURL(kMerchantUrl), | 1503 wallet_client_->GetWalletItems(GURL(kMerchantUrl), |
1513 std::vector<WalletClient::RiskCapability>()); | 1504 std::vector<WalletClient::RiskCapability>()); |
1514 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1505 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1556 wallet_client_->GetWalletItems(GURL(kMerchantUrl), risk_capabilities); | 1547 wallet_client_->GetWalletItems(GURL(kMerchantUrl), risk_capabilities); |
1557 wallet_client_->GetWalletItems(GURL(kMerchantUrl), risk_capabilities); | 1548 wallet_client_->GetWalletItems(GURL(kMerchantUrl), risk_capabilities); |
1558 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1549 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
1559 | 1550 |
1560 wallet_client_->CancelPendingRequests(); | 1551 wallet_client_->CancelPendingRequests(); |
1561 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1552 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
1562 } | 1553 } |
1563 | 1554 |
1564 } // namespace wallet | 1555 } // namespace wallet |
1565 } // namespace autofill | 1556 } // namespace autofill |
OLD | NEW |