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

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

Issue 661026: Only load text fields in the form structure. This prevents us from trying to... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 10 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_structure.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2010 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 "base/scoped_ptr.h"
6 #include "base/string_util.h"
7 #include "chrome/browser/autofill/form_structure.h"
8 #include "googleurl/src/gurl.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "third_party/WebKit/WebKit/chromium/public/WebInputElement.h"
11 #include "webkit/glue/form_field_values.h"
12
13 using WebKit::WebInputElement;
14
15 TEST(FormStructureTest, FieldCount) {
16 webkit_glue::FormFieldValues values;
17 values.method = ASCIIToUTF16("post");
18 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("username"),
19 ASCIIToUTF16("username"),
20 string16(),
21 ASCIIToUTF16("text"),
22 WebInputElement::Text));
23 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("password"),
24 ASCIIToUTF16("password"),
25 string16(),
26 ASCIIToUTF16("password"),
27 WebInputElement::Password));
28 values.elements.push_back(webkit_glue::FormField(string16(),
29 ASCIIToUTF16("Submit"),
30 string16(),
31 ASCIIToUTF16("submit"),
32 WebInputElement::Submit));
33
34 FormStructure form_structure(values);
35
36 // Only text fields are counted.
37 EXPECT_EQ(1U, form_structure.field_count());
38 }
39
40 TEST(FormStructureTest, IsAutoFillable) {
41 scoped_ptr<FormStructure> form_structure;
42 webkit_glue::FormFieldValues values;
43
44 // We need at least three text fields to be auto-fillable.
45 values.method = ASCIIToUTF16("post");
46 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("username"),
47 ASCIIToUTF16("username"),
48 string16(),
49 ASCIIToUTF16("text"),
50 WebInputElement::Text));
51 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("password"),
52 ASCIIToUTF16("password"),
53 string16(),
54 ASCIIToUTF16("password"),
55 WebInputElement::Password));
56 values.elements.push_back(webkit_glue::FormField(string16(),
57 ASCIIToUTF16("Submit"),
58 string16(),
59 ASCIIToUTF16("submit"),
60 WebInputElement::Submit));
61 form_structure.reset(new FormStructure(values));
62 EXPECT_FALSE(form_structure->IsAutoFillable());
63
64 // We now have three text fields.
65 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("First Name"),
66 ASCIIToUTF16("firstname"),
67 string16(),
68 ASCIIToUTF16("text"),
69 WebInputElement::Text));
70 values.elements.push_back(webkit_glue::FormField(ASCIIToUTF16("Last Name"),
71 ASCIIToUTF16("lastname"),
72 string16(),
73 ASCIIToUTF16("text"),
74 WebInputElement::Text));
75 form_structure.reset(new FormStructure(values));
76 EXPECT_TRUE(form_structure->IsAutoFillable());
77
78 // The method must be 'post'.
79 values.method = ASCIIToUTF16("get");
80 form_structure.reset(new FormStructure(values));
81 EXPECT_FALSE(form_structure->IsAutoFillable());
82
83 // The target cannot include http(s)://*/search...
84 values.method = ASCIIToUTF16("post");
85 values.target_url = GURL("http://google.com/search?q=hello");
86 form_structure.reset(new FormStructure(values));
87 EXPECT_FALSE(form_structure->IsAutoFillable());
88
89 // But search can be in the URL.
90 values.target_url = GURL("http://search.com/?q=hello");
91 form_structure.reset(new FormStructure(values));
92 EXPECT_TRUE(form_structure->IsAutoFillable());
93 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/form_structure.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698