Chromium Code Reviews| Index: chrome/browser/autofill/wallet/full_wallet_unittest.cc |
| diff --git a/chrome/browser/autofill/wallet/full_wallet_unittest.cc b/chrome/browser/autofill/wallet/full_wallet_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..408ce97a490e840468788156e6025d5f782dad7d |
| --- /dev/null |
| +++ b/chrome/browser/autofill/wallet/full_wallet_unittest.cc |
| @@ -0,0 +1,421 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/json/json_reader.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/autofill/wallet/full_wallet.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace { |
| + |
| +static const char kFullWalletValidResponse[] = |
| + "{" |
| + " \"expiration_month\":12," |
|
Dan Beam
2012/11/30 19:55:52
nit: 3 \s -> 2 \s
ahutter
2012/12/01 04:06:51
Do you mean the JSON?
Dan Beam
2012/12/05 19:34:59
Yes, basically -1 \s from all the JSON you've put
|
| + " \"expiration_year\":2012," |
| + " \"iin\":\"iin\"," |
| + " \"rest\":\"rest\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"," |
| + " \"postal_code_number\":\"postal_code_number\"," |
| + " \"country_name_code\":\"country_name_code\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMissingExpirationMonth[] = |
| + "{" |
| + " \"expiration_year\":2012," |
| + " \"iin\":\"iin\"," |
| + " \"rest\":\"rest\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"," |
| + " \"postal_code_number\":\"postal_code_number\"," |
| + " \"country_name_code\":\"country_name_code\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMissingExpirationYear[] = |
| + "{" |
| + " \"expiration_month\":12," |
| + " \"iin\":\"iin\"," |
| + " \"rest\":\"rest\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"," |
| + " \"postal_code_number\":\"postal_code_number\"," |
| + " \"country_name_code\":\"country_name_code\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMissingIin[] = |
| + "{" |
| + " \"expiration_month\":12," |
| + " \"expiration_year\":2012," |
| + " \"rest\":\"rest\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"," |
| + " \"postal_code_number\":\"postal_code_number\"," |
| + " \"country_name_code\":\"country_name_code\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMissingRest[] = |
| + "{" |
| + " \"expiration_month\":12," |
| + " \"expiration_year\":2012," |
| + " \"iin\":\"iin\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"," |
| + " \"postal_code_number\":\"postal_code_number\"," |
| + " \"country_name_code\":\"country_name_code\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMissingBillingAddress[] = |
| + "{" |
| + " \"expiration_month\":12," |
| + " \"expiration_year\":2012," |
| + " \"iin\":\"iin\"," |
| + " \"rest\":\"rest\"," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletWithRequiredActions[] = |
| + "{" |
| + " \"required_action\":" |
| + " [" |
| + " \"required_action\"" |
| + " ]" |
| + "}"; |
| + |
| +static const char kFullWalletMalformedBillingAddress[] = |
| + "{" |
| + " \"expiration_month\":12," |
| + " \"expiration_year\":2012," |
| + " \"iin\":\"iin\"," |
| + " \"rest\":\"rest\"," |
| + " \"billing_address\":" |
| + " {" |
| + " \"id\":\"id\"," |
| + " \"phone_number\":\"phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"address_line_1\"," |
| + " \"address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"locality_name\"," |
| + " \"administrative_area_name\":\"administrative_area_name\"" |
| + " }" |
| + " }," |
| + " \"shipping_address\":" |
| + " {" |
| + " \"id\":\"ship_id\"," |
| + " \"phone_number\":\"ship_phone_number\"," |
| + " \"postal_address\":" |
| + " {" |
| + " \"recipient_name\":\"ship_recipient_name\"," |
| + " \"address_line\":" |
| + " [" |
| + " \"ship_address_line_1\"," |
| + " \"ship_address_line_2\"" |
| + " ]," |
| + " \"locality_name\":\"ship_locality_name\"," |
| + " \"administrative_area_name\":\"ship_administrative_area_name\"," |
| + " \"postal_code_number\":\"ship_postal_code_number\"," |
| + " \"country_name_code\":\"ship_country_name_code\"" |
| + " }" |
| + " }," |
| + " \"required_action\":" |
| + " [" |
| + " ]" |
| + "}"; |
| + |
| +} // end anonymous namespace |
| + |
| +namespace wallet { |
| + |
| +class FullWalletTest : public testing::Test { |
| + public: |
| + FullWalletTest() {} |
| + virtual void SetUp() { |
| + dict.reset(); |
| + } |
| + protected: |
| + void SetUpDictionary(const std::string& json) { |
| + scoped_ptr<Value> value(base::JSONReader::Read(json)); |
| + if (value.get() && value->IsType(Value::TYPE_DICTIONARY)) { |
| + dict.reset(static_cast<DictionaryValue*>(value.release())); |
| + } |
| + } |
| + scoped_ptr<DictionaryValue> dict; |
| +}; |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMissingExpirationMonth) { |
| + SetUpDictionary(kFullWalletMissingExpirationMonth); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMissingExpirationYear) { |
| + SetUpDictionary(kFullWalletMissingExpirationYear); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMissingIin) { |
| + SetUpDictionary(kFullWalletMissingIin); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMissingRest) { |
| + SetUpDictionary(kFullWalletMissingRest); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMissingBillingAddress) { |
| + SetUpDictionary(kFullWalletMissingBillingAddress); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletMalformedBillingAddress) { |
| + SetUpDictionary(kFullWalletMalformedBillingAddress); |
| + ASSERT_EQ(NULL, FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWalletWithRequiredAction) { |
| + SetUpDictionary(kFullWalletWithRequiredActions); |
| + std::vector<std::string> required_actions; |
| + required_actions.push_back("required_action"); |
| + FullWallet fullWallet(-1, |
| + -1, |
| + "", |
| + "", |
| + NULL, |
| + NULL, |
| + required_actions); |
| + ASSERT_EQ(fullWallet, *FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +TEST_F(FullWalletTest, CreateFullWallet) { |
| + SetUpDictionary(kFullWalletValidResponse); |
| + Address* billing_address = new Address("country_name_code", |
| + "recipient_name", |
| + "address_line_1", |
| + "address_line_2", |
| + "locality_name", |
| + "administrative_area_name", |
| + "postal_code_number", |
| + "phone_number", |
| + "id"); |
| + Address* shipping_address = new Address("ship_country_name_code", |
| + "ship_recipient_name", |
| + "ship_address_line_1", |
| + "ship_address_line_2", |
| + "ship_locality_name", |
| + "ship_administrative_area_name", |
| + "ship_postal_code_number", |
| + "ship_phone_number", |
| + "ship_id"); |
| + std::vector<std::string> required_actions; |
| + FullWallet fullWallet(12, |
|
Dan Beam
2012/11/30 19:55:52
nit: s/fullWallet/full_wallet/
ahutter
2012/12/01 04:06:51
Done.
|
| + 2012, |
| + "iin", |
| + "rest", |
| + billing_address, |
| + shipping_address, |
| + required_actions); |
| + ASSERT_EQ(fullWallet, *FullWallet::CreateFullWallet(dict.get())); |
| +} |
| + |
| +} // end wallet namespace |