| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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. | 86 // Make sure to query for Autofill suggestions before selecting one. |
| 87 autofill_agent_->element_ = firstname; |
| 87 autofill_agent_->QueryAutofillSuggestions(firstname, false); | 88 autofill_agent_->QueryAutofillSuggestions(firstname, false); |
| 88 | 89 |
| 89 // Accept suggestion that contains a label. Labeled items indicate Autofill | 90 // Accept suggestion that contains a label. Labeled items indicate Autofill |
| 90 // as opposed to Autocomplete. We're testing this distinction below with | 91 // as opposed to Autocomplete. We're testing this distinction below with |
| 91 // the |AutofillHostMsg_FillAutofillFormData::ID| message. | 92 // the |AutofillHostMsg_FillAutofillFormData::ID| message. |
| 92 autofill_agent_->didAcceptAutofillSuggestion( | 93 autofill_agent_->didAcceptAutofillSuggestion( |
| 93 firstname, | 94 firstname, |
| 94 WebKit::WebString::fromUTF8("Johnny"), | 95 WebKit::WebString::fromUTF8("Johnny"), |
| 95 WebKit::WebString::fromUTF8("Home"), | 96 WebKit::WebString::fromUTF8("Home"), |
| 96 1, | 97 1, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 // field. | 147 // field. |
| 147 WebFrame* web_frame = GetMainFrame(); | 148 WebFrame* web_frame = GetMainFrame(); |
| 148 WebDocument document = web_frame->document(); | 149 WebDocument document = web_frame->document(); |
| 149 WebInputElement firstname = | 150 WebInputElement firstname = |
| 150 document.getElementById("firstname").to<WebInputElement>(); | 151 document.getElementById("firstname").to<WebInputElement>(); |
| 151 WebInputElement middlename = | 152 WebInputElement middlename = |
| 152 document.getElementById("middlename").to<WebInputElement>(); | 153 document.getElementById("middlename").to<WebInputElement>(); |
| 153 middlename.setAutofilled(true); | 154 middlename.setAutofilled(true); |
| 154 | 155 |
| 155 // Make sure to query for Autofill suggestions before selecting one. | 156 // Make sure to query for Autofill suggestions before selecting one. |
| 157 autofill_agent_->element_ = firstname; |
| 156 autofill_agent_->QueryAutofillSuggestions(firstname, false); | 158 autofill_agent_->QueryAutofillSuggestions(firstname, false); |
| 157 | 159 |
| 158 // Accept a suggestion in a form that has been auto-filled. This triggers | 160 // Accept a suggestion in a form that has been auto-filled. This triggers |
| 159 // the direct filling of the firstname element with value parameter. | 161 // the direct filling of the firstname element with value parameter. |
| 160 autofill_agent_->didAcceptAutofillSuggestion(firstname, | 162 autofill_agent_->didAcceptAutofillSuggestion(firstname, |
| 161 WebString::fromUTF8("David"), | 163 WebString::fromUTF8("David"), |
| 162 WebString(), | 164 WebString(), |
| 163 0, | 165 0, |
| 164 0); | 166 0); |
| 165 | 167 |
| 166 ProcessPendingMessages(); | 168 ProcessPendingMessages(); |
| 167 const IPC::Message* message2 = | 169 const IPC::Message* message2 = |
| 168 render_thread_->sink().GetUniqueMessageMatching( | 170 render_thread_->sink().GetUniqueMessageMatching( |
| 169 AutofillHostMsg_FillAutofillFormData::ID); | 171 AutofillHostMsg_FillAutofillFormData::ID); |
| 170 | 172 |
| 171 // No message should be sent in this case. |firstname| is filled directly. | 173 // No message should be sent in this case. |firstname| is filled directly. |
| 172 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 174 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
| 173 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 175 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace autofill | 178 } // namespace autofill |
| OLD | NEW |