| 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_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/test/base/testing_profile.h" | |
| 13 #include "components/autofill/content/browser/wallet/full_wallet.h" | 12 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 14 #include "components/autofill/content/browser/wallet/instrument.h" | 13 #include "components/autofill/content/browser/wallet/instrument.h" |
| 15 #include "components/autofill/content/browser/wallet/wallet_client.h" | 14 #include "components/autofill/content/browser/wallet/wallet_client.h" |
| 16 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" | 15 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" |
| 17 #include "components/autofill/content/browser/wallet/wallet_items.h" | 16 #include "components/autofill/content/browser/wallet/wallet_items.h" |
| 18 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 17 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
| 19 #include "components/autofill/core/browser/autofill_metrics.h" | 18 #include "components/autofill/core/browser/autofill_metrics.h" |
| 20 #include "components/autofill/core/common/autocheckout_status.h" | 19 #include "components/autofill/core/common/autocheckout_status.h" |
| 20 #include "content/public/test/test_browser_context.h" |
| 21 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
| 22 #include "googleurl/src/gurl.h" | 22 #include "googleurl/src/gurl.h" |
| 23 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 24 #include "net/http/http_status_code.h" | 24 #include "net/http/http_status_code.h" |
| 25 #include "net/url_request/test_url_fetcher_factory.h" | 25 #include "net/url_request/test_url_fetcher_factory.h" |
| 26 #include "net/url_request/url_fetcher_delegate.h" | 26 #include "net/url_request/url_fetcher_delegate.h" |
| 27 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 size_t full_wallets_received_; | 722 size_t full_wallets_received_; |
| 723 size_t wallet_items_received_; | 723 size_t wallet_items_received_; |
| 724 | 724 |
| 725 testing::StrictMock<MockAutofillMetrics> metric_logger_; | 725 testing::StrictMock<MockAutofillMetrics> metric_logger_; |
| 726 }; | 726 }; |
| 727 | 727 |
| 728 } // namespace | 728 } // namespace |
| 729 | 729 |
| 730 class WalletClientTest : public testing::Test { | 730 class WalletClientTest : public testing::Test { |
| 731 public: | 731 public: |
| 732 WalletClientTest() : io_thread_(content::BrowserThread::IO) {} | 732 WalletClientTest() {} |
| 733 | 733 |
| 734 virtual void SetUp() OVERRIDE { | 734 virtual void SetUp() OVERRIDE { |
| 735 io_thread_.StartIOThread(); | |
| 736 profile_.CreateRequestContext(); | |
| 737 wallet_client_.reset( | 735 wallet_client_.reset( |
| 738 new WalletClient(profile_.GetRequestContext(), &delegate_)); | 736 new WalletClient(browser_context_.GetRequestContext(), &delegate_)); |
| 739 } | 737 } |
| 740 | 738 |
| 741 virtual void TearDown() OVERRIDE { | 739 virtual void TearDown() OVERRIDE { |
| 742 wallet_client_.reset(); | 740 wallet_client_.reset(); |
| 743 profile_.ResetRequestContext(); | |
| 744 io_thread_.Stop(); | |
| 745 } | 741 } |
| 746 | 742 |
| 747 std::string GetData(net::TestURLFetcher* fetcher) { | 743 std::string GetData(net::TestURLFetcher* fetcher) { |
| 748 std::string data = fetcher->upload_data(); | 744 std::string data = fetcher->upload_data(); |
| 749 scoped_ptr<Value> root(base::JSONReader::Read(data)); | 745 scoped_ptr<Value> root(base::JSONReader::Read(data)); |
| 750 | 746 |
| 751 // If this is not a JSON dictionary, return plain text. | 747 // If this is not a JSON dictionary, return plain text. |
| 752 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) | 748 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) |
| 753 return data; | 749 return data; |
| 754 | 750 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 774 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 770 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 775 ASSERT_TRUE(fetcher); | 771 ASSERT_TRUE(fetcher); |
| 776 EXPECT_EQ(request_body, GetData(fetcher)); | 772 EXPECT_EQ(request_body, GetData(fetcher)); |
| 777 fetcher->set_response_code(response_code); | 773 fetcher->set_response_code(response_code); |
| 778 fetcher->SetResponseString(response_body); | 774 fetcher->SetResponseString(response_body); |
| 779 fetcher->delegate()->OnURLFetchComplete(fetcher); | 775 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 780 } | 776 } |
| 781 | 777 |
| 782 protected: | 778 protected: |
| 783 scoped_ptr<WalletClient> wallet_client_; | 779 scoped_ptr<WalletClient> wallet_client_; |
| 780 content::TestBrowserContext browser_context_; |
| 784 MockWalletClientDelegate delegate_; | 781 MockWalletClientDelegate delegate_; |
| 785 | 782 |
| 786 private: | 783 private: |
| 787 // The profile's request context must be released on the IO thread. | |
| 788 content::TestBrowserThread io_thread_; | |
| 789 TestingProfile profile_; | |
| 790 net::TestURLFetcherFactory factory_; | 784 net::TestURLFetcherFactory factory_; |
| 791 }; | 785 }; |
| 792 | 786 |
| 793 TEST_F(WalletClientTest, WalletError) { | 787 TEST_F(WalletClientTest, WalletError) { |
| 794 EXPECT_CALL(delegate_, OnWalletError( | 788 EXPECT_CALL(delegate_, OnWalletError( |
| 795 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 789 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
| 796 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 790 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
| 797 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); | 791 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); |
| 798 delegate_.ExpectWalletErrorMetric( | 792 delegate_.ExpectWalletErrorMetric( |
| 799 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 793 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1805 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
| 1812 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1806 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
| 1813 | 1807 |
| 1814 wallet_client_->CancelRequests(); | 1808 wallet_client_->CancelRequests(); |
| 1815 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1809 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
| 1816 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1810 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1817 } | 1811 } |
| 1818 | 1812 |
| 1819 } // namespace wallet | 1813 } // namespace wallet |
| 1820 } // namespace autofill | 1814 } // namespace autofill |
| OLD | NEW |