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

Unified Diff: components/autofill/core/browser/autofill_profile_unittest.cc

Issue 261993006: Modified to allow to preserve two-word string in first-name and last-name in autofill profile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/autofill_profile_unittest.cc
diff --git a/components/autofill/core/browser/autofill_profile_unittest.cc b/components/autofill/core/browser/autofill_profile_unittest.cc
index de550bd827bd869c9966a9a650fba85111e746db..324ae093e758ca54f82606eb1651ed7f306474bc 100644
--- a/components/autofill/core/browser/autofill_profile_unittest.cc
+++ b/components/autofill/core/browser/autofill_profile_unittest.cc
@@ -3,15 +3,18 @@
// found in the LICENSE file.
#include "base/basictypes.h"
+#include "base/format_macros.h"
#include "base/guid.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
#include "base/stl_util.h"
#include "base/strings/string16.h"
+#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/autofill_test_utils.h"
#include "components/autofill/core/browser/autofill_type.h"
+#include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/common/form_field_data.h"
#include "grit/components_strings.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -898,4 +901,80 @@ TEST(AutofillProfileTest, FullAddress) {
EXPECT_TRUE(profile.GetInfo(full_address, "en-US").empty());
}
+TEST(AutofillProfileTest, OverwriteOrAppendNames) {
+ typedef struct {
+ std::string starting_names[3];
+ std::string additional_names[3];
+ std::string expected_result[3];
+ } TestCase;
Ilya Sherman 2014/06/03 00:25:32 nit: "typedef struct { ... } TestCase" -> "struct
Pritam Nikam 2014/06/03 15:37:34 Done.
+
+ TestCase test_cases[] = {
+ // Identical name.
+ {{"Marion", "Mitchell", "Morrison"},
+ {"Marion", "Mitchell", "Morrison"},
+ {"Marion", "Mitchell", "Morrison"}},
+
+ // A parse that has a two-word last name should take precedence over a
+ // parse that assumes the two names are a middle and a last name.
+ {{"Marion", "Mitchell", "Morrison"},
+ {"Marion", "", "Mitchell Morrison"},
+ {"Marion", "", "Mitchell Morrison"}},
+ {{"Marion", "", "Mitchell Morrison"},
+ {"Marion", "Mitchell", "Morrison"},
+ {"Marion", "", "Mitchell Morrison"}},
+
+ // A parse that has a two-word first name should take precedence over a
+ // parse that assumes the two names are a first and a middle name.
+ {{"Marion", "Mitchell", "Morrison"},
+ {"Marion Mitchell", "", "Morrison"},
+ {"Marion Mitchell", "", "Morrison"}},
+ {{"Marion Mitchell", "", "Morrison"},
+ {"Marion", "Mitchell", "Morrison"},
+ {"Marion Mitchell", "", "Morrison"}},
+
+ // A parse that has a two-word first name and two-word last name should
+ // take precedence over a parse that assumes the two names middle and
Ilya Sherman 2014/06/03 00:25:32 nit: "the two names middle" -> "two middle names"
Pritam Nikam 2014/06/03 15:37:34 Done.
+ // one last name.
+ {{"Arthur", "Ignatius Conan", "Doyle"},
+ {"Arthur Ignatius", "", "Conan Doyle"},
+ {"Arthur Ignatius", "", "Conan Doyle"}},
+ {{"Arthur Ignatius", "", "Conan Doyle"},
+ {"Arthur", "Ignatius Conan", "Doyle"},
+ {"Arthur Ignatius", "", "Conan Doyle"}}};
Ilya Sherman 2014/06/03 00:25:32 Please also add test cases where the starting prof
Ilya Sherman 2014/06/03 00:25:32 Please also add a test case where the names do not
Ilya Sherman 2014/06/03 00:25:32 Please also include a test case for merging {"Mari
Pritam Nikam 2014/06/03 15:37:34 Done. Added in end of the test case. Please have
Pritam Nikam 2014/06/03 15:37:34 Done. Added in end of the test case. Please have
Pritam Nikam 2014/06/03 15:37:34 Done. Added in end of the test case. Please have
+
+ for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) {
+ SCOPED_TRACE(base::StringPrintf("i: %" PRIuS, i));
+
+ // Construct the starting_profile.
+ AutofillProfile starting_profile(base::GenerateGUID(),
+ "https://www.example.com/");
+ starting_profile.SetRawInfo(NAME_FIRST,
+ ASCIIToUTF16(test_cases[i].starting_names[0]));
+ starting_profile.SetRawInfo(NAME_MIDDLE,
+ ASCIIToUTF16(test_cases[i].starting_names[1]));
+ starting_profile.SetRawInfo(NAME_LAST,
+ ASCIIToUTF16(test_cases[i].starting_names[2]));
+
+ // Construct the additional_profile.
+ AutofillProfile additional_profile(base::GenerateGUID(),
+ "https://www.example.com/");
+ additional_profile.SetRawInfo(
+ NAME_FIRST, ASCIIToUTF16(test_cases[i].additional_names[0]));
+ additional_profile.SetRawInfo(
+ NAME_MIDDLE, ASCIIToUTF16(test_cases[i].additional_names[1]));
+ additional_profile.SetRawInfo(
+ NAME_LAST, ASCIIToUTF16(test_cases[i].additional_names[2]));
+
+ // test OverwriteOrAppendNames() via public helper interface
Ilya Sherman 2014/06/03 00:25:32 nit: "Merge the names from the |additional_profile
Pritam Nikam 2014/06/03 15:37:34 Done.
+ starting_profile.OverwriteWithOrAddTo(additional_profile, "en-US");
+
+ // Verify the test expectations.
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_FIRST),
+ ASCIIToUTF16(test_cases[i].expected_result[0]));
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_MIDDLE),
+ ASCIIToUTF16(test_cases[i].expected_result[1]));
+ EXPECT_EQ(starting_profile.GetRawInfo(NAME_LAST),
+ ASCIIToUTF16(test_cases[i].expected_result[2]));
+ }
+}
Ilya Sherman 2014/06/03 00:25:32 nit: Please leave a blank line after this one.
Pritam Nikam 2014/06/03 15:37:34 Done.
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698