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

Unified 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: Added comments in autocomplete_history_manager.cc. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/common/autofill_util_unittest.cc
diff --git a/components/autofill/core/common/autofill_util_unittest.cc b/components/autofill/core/common/autofill_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..3613d395718bcbbc2839838cc8090ba0d38b79d1
--- /dev/null
+++ b/components/autofill/core/common/autofill_util_unittest.cc
@@ -0,0 +1,79 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/autofill/core/common/autofill_util.h"
+
+#include "base/command_line.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/autofill/core/common/autofill_switches.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+// Tests for ContainsTokenThatStartsWith().
+TEST(AutofillUtilTest, ContainsTokenThatStartsWith) {
+ // ContainsTokenThatStartsWith should not work yet without a flag.
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("a"), false));
+
+ // Token matching is currently behind a flag.
+ base::CommandLine::ForCurrentProcess()->AppendSwitch(
+ autofill::switches::kEnableSuggestionsWithSubstringMatch);
+
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
please use gerrit instead 2015/06/29 22:06:29 Use an array of structs similar to the next test c
Pritam Nikam 2015/06/30 15:05:51 Done.
+ base::ASCIIToUTF16("a"), false));
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("b"), false));
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("Ab"), false));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("Ab"), true));
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("cd"), true));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("d"), false));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("b@"), true));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("cd.b"), false));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::string16(),
+ base::ASCIIToUTF16("ab"), false));
+ EXPECT_FALSE(ContainsTokenThatStartsWith(base::string16(),
+ base::ASCIIToUTF16("ab"), true));
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab"),
+ base::string16(), false));
+ EXPECT_TRUE(ContainsTokenThatStartsWith(base::ASCIIToUTF16("ab"),
+ base::string16(), true));
+}
+
+// Tests for GetTextSelectionStart().
+TEST(AutofillUtilTest, GetTextSelectionStart) {
+ const struct {
+ base::string16 field_suggestion;
please use gerrit instead 2015/06/29 22:06:29 Use "char*" instead of "base::string16". Don't bas
Pritam Nikam 2015/06/30 15:05:51 Done.
+ base::string16 field_contents;
+ size_t expected_start;
+ } test_cases[] = {
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("a"), 1},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("Ab"), 2},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("cd"), 5},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("ab@c"), 4},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("cd.b"), 7},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("b"), 7},
+ {base::ASCIIToUTF16("ba.a.ab"), base::ASCIIToUTF16("a.a"), 6},
+ {base::ASCIIToUTF16("texample@example.com"),
+ base::ASCIIToUTF16("example"),
+ 16}};
+
+ for (size_t i = 0; i < arraysize(test_cases); ++i) {
+ SCOPED_TRACE(testing::Message()
+ << "suggestion = " << test_cases[i].field_suggestion
+ << ", contents = " << test_cases[i].field_contents);
+
+ size_t start = GetTextSelectionStart(test_cases[i].field_suggestion,
+ test_cases[i].field_contents);
+ EXPECT_EQ(test_cases[i].expected_start, start);
+ }
+}
+
+} // autofill

Powered by Google App Engine
This is Rietveld 408576698