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

Side by Side Diff: components/autofill/core/common/autofill_util_unittest.cc

Issue 2478463002: Reland of place for loops with |arraysize| with for each loops (Closed)
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « components/autofill/core/common/autofill_regexes_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (size_t i = 0; i < arraysize(kTestCases); ++i) { 52 for (const auto& test_case : kTestCases) {
53 SCOPED_TRACE(testing::Message() 53 SCOPED_TRACE(testing::Message()
54 << "suggestion = " << kTestCases[i].field_suggestion 54 << "suggestion = " << test_case.field_suggestion
55 << ", contents = " << kTestCases[i].field_contents 55 << ", contents = " << test_case.field_contents
56 << ", case_sensitive = " << kTestCases[i].case_sensitive); 56 << ", case_sensitive = " << test_case.case_sensitive);
57 57
58 EXPECT_EQ(kTestCases[i].expected_result, 58 EXPECT_EQ(test_case.expected_result,
59 FieldIsSuggestionSubstringStartingOnTokenBoundary( 59 FieldIsSuggestionSubstringStartingOnTokenBoundary(
60 base::ASCIIToUTF16(kTestCases[i].field_suggestion), 60 base::ASCIIToUTF16(test_case.field_suggestion),
61 base::ASCIIToUTF16(kTestCases[i].field_contents), 61 base::ASCIIToUTF16(test_case.field_contents),
62 kTestCases[i].case_sensitive)); 62 test_case.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 (size_t i = 0; i < arraysize(kTestCases); ++i) { 88 for (const auto& test_case : kTestCases) {
89 SCOPED_TRACE(testing::Message() 89 SCOPED_TRACE(testing::Message()
90 << "suggestion = " << kTestCases[i].field_suggestion 90 << "suggestion = " << test_case.field_suggestion
91 << ", contents = " << kTestCases[i].field_contents 91 << ", contents = " << test_case.field_contents
92 << ", case_sensitive = " << kTestCases[i].case_sensitive); 92 << ", case_sensitive = " << test_case.case_sensitive);
93 93
94 EXPECT_EQ(kTestCases[i].expected_start, 94 EXPECT_EQ(
95 GetTextSelectionStart( 95 test_case.expected_start,
96 base::ASCIIToUTF16(kTestCases[i].field_suggestion), 96 GetTextSelectionStart(base::ASCIIToUTF16(test_case.field_suggestion),
97 base::ASCIIToUTF16(kTestCases[i].field_contents), 97 base::ASCIIToUTF16(test_case.field_contents),
98 kTestCases[i].case_sensitive)); 98 test_case.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 (size_t i = 0; i < arraysize(kTestCases); ++i) { 123 for (const auto& test_case : kTestCases) {
124 SCOPED_TRACE(testing::Message() << "attribute = " 124 SCOPED_TRACE(testing::Message() << "attribute = " << test_case.attribute);
125 << kTestCases[i].attribute);
126 125
127 EXPECT_EQ(kTestCases[i].tokens, 126 EXPECT_EQ(test_case.tokens,
128 LowercaseAndTokenizeAttributeString(kTestCases[i].attribute)); 127 LowercaseAndTokenizeAttributeString(test_case.attribute));
129 } 128 }
130 } 129 }
131 } // namespace autofill 130 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/common/autofill_regexes_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698