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 } 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", false, false}, |
| 39 {"", "ab", true, false}, |
| 40 {"ab", "", false, true}, |
| 41 {"ab", "", true, true}, |
| 42 }; |
| 43 |
| 44 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 45 SCOPED_TRACE(testing::Message() |
| 46 << "suggestion = " << test_cases[i].field_suggestion |
| 47 << ", contents = " << test_cases[i].field_contents); |
| 48 |
| 49 EXPECT_EQ(test_cases[i].expected_result, |
| 50 ContainsTokenThatStartsWith( |
| 51 base::ASCIIToUTF16(test_cases[i].field_suggestion), |
| 52 base::ASCIIToUTF16(test_cases[i].field_contents), |
| 53 test_cases[i].case_sensitive)); |
| 54 } |
| 55 } |
| 56 |
| 57 // Tests for GetTextSelectionStart(). |
| 58 TEST(AutofillUtilTest, GetTextSelectionStart) { |
| 59 const struct { |
| 60 const char* const field_suggestion; |
| 61 const char* const field_contents; |
| 62 size_t expected_start; |
| 63 } test_cases[] = { |
| 64 {"ab@cd.b", "a", 1}, |
| 65 {"ab@cd.b", "Ab", 2}, |
| 66 {"ab@cd.b", "cd", 5}, |
| 67 {"ab@cd.b", "ab@c", 4}, |
| 68 {"ab@cd.b", "cd.b", 7}, |
| 69 {"ab@cd.b", "b", 7}, |
| 70 {"ba.a.ab", "a.a", 6}, |
| 71 {"texample@example.com", "example", 16}, |
| 72 }; |
| 73 |
| 74 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 75 SCOPED_TRACE(testing::Message() |
| 76 << "suggestion = " << test_cases[i].field_suggestion |
| 77 << ", contents = " << test_cases[i].field_contents); |
| 78 |
| 79 EXPECT_EQ(test_cases[i].expected_start, |
| 80 GetTextSelectionStart( |
| 81 base::ASCIIToUTF16(test_cases[i].field_suggestion), |
| 82 base::ASCIIToUTF16(test_cases[i].field_contents))); |
| 83 } |
| 84 } |
| 85 |
| 86 } // autofill |
OLD | NEW |