| Index: components/autofill/core/common/autofill_util_unittest.cc
|
| diff --git a/components/autofill/core/common/autofill_util_unittest.cc b/components/autofill/core/common/autofill_util_unittest.cc
|
| index 2115b3ed3ab2d5f985c0e1b1cad6281ba0dbdfd8..6e04dc76031f980e818546f76d3881012c25a7bc 100644
|
| --- a/components/autofill/core/common/autofill_util_unittest.cc
|
| +++ b/components/autofill/core/common/autofill_util_unittest.cc
|
| @@ -15,7 +15,18 @@
|
| namespace autofill {
|
|
|
| // Tests for FieldIsSuggestionSubstringStartingOnTokenBoundary().
|
| -TEST(AutofillUtilTest, FieldIsSuggestionSubstringStartingOnTokenBoundary) {
|
| +struct FieldIsTokenBoundarySubstringCase {
|
| + const char* const field_suggestion;
|
| + const char* const field_contents;
|
| + const bool case_sensitive;
|
| + const bool expected_result;
|
| +};
|
| +
|
| +class FieldIsTokenBoundarySubstringCaseTest
|
| + : public testing::TestWithParam<FieldIsTokenBoundarySubstringCase> {};
|
| +
|
| +TEST_P(FieldIsTokenBoundarySubstringCaseTest,
|
| + FieldIsSuggestionSubstringStartingOnTokenBoundary) {
|
| // FieldIsSuggestionSubstringStartingOnTokenBoundary should not work yet
|
| // without a flag.
|
| EXPECT_FALSE(FieldIsSuggestionSubstringStartingOnTokenBoundary(
|
| @@ -25,106 +36,124 @@ TEST(AutofillUtilTest, FieldIsSuggestionSubstringStartingOnTokenBoundary) {
|
| base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| switches::kEnableSuggestionsWithSubstringMatch);
|
|
|
| - const struct {
|
| - const char* const field_suggestion;
|
| - const char* const field_contents;
|
| - bool case_sensitive;
|
| - bool expected_result;
|
| - } kTestCases[] = {
|
| - {"ab@cd.b", "a", false, true},
|
| - {"ab@cd.b", "b", false, true},
|
| - {"ab@cd.b", "Ab", false, true},
|
| - {"ab@cd.b", "Ab", true, false},
|
| - {"ab@cd.b", "cd", true, true},
|
| - {"ab@cd.b", "d", false, false},
|
| - {"ab@cd.b", "b@", true, false},
|
| - {"ab@cd.b", "ab", false, true},
|
| - {"ab@cd.b", "cd.b", true, true},
|
| - {"ab@cd.b", "b@cd", false, false},
|
| - {"ab@cd.b", "ab@c", false, true},
|
| - {"ba.a.ab", "a.a", false, true},
|
| - {"", "ab", false, false},
|
| - {"", "ab", true, false},
|
| - {"ab", "", false, true},
|
| - {"ab", "", true, true},
|
| - };
|
| -
|
| - for (const auto& test_case : kTestCases) {
|
| - SCOPED_TRACE(testing::Message()
|
| - << "suggestion = " << test_case.field_suggestion
|
| - << ", contents = " << test_case.field_contents
|
| - << ", case_sensitive = " << test_case.case_sensitive);
|
| -
|
| - EXPECT_EQ(test_case.expected_result,
|
| - FieldIsSuggestionSubstringStartingOnTokenBoundary(
|
| - base::ASCIIToUTF16(test_case.field_suggestion),
|
| - base::ASCIIToUTF16(test_case.field_contents),
|
| - test_case.case_sensitive));
|
| - }
|
| + auto test_case = GetParam();
|
| + SCOPED_TRACE(testing::Message()
|
| + << "suggestion = " << test_case.field_suggestion
|
| + << ", contents = " << test_case.field_contents
|
| + << ", case_sensitive = " << test_case.case_sensitive);
|
| +
|
| + EXPECT_EQ(test_case.expected_result,
|
| + FieldIsSuggestionSubstringStartingOnTokenBoundary(
|
| + base::ASCIIToUTF16(test_case.field_suggestion),
|
| + base::ASCIIToUTF16(test_case.field_contents),
|
| + test_case.case_sensitive));
|
| }
|
|
|
| +INSTANTIATE_TEST_CASE_P(
|
| + AutofillUtilTest,
|
| + FieldIsTokenBoundarySubstringCaseTest,
|
| + testing::Values(
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "a", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "b", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "Ab", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "Ab", true, false},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "cd", true, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "d", false, false},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "b@", true, false},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "ab", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "cd.b", true, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "b@cd", false, false},
|
| + FieldIsTokenBoundarySubstringCase{"ab@cd.b", "ab@c", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ba.a.ab", "a.a", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"", "ab", false, false},
|
| + FieldIsTokenBoundarySubstringCase{"", "ab", true, false},
|
| + FieldIsTokenBoundarySubstringCase{"ab", "", false, true},
|
| + FieldIsTokenBoundarySubstringCase{"ab", "", true, true}));
|
| +
|
| // Tests for GetTextSelectionStart().
|
| -TEST(AutofillUtilTest, GetTextSelectionStart) {
|
| - const size_t kInvalid = base::string16::npos;
|
| - const struct {
|
| - const char* const field_suggestion;
|
| - const char* const field_contents;
|
| - bool case_sensitive;
|
| - size_t expected_start;
|
| - } kTestCases[] = {
|
| - {"ab@cd.b", "a", false, 1},
|
| - {"ab@cd.b", "A", true, kInvalid},
|
| - {"ab@cd.b", "Ab", false, 2},
|
| - {"ab@cd.b", "Ab", true, kInvalid},
|
| - {"ab@cd.b", "cd", false, 5},
|
| - {"ab@cd.b", "ab@c", false, 4},
|
| - {"ab@cd.b", "cd.b", false, 7},
|
| - {"ab@cd.b", "b@cd", false, kInvalid},
|
| - {"ab@cd.b", "b", false, 7},
|
| - {"ba.a.ab", "a.a", false, 6},
|
| - {"texample@example.com", "example", false, 16},
|
| - };
|
| -
|
| - for (const auto& test_case : kTestCases) {
|
| - SCOPED_TRACE(testing::Message()
|
| - << "suggestion = " << test_case.field_suggestion
|
| - << ", contents = " << test_case.field_contents
|
| - << ", case_sensitive = " << test_case.case_sensitive);
|
| -
|
| - EXPECT_EQ(
|
| - test_case.expected_start,
|
| - GetTextSelectionStart(base::ASCIIToUTF16(test_case.field_suggestion),
|
| - base::ASCIIToUTF16(test_case.field_contents),
|
| - test_case.case_sensitive));
|
| - }
|
| +struct GetTextSelectionStartCase {
|
| + const char* const field_suggestion;
|
| + const char* const field_contents;
|
| + const bool case_sensitive;
|
| + const size_t expected_start;
|
| +};
|
| +
|
| +class GetTextSelectionStartTest
|
| + : public testing::TestWithParam<GetTextSelectionStartCase> {};
|
| +
|
| +TEST_P(GetTextSelectionStartTest, GetTextSelectionStart) {
|
| + auto test_case = GetParam();
|
| + SCOPED_TRACE(testing::Message()
|
| + << "suggestion = " << test_case.field_suggestion
|
| + << ", contents = " << test_case.field_contents
|
| + << ", case_sensitive = " << test_case.case_sensitive);
|
| + EXPECT_EQ(
|
| + test_case.expected_start,
|
| + GetTextSelectionStart(base::ASCIIToUTF16(test_case.field_suggestion),
|
| + base::ASCIIToUTF16(test_case.field_contents),
|
| + test_case.case_sensitive));
|
| }
|
|
|
| +INSTANTIATE_TEST_CASE_P(
|
| + AutofillUtilTest,
|
| + GetTextSelectionStartTest,
|
| + testing::Values(
|
| + GetTextSelectionStartCase{"ab@cd.b", "a", false, 1},
|
| + GetTextSelectionStartCase{"ab@cd.b", "A", true, base::string16::npos},
|
| + GetTextSelectionStartCase{"ab@cd.b", "Ab", false, 2},
|
| + GetTextSelectionStartCase{"ab@cd.b", "Ab", true, base::string16::npos},
|
| + GetTextSelectionStartCase{"ab@cd.b", "cd", false, 5},
|
| + GetTextSelectionStartCase{"ab@cd.b", "ab@c", false, 4},
|
| + GetTextSelectionStartCase{"ab@cd.b", "cd.b", false, 7},
|
| + GetTextSelectionStartCase{"ab@cd.b", "b@cd", false,
|
| + base::string16::npos},
|
| + GetTextSelectionStartCase{"ab@cd.b", "b", false, 7},
|
| + GetTextSelectionStartCase{"ba.a.ab", "a.a", false, 6},
|
| + GetTextSelectionStartCase{"texample@example.com", "example", false,
|
| + 16}));
|
| +
|
| // Tests for LowercaseAndTokenizeAttributeString
|
| -TEST(AutofillUtilTest, LowercaseAndTokenizeAttributeString) {
|
| - const struct {
|
| - const char* const attribute;
|
| - std::vector<std::string> tokens;
|
| - } kTestCases[] = {
|
| - // Test leading and trailing whitespace, test tabs and newlines
|
| - {"foo bar baz", {"foo", "bar", "baz"}},
|
| - {" foo bar baz ", {"foo", "bar", "baz"}},
|
| - {"foo\tbar baz ", {"foo", "bar", "baz"}},
|
| - {"foo\nbar baz ", {"foo", "bar", "baz"}},
|
| -
|
| - // Test different forms of capitalization
|
| - {"FOO BAR BAZ", {"foo", "bar", "baz"}},
|
| - {"foO baR bAz", {"foo", "bar", "baz"}},
|
| -
|
| - // Test collapsing of multiple whitespace characters in a row
|
| - {" \t\t\n\n ", std::vector<std::string>()},
|
| - {"foO baR bAz", {"foo", "bar", "baz"}},
|
| - };
|
| -
|
| - for (const auto& test_case : kTestCases) {
|
| - SCOPED_TRACE(testing::Message() << "attribute = " << test_case.attribute);
|
| -
|
| - EXPECT_EQ(test_case.tokens,
|
| - LowercaseAndTokenizeAttributeString(test_case.attribute));
|
| - }
|
| +struct LowercaseAndTokenizeAttributeStringCase {
|
| + const char* const attribute;
|
| + std::vector<std::string> tokens;
|
| +};
|
| +
|
| +class LowercaseAndTokenizeAttributeStringTest
|
| + : public testing::TestWithParam<LowercaseAndTokenizeAttributeStringCase> {};
|
| +
|
| +TEST_P(LowercaseAndTokenizeAttributeStringTest,
|
| + LowercaseAndTokenizeAttributeStringTest) {
|
| + auto test_case = GetParam();
|
| + SCOPED_TRACE(testing::Message() << "attribute = " << test_case.attribute);
|
| +
|
| + EXPECT_EQ(test_case.tokens,
|
| + LowercaseAndTokenizeAttributeString(test_case.attribute));
|
| }
|
| +
|
| +INSTANTIATE_TEST_CASE_P(
|
| + AutofillUtilTest,
|
| + LowercaseAndTokenizeAttributeStringTest,
|
| + testing::Values(
|
| + // Test leading and trailing whitespace, test tabs and newlines
|
| + LowercaseAndTokenizeAttributeStringCase{"foo bar baz",
|
| + {"foo", "bar", "baz"}},
|
| + LowercaseAndTokenizeAttributeStringCase{" foo bar baz ",
|
| + {"foo", "bar", "baz"}},
|
| + LowercaseAndTokenizeAttributeStringCase{"foo\tbar baz ",
|
| + {"foo", "bar", "baz"}},
|
| + LowercaseAndTokenizeAttributeStringCase{"foo\nbar baz ",
|
| + {"foo", "bar", "baz"}},
|
| +
|
| + // Test different forms of capitalization
|
| + LowercaseAndTokenizeAttributeStringCase{"FOO BAR BAZ",
|
| + {"foo", "bar", "baz"}},
|
| + LowercaseAndTokenizeAttributeStringCase{"foO baR bAz",
|
| + {"foo", "bar", "baz"}},
|
| +
|
| + // Test collapsing of multiple whitespace characters in a row
|
| + LowercaseAndTokenizeAttributeStringCase{" \t\t\n\n ",
|
| + std::vector<std::string>()},
|
| + LowercaseAndTokenizeAttributeStringCase{"foO baR bAz",
|
| + {"foo", "bar", "baz"}}));
|
| +
|
| } // namespace autofill
|
|
|