| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/string16.h" |
| 5 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/autofill/autofill_field.h" | 7 #include "chrome/browser/autofill/autofill_field.h" |
| 7 #include "chrome/browser/autofill/form_field.h" | 8 #include "chrome/browser/autofill/form_field.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 10 |
| 10 TEST(FormFieldTest, Match) { | 11 TEST(FormFieldTest, Match) { |
| 11 AutofillField field; | 12 AutofillField field; |
| 12 | 13 |
| 13 // Empty strings match. | 14 // Empty strings match. |
| 14 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL)); | 15 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL)); |
| 15 | 16 |
| 16 // Empty pattern matches non-empty string. | 17 // Empty pattern matches non-empty string. |
| 17 field.label = ASCIIToUTF16("a"); | 18 field.label = ASCIIToUTF16("a"); |
| 18 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL)); | 19 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL)); |
| 19 | 20 |
| 20 // Strictly empty pattern matches empty string. | 21 // Strictly empty pattern matches empty string. |
| 21 field.label = ASCIIToUTF16(""); | 22 field.label = string16(); |
| 22 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^$"), | 23 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^$"), |
| 23 FormField::MATCH_LABEL)); | 24 FormField::MATCH_LABEL)); |
| 24 | 25 |
| 25 // Strictly empty pattern does not match non-empty string. | 26 // Strictly empty pattern does not match non-empty string. |
| 26 field.label = ASCIIToUTF16("a"); | 27 field.label = ASCIIToUTF16("a"); |
| 27 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^$"), | 28 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^$"), |
| 28 FormField::MATCH_LABEL)); | 29 FormField::MATCH_LABEL)); |
| 29 | 30 |
| 30 // Non-empty pattern doesn't match empty string. | 31 // Non-empty pattern doesn't match empty string. |
| 31 field.label = string16(); | 32 field.label = string16(); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 field.label = ASCIIToUTF16("contains word:"); | 107 field.label = ASCIIToUTF16("contains word:"); |
| 107 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("\\bword\\b"), | 108 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("\\bword\\b"), |
| 108 FormField::MATCH_LABEL)); | 109 FormField::MATCH_LABEL)); |
| 109 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"), | 110 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcon\\b"), |
| 110 FormField::MATCH_LABEL)); | 111 FormField::MATCH_LABEL)); |
| 111 // Make sure the circumflex in 'crepe' is not treated as a word boundary. | 112 // Make sure the circumflex in 'crepe' is not treated as a word boundary. |
| 112 field.label = UTF8ToUTF16("cr" "\xC3\xAA" "pe"); | 113 field.label = UTF8ToUTF16("cr" "\xC3\xAA" "pe"); |
| 113 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"), | 114 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("\\bcr\\b"), |
| 114 FormField::MATCH_LABEL)); | 115 FormField::MATCH_LABEL)); |
| 115 } | 116 } |
| OLD | NEW |