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

Side by Side Diff: chrome/renderer/autofill/autofill_browsertest.cc

Issue 7576001: Refactor webkit_glue::FormField to remove hacky methods (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only FormField class refactoring Created 9 years, 4 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
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/common/autofill_messages.h" 6 #include "chrome/common/autofill_messages.h"
7 #include "chrome/test/base/render_view_test.h" 7 #include "chrome/test/base/render_view_test.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h" 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
12 #include "webkit/glue/form_data.h" 12 #include "webkit/glue/form_data.h"
13 #include "webkit/glue/form_field.h" 13 #include "webkit/glue/form_field.h"
14 14
15 using WebKit::WebDocument; 15 using WebKit::WebDocument;
16 using WebKit::WebFrame; 16 using WebKit::WebFrame;
17 using WebKit::WebInputElement; 17 using WebKit::WebInputElement;
18 using WebKit::WebString; 18 using WebKit::WebString;
19 using webkit_glue::FormData; 19 using webkit_glue::FormData;
20 using webkit_glue::FormField; 20 using webkit_glue::FormField;
21 21
22 namespace {
23
24 void ExpectFieldEquals(const FormField& expected, const FormField& actual) {
25 EXPECT_EQ(expected.label, actual.label);
26 EXPECT_EQ(expected.name, actual.name);
27 EXPECT_EQ(expected.value, actual.value);
28 EXPECT_EQ(expected.form_control_type, actual.form_control_type);
29 EXPECT_EQ(expected.max_length, actual.max_length);
30 EXPECT_EQ(expected.is_autofilled, actual.is_autofilled);
31 }
32
33 } // namespace
34
22 TEST_F(RenderViewTest, SendForms) { 35 TEST_F(RenderViewTest, SendForms) {
23 // Don't want any delay for form state sync changes. This will still post a 36 // Don't want any delay for form state sync changes. This will still post a
24 // message so updates will get coalesced, but as soon as we spin the message 37 // message so updates will get coalesced, but as soon as we spin the message
25 // loop, it will generate an update. 38 // loop, it will generate an update.
26 view_->set_send_content_state_immediately(true); 39 view_->set_send_content_state_immediately(true);
27 40
28 LoadHTML("<form method=\"POST\">" 41 LoadHTML("<form method=\"POST\">"
29 " <input type=\"text\" id=\"firstname\"/>" 42 " <input type=\"text\" id=\"firstname\"/>"
30 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" 43 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>"
31 " <input type=\"hidden\" id=\"lastname\"/>" 44 " <input type=\"hidden\" id=\"lastname\"/>"
32 " <select id=\"state\"/>" 45 " <select id=\"state\"/>"
33 " <option>?</option>" 46 " <option>?</option>"
34 " <option>California</option>" 47 " <option>California</option>"
35 " <option>Texas</option>" 48 " <option>Texas</option>"
36 " </select>" 49 " </select>"
37 "</form>"); 50 "</form>");
38 51
39 // Verify that "FormsSeen" sends the expected number of fields. 52 // Verify that "FormsSeen" sends the expected number of fields.
40 ProcessPendingMessages(); 53 ProcessPendingMessages();
41 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( 54 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
42 AutofillHostMsg_FormsSeen::ID); 55 AutofillHostMsg_FormsSeen::ID);
43 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); 56 ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
44 AutofillHostMsg_FormsSeen::Param params; 57 AutofillHostMsg_FormsSeen::Param params;
45 AutofillHostMsg_FormsSeen::Read(message, &params); 58 AutofillHostMsg_FormsSeen::Read(message, &params);
46 const std::vector<FormData>& forms = params.a; 59 const std::vector<FormData>& forms = params.a;
47 ASSERT_EQ(1UL, forms.size()); 60 ASSERT_EQ(1UL, forms.size());
48 ASSERT_EQ(3UL, forms[0].fields.size()); 61 ASSERT_EQ(3UL, forms[0].fields.size());
49 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( 62
50 FormField(string16(), 63 FormField expected;
51 ASCIIToUTF16("firstname"), 64
52 string16(), 65 expected.name = ASCIIToUTF16("firstname");
53 ASCIIToUTF16("text"), 66 expected.value = string16();
54 WebInputElement::defaultMaxLength(), 67 expected.form_control_type = ASCIIToUTF16("text");
55 false))) << forms[0].fields[0]; 68 expected.max_length = WebInputElement::defaultMaxLength();
56 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( 69 ExpectFieldEquals(expected, forms[0].fields[0]);
57 FormField(string16(), 70
58 ASCIIToUTF16("middlename"), 71 expected.name = ASCIIToUTF16("middlename");
59 string16(), 72 expected.value = string16();
60 ASCIIToUTF16("text"), 73 expected.form_control_type = ASCIIToUTF16("text");
61 WebInputElement::defaultMaxLength(), 74 expected.max_length = WebInputElement::defaultMaxLength();
62 false))) << forms[0].fields[1]; 75 ExpectFieldEquals(expected, forms[0].fields[1]);
63 EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( 76
64 FormField(string16(), 77 expected.name = ASCIIToUTF16("state");
65 ASCIIToUTF16("state"), 78 expected.value = ASCIIToUTF16("?");
66 ASCIIToUTF16("?"), 79 expected.form_control_type = ASCIIToUTF16("select-one");
67 ASCIIToUTF16("select-one"), 80 expected.max_length = 0;
68 0, 81 ExpectFieldEquals(expected, forms[0].fields[2]);
69 false))) << forms[0].fields[2];
70 82
71 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of 83 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of
72 // fields. 84 // fields.
73 WebFrame* web_frame = GetMainFrame(); 85 WebFrame* web_frame = GetMainFrame();
74 WebDocument document = web_frame->document(); 86 WebDocument document = web_frame->document();
75 WebInputElement firstname = 87 WebInputElement firstname =
76 document.getElementById("firstname").to<WebInputElement>(); 88 document.getElementById("firstname").to<WebInputElement>();
77 89
78 // Accept suggestion that contains a label. Labeled items indicate Autofill 90 // Accept suggestion that contains a label. Labeled items indicate Autofill
79 // as opposed to Autocomplete. We're testing this distinction below with 91 // as opposed to Autocomplete. We're testing this distinction below with
80 // the |AutofillHostMsg_FillAutofillFormData::ID| message. 92 // the |AutofillHostMsg_FillAutofillFormData::ID| message.
81 autofill_agent_->didAcceptAutofillSuggestion( 93 autofill_agent_->didAcceptAutofillSuggestion(
82 firstname, 94 firstname,
83 WebKit::WebString::fromUTF8("Johnny"), 95 WebKit::WebString::fromUTF8("Johnny"),
84 WebKit::WebString::fromUTF8("Home"), 96 WebKit::WebString::fromUTF8("Home"),
85 1, 97 1,
86 -1); 98 -1);
87 99
88 ProcessPendingMessages(); 100 ProcessPendingMessages();
89 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( 101 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
90 AutofillHostMsg_FillAutofillFormData::ID); 102 AutofillHostMsg_FillAutofillFormData::ID);
91 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); 103 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2);
92 AutofillHostMsg_FillAutofillFormData::Param params2; 104 AutofillHostMsg_FillAutofillFormData::Param params2;
93 AutofillHostMsg_FillAutofillFormData::Read(message2, &params2); 105 AutofillHostMsg_FillAutofillFormData::Read(message2, &params2);
94 const FormData& form2 = params2.b; 106 const FormData& form2 = params2.b;
95 ASSERT_EQ(3UL, form2.fields.size()); 107 ASSERT_EQ(3UL, form2.fields.size());
96 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( 108
97 FormField(string16(), 109 expected.name = ASCIIToUTF16("firstname");
98 ASCIIToUTF16("firstname"), 110 expected.value = string16();
99 string16(), 111 expected.form_control_type = ASCIIToUTF16("text");
100 ASCIIToUTF16("text"), 112 expected.max_length = WebInputElement::defaultMaxLength();
101 WebInputElement::defaultMaxLength(), 113 ExpectFieldEquals(expected, form2.fields[0]);
102 false))) << form2.fields[0]; 114
103 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( 115 expected.name = ASCIIToUTF16("middlename");
104 FormField(string16(), 116 expected.value = string16();
105 ASCIIToUTF16("middlename"), 117 expected.form_control_type = ASCIIToUTF16("text");
106 string16(), 118 expected.max_length = WebInputElement::defaultMaxLength();
107 ASCIIToUTF16("text"), 119 ExpectFieldEquals(expected, form2.fields[1]);
108 WebInputElement::defaultMaxLength(), 120
109 false))) << form2.fields[1]; 121 expected.name = ASCIIToUTF16("state");
110 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( 122 expected.value = ASCIIToUTF16("?");
111 FormField(string16(), 123 expected.form_control_type = ASCIIToUTF16("select-one");
112 ASCIIToUTF16("state"), 124 expected.max_length = 0;
113 ASCIIToUTF16("?"), 125 ExpectFieldEquals(expected, form2.fields[2]);
114 ASCIIToUTF16("select-one"),
115 0,
116 false))) << form2.fields[2];
117 } 126 }
118 127
119 TEST_F(RenderViewTest, FillFormElement) { 128 TEST_F(RenderViewTest, FillFormElement) {
120 // Don't want any delay for form state sync changes. This will still post a 129 // Don't want any delay for form state sync changes. This will still post a
121 // message so updates will get coalesced, but as soon as we spin the message 130 // message so updates will get coalesced, but as soon as we spin the message
122 // loop, it will generate an update. 131 // loop, it will generate an update.
123 view_->set_send_content_state_immediately(true); 132 view_->set_send_content_state_immediately(true);
124 133
125 LoadHTML("<form method=\"POST\">" 134 LoadHTML("<form method=\"POST\">"
126 " <input type=\"text\" id=\"firstname\"/>" 135 " <input type=\"text\" id=\"firstname\"/>"
(...skipping 25 matching lines...) Expand all
152 0); 161 0);
153 162
154 ProcessPendingMessages(); 163 ProcessPendingMessages();
155 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( 164 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
156 AutofillHostMsg_FillAutofillFormData::ID); 165 AutofillHostMsg_FillAutofillFormData::ID);
157 166
158 // No message should be sent in this case. |firstname| is filled directly. 167 // No message should be sent in this case. |firstname| is filled directly.
159 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); 168 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2);
160 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); 169 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David"));
161 } 170 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698