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

Side by Side Diff: chrome/browser/autofill/form_field_unittest.cc

Issue 7043027: Autofill refactor form_field.h/cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OVERRIDE glitch. Created 9 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/name_field.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/utf_string_conversions.h" 5 #include "base/utf_string_conversions.h"
6 #include "chrome/browser/autofill/autofill_field.h" 6 #include "chrome/browser/autofill/autofill_field.h"
7 #include "chrome/browser/autofill/form_field.h" 7 #include "chrome/browser/autofill/form_field.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace {
11
12 TEST(FormFieldTest, Match) { 10 TEST(FormFieldTest, Match) {
13 AutofillField field; 11 AutofillField field;
14 12
15 // Empty strings match. 13 // Empty strings match.
16 EXPECT_TRUE(FormField::Match(&field, string16(), true)); 14 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL));
17 15
18 // Empty pattern matches non-empty string. 16 // Empty pattern matches non-empty string.
19 field.label = ASCIIToUTF16("a"); 17 field.label = ASCIIToUTF16("a");
20 EXPECT_TRUE(FormField::Match(&field, string16(), true)); 18 EXPECT_TRUE(FormField::Match(&field, string16(), FormField::MATCH_LABEL));
21 19
22 // Strictly empty pattern matches empty string. 20 // Strictly empty pattern matches empty string.
23 field.label = ASCIIToUTF16(""); 21 field.label = ASCIIToUTF16("");
24 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^$"), true)); 22 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^$"),
23 FormField::MATCH_LABEL));
25 24
26 // Strictly empty pattern does not match non-empty string. 25 // Strictly empty pattern does not match non-empty string.
27 field.label = ASCIIToUTF16("a"); 26 field.label = ASCIIToUTF16("a");
28 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^$"), true)); 27 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^$"),
28 FormField::MATCH_LABEL));
29 29
30 // Non-empty pattern doesn't match empty string. 30 // Non-empty pattern doesn't match empty string.
31 field.label = string16(); 31 field.label = string16();
32 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("a"), true)); 32 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("a"),
33 FormField::MATCH_LABEL));
33 34
34 // Beginning of line. 35 // Beginning of line.
35 field.label = ASCIIToUTF16("head_tail"); 36 field.label = ASCIIToUTF16("head_tail");
36 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^head"), true)); 37 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^head"),
37 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^tail"), true)); 38 FormField::MATCH_LABEL));
39 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^tail"),
40 FormField::MATCH_LABEL));
38 41
39 // End of line. 42 // End of line.
40 field.label = ASCIIToUTF16("head_tail"); 43 field.label = ASCIIToUTF16("head_tail");
41 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("head$"), true)); 44 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("head$"),
42 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("tail$"), true)); 45 FormField::MATCH_LABEL));
46 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("tail$"),
47 FormField::MATCH_LABEL));
43 48
44 // Exact. 49 // Exact.
45 field.label = ASCIIToUTF16("head_tail"); 50 field.label = ASCIIToUTF16("head_tail");
46 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^head$"), true)); 51 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^head$"),
47 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^tail$"), true)); 52 FormField::MATCH_LABEL));
48 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^head_tail$"), true)); 53 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("^tail$"),
54 FormField::MATCH_LABEL));
55 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("^head_tail$"),
56 FormField::MATCH_LABEL));
49 57
50 // Escaped dots. 58 // Escaped dots.
51 field.label = ASCIIToUTF16("m.i."); 59 field.label = ASCIIToUTF16("m.i.");
52 // Note: This pattern is misleading as the "." characters are wild cards. 60 // Note: This pattern is misleading as the "." characters are wild cards.
53 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m.i."), true)); 61 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m.i."),
54 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m\\.i\\."), true)); 62 FormField::MATCH_LABEL));
63 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m\\.i\\."),
64 FormField::MATCH_LABEL));
55 field.label = ASCIIToUTF16("mXiX"); 65 field.label = ASCIIToUTF16("mXiX");
56 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m.i."), true)); 66 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("m.i."),
57 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("m\\.i\\."), true)); 67 FormField::MATCH_LABEL));
68 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("m\\.i\\."),
69 FormField::MATCH_LABEL));
58 70
59 // Repetition. 71 // Repetition.
60 field.label = ASCIIToUTF16("headtail"); 72 field.label = ASCIIToUTF16("headtail");
61 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"), true)); 73 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"),
74 FormField::MATCH_LABEL));
62 field.label = ASCIIToUTF16("headXtail"); 75 field.label = ASCIIToUTF16("headXtail");
63 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"), true)); 76 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"),
77 FormField::MATCH_LABEL));
64 field.label = ASCIIToUTF16("headXXXtail"); 78 field.label = ASCIIToUTF16("headXXXtail");
65 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"), true)); 79 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.*tail"),
80 FormField::MATCH_LABEL));
66 field.label = ASCIIToUTF16("headtail"); 81 field.label = ASCIIToUTF16("headtail");
67 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("head.+tail"), true)); 82 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("head.+tail"),
83 FormField::MATCH_LABEL));
68 field.label = ASCIIToUTF16("headXtail"); 84 field.label = ASCIIToUTF16("headXtail");
69 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.+tail"), true)); 85 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.+tail"),
86 FormField::MATCH_LABEL));
70 field.label = ASCIIToUTF16("headXXXtail"); 87 field.label = ASCIIToUTF16("headXXXtail");
71 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.+tail"), true)); 88 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head.+tail"),
89 FormField::MATCH_LABEL));
72 90
73 // Alternation. 91 // Alternation.
74 field.label = ASCIIToUTF16("head_tail"); 92 field.label = ASCIIToUTF16("head_tail");
75 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head|other"), true)); 93 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head|other"),
76 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("tail|other"), true)); 94 FormField::MATCH_LABEL));
77 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("bad|good"), true)); 95 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("tail|other"),
96 FormField::MATCH_LABEL));
97 EXPECT_FALSE(FormField::Match(&field, ASCIIToUTF16("bad|good"),
98 FormField::MATCH_LABEL));
78 99
79 // Case sensitivity. 100 // Case sensitivity.
80 field.label = ASCIIToUTF16("xxxHeAd_tAiLxxx"); 101 field.label = ASCIIToUTF16("xxxHeAd_tAiLxxx");
81 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head_tail"), true)); 102 EXPECT_TRUE(FormField::Match(&field, ASCIIToUTF16("head_tail"),
103 FormField::MATCH_LABEL));
82 } 104 }
83
84 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_field.cc ('k') | chrome/browser/autofill/name_field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698