OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/core/common/autofill_util.h" | 5 #include "components/autofill/core/common/autofill_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 {"ab@cd.b", "cd.b", true, true}, | 42 {"ab@cd.b", "cd.b", true, true}, |
43 {"ab@cd.b", "b@cd", false, false}, | 43 {"ab@cd.b", "b@cd", false, false}, |
44 {"ab@cd.b", "ab@c", false, true}, | 44 {"ab@cd.b", "ab@c", false, true}, |
45 {"ba.a.ab", "a.a", false, true}, | 45 {"ba.a.ab", "a.a", false, true}, |
46 {"", "ab", false, false}, | 46 {"", "ab", false, false}, |
47 {"", "ab", true, false}, | 47 {"", "ab", true, false}, |
48 {"ab", "", false, true}, | 48 {"ab", "", false, true}, |
49 {"ab", "", true, true}, | 49 {"ab", "", true, true}, |
50 }; | 50 }; |
51 | 51 |
52 for (const auto& test_case : kTestCases) { | 52 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
53 SCOPED_TRACE(testing::Message() | 53 SCOPED_TRACE(testing::Message() |
54 << "suggestion = " << test_case.field_suggestion | 54 << "suggestion = " << kTestCases[i].field_suggestion |
55 << ", contents = " << test_case.field_contents | 55 << ", contents = " << kTestCases[i].field_contents |
56 << ", case_sensitive = " << test_case.case_sensitive); | 56 << ", case_sensitive = " << kTestCases[i].case_sensitive); |
57 | 57 |
58 EXPECT_EQ(test_case.expected_result, | 58 EXPECT_EQ(kTestCases[i].expected_result, |
59 FieldIsSuggestionSubstringStartingOnTokenBoundary( | 59 FieldIsSuggestionSubstringStartingOnTokenBoundary( |
60 base::ASCIIToUTF16(test_case.field_suggestion), | 60 base::ASCIIToUTF16(kTestCases[i].field_suggestion), |
61 base::ASCIIToUTF16(test_case.field_contents), | 61 base::ASCIIToUTF16(kTestCases[i].field_contents), |
62 test_case.case_sensitive)); | 62 kTestCases[i].case_sensitive)); |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 // Tests for GetTextSelectionStart(). | 66 // Tests for GetTextSelectionStart(). |
67 TEST(AutofillUtilTest, GetTextSelectionStart) { | 67 TEST(AutofillUtilTest, GetTextSelectionStart) { |
68 const size_t kInvalid = base::string16::npos; | 68 const size_t kInvalid = base::string16::npos; |
69 const struct { | 69 const struct { |
70 const char* const field_suggestion; | 70 const char* const field_suggestion; |
71 const char* const field_contents; | 71 const char* const field_contents; |
72 bool case_sensitive; | 72 bool case_sensitive; |
73 size_t expected_start; | 73 size_t expected_start; |
74 } kTestCases[] = { | 74 } kTestCases[] = { |
75 {"ab@cd.b", "a", false, 1}, | 75 {"ab@cd.b", "a", false, 1}, |
76 {"ab@cd.b", "A", true, kInvalid}, | 76 {"ab@cd.b", "A", true, kInvalid}, |
77 {"ab@cd.b", "Ab", false, 2}, | 77 {"ab@cd.b", "Ab", false, 2}, |
78 {"ab@cd.b", "Ab", true, kInvalid}, | 78 {"ab@cd.b", "Ab", true, kInvalid}, |
79 {"ab@cd.b", "cd", false, 5}, | 79 {"ab@cd.b", "cd", false, 5}, |
80 {"ab@cd.b", "ab@c", false, 4}, | 80 {"ab@cd.b", "ab@c", false, 4}, |
81 {"ab@cd.b", "cd.b", false, 7}, | 81 {"ab@cd.b", "cd.b", false, 7}, |
82 {"ab@cd.b", "b@cd", false, kInvalid}, | 82 {"ab@cd.b", "b@cd", false, kInvalid}, |
83 {"ab@cd.b", "b", false, 7}, | 83 {"ab@cd.b", "b", false, 7}, |
84 {"ba.a.ab", "a.a", false, 6}, | 84 {"ba.a.ab", "a.a", false, 6}, |
85 {"texample@example.com", "example", false, 16}, | 85 {"texample@example.com", "example", false, 16}, |
86 }; | 86 }; |
87 | 87 |
88 for (const auto& test_case : kTestCases) { | 88 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
89 SCOPED_TRACE(testing::Message() | 89 SCOPED_TRACE(testing::Message() |
90 << "suggestion = " << test_case.field_suggestion | 90 << "suggestion = " << kTestCases[i].field_suggestion |
91 << ", contents = " << test_case.field_contents | 91 << ", contents = " << kTestCases[i].field_contents |
92 << ", case_sensitive = " << test_case.case_sensitive); | 92 << ", case_sensitive = " << kTestCases[i].case_sensitive); |
93 | 93 |
94 EXPECT_EQ( | 94 EXPECT_EQ(kTestCases[i].expected_start, |
95 test_case.expected_start, | 95 GetTextSelectionStart( |
96 GetTextSelectionStart(base::ASCIIToUTF16(test_case.field_suggestion), | 96 base::ASCIIToUTF16(kTestCases[i].field_suggestion), |
97 base::ASCIIToUTF16(test_case.field_contents), | 97 base::ASCIIToUTF16(kTestCases[i].field_contents), |
98 test_case.case_sensitive)); | 98 kTestCases[i].case_sensitive)); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 // Tests for LowercaseAndTokenizeAttributeString | 102 // Tests for LowercaseAndTokenizeAttributeString |
103 TEST(AutofillUtilTest, LowercaseAndTokenizeAttributeString) { | 103 TEST(AutofillUtilTest, LowercaseAndTokenizeAttributeString) { |
104 const struct { | 104 const struct { |
105 const char* const attribute; | 105 const char* const attribute; |
106 std::vector<std::string> tokens; | 106 std::vector<std::string> tokens; |
107 } kTestCases[] = { | 107 } kTestCases[] = { |
108 // Test leading and trailing whitespace, test tabs and newlines | 108 // Test leading and trailing whitespace, test tabs and newlines |
109 {"foo bar baz", {"foo", "bar", "baz"}}, | 109 {"foo bar baz", {"foo", "bar", "baz"}}, |
110 {" foo bar baz ", {"foo", "bar", "baz"}}, | 110 {" foo bar baz ", {"foo", "bar", "baz"}}, |
111 {"foo\tbar baz ", {"foo", "bar", "baz"}}, | 111 {"foo\tbar baz ", {"foo", "bar", "baz"}}, |
112 {"foo\nbar baz ", {"foo", "bar", "baz"}}, | 112 {"foo\nbar baz ", {"foo", "bar", "baz"}}, |
113 | 113 |
114 // Test different forms of capitalization | 114 // Test different forms of capitalization |
115 {"FOO BAR BAZ", {"foo", "bar", "baz"}}, | 115 {"FOO BAR BAZ", {"foo", "bar", "baz"}}, |
116 {"foO baR bAz", {"foo", "bar", "baz"}}, | 116 {"foO baR bAz", {"foo", "bar", "baz"}}, |
117 | 117 |
118 // Test collapsing of multiple whitespace characters in a row | 118 // Test collapsing of multiple whitespace characters in a row |
119 {" \t\t\n\n ", std::vector<std::string>()}, | 119 {" \t\t\n\n ", std::vector<std::string>()}, |
120 {"foO baR bAz", {"foo", "bar", "baz"}}, | 120 {"foO baR bAz", {"foo", "bar", "baz"}}, |
121 }; | 121 }; |
122 | 122 |
123 for (const auto& test_case : kTestCases) { | 123 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
124 SCOPED_TRACE(testing::Message() << "attribute = " << test_case.attribute); | 124 SCOPED_TRACE(testing::Message() << "attribute = " |
| 125 << kTestCases[i].attribute); |
125 | 126 |
126 EXPECT_EQ(test_case.tokens, | 127 EXPECT_EQ(kTestCases[i].tokens, |
127 LowercaseAndTokenizeAttributeString(test_case.attribute)); | 128 LowercaseAndTokenizeAttributeString(kTestCases[i].attribute)); |
128 } | 129 } |
129 } | 130 } |
130 } // namespace autofill | 131 } // namespace autofill |
OLD | NEW |