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

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

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months 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
OLDNEW
(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 } test_cases[] = {
30 {"ab@cd.b", "a", false, true},
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(test_cases); ++i) {
47 SCOPED_TRACE(testing::Message()
48 << "suggestion = " << test_cases[i].field_suggestion
49 << ", contents = " << test_cases[i].field_contents
50 << ", case_sensitive = " << test_cases[i].case_sensitive);
51
52 EXPECT_EQ(test_cases[i].expected_result,
53 ContainsTokenThatStartsWith(
54 base::ASCIIToUTF16(test_cases[i].field_suggestion),
55 base::ASCIIToUTF16(test_cases[i].field_contents),
56 test_cases[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 } test_cases[] = {
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(test_cases); ++i) {
83 SCOPED_TRACE(testing::Message()
84 << "suggestion = " << test_cases[i].field_suggestion
85 << ", contents = " << test_cases[i].field_contents
86 << ", case_sensitive = " << test_cases[i].case_sensitive);
87
88 EXPECT_EQ(test_cases[i].expected_start,
89 GetTextSelectionStart(
90 base::ASCIIToUTF16(test_cases[i].field_suggestion),
91 base::ASCIIToUTF16(test_cases[i].field_contents),
92 test_cases[i].case_sensitive));
93 }
94 }
95
96 } // autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698