OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 5 #include "base/logging.h" |
6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/autofill/wallet/cart.h" | 8 #include "chrome/browser/autofill/wallet/cart.h" |
9 #include "chrome/browser/autofill/wallet/full_wallet.h" | 9 #include "chrome/browser/autofill/wallet/full_wallet.h" |
10 #include "chrome/browser/autofill/wallet/wallet_client.h" | 10 #include "chrome/browser/autofill/wallet/wallet_client.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 | 160 |
161 const char kSendExtendedAutofillStatusOfFailureValidRequest[] = | 161 const char kSendExtendedAutofillStatusOfFailureValidRequest[] = |
162 "{" | 162 "{" |
163 "\"api_key\":\"abcdefg\"," | 163 "\"api_key\":\"abcdefg\"," |
164 "\"google_transaction_id\":\"google_transaction_id\"," | 164 "\"google_transaction_id\":\"google_transaction_id\"," |
165 "\"hostname\":\"hostname\"," | 165 "\"hostname\":\"hostname\"," |
166 "\"reason\":\"CANNOT_PROCEED\"," | 166 "\"reason\":\"CANNOT_PROCEED\"," |
167 "\"success\":false" | 167 "\"success\":false" |
168 "}"; | 168 "}"; |
169 | 169 |
170 const char kEscrowSensitiveInformationRequest[] = | |
171 "gid=obfuscated_gaia_id&cardNumber=pan&cvv=cvn"; | |
172 | |
170 } // anonymous namespace | 173 } // anonymous namespace |
171 | 174 |
172 namespace wallet { | 175 namespace wallet { |
173 | 176 |
174 class WalletClientTest : public testing::Test { | 177 class WalletClientTest : public testing::Test { |
175 public: | 178 public: |
176 WalletClientTest() : io_thread_(content::BrowserThread::IO) {} | 179 WalletClientTest() : io_thread_(content::BrowserThread::IO) {} |
177 | 180 |
178 virtual void SetUp() { | 181 virtual void SetUp() { |
179 io_thread_.StartIOThread(); | 182 io_thread_.StartIOThread(); |
(...skipping 15 matching lines...) Expand all Loading... | |
195 | 198 |
196 class MockWalletClientObserver | 199 class MockWalletClientObserver |
197 : public wallet::WalletClient::WalletClientObserver { | 200 : public wallet::WalletClient::WalletClientObserver { |
198 public: | 201 public: |
199 MockWalletClientObserver() {} | 202 MockWalletClientObserver() {} |
200 ~MockWalletClientObserver() {} | 203 ~MockWalletClientObserver() {} |
201 | 204 |
202 MOCK_METHOD0(OnAcceptLegalDocuments, void()); | 205 MOCK_METHOD0(OnAcceptLegalDocuments, void()); |
203 MOCK_METHOD2(OnEncryptOtp, void(const std::string& encrypted_otp, | 206 MOCK_METHOD2(OnEncryptOtp, void(const std::string& encrypted_otp, |
204 const std::string& session_material)); | 207 const std::string& session_material)); |
208 MOCK_METHOD1(OnEscrowSensitiveInformation, | |
209 void(const std::string& escrow_handle)); | |
205 MOCK_METHOD1(OnGetFullWallet, void(FullWallet* full_wallet)); | 210 MOCK_METHOD1(OnGetFullWallet, void(FullWallet* full_wallet)); |
206 MOCK_METHOD1(OnGetWalletItems, void(WalletItems* wallet_items)); | 211 MOCK_METHOD1(OnGetWalletItems, void(WalletItems* wallet_items)); |
207 MOCK_METHOD0(OnSendExtendedAutofillStatus, void()); | 212 MOCK_METHOD0(OnSendExtendedAutofillStatus, void()); |
208 MOCK_METHOD0(OnWalletError, void()); | 213 MOCK_METHOD0(OnWalletError, void()); |
209 MOCK_METHOD1(OnNetworkError, void(int response_code)); | 214 MOCK_METHOD1(OnNetworkError, void(int response_code)); |
210 }; | 215 }; |
211 | 216 |
212 // TODO(ahutter): Implement API compatibility tests. See | 217 // TODO(ahutter): Implement API compatibility tests. See |
213 // http://crbug.com/164465. | 218 // http://crbug.com/164465. |
214 | 219 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 287 |
283 WalletClient wallet_client(profile_.GetRequestContext()); | 288 WalletClient wallet_client(profile_.GetRequestContext()); |
284 wallet_client.SendExtendedAutofillStatus(true, "", "", "", &observer); | 289 wallet_client.SendExtendedAutofillStatus(true, "", "", "", &observer); |
285 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 290 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
286 DCHECK(fetcher); | 291 DCHECK(fetcher); |
287 fetcher->set_response_code(net::HTTP_BAD_REQUEST); | 292 fetcher->set_response_code(net::HTTP_BAD_REQUEST); |
288 fetcher->delegate()->OnURLFetchComplete(fetcher); | 293 fetcher->delegate()->OnURLFetchComplete(fetcher); |
289 } | 294 } |
290 | 295 |
291 // TODO(ahutter): Add test for EncryptOtp. | 296 // TODO(ahutter): Add test for EncryptOtp. |
292 // TODO(ahutter): Add retry and failure tests for EncryptOtp, GetWalletItems, | 297 // TODO(ahutter): Add failure tests for EncryptOtp, GetWalletItems, |
293 // GetFullWallet for when data is missing or invalid. | 298 // GetFullWallet for when data is missing or invalid. |
294 | 299 |
300 TEST_F(WalletClientTest, EscrowSensitiveInformationSuccess) { | |
301 MockWalletClientObserver observer; | |
302 EXPECT_CALL(observer, OnEscrowSensitiveInformation("abc")).Times(1); | |
303 | |
304 net::TestURLFetcherFactory factory; | |
305 | |
306 WalletClient wallet_client(profile_.GetRequestContext()); | |
307 wallet_client.EscrowSensitiveInformation("pan", | |
308 "cvn", | |
309 "obfuscated_gaia_id", | |
310 &observer); | |
311 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
312 DCHECK(fetcher); | |
Ilya Sherman
2013/01/09 23:30:48
Unit tests should not use DCHECKs, as they can cra
ahutter
2013/01/10 00:24:46
Done.
| |
313 ASSERT_EQ(kEscrowSensitiveInformationRequest, fetcher->upload_data()); | |
Ilya Sherman
2013/01/09 23:30:48
nit: I think Chrome code prefers EXPECT_EQ for thi
ahutter
2013/01/10 00:24:46
Done.
| |
314 fetcher->set_response_code(net::HTTP_OK); | |
315 fetcher->SetResponseString("abc"); | |
316 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
317 } | |
318 | |
319 TEST_F(WalletClientTest, EscrowSensitiveInformationFailure) { | |
320 MockWalletClientObserver observer; | |
321 EXPECT_CALL(observer, OnWalletError()).Times(1); | |
322 | |
323 net::TestURLFetcherFactory factory; | |
324 | |
325 WalletClient wallet_client(profile_.GetRequestContext()); | |
326 wallet_client.EscrowSensitiveInformation("pan", | |
327 "cvn", | |
328 "obfuscated_gaia_id", | |
329 &observer); | |
330 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | |
331 DCHECK(fetcher); | |
332 ASSERT_EQ(kEscrowSensitiveInformationRequest, fetcher->upload_data()); | |
333 fetcher->set_response_code(net::HTTP_OK); | |
334 fetcher->SetResponseString(""); | |
335 fetcher->delegate()->OnURLFetchComplete(fetcher); | |
336 } | |
337 | |
295 TEST_F(WalletClientTest, GetFullWallet) { | 338 TEST_F(WalletClientTest, GetFullWallet) { |
296 MockWalletClientObserver observer; | 339 MockWalletClientObserver observer; |
297 EXPECT_CALL(observer, OnGetFullWallet(testing::NotNull())).Times(1); | 340 EXPECT_CALL(observer, OnGetFullWallet(testing::NotNull())).Times(1); |
298 | 341 |
299 net::TestURLFetcherFactory factory; | 342 net::TestURLFetcherFactory factory; |
300 | 343 |
301 WalletClient wallet_client(profile_.GetRequestContext()); | 344 WalletClient wallet_client(profile_.GetRequestContext()); |
302 Cart cart("currency_code", "currency_code"); | 345 Cart cart("currency_code", "currency_code"); |
303 wallet_client.GetFullWallet("instrument_id", | 346 wallet_client.GetFullWallet("instrument_id", |
304 "shipping_address_id", | 347 "shipping_address_id", |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 430 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
388 DCHECK(fetcher); | 431 DCHECK(fetcher); |
389 ASSERT_EQ(kSendExtendedAutofillStatusOfFailureValidRequest, | 432 ASSERT_EQ(kSendExtendedAutofillStatusOfFailureValidRequest, |
390 fetcher->upload_data()); | 433 fetcher->upload_data()); |
391 fetcher->set_response_code(net::HTTP_OK); | 434 fetcher->set_response_code(net::HTTP_OK); |
392 fetcher->delegate()->OnURLFetchComplete(fetcher); | 435 fetcher->delegate()->OnURLFetchComplete(fetcher); |
393 } | 436 } |
394 | 437 |
395 } // namespace wallet | 438 } // namespace wallet |
396 | 439 |
OLD | NEW |