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

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: Fixed unittest for Android bot. 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 FieldIsSuggestionSubstringStartingOnTokenBoundary().
15 TEST(AutofillUtilTest, FieldIsSuggestionSubstringStartingOnTokenBoundary) {
16 // FieldIsSuggestionSubstringStartingOnTokenBoundary should not work yet
17 // without a flag.
18 EXPECT_FALSE(FieldIsSuggestionSubstringStartingOnTokenBoundary(
19 base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("a"), false));
20
21 // Token matching is currently behind a flag.
22 base::CommandLine::ForCurrentProcess()->AppendSwitch(
23 autofill::switches::kEnableSuggestionsWithSubstringMatch);
24
25 const struct {
26 const char* const field_suggestion;
27 const char* const field_contents;
28 bool case_sensitive;
29 bool expected_result;
30 } kTestCases[] = {
31 {"ab@cd.b", "a", false, true},
32 {"ab@cd.b", "b", false, true},
33 {"ab@cd.b", "Ab", false, true},
34 {"ab@cd.b", "Ab", true, false},
35 {"ab@cd.b", "cd", true, true},
36 {"ab@cd.b", "d", false, false},
37 {"ab@cd.b", "b@", true, false},
38 {"ab@cd.b", "ab", false, true},
39 {"ab@cd.b", "cd.b", true, true},
40 {"ab@cd.b", "b@cd", false, false},
41 {"ab@cd.b", "b", false, true},
vabr (Chromium) 2015/07/13 14:04:26 You duplicated this line (see line 32), and there
Pritam Nikam 2015/07/14 10:30:07 Done. I guess I've missed it out of excitement :)
42 {"ba.a.ab", "a.a", false, true},
43 {"", "ab", false, false},
44 {"", "ab", true, false},
45 {"ab", "", false, true},
46 {"ab", "", true, true},
47 };
48
49 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
50 SCOPED_TRACE(testing::Message()
51 << "suggestion = " << kTestCases[i].field_suggestion
52 << ", contents = " << kTestCases[i].field_contents
53 << ", case_sensitive = " << kTestCases[i].case_sensitive);
54
55 EXPECT_EQ(kTestCases[i].expected_result,
56 FieldIsSuggestionSubstringStartingOnTokenBoundary(
57 base::ASCIIToUTF16(kTestCases[i].field_suggestion),
58 base::ASCIIToUTF16(kTestCases[i].field_contents),
59 kTestCases[i].case_sensitive));
60 }
61 }
62
63 // Tests for GetTextSelectionStart().
64 TEST(AutofillUtilTest, GetTextSelectionStart) {
65 const size_t kInvalid = base::string16::npos;
66 const struct {
67 const char* const field_suggestion;
68 const char* const field_contents;
69 bool case_sensitive;
70 size_t expected_start;
71 } kTestCases[] = {
72 {"ab@cd.b", "a", false, 1},
73 {"ab@cd.b", "A", true, kInvalid},
74 {"ab@cd.b", "Ab", false, 2},
75 {"ab@cd.b", "Ab", true, kInvalid},
76 {"ab@cd.b", "cd", false, 5},
77 {"ab@cd.b", "ab@c", false, 4},
78 {"ab@cd.b", "cd.b", false, 7},
79 {"ab@cd.b", "b@cd", false, kInvalid},
80 {"ab@cd.b", "b", false, 7},
81 {"ba.a.ab", "a.a", false, 6},
82 {"texample@example.com", "example", false, 16},
83 };
84
85 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
86 SCOPED_TRACE(testing::Message()
87 << "suggestion = " << kTestCases[i].field_suggestion
88 << ", contents = " << kTestCases[i].field_contents
89 << ", case_sensitive = " << kTestCases[i].case_sensitive);
90
91 EXPECT_EQ(kTestCases[i].expected_start,
92 GetTextSelectionStart(
93 base::ASCIIToUTF16(kTestCases[i].field_suggestion),
94 base::ASCIIToUTF16(kTestCases[i].field_contents),
95 kTestCases[i].case_sensitive));
96 }
97 }
98
99 } // autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698