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

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: Changes from Dane's review Created 8 years, 1 month 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..a48ba6c97a99fa9cfd7cbd15ee8ebe9dd054fd24
--- /dev/null
+++ b/chrome/browser/autofill/wallet/wallet_address_unittest.cc
@@ -0,0 +1,231 @@
+// 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/wallet_address.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace {
+static 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\""
+ " }"
+ "}";
+
+static 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\""
+ " }"
+ "}";
+
+static 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\""
+ " }"
+ "}";
+
+static 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\""
+ " }"
+ "}";
+
+static 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\""
+ " }"
+ "}";
+
+static const char kClientAddressMissingCountryCode[] =
+ "{"
+ " \"name\":\"name\","
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"postal_code\":\"postal_code\","
+ " \"phone_number\":\"phone_number\""
+ "}";
+
+static const char kClientAddressMissingPostalCode[] =
+ "{"
+ " \"name\":\"name\","
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"phone_number\":\"phone_number\","
+ " \"country_code\":\"country_code\""
+ "}";
+
+static const char kClientAddressMissingName[] =
+ "{"
+ " \"address1\":\"address1\","
+ " \"address2\":\"address2\","
+ " \"city\":\"city\","
+ " \"state\":\"state\","
+ " \"postal_code\":\"postal_code\","
+ " \"phone_number\":\"phone_number\","
+ " \"country_code\":\"country_code\""
+ "}";
+
+static 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));
+ if (value.get() && value->IsType(Value::TYPE_DICTIONARY)) {
+ dict.reset(static_cast<DictionaryValue*>(value.release()));
+ }
+ }
+ scoped_ptr<DictionaryValue> dict;
+};
+
+TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingObjectId) {
+ SetUpDictionary(kAddressMissingObjectId);
+ ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingCountryNameCode) {
+ SetUpDictionary(kAddressMissingCountryNameCode);
+ ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingRecipientName) {
+ SetUpDictionary(kAddressMissingRecipientName);
+ ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromIdedDictionaryMissingPostalCodeNumber) {
+ SetUpDictionary(kAddressMissingPostalCodeNumber);
+ ASSERT_EQ(NULL, Address::CreateFromIdedDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromIdedDictionary) {
+ 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::CreateFromIdedDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingCountryNameCode) {
+ SetUpDictionary(kClientAddressMissingCountryCode);
+ ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingName) {
+ SetUpDictionary(kClientAddressMissingName);
+ ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromDisplayDictionaryMissingPostalCode) {
+ SetUpDictionary(kClientAddressMissingPostalCode);
+ ASSERT_EQ(NULL, Address::CreateFromDisplayDictionary(dict.get()));
+}
+
+TEST_F(WalletAddressTest, CreateFromDisplayDictionary) {
+ SetUpDictionary(kClientValidAddress);
+ Address address("country_code",
+ "name",
+ "address1",
+ "address2",
+ "city",
+ "state",
+ "postal_code",
+ "phone_number",
+ "");
+ ASSERT_EQ(address, *Address::CreateFromDisplayDictionary(dict.get()));
+}
+
+} // end wallet namespace

Powered by Google App Engine
This is Rietveld 408576698