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" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "components/autofill/content/browser/autocheckout_steps.h" | 13 #include "components/autofill/content/browser/autocheckout_steps.h" |
14 #include "components/autofill/content/browser/wallet/full_wallet.h" | 14 #include "components/autofill/content/browser/wallet/full_wallet.h" |
15 #include "components/autofill/content/browser/wallet/instrument.h" | 15 #include "components/autofill/content/browser/wallet/instrument.h" |
16 #include "components/autofill/content/browser/wallet/wallet_client.h" | 16 #include "components/autofill/content/browser/wallet/wallet_client.h" |
17 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" | 17 #include "components/autofill/content/browser/wallet/wallet_client_delegate.h" |
18 #include "components/autofill/content/browser/wallet/wallet_items.h" | 18 #include "components/autofill/content/browser/wallet/wallet_items.h" |
19 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 19 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
20 #include "components/autofill/core/browser/autofill_metrics.h" | 20 #include "components/autofill/core/browser/autofill_metrics.h" |
21 #include "components/autofill/core/common/autocheckout_status.h" | 21 #include "components/autofill/core/common/autocheckout_status.h" |
22 #include "content/public/test/test_browser_context.h" | 22 #include "content/public/test/test_browser_context.h" |
23 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread_bundle.h" |
24 #include "net/base/escape.h" | 24 #include "net/base/escape.h" |
25 #include "net/base/net_errors.h" | 25 #include "net/base/net_errors.h" |
26 #include "net/http/http_request_headers.h" | 26 #include "net/http/http_request_headers.h" |
27 #include "net/http/http_status_code.h" | 27 #include "net/http/http_status_code.h" |
28 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
29 #include "net/url_request/url_fetcher_delegate.h" | 29 #include "net/url_request/url_fetcher_delegate.h" |
30 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
31 #include "testing/gmock/include/gmock/gmock.h" | 31 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 32 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "url/gurl.h" | 33 #include "url/gurl.h" |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 size_t full_wallets_received_; | 651 size_t full_wallets_received_; |
652 size_t wallet_items_received_; | 652 size_t wallet_items_received_; |
653 | 653 |
654 testing::StrictMock<MockAutofillMetrics> metric_logger_; | 654 testing::StrictMock<MockAutofillMetrics> metric_logger_; |
655 }; | 655 }; |
656 | 656 |
657 } // namespace | 657 } // namespace |
658 | 658 |
659 class WalletClientTest : public testing::Test { | 659 class WalletClientTest : public testing::Test { |
660 public: | 660 public: |
661 WalletClientTest() {} | |
662 | |
663 virtual void SetUp() OVERRIDE { | 661 virtual void SetUp() OVERRIDE { |
664 wallet_client_.reset( | 662 wallet_client_.reset( |
665 new WalletClient(browser_context_.GetRequestContext(), &delegate_)); | 663 new WalletClient(browser_context_.GetRequestContext(), &delegate_)); |
666 } | 664 } |
667 | 665 |
668 virtual void TearDown() OVERRIDE { | 666 virtual void TearDown() OVERRIDE { |
669 wallet_client_.reset(); | 667 wallet_client_.reset(); |
670 } | 668 } |
671 | 669 |
672 void VerifyAndFinishRequest(net::HttpStatusCode response_code, | 670 void VerifyAndFinishRequest(net::HttpStatusCode response_code, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
765 return upload_data; | 763 return upload_data; |
766 | 764 |
767 // Remove api_key entry (to prevent accidental leak), return JSON as text. | 765 // Remove api_key entry (to prevent accidental leak), return JSON as text. |
768 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get()); | 766 DictionaryValue* dict = static_cast<DictionaryValue*>(root.get()); |
769 dict->Remove("api_key", NULL); | 767 dict->Remove("api_key", NULL); |
770 std::string clean_upload_data; | 768 std::string clean_upload_data; |
771 base::JSONWriter::Write(dict, &clean_upload_data); | 769 base::JSONWriter::Write(dict, &clean_upload_data); |
772 return clean_upload_data; | 770 return clean_upload_data; |
773 } | 771 } |
774 | 772 |
| 773 // The profile's request context must be released on the IO thread. |
| 774 content::TestBrowserThreadBundle thread_bundle_; |
| 775 |
775 net::TestURLFetcherFactory factory_; | 776 net::TestURLFetcherFactory factory_; |
776 }; | 777 }; |
777 | 778 |
778 TEST_F(WalletClientTest, WalletError) { | 779 TEST_F(WalletClientTest, WalletError) { |
779 EXPECT_CALL(delegate_, OnWalletError( | 780 EXPECT_CALL(delegate_, OnWalletError( |
780 WalletClient::SERVICE_UNAVAILABLE)).Times(1); | 781 WalletClient::SERVICE_UNAVAILABLE)).Times(1); |
781 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); | 782 delegate_.ExpectLogWalletApiCallDuration(AutofillMetrics::SEND_STATUS, 1); |
782 delegate_.ExpectBaselineMetrics(); | 783 delegate_.ExpectBaselineMetrics(); |
783 delegate_.ExpectWalletErrorMetric( | 784 delegate_.ExpectWalletErrorMetric( |
784 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); | 785 AutofillMetrics::WALLET_SERVICE_UNAVAILABLE); |
(...skipping 783 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1568 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); | 1569 wallet_client_->GetWalletItems(GURL(kMerchantUrl)); |
1569 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); | 1570 EXPECT_EQ(2U, wallet_client_->pending_requests_.size()); |
1570 | 1571 |
1571 wallet_client_->CancelRequests(); | 1572 wallet_client_->CancelRequests(); |
1572 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); | 1573 EXPECT_EQ(0U, wallet_client_->pending_requests_.size()); |
1573 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); | 1574 EXPECT_FALSE(wallet_client_->HasRequestInProgress()); |
1574 } | 1575 } |
1575 | 1576 |
1576 } // namespace wallet | 1577 } // namespace wallet |
1577 } // namespace autofill | 1578 } // namespace autofill |
OLD | NEW |