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