OLD | NEW |
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/chrome_render_view_test.h" | 7 #include "chrome/test/base/chrome_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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 expected.max_length = 0; | 76 expected.max_length = 0; |
77 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[3]); | 77 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[3]); |
78 | 78 |
79 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of | 79 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of |
80 // fields. | 80 // fields. |
81 WebFrame* web_frame = GetMainFrame(); | 81 WebFrame* web_frame = GetMainFrame(); |
82 WebDocument document = web_frame->document(); | 82 WebDocument document = web_frame->document(); |
83 WebInputElement firstname = | 83 WebInputElement firstname = |
84 document.getElementById("firstname").to<WebInputElement>(); | 84 document.getElementById("firstname").to<WebInputElement>(); |
85 | 85 |
| 86 // Make sure to query for Autofill suggestions before selecting one. |
| 87 autofill_agent_->QueryAutofillSuggestions(firstname, false); |
| 88 |
86 // Accept suggestion that contains a label. Labeled items indicate Autofill | 89 // Accept suggestion that contains a label. Labeled items indicate Autofill |
87 // as opposed to Autocomplete. We're testing this distinction below with | 90 // as opposed to Autocomplete. We're testing this distinction below with |
88 // the |AutofillHostMsg_FillAutofillFormData::ID| message. | 91 // the |AutofillHostMsg_FillAutofillFormData::ID| message. |
89 autofill_agent_->didAcceptAutofillSuggestion( | 92 autofill_agent_->didAcceptAutofillSuggestion( |
90 firstname, | 93 firstname, |
91 WebKit::WebString::fromUTF8("Johnny"), | 94 WebKit::WebString::fromUTF8("Johnny"), |
92 WebKit::WebString::fromUTF8("Home"), | 95 WebKit::WebString::fromUTF8("Home"), |
93 1, | 96 1, |
94 -1); | 97 -1); |
95 | 98 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // Verify that |didAcceptAutofillSuggestion()| sets the value of the expected | 145 // Verify that |didAcceptAutofillSuggestion()| sets the value of the expected |
143 // field. | 146 // field. |
144 WebFrame* web_frame = GetMainFrame(); | 147 WebFrame* web_frame = GetMainFrame(); |
145 WebDocument document = web_frame->document(); | 148 WebDocument document = web_frame->document(); |
146 WebInputElement firstname = | 149 WebInputElement firstname = |
147 document.getElementById("firstname").to<WebInputElement>(); | 150 document.getElementById("firstname").to<WebInputElement>(); |
148 WebInputElement middlename = | 151 WebInputElement middlename = |
149 document.getElementById("middlename").to<WebInputElement>(); | 152 document.getElementById("middlename").to<WebInputElement>(); |
150 middlename.setAutofilled(true); | 153 middlename.setAutofilled(true); |
151 | 154 |
| 155 // Make sure to query for Autofill suggestions before selecting one. |
| 156 autofill_agent_->QueryAutofillSuggestions(firstname, false); |
| 157 |
152 // Accept a suggestion in a form that has been auto-filled. This triggers | 158 // Accept a suggestion in a form that has been auto-filled. This triggers |
153 // the direct filling of the firstname element with value parameter. | 159 // the direct filling of the firstname element with value parameter. |
154 autofill_agent_->didAcceptAutofillSuggestion(firstname, | 160 autofill_agent_->didAcceptAutofillSuggestion(firstname, |
155 WebString::fromUTF8("David"), | 161 WebString::fromUTF8("David"), |
156 WebString(), | 162 WebString(), |
157 0, | 163 0, |
158 0); | 164 0); |
159 | 165 |
160 ProcessPendingMessages(); | 166 ProcessPendingMessages(); |
161 const IPC::Message* message2 = | 167 const IPC::Message* message2 = |
162 render_thread_->sink().GetUniqueMessageMatching( | 168 render_thread_->sink().GetUniqueMessageMatching( |
163 AutofillHostMsg_FillAutofillFormData::ID); | 169 AutofillHostMsg_FillAutofillFormData::ID); |
164 | 170 |
165 // No message should be sent in this case. |firstname| is filled directly. | 171 // No message should be sent in this case. |firstname| is filled directly. |
166 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 172 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
167 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 173 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
168 } | 174 } |
169 | 175 |
170 } // namespace autofill | 176 } // namespace autofill |
OLD | NEW |