| 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/browser/autofill_metrics.h" | 12 #include "components/autofill/browser/autofill_metrics.h" |
| 14 #include "components/autofill/content/browser/wallet/full_wallet.h" | 13 #include "components/autofill/content/browser/wallet/full_wallet.h" |
| 15 #include "components/autofill/content/browser/wallet/instrument.h" | 14 #include "components/autofill/content/browser/wallet/instrument.h" |
| 16 #include "components/autofill/content/browser/wallet/wallet_client.h" | 15 #include "components/autofill/content/browser/wallet/wallet_client.h" |
| 17 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" | 16 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" |
| 18 #include "components/autofill/content/browser/wallet/wallet_items.h" | 17 #include "components/autofill/content/browser/wallet/wallet_items.h" |
| 19 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 18 #include "components/autofill/content/browser/wallet/wallet_test_util.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 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() : io_thread_(content::BrowserThread::IO) {} |
| 733 | 733 |
| 734 virtual void SetUp() OVERRIDE { | 734 virtual void SetUp() OVERRIDE { |
| 735 io_thread_.StartIOThread(); | 735 io_thread_.StartIOThread(); |
| 736 profile_.CreateRequestContext(); | |
| 737 wallet_client_.reset( | 736 wallet_client_.reset( |
| 738 new WalletClient(profile_.GetRequestContext(), &delegate_)); | 737 new WalletClient(browser_context_.GetRequestContext(), &delegate_)); |
| 739 } | 738 } |
| 740 | 739 |
| 741 virtual void TearDown() OVERRIDE { | 740 virtual void TearDown() OVERRIDE { |
| 742 wallet_client_.reset(); | 741 wallet_client_.reset(); |
| 743 profile_.ResetRequestContext(); | |
| 744 io_thread_.Stop(); | 742 io_thread_.Stop(); |
| 745 } | 743 } |
| 746 | 744 |
| 747 std::string GetData(net::TestURLFetcher* fetcher) { | 745 std::string GetData(net::TestURLFetcher* fetcher) { |
| 748 std::string data = fetcher->upload_data(); | 746 std::string data = fetcher->upload_data(); |
| 749 scoped_ptr<Value> root(base::JSONReader::Read(data)); | 747 scoped_ptr<Value> root(base::JSONReader::Read(data)); |
| 750 | 748 |
| 751 // If this is not a JSON dictionary, return plain text. | 749 // If this is not a JSON dictionary, return plain text. |
| 752 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) | 750 if (root.get() == NULL || !root->IsType(Value::TYPE_DICTIONARY)) |
| 753 return data; | 751 return data; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 774 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); | 772 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 775 ASSERT_TRUE(fetcher); | 773 ASSERT_TRUE(fetcher); |
| 776 EXPECT_EQ(request_body, GetData(fetcher)); | 774 EXPECT_EQ(request_body, GetData(fetcher)); |
| 777 fetcher->set_response_code(response_code); | 775 fetcher->set_response_code(response_code); |
| 778 fetcher->SetResponseString(response_body); | 776 fetcher->SetResponseString(response_body); |
| 779 fetcher->delegate()->OnURLFetchComplete(fetcher); | 777 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 780 } | 778 } |
| 781 | 779 |
| 782 protected: | 780 protected: |
| 783 scoped_ptr<WalletClient> wallet_client_; | 781 scoped_ptr<WalletClient> wallet_client_; |
| 782 content::TestBrowserContext browser_context_; |
| 784 MockWalletClientDelegate delegate_; | 783 MockWalletClientDelegate delegate_; |
| 785 | 784 |
| 786 private: | 785 private: |
| 787 // The profile's request context must be released on the IO thread. | 786 // The profile's request context must be released on the IO thread. |
| 788 content::TestBrowserThread io_thread_; | 787 content::TestBrowserThread io_thread_; |
| 789 TestingProfile profile_; | |
| 790 net::TestURLFetcherFactory factory_; | 788 net::TestURLFetcherFactory factory_; |
| 791 }; | 789 }; |
| 792 | 790 |
| 793 TEST_F(WalletClientTest, WalletError) { | 791 TEST_F(WalletClientTest, WalletError) { |
| 794 EXPECT_CALL(delegate_, OnWalletError( | 792 EXPECT_CALL(delegate_, OnWalletError( |
| 795 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 793 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
| 796 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 794 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
| 797 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); | 795 delegate_.ExpectBaselineMetrics(NO_ESCROW_REQUEST, HAS_WALLET_REQUEST); |
| 798 delegate_.ExpectWalletErrorMetric( | 796 delegate_.ExpectWalletErrorMetric( |
| 799 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 797 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
| (...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1811 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1809 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
| 1812 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1810 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
| 1813 | 1811 |
| 1814 wallet_client_->CancelRequests(); | 1812 wallet_client_->CancelRequests(); |
| 1815 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1813 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
| 1816 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1814 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
| 1817 } | 1815 } |
| 1818 | 1816 |
| 1819 } // namespace wallet | 1817 } // namespace wallet |
| 1820 } // namespace autofill | 1818 } // namespace autofill |
| OLD | NEW |