Chromium Code Reviews| Index: components/autofill/core/browser/webdata/autofill_table_unittest.cc |
| diff --git a/components/autofill/core/browser/webdata/autofill_table_unittest.cc b/components/autofill/core/browser/webdata/autofill_table_unittest.cc |
| index f3cf2006b1ac6c27f43c08654179e51bc4bea717..31a6068d43198f65935fe1b66cadd291b84116ff 100644 |
| --- a/components/autofill/core/browser/webdata/autofill_table_unittest.cc |
| +++ b/components/autofill/core/browser/webdata/autofill_table_unittest.cc |
| @@ -5,6 +5,7 @@ |
| #include <utility> |
| #include <vector> |
| +#include "base/command_line.h" |
| #include "base/files/file_util.h" |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/guid.h" |
| @@ -21,6 +22,8 @@ |
| #include "components/autofill/core/browser/webdata/autofill_change.h" |
| #include "components/autofill/core/browser/webdata/autofill_entry.h" |
| #include "components/autofill/core/browser/webdata/autofill_table.h" |
| +#include "components/autofill/core/common/autofill_switches.h" |
| +#include "components/autofill/core/common/autofill_util.h" |
| #include "components/autofill/core/common/form_field_data.h" |
| #include "components/os_crypt/os_crypt.h" |
| #include "components/webdata/common/web_database.h" |
| @@ -1856,4 +1859,60 @@ TEST_F(AutofillTableTest, DeleteUnmaskedCard) { |
| outputs.clear(); |
| } |
| +TEST_F(AutofillTableTest, GetFormValuesForElementName) { |
|
please use gerrit instead
2015/07/06 20:15:18
Please use a test name that mentions the substring
Pritam Nikam
2015/07/07 16:18:31
Done.
|
| + // Token matching is currently behind a flag. |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + autofill::switches::kEnableSuggestionsWithSubstringMatch); |
| + |
| + const size_t kMaxCount = 2; |
| + const struct { |
| + const char* const field_suggestion[kMaxCount]; |
| + const char* const field_contents; |
| + size_t expected_suggestion_count; |
| + const char* const expected_suggestion[kMaxCount]; |
| + } kTestCases[] = { |
| + {{"user.test", "test_user"}, "TEST", 2, {"test_user", "user.test"}}, |
| + {{"user test", "test-user"}, "user", 2, {"user test", "test-user"}}, |
| + {{"user test", "test-rest"}, "user", 1, {"user test", nullptr}}, |
| + {{"user@test", "test_user"}, "user@t", 1, {"user@test", nullptr}}, |
| + {{"user.test", "test_user"}, "er.tes", 0, {nullptr, nullptr}}, |
| + {{"user test", "test_user"}, "_ser", 0, {nullptr, nullptr}}, |
| + {{"user.test", "test_user"}, "%ser", 0, {nullptr, nullptr}}, |
| + {{"user.test", "test_user"}, |
| + "; DROP TABLE autofill;", |
| + 0, |
| + {nullptr, nullptr}}, |
| + }; |
| + |
| + for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| + SCOPED_TRACE(testing::Message() |
| + << "suggestion = " << kTestCases[i].field_suggestion[0] |
| + << ", contents = " << kTestCases[i].field_contents); |
| + |
| + Time t1 = Time::Now(); |
| + |
| + // Simulate the submission of a handful of entries in a field called "Name". |
| + AutofillChangeList changes; |
| + FormFieldData field; |
| + for (size_t k = 0; k < kMaxCount; ++k) { |
| + field.name = ASCIIToUTF16("Name"); |
| + field.value = ASCIIToUTF16(kTestCases[i].field_suggestion[k]); |
| + table_->AddFormFieldValue(field, &changes); |
| + } |
| + |
| + std::vector<base::string16> v; |
| + table_->GetFormValuesForElementName( |
| + ASCIIToUTF16("Name"), ASCIIToUTF16(kTestCases[i].field_contents), &v, |
| + 6); |
| + |
| + EXPECT_EQ(kTestCases[i].expected_suggestion_count, v.size()); |
| + for (size_t j = 0; j < kTestCases[i].expected_suggestion_count; ++j) { |
| + EXPECT_EQ(ASCIIToUTF16(kTestCases[i].expected_suggestion[j]), v[j]); |
| + } |
| + |
| + changes.clear(); |
| + table_->RemoveFormElementsAddedBetween(t1, Time(), &changes); |
| + } |
| +} |
| + |
| } // namespace autofill |