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/run_loop.h" | 9 #include "base/run_loop.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 1684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1695 | 1695 |
1696 wallet_client_->GetWalletItems(); | 1696 wallet_client_->GetWalletItems(); |
1697 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); | 1697 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1698 | 1698 |
1699 VerifyAndFinishRequest(net::HTTP_OK, | 1699 VerifyAndFinishRequest(net::HTTP_OK, |
1700 kGetWalletItemsValidRequest, | 1700 kGetWalletItemsValidRequest, |
1701 kGetWalletItemsValidResponse); | 1701 kGetWalletItemsValidResponse); |
1702 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1702 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1703 } | 1703 } |
1704 | 1704 |
1705 TEST_F(WalletClientTest, PendingRequest) { | 1705 TEST_F(WalletClientTest, ErrorResponse) { |
1706 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1706 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1707 | |
1708 // Shouldn't queue the first request. | |
1709 delegate_.ExpectBaselineMetrics(); | 1707 delegate_.ExpectBaselineMetrics(); |
1710 wallet_client_->GetWalletItems(); | 1708 wallet_client_->GetWalletItems(); |
1711 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1709 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1712 testing::Mock::VerifyAndClear(delegate_.metric_logger()); | |
1713 | |
1714 wallet_client_->GetWalletItems(); | |
1715 EXPECT_EQ(1U, wallet_client_->pending_requests_.size()); | |
1716 | |
1717 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | |
1718 1); | |
1719 delegate_.ExpectBaselineMetrics(); | |
1720 VerifyAndFinishRequest(net::HTTP_OK, | |
1721 kGetWalletItemsValidRequest, | |
1722 kGetWalletItemsValidResponse); | |
1723 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | |
1724 testing::Mock::VerifyAndClear(delegate_.metric_logger()); | 1710 testing::Mock::VerifyAndClear(delegate_.metric_logger()); |
1725 | 1711 |
1726 EXPECT_CALL(delegate_, OnWalletError( | 1712 EXPECT_CALL(delegate_, OnWalletError( |
1727 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 1713 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
1728 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1714 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1729 1); | 1715 1); |
1730 delegate_.ExpectWalletErrorMetric( | 1716 delegate_.ExpectWalletErrorMetric( |
1731 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 1717 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
1732 | 1718 |
1733 // Finish the second request. | |
1734 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, | 1719 VerifyAndFinishRequest(net::HTTP_INTERNAL_SERVER_ERROR, |
1735 kGetWalletItemsValidRequest, | 1720 kGetWalletItemsValidRequest, |
1736 kErrorResponse); | 1721 kErrorResponse); |
1737 } | 1722 } |
1738 | 1723 |
1739 TEST_F(WalletClientTest, CancelRequests) { | 1724 TEST_F(WalletClientTest, CancelRequest) { |
1740 ASSERT_EQ(0U, wallet_client_->pending_requests_.size()); | 1725 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1741 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, | 1726 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::GET_WALLET_ITEMS, |
1742 0); | 1727 0); |
1743 delegate_.ExpectBaselineMetrics(); | 1728 delegate_.ExpectBaselineMetrics(); |
1744 | 1729 |
1745 wallet_client_->GetWalletItems(); | 1730 wallet_client_->GetWalletItems(); |
1746 wallet_client_->GetWalletItems(); | 1731 EXPECT_TRUE(wallet_client_->HasRequestInProgress()); |
1747 wallet_client_->GetWalletItems(); | 1732 wallet_client_->CancelRequest(); |
1748 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | |
1749 | |
1750 wallet_client_->CancelRequests(); | |
1751 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | |
1752 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1733 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1753 } | 1734 } |
1754 | 1735 |
1755 } // namespace wallet | 1736 } // namespace wallet |
1756 } // namespace autofill | 1737 } // namespace autofill |
OLD | NEW |