OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/autofill/core/common/autofill_util.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/strings/utf_string_conversions.h" | |
9 #include "components/autofill/core/common/autofill_switches.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace autofill { | |
13 | |
14 // Tests for ContainsTokenThatStartsWith(). | |
15 TEST(AutofillUtilTest, ContainsTokenThatStartsWith) { | |
16 // ContainsTokenThatStartsWith should not work yet without a flag. | |
17 EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"), | |
18 base::ASCIIToUTF16("a"), false)); | |
19 | |
20 // Token matching is currently behind a flag. | |
21 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
22 autofill::switches::kEnableSuggestionsWithSubstringMatch); | |
23 | |
24 const struct { | |
25 const char* const field_suggestion; | |
26 const char* const field_contents; | |
27 bool case_sensitive; | |
28 bool expected_result; | |
29 } kTestCases[] = { | |
30 {"ab@cd.b", "a", false, true}, | |
vabr (Chromium)
2015/07/09 06:17:52
You don't include cases spanning more tokens and s
Pritam Nikam
2015/07/10 16:58:46
Done.
I've already added 2 test-cases:
(line: 38
| |
31 {"ab@cd.b", "b", false, true}, | |
32 {"ab@cd.b", "Ab", false, true}, | |
33 {"ab@cd.b", "Ab", true, false}, | |
34 {"ab@cd.b", "cd", true, true}, | |
35 {"ab@cd.b", "d", false, false}, | |
36 {"ab@cd.b", "b@", true, false}, | |
37 {"ab@cd.b", "ab", false, true}, | |
38 {"ab@cd.b", "cd.b", true, true}, | |
39 {"ab@cd.b", "b@cd", false, false}, | |
40 {"", "ab", false, false}, | |
41 {"", "ab", true, false}, | |
42 {"ab", "", false, true}, | |
43 {"ab", "", true, true}, | |
44 }; | |
45 | |
46 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
47 SCOPED_TRACE(testing::Message() | |
48 << "suggestion = " << kTestCases[i].field_suggestion | |
49 << ", contents = " << kTestCases[i].field_contents | |
50 << ", case_sensitive = " << kTestCases[i].case_sensitive); | |
51 | |
52 EXPECT_EQ(kTestCases[i].expected_result, | |
53 ContainsTokenThatStartsWith( | |
54 base::ASCIIToUTF16(kTestCases[i].field_suggestion), | |
55 base::ASCIIToUTF16(kTestCases[i].field_contents), | |
56 kTestCases[i].case_sensitive)); | |
57 } | |
58 } | |
59 | |
60 // Tests for GetTextSelectionStart(). | |
61 TEST(AutofillUtilTest, GetTextSelectionStart) { | |
62 const size_t kInvalid = base::string16::npos; | |
63 const struct { | |
64 const char* const field_suggestion; | |
65 const char* const field_contents; | |
66 bool case_sensitive; | |
67 size_t expected_start; | |
68 } kTestCases[] = { | |
69 {"ab@cd.b", "a", false, 1}, | |
70 {"ab@cd.b", "A", true, kInvalid}, | |
71 {"ab@cd.b", "Ab", false, 2}, | |
72 {"ab@cd.b", "Ab", true, kInvalid}, | |
73 {"ab@cd.b", "cd", false, 5}, | |
74 {"ab@cd.b", "ab@c", false, 4}, | |
75 {"ab@cd.b", "cd.b", false, 7}, | |
76 {"ab@cd.b", "b@cd", false, kInvalid}, | |
77 {"ab@cd.b", "b", false, 7}, | |
78 {"ba.a.ab", "a.a", false, 6}, | |
79 {"texample@example.com", "example", false, 16}, | |
80 }; | |
81 | |
82 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | |
83 SCOPED_TRACE(testing::Message() | |
84 << "suggestion = " << kTestCases[i].field_suggestion | |
85 << ", contents = " << kTestCases[i].field_contents | |
86 << ", case_sensitive = " << kTestCases[i].case_sensitive); | |
87 | |
88 EXPECT_EQ(kTestCases[i].expected_start, | |
89 GetTextSelectionStart( | |
90 base::ASCIIToUTF16(kTestCases[i].field_suggestion), | |
91 base::ASCIIToUTF16(kTestCases[i].field_contents), | |
92 kTestCases[i].case_sensitive)); | |
93 } | |
94 } | |
95 | |
96 } // autofill | |
OLD | NEW |