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

Unified Diff: chrome/browser/autofill/wallet/wallet_address_unittest.cc

Issue 11293078: Integrating Online Wallet into Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes from latest code review Created 8 years 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/wallet/wallet_address_unittest.cc
diff --git a/chrome/browser/autofill/wallet/wallet_address_unittest.cc b/chrome/browser/autofill/wallet/wallet_address_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7cfad90cab7e3de3afb10ccb15f0658977df6987
--- /dev/null
+++ b/chrome/browser/autofill/wallet/wallet_address_unittest.cc
@@ -0,0 +1,233 @@
+// 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/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/values.h"
+#include "chrome/browser/autofill/wallet/wallet_address.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+
+const char kAddressMissingObjectId[] =
+ "{"
+ " \"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\""
+ " }"
+ "}";
+
+const char kAddressMissingCountryNameCode[] =
+ "{"
+ " \"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\""
+ " }"
+ "}";
+
+const char kAddressMissingRecipientName[] =
+ "{"
+ " \"id\":\"id\","
+ " \"phone_number\":\"phone_number\","
+ " \"postal_address\":"
+ " {"
+ " \"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\""
+ " }"
+ "}";
+
+const char kAddressMissingPostalCodeNumber[] =
+ "{"
+ " \"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\","
+ " \"country_name_code\":\"country_name_code\""
+ " }"
+ "}";
+
+const char kValidAddress[] =
+ "{"
+ " \"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\","
+ " \"country_name_code\":\"country_name_code\","
+ " \"postal_code_number\":\"postal_code_number\""
+ " }"
+ "}";
+
+const char kClientAddressMissingCountryCode[] =
+ "{"
+ " \"name\":\"name\","
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"postal_code\":\"postal_code\","
+ " \"phone_number\":\"phone_number\""
+ "}";
+
+const char kClientAddressMissingPostalCode[] =
+ "{"
+ " \"name\":\"name\","
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"phone_number\":\"phone_number\","
+ " \"country_code\":\"country_code\""
+ "}";
+
+const char kClientAddressMissingName[] =
+ "{"
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"postal_code\":\"postal_code\","
+ " \"phone_number\":\"phone_number\","
+ " \"country_code\":\"country_code\""
+ "}";
+
+const char kClientValidAddress[] =
+ "{"
+ " \"name\":\"name\","
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"postal_code\":\"postal_code\","
+ " \"phone_number\":\"phone_number\","
+ " \"country_code\":\"country_code\""
+ "}";
+
+} // end anonymous namespace
+
+namespace wallet {
+
+class WalletAddressTest : public testing::Test {
+ public:
+ WalletAddressTest() {}
+ virtual void SetUp() {
+ dict.reset();
+ }
+ protected:
+ void SetUpDictionary(const std::string& json) {
+ scoped_ptr<Value> value(base::JSONReader::Read(json));
+ DCHECK(value.get());
+ DCHECK(value->IsType(Value::TYPE_DICTIONARY));
+ dict.reset(static_cast<DictionaryValue*>(value.release()));
+ }
+ scoped_ptr<const DictionaryValue> dict;
+};
+
+TEST_F(WalletAddressTest, CreateAddressWithIDMissingObjectId) {
+ SetUpDictionary(kAddressMissingObjectId);
+ ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateAddressWithIDMissingCountryNameCode) {
+ SetUpDictionary(kAddressMissingCountryNameCode);
+ ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateAddressWithIDMissingRecipientName) {
+ SetUpDictionary(kAddressMissingRecipientName);
+ ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateAddressWithIDMissingPostalCodeNumber) {
+ SetUpDictionary(kAddressMissingPostalCodeNumber);
+ ASSERT_EQ(NULL, Address::CreateAddressWithID(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateAddressWithID) {
+ SetUpDictionary(kValidAddress);
+ Address address("country_name_code",
+ "recipient_name",
+ "address_line_1",
+ "address_line_2",
+ "locality_name",
+ "administrative_area_name",
+ "postal_code_number",
+ "phone_number",
+ "id");
+ ASSERT_EQ(address, *Address::CreateAddressWithID(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateDisplayAddressMissingCountryNameCode) {
+ SetUpDictionary(kClientAddressMissingCountryCode);
+ ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateDisplayAddressMissingName) {
+ SetUpDictionary(kClientAddressMissingName);
+ ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateDisplayAddressMissingPostalCode) {
+ SetUpDictionary(kClientAddressMissingPostalCode);
+ ASSERT_EQ(NULL, Address::CreateDisplayAddress(*dict));
+}
+
+TEST_F(WalletAddressTest, CreateDisplayAddress) {
+ SetUpDictionary(kClientValidAddress);
+ Address address("country_code",
+ "name",
+ "address1",
+ "address2",
+ "city",
+ "state",
+ "postal_code",
+ "phone_number",
+ "");
+ ASSERT_EQ(address, *Address::CreateDisplayAddress(*dict));
+}
+
+} // end wallet namespace

Powered by Google App Engine
This is Rietveld 408576698