| 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/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "chrome/test/base/testing_profile.h" | |
| 7 #include "components/autofill/content/browser/wallet/encryption_escrow_client.h" | 6 #include "components/autofill/content/browser/wallet/encryption_escrow_client.h" |
| 8 #include "components/autofill/content/browser/wallet/encryption_escrow_client_ob
server.h" | 7 #include "components/autofill/content/browser/wallet/encryption_escrow_client_ob
server.h" |
| 9 #include "components/autofill/content/browser/wallet/instrument.h" | 8 #include "components/autofill/content/browser/wallet/instrument.h" |
| 10 #include "components/autofill/content/browser/wallet/wallet_test_util.h" | 9 #include "components/autofill/content/browser/wallet/wallet_test_util.h" |
| 10 #include "content/public/test/test_browser_context.h" |
| 11 #include "content/public/test/test_browser_thread.h" | 11 #include "content/public/test/test_browser_thread.h" |
| 12 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 13 #include "net/base/net_errors.h" | 13 #include "net/base/net_errors.h" |
| 14 #include "net/http/http_status_code.h" | 14 #include "net/http/http_status_code.h" |
| 15 #include "net/url_request/test_url_fetcher_factory.h" | 15 #include "net/url_request/test_url_fetcher_factory.h" |
| 16 #include "net/url_request/url_fetcher_delegate.h" | 16 #include "net/url_request/url_fetcher_delegate.h" |
| 17 #include "net/url_request/url_request_status.h" | 17 #include "net/url_request/url_request_status.h" |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 | 20 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 : EncryptionEscrowClient(context_getter, observer) {} | 59 : EncryptionEscrowClient(context_getter, observer) {} |
| 60 | 60 |
| 61 bool HasRequestInProgress() const { | 61 bool HasRequestInProgress() const { |
| 62 return request() != NULL; | 62 return request() != NULL; |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 class EncryptionEscrowClientTest : public testing::Test { | 66 class EncryptionEscrowClientTest : public testing::Test { |
| 67 public: | 67 public: |
| 68 EncryptionEscrowClientTest() | 68 EncryptionEscrowClientTest() |
| 69 : instrument_(GetTestInstrument()), | 69 : instrument_(GetTestInstrument()) {} |
| 70 io_thread_(content::BrowserThread::IO) {} | |
| 71 | 70 |
| 72 virtual void SetUp() OVERRIDE { | 71 virtual void SetUp() OVERRIDE { |
| 73 io_thread_.StartIOThread(); | |
| 74 profile_.CreateRequestContext(); | |
| 75 encryption_escrow_client_.reset(new TestEncryptionEscrowClient( | 72 encryption_escrow_client_.reset(new TestEncryptionEscrowClient( |
| 76 profile_.GetRequestContext(), &observer_)); | 73 browser_context_.GetRequestContext(), &observer_)); |
| 77 } | 74 } |
| 78 | 75 |
| 79 virtual void TearDown() OVERRIDE { | 76 virtual void TearDown() OVERRIDE { |
| 80 encryption_escrow_client_.reset(); | 77 encryption_escrow_client_.reset(); |
| 81 profile_.ResetRequestContext(); | |
| 82 io_thread_.Stop(); | |
| 83 } | 78 } |
| 84 | 79 |
| 85 std::vector<uint8> MakeOneTimePad() { | 80 std::vector<uint8> MakeOneTimePad() { |
| 86 std::vector<uint8> one_time_pad; | 81 std::vector<uint8> one_time_pad; |
| 87 one_time_pad.push_back(0); | 82 one_time_pad.push_back(0); |
| 88 one_time_pad.push_back(1); | 83 one_time_pad.push_back(1); |
| 89 one_time_pad.push_back(2); | 84 one_time_pad.push_back(2); |
| 90 one_time_pad.push_back(3); | 85 one_time_pad.push_back(3); |
| 91 one_time_pad.push_back(4); | 86 one_time_pad.push_back(4); |
| 92 one_time_pad.push_back(5); | 87 one_time_pad.push_back(5); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 104 fetcher->delegate()->OnURLFetchComplete(fetcher); | 99 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 105 } | 100 } |
| 106 | 101 |
| 107 protected: | 102 protected: |
| 108 scoped_ptr<TestEncryptionEscrowClient> encryption_escrow_client_; | 103 scoped_ptr<TestEncryptionEscrowClient> encryption_escrow_client_; |
| 109 testing::StrictMock<MockEncryptionEscrowClientObserver> observer_; | 104 testing::StrictMock<MockEncryptionEscrowClientObserver> observer_; |
| 110 scoped_ptr<Instrument> instrument_; | 105 scoped_ptr<Instrument> instrument_; |
| 111 | 106 |
| 112 | 107 |
| 113 private: | 108 private: |
| 114 // The profile's request context must be released on the IO thread. | 109 content::TestBrowserContext browser_context_; |
| 115 content::TestBrowserThread io_thread_; | |
| 116 TestingProfile profile_; | |
| 117 net::TestURLFetcherFactory factory_; | 110 net::TestURLFetcherFactory factory_; |
| 118 }; | 111 }; |
| 119 | 112 |
| 120 TEST_F(EncryptionEscrowClientTest, NetworkError) { | 113 TEST_F(EncryptionEscrowClientTest, NetworkError) { |
| 121 EXPECT_CALL(observer_, OnDidMakeRequest()).Times(1); | 114 EXPECT_CALL(observer_, OnDidMakeRequest()).Times(1); |
| 122 EXPECT_CALL(observer_, OnNetworkError()).Times(1); | 115 EXPECT_CALL(observer_, OnNetworkError()).Times(1); |
| 123 | 116 |
| 124 encryption_escrow_client_->EscrowInstrumentInformation(*instrument_, | 117 encryption_escrow_client_->EscrowInstrumentInformation(*instrument_, |
| 125 "obfuscated_gaia_id"); | 118 "obfuscated_gaia_id"); |
| 126 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, | 119 VerifyAndFinishRequest(net::HTTP_UNAUTHORIZED, |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 188 |
| 196 encryption_escrow_client_->EncryptOneTimePad(MakeOneTimePad()); | 189 encryption_escrow_client_->EncryptOneTimePad(MakeOneTimePad()); |
| 197 EXPECT_TRUE(encryption_escrow_client_->HasRequestInProgress()); | 190 EXPECT_TRUE(encryption_escrow_client_->HasRequestInProgress()); |
| 198 | 191 |
| 199 encryption_escrow_client_->CancelRequest(); | 192 encryption_escrow_client_->CancelRequest(); |
| 200 EXPECT_FALSE(encryption_escrow_client_->HasRequestInProgress()); | 193 EXPECT_FALSE(encryption_escrow_client_->HasRequestInProgress()); |
| 201 } | 194 } |
| 202 | 195 |
| 203 } // namespace wallet | 196 } // namespace wallet |
| 204 } // namespace autofill | 197 } // namespace autofill |
| OLD | NEW |