Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: chrome/browser/autofill/wallet/wallet_items_unittest.cc

Issue 11777007: Adds wallet::RequiredAction for when we start interacting with Online Wallet. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ahutter@ review Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/autofill/wallet/required_action.h"
9 #include "chrome/browser/autofill/wallet/wallet_items.h" 10 #include "chrome/browser/autofill/wallet/wallet_items.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace { 13 namespace {
13 14
14 const char kMaskedInstrument[] = 15 const char kMaskedInstrument[] =
15 "{" 16 "{"
16 " \"descriptive_name\":\"descriptive_name\"," 17 " \"descriptive_name\":\"descriptive_name\","
17 " \"type\":\"VISA\"," 18 " \"type\":\"VISA\","
18 " \"supported_currency\":" 19 " \"supported_currency\":"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 "{" 207 "{"
207 " \"legal_document_id\":\"doc_id\"," 208 " \"legal_document_id\":\"doc_id\","
208 " \"display_name\":\"display_name\"" 209 " \"display_name\":\"display_name\""
209 "}"; 210 "}";
210 211
211 const char kWalletItemsWithRequiredActions[] = 212 const char kWalletItemsWithRequiredActions[] =
212 "{" 213 "{"
213 " \"google_transaction_id\":\"google_transaction_id\"," 214 " \"google_transaction_id\":\"google_transaction_id\","
214 " \"required_action\":" 215 " \"required_action\":"
215 " [" 216 " ["
216 " \"required_action\"" 217 " \" setup_wallet\","
218 " \"AcCePt_ToS \","
219 " \" \\tGAIA_auth \\n\\r\","
220 " \"INVALID_form_field\""
217 " ]" 221 " ]"
218 "}"; 222 "}";
219 223
224 const char kWalletItemsWithInvalidRequiredActions[] =
225 "{"
226 " \"google_transaction_id\":\"google_transaction_id\","
227 " \"required_action\":"
228 " ["
229 " \"cvc_risk_CHALLENGE\","
230 " \"UPGRADE_MIN_ADDRESS\","
231 " \"update_EXPIRATION_date\","
232 " \" 忍者の正体 \""
233 " ]"
234 "}";
235
220 const char kWalletItems[] = 236 const char kWalletItems[] =
221 "{" 237 "{"
222 " \"required_action\":" 238 " \"required_action\":"
223 " [" 239 " ["
224 " ]," 240 " ],"
225 " \"google_transaction_id\":\"google_transaction_id\"," 241 " \"google_transaction_id\":\"google_transaction_id\","
226 " \"instrument\":" 242 " \"instrument\":"
227 " [" 243 " ["
228 " {" 244 " {"
229 " \"descriptive_name\":\"descriptive_name\"," 245 " \"descriptive_name\":\"descriptive_name\","
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 394
379 TEST_F(WalletItemsTest, CreateLegalDocument) { 395 TEST_F(WalletItemsTest, CreateLegalDocument) {
380 SetUpDictionary(kLegalDocument); 396 SetUpDictionary(kLegalDocument);
381 WalletItems::LegalDocument expected("doc_id", "display_name", "doc_body"); 397 WalletItems::LegalDocument expected("doc_id", "display_name", "doc_body");
382 ASSERT_EQ(expected, 398 ASSERT_EQ(expected,
383 *WalletItems::LegalDocument::CreateLegalDocument(*dict)); 399 *WalletItems::LegalDocument::CreateLegalDocument(*dict));
384 } 400 }
385 401
386 TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) { 402 TEST_F(WalletItemsTest, CreateWalletItemsWithRequiredActions) {
387 SetUpDictionary(kWalletItemsWithRequiredActions); 403 SetUpDictionary(kWalletItemsWithRequiredActions);
388 std::vector<std::string> required_actions; 404
389 required_actions.push_back("required_action"); 405 std::vector<RequiredAction> required_actions;
406 required_actions.push_back(SETUP_WALLET);
407 required_actions.push_back(ACCEPT_TOS);
408 required_actions.push_back(GAIA_AUTH);
409 required_actions.push_back(INVALID_FORM_FIELD);
410
390 WalletItems expected(required_actions, "google_transaction_id", "", ""); 411 WalletItems expected(required_actions, "google_transaction_id", "", "");
391 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); 412 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
413
414 DCHECK(!required_actions.empty());
415 required_actions.pop_back();
416 WalletItems different_required_actions(
417 required_actions, "google_transaction_id", "", "");
418 ASSERT_NE(expected, different_required_actions);
419 }
420
421 TEST_F(WalletItemsTest, CreateWalletItemsWithInvalidRequiredActions) {
422 SetUpDictionary(kWalletItemsWithInvalidRequiredActions);
423 ASSERT_EQ(NULL, WalletItems::CreateWalletItems(*dict).get());
392 } 424 }
393 425
394 TEST_F(WalletItemsTest, CreateWalletItems) { 426 TEST_F(WalletItemsTest, CreateWalletItems) {
395 SetUpDictionary(kWalletItems); 427 SetUpDictionary(kWalletItems);
396 std::vector<std::string> required_actions; 428 std::vector<RequiredAction> required_actions;
397 WalletItems expected(required_actions, 429 WalletItems expected(required_actions,
398 "google_transaction_id", 430 "google_transaction_id",
399 "default_instrument_id", 431 "default_instrument_id",
400 "default_address_id"); 432 "default_address_id");
401 433
402 scoped_ptr<Address> billing_address(new Address("country_code", 434 scoped_ptr<Address> billing_address(new Address("country_code",
403 "name", 435 "name",
404 "address1", 436 "address1",
405 "address2", 437 "address2",
406 "city", 438 "city",
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 new WalletItems::LegalDocument("doc_id", 470 new WalletItems::LegalDocument("doc_id",
439 "display_name", 471 "display_name",
440 "doc_body")); 472 "doc_body"));
441 expected.AddLegalDocument(legal_document.Pass()); 473 expected.AddLegalDocument(legal_document.Pass());
442 474
443 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict)); 475 ASSERT_EQ(expected, *WalletItems::CreateWalletItems(*dict));
444 } 476 }
445 477
446 } // namespace wallet 478 } // namespace wallet
447 479
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698