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

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

Issue 6874038: Remove the last Chrome dependencies from renderer, and enforce no more includes through DEPS. I ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/utf_string_conversions.h"
6 #include "chrome/common/autofill_messages.h"
7 #include "chrome/test/render_view_test.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
12 #include "webkit/glue/form_data.h"
13 #include "webkit/glue/form_field.h"
14
15 using WebKit::WebDocument;
16 using WebKit::WebFrame;
17 using WebKit::WebInputElement;
18 using WebKit::WebString;
19 using webkit_glue::FormData;
20 using webkit_glue::FormField;
21
22 TEST_F(RenderViewTest, SendForms) {
23 // 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
25 // loop, it will generate an update.
26 view_->set_send_content_state_immediately(true);
27
28 LoadHTML("<form method=\"POST\">"
29 " <input type=\"text\" id=\"firstname\"/>"
30 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>"
31 " <input type=\"hidden\" id=\"lastname\"/>"
32 " <select id=\"state\"/>"
33 " <option>?</option>"
34 " <option>California</option>"
35 " <option>Texas</option>"
36 " </select>"
37 "</form>");
38
39 // Verify that "FormsSeen" sends the expected number of fields.
40 ProcessPendingMessages();
41 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
42 AutofillHostMsg_FormsSeen::ID);
43 ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
44 AutofillHostMsg_FormsSeen::Param params;
45 AutofillHostMsg_FormsSeen::Read(message, &params);
46 const std::vector<FormData>& forms = params.a;
47 ASSERT_EQ(1UL, forms.size());
48 ASSERT_EQ(3UL, forms[0].fields.size());
49 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack(
50 FormField(string16(),
51 ASCIIToUTF16("firstname"),
52 string16(),
53 ASCIIToUTF16("text"),
54 WebInputElement::defaultMaxLength(),
55 false))) << forms[0].fields[0];
56 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack(
57 FormField(string16(),
58 ASCIIToUTF16("middlename"),
59 string16(),
60 ASCIIToUTF16("text"),
61 WebInputElement::defaultMaxLength(),
62 false))) << forms[0].fields[1];
63 EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack(
64 FormField(string16(),
65 ASCIIToUTF16("state"),
66 ASCIIToUTF16("?"),
67 ASCIIToUTF16("select-one"),
68 0,
69 false))) << forms[0].fields[2];
70
71 // Verify that |didAcceptAutoFillSuggestion()| sends the expected number of
72 // fields.
73 WebFrame* web_frame = GetMainFrame();
74 WebDocument document = web_frame->document();
75 WebInputElement firstname =
76 document.getElementById("firstname").to<WebInputElement>();
77
78 // Accept suggestion that contains a label. Labeled items indicate Autofill
79 // as opposed to Autocomplete. We're testing this distinction below with
80 // the |AutofillHostMsg_FillAutofillFormData::ID| message.
81 autofill_agent_->didAcceptAutoFillSuggestion(
82 firstname,
83 WebKit::WebString::fromUTF8("Johnny"),
84 WebKit::WebString::fromUTF8("Home"),
85 1,
86 -1);
87
88 ProcessPendingMessages();
89 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
90 AutofillHostMsg_FillAutofillFormData::ID);
91 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2);
92 AutofillHostMsg_FillAutofillFormData::Param params2;
93 AutofillHostMsg_FillAutofillFormData::Read(message2, &params2);
94 const FormData& form2 = params2.b;
95 ASSERT_EQ(3UL, form2.fields.size());
96 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack(
97 FormField(string16(),
98 ASCIIToUTF16("firstname"),
99 string16(),
100 ASCIIToUTF16("text"),
101 WebInputElement::defaultMaxLength(),
102 false))) << form2.fields[0];
103 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack(
104 FormField(string16(),
105 ASCIIToUTF16("middlename"),
106 string16(),
107 ASCIIToUTF16("text"),
108 WebInputElement::defaultMaxLength(),
109 false))) << form2.fields[1];
110 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack(
111 FormField(string16(),
112 ASCIIToUTF16("state"),
113 ASCIIToUTF16("?"),
114 ASCIIToUTF16("select-one"),
115 0,
116 false))) << form2.fields[2];
117 }
118
119 TEST_F(RenderViewTest, FillFormElement) {
120 // 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
122 // loop, it will generate an update.
123 view_->set_send_content_state_immediately(true);
124
125 LoadHTML("<form method=\"POST\">"
126 " <input type=\"text\" id=\"firstname\"/>"
127 " <input type=\"text\" id=\"middlename\"/>"
128 "</form>");
129
130 // Verify that "FormsSeen" isn't sent, as there are too few fields.
131 ProcessPendingMessages();
132 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
133 AutofillHostMsg_FormsSeen::ID);
134 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message);
135
136 // Verify that |didAcceptAutoFillSuggestion()| sets the value of the expected
137 // field.
138 WebFrame* web_frame = GetMainFrame();
139 WebDocument document = web_frame->document();
140 WebInputElement firstname =
141 document.getElementById("firstname").to<WebInputElement>();
142 WebInputElement middlename =
143 document.getElementById("middlename").to<WebInputElement>();
144 middlename.setAutofilled(true);
145
146 // Accept a suggestion in a form that has been auto-filled. This triggers
147 // the direct filling of the firstname element with value parameter.
148 autofill_agent_->didAcceptAutoFillSuggestion(firstname,
149 WebString::fromUTF8("David"),
150 WebString(),
151 0,
152 0);
153
154 ProcessPendingMessages();
155 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
156 AutofillHostMsg_FillAutofillFormData::ID);
157
158 // No message should be sent in this case. |firstname| is filled directly.
159 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2);
160 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David"));
161 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698