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

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: Addresses Vaclav's inputs unittests. Created 5 years, 9 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..2ae7271e1802e162669cead51a65615417888f83
--- /dev/null
+++ b/components/autofill/core/common/autofill_util_unittest.cc
@@ -0,0 +1,61 @@
+// 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/strings/utf_string_conversions.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace autofill {
+
+// Tests for IsContentsPrefixOfSuggestionToken().
+TEST(AutofillUtilTest, IsContentsPrefixOfSuggestionToken) {
+ EXPECT_TRUE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("a"), false));
vabr (Chromium) 2015/03/31 09:38:07 Please also test the same for the 2nd argument bei
Pritam Nikam 2015/03/31 14:26:12 Done.
+ EXPECT_TRUE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("Ab"), false));
vabr (Chromium) 2015/03/31 09:38:07 Please also add the same test call with the 3rd ar
Pritam Nikam 2015/03/31 14:26:12 Done.
+ EXPECT_TRUE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("cd"), true));
+ EXPECT_FALSE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("d"), false));
+ EXPECT_FALSE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("b@"), true));
+ EXPECT_FALSE(IsContentsPrefixOfSuggestionToken(
+ base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("cd.b"), false));
+}
+
+// Tests for ComputeRange().
+TEST(AutofillUtilTest, ComputeRange) {
+ const struct {
+ base::string16 field_suggestion;
+ base::string16 field_contents;
+ size_t expected_offset;
+ size_t expected_start;
+ size_t expected_end;
+ } TestCases[] = {
vabr (Chromium) 2015/03/31 09:38:07 TestCases is a bad naming style for a const variab
Pritam Nikam 2015/03/31 14:26:12 Done.
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("a"), 0, 1, 7},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("Ab"), 0, 2, 7},
+ {base::ASCIIToUTF16("ab@cd.b"), base::ASCIIToUTF16("cd"), 3, 5, 7},
+ {base::ASCIIToUTF16("ab@cd.b"),
+ base::ASCIIToUTF16("dc"),
+ base::string16::npos,
+ -1,
+ -1}};
+
+ for (size_t i = 0; i < arraysize(TestCases); ++i) {
+ size_t start = 0;
vabr (Chromium) 2015/03/31 09:38:07 Please use SCOPED_TRACE(testing::Message() << "sug
Pritam Nikam 2015/03/31 14:26:12 Done.
+ size_t end = 0;
+ size_t offset = 0;
+
+ offset = ComputeRange(TestCases[i].field_suggestion,
+ TestCases[i].field_contents, &start, &end);
+ EXPECT_EQ(TestCases[i].expected_offset, offset);
+ if (base::string16::npos != offset) {
+ EXPECT_EQ(TestCases[i].expected_start, start);
+ EXPECT_EQ(TestCases[i].expected_end, end);
+ }
+ }
+}
+
+} // autofill

Powered by Google App Engine
This is Rietveld 408576698