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

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: Fix copyright header 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
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/autofill/form_manager_browsertest.cc » ('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/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"
(...skipping 28 matching lines...) Expand all
39 // Verify that "FormsSeen" sends the expected number of fields. 39 // Verify that "FormsSeen" sends the expected number of fields.
40 ProcessPendingMessages(); 40 ProcessPendingMessages();
41 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( 41 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching(
42 AutofillHostMsg_FormsSeen::ID); 42 AutofillHostMsg_FormsSeen::ID);
43 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); 43 ASSERT_NE(static_cast<IPC::Message*>(NULL), message);
44 AutofillHostMsg_FormsSeen::Param params; 44 AutofillHostMsg_FormsSeen::Param params;
45 AutofillHostMsg_FormsSeen::Read(message, &params); 45 AutofillHostMsg_FormsSeen::Read(message, &params);
46 const std::vector<FormData>& forms = params.a; 46 const std::vector<FormData>& forms = params.a;
47 ASSERT_EQ(1UL, forms.size()); 47 ASSERT_EQ(1UL, forms.size());
48 ASSERT_EQ(3UL, forms[0].fields.size()); 48 ASSERT_EQ(3UL, forms[0].fields.size());
49 EXPECT_TRUE(forms[0].fields[0].StrictlyEqualsHack( 49
50 FormField(string16(), 50 FormField expected;
51 ASCIIToUTF16("firstname"), 51
52 string16(), 52 expected.name = ASCIIToUTF16("firstname");
53 ASCIIToUTF16("text"), 53 expected.value = string16();
54 WebInputElement::defaultMaxLength(), 54 expected.form_control_type = ASCIIToUTF16("text");
55 false))) << forms[0].fields[0]; 55 expected.max_length = WebInputElement::defaultMaxLength();
56 EXPECT_TRUE(forms[0].fields[1].StrictlyEqualsHack( 56 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[0]);
57 FormField(string16(), 57
58 ASCIIToUTF16("middlename"), 58 expected.name = ASCIIToUTF16("middlename");
59 string16(), 59 expected.value = string16();
60 ASCIIToUTF16("text"), 60 expected.form_control_type = ASCIIToUTF16("text");
61 WebInputElement::defaultMaxLength(), 61 expected.max_length = WebInputElement::defaultMaxLength();
62 false))) << forms[0].fields[1]; 62 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[1]);
63 EXPECT_TRUE(forms[0].fields[2].StrictlyEqualsHack( 63
64 FormField(string16(), 64 expected.name = ASCIIToUTF16("state");
65 ASCIIToUTF16("state"), 65 expected.value = ASCIIToUTF16("?");
66 ASCIIToUTF16("?"), 66 expected.form_control_type = ASCIIToUTF16("select-one");
67 ASCIIToUTF16("select-one"), 67 expected.max_length = 0;
68 0, 68 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[2]);
69 false))) << forms[0].fields[2];
70 69
71 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of 70 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of
72 // fields. 71 // fields.
73 WebFrame* web_frame = GetMainFrame(); 72 WebFrame* web_frame = GetMainFrame();
74 WebDocument document = web_frame->document(); 73 WebDocument document = web_frame->document();
75 WebInputElement firstname = 74 WebInputElement firstname =
76 document.getElementById("firstname").to<WebInputElement>(); 75 document.getElementById("firstname").to<WebInputElement>();
77 76
78 // Accept suggestion that contains a label. Labeled items indicate Autofill 77 // Accept suggestion that contains a label. Labeled items indicate Autofill
79 // as opposed to Autocomplete. We're testing this distinction below with 78 // as opposed to Autocomplete. We're testing this distinction below with
80 // the |AutofillHostMsg_FillAutofillFormData::ID| message. 79 // the |AutofillHostMsg_FillAutofillFormData::ID| message.
81 autofill_agent_->didAcceptAutofillSuggestion( 80 autofill_agent_->didAcceptAutofillSuggestion(
82 firstname, 81 firstname,
83 WebKit::WebString::fromUTF8("Johnny"), 82 WebKit::WebString::fromUTF8("Johnny"),
84 WebKit::WebString::fromUTF8("Home"), 83 WebKit::WebString::fromUTF8("Home"),
85 1, 84 1,
86 -1); 85 -1);
87 86
88 ProcessPendingMessages(); 87 ProcessPendingMessages();
89 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( 88 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
90 AutofillHostMsg_FillAutofillFormData::ID); 89 AutofillHostMsg_FillAutofillFormData::ID);
91 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2); 90 ASSERT_NE(static_cast<IPC::Message*>(NULL), message2);
92 AutofillHostMsg_FillAutofillFormData::Param params2; 91 AutofillHostMsg_FillAutofillFormData::Param params2;
93 AutofillHostMsg_FillAutofillFormData::Read(message2, &params2); 92 AutofillHostMsg_FillAutofillFormData::Read(message2, &params2);
94 const FormData& form2 = params2.b; 93 const FormData& form2 = params2.b;
95 ASSERT_EQ(3UL, form2.fields.size()); 94 ASSERT_EQ(3UL, form2.fields.size());
96 EXPECT_TRUE(form2.fields[0].StrictlyEqualsHack( 95
97 FormField(string16(), 96 expected.name = ASCIIToUTF16("firstname");
98 ASCIIToUTF16("firstname"), 97 expected.value = string16();
99 string16(), 98 expected.form_control_type = ASCIIToUTF16("text");
100 ASCIIToUTF16("text"), 99 expected.max_length = WebInputElement::defaultMaxLength();
101 WebInputElement::defaultMaxLength(), 100 EXPECT_FORM_FIELD_EQUALS(expected, form2.fields[0]);
102 false))) << form2.fields[0]; 101
103 EXPECT_TRUE(form2.fields[1].StrictlyEqualsHack( 102 expected.name = ASCIIToUTF16("middlename");
104 FormField(string16(), 103 expected.value = string16();
105 ASCIIToUTF16("middlename"), 104 expected.form_control_type = ASCIIToUTF16("text");
106 string16(), 105 expected.max_length = WebInputElement::defaultMaxLength();
107 ASCIIToUTF16("text"), 106 EXPECT_FORM_FIELD_EQUALS(expected, form2.fields[1]);
108 WebInputElement::defaultMaxLength(), 107
109 false))) << form2.fields[1]; 108 expected.name = ASCIIToUTF16("state");
110 EXPECT_TRUE(form2.fields[2].StrictlyEqualsHack( 109 expected.value = ASCIIToUTF16("?");
111 FormField(string16(), 110 expected.form_control_type = ASCIIToUTF16("select-one");
112 ASCIIToUTF16("state"), 111 expected.max_length = 0;
113 ASCIIToUTF16("?"), 112 EXPECT_FORM_FIELD_EQUALS(expected, form2.fields[2]);
114 ASCIIToUTF16("select-one"),
115 0,
116 false))) << form2.fields[2];
117 } 113 }
118 114
119 TEST_F(RenderViewTest, FillFormElement) { 115 TEST_F(RenderViewTest, FillFormElement) {
120 // Don't want any delay for form state sync changes. This will still post a 116 // 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 117 // message so updates will get coalesced, but as soon as we spin the message
122 // loop, it will generate an update. 118 // loop, it will generate an update.
123 view_->set_send_content_state_immediately(true); 119 view_->set_send_content_state_immediately(true);
124 120
125 LoadHTML("<form method=\"POST\">" 121 LoadHTML("<form method=\"POST\">"
126 " <input type=\"text\" id=\"firstname\"/>" 122 " <input type=\"text\" id=\"firstname\"/>"
(...skipping 25 matching lines...) Expand all
152 0); 148 0);
153 149
154 ProcessPendingMessages(); 150 ProcessPendingMessages();
155 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( 151 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching(
156 AutofillHostMsg_FillAutofillFormData::ID); 152 AutofillHostMsg_FillAutofillFormData::ID);
157 153
158 // No message should be sent in this case. |firstname| is filled directly. 154 // No message should be sent in this case. |firstname| is filled directly.
159 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); 155 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2);
160 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); 156 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David"));
161 } 157 }
OLDNEW
« no previous file with comments | « chrome/chrome_tests.gypi ('k') | chrome/renderer/autofill/form_manager_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698