| 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/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 11 matching lines...) Expand all Loading... |
| 22 namespace autofill { | 22 namespace autofill { |
| 23 | 23 |
| 24 TEST_F(RenderViewTest, SendForms) { | 24 TEST_F(RenderViewTest, SendForms) { |
| 25 // Don't want any delay for form state sync changes. This will still post a | 25 // Don't want any delay for form state sync changes. This will still post a |
| 26 // message so updates will get coalesced, but as soon as we spin the message | 26 // message so updates will get coalesced, but as soon as we spin the message |
| 27 // loop, it will generate an update. | 27 // loop, it will generate an update. |
| 28 view_->set_send_content_state_immediately(true); | 28 view_->set_send_content_state_immediately(true); |
| 29 | 29 |
| 30 LoadHTML("<form method=\"POST\">" | 30 LoadHTML("<form method=\"POST\">" |
| 31 " <input type=\"text\" id=\"firstname\"/>" | 31 " <input type=\"text\" id=\"firstname\"/>" |
| 32 " <input type=\"text\" id=\"middlename\" autoComplete=\"off\"/>" | 32 " <input type=\"text\" id=\"middlename\"/>" |
| 33 " <input type=\"hidden\" id=\"lastname\"/>" | 33 " <input type=\"text\" id=\"lastname\" autoComplete=\"off\"/>" |
| 34 " <input type=\"hidden\" id=\"email\"/>" |
| 34 " <select id=\"state\"/>" | 35 " <select id=\"state\"/>" |
| 35 " <option>?</option>" | 36 " <option>?</option>" |
| 36 " <option>California</option>" | 37 " <option>California</option>" |
| 37 " <option>Texas</option>" | 38 " <option>Texas</option>" |
| 38 " </select>" | 39 " </select>" |
| 39 "</form>"); | 40 "</form>"); |
| 40 | 41 |
| 41 // Verify that "FormsSeen" sends the expected number of fields. | 42 // Verify that "FormsSeen" sends the expected number of fields. |
| 42 ProcessPendingMessages(); | 43 ProcessPendingMessages(); |
| 43 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 44 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
| 44 AutofillHostMsg_FormsSeen::ID); | 45 AutofillHostMsg_FormsSeen::ID); |
| 45 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); | 46 ASSERT_NE(static_cast<IPC::Message*>(NULL), message); |
| 46 AutofillHostMsg_FormsSeen::Param params; | 47 AutofillHostMsg_FormsSeen::Param params; |
| 47 AutofillHostMsg_FormsSeen::Read(message, ¶ms); | 48 AutofillHostMsg_FormsSeen::Read(message, ¶ms); |
| 48 const std::vector<FormData>& forms = params.a; | 49 const std::vector<FormData>& forms = params.a; |
| 49 ASSERT_EQ(1UL, forms.size()); | 50 ASSERT_EQ(1UL, forms.size()); |
| 50 ASSERT_EQ(3UL, forms[0].fields.size()); | 51 ASSERT_EQ(4UL, forms[0].fields.size()); |
| 51 | 52 |
| 52 FormField expected; | 53 FormField expected; |
| 53 | 54 |
| 54 expected.name = ASCIIToUTF16("firstname"); | 55 expected.name = ASCIIToUTF16("firstname"); |
| 55 expected.value = string16(); | 56 expected.value = string16(); |
| 56 expected.form_control_type = ASCIIToUTF16("text"); | 57 expected.form_control_type = ASCIIToUTF16("text"); |
| 57 expected.max_length = WebInputElement::defaultMaxLength(); | 58 expected.max_length = WebInputElement::defaultMaxLength(); |
| 58 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[0]); | 59 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[0]); |
| 59 | 60 |
| 60 expected.name = ASCIIToUTF16("middlename"); | 61 expected.name = ASCIIToUTF16("middlename"); |
| 61 expected.value = string16(); | 62 expected.value = string16(); |
| 62 expected.form_control_type = ASCIIToUTF16("text"); | 63 expected.form_control_type = ASCIIToUTF16("text"); |
| 63 expected.max_length = WebInputElement::defaultMaxLength(); | 64 expected.max_length = WebInputElement::defaultMaxLength(); |
| 64 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[1]); | 65 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[1]); |
| 65 | 66 |
| 67 expected.name = ASCIIToUTF16("lastname"); |
| 68 expected.value = string16(); |
| 69 expected.form_control_type = ASCIIToUTF16("text"); |
| 70 expected.max_length = WebInputElement::defaultMaxLength(); |
| 71 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[2]); |
| 72 |
| 66 expected.name = ASCIIToUTF16("state"); | 73 expected.name = ASCIIToUTF16("state"); |
| 67 expected.value = ASCIIToUTF16("?"); | 74 expected.value = ASCIIToUTF16("?"); |
| 68 expected.form_control_type = ASCIIToUTF16("select-one"); | 75 expected.form_control_type = ASCIIToUTF16("select-one"); |
| 69 expected.max_length = 0; | 76 expected.max_length = 0; |
| 70 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[2]); | 77 EXPECT_FORM_FIELD_EQUALS(expected, forms[0].fields[3]); |
| 71 | 78 |
| 72 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of | 79 // Verify that |didAcceptAutofillSuggestion()| sends the expected number of |
| 73 // fields. | 80 // fields. |
| 74 WebFrame* web_frame = GetMainFrame(); | 81 WebFrame* web_frame = GetMainFrame(); |
| 75 WebDocument document = web_frame->document(); | 82 WebDocument document = web_frame->document(); |
| 76 WebInputElement firstname = | 83 WebInputElement firstname = |
| 77 document.getElementById("firstname").to<WebInputElement>(); | 84 document.getElementById("firstname").to<WebInputElement>(); |
| 78 | 85 |
| 79 // Accept suggestion that contains a label. Labeled items indicate Autofill | 86 // Accept suggestion that contains a label. Labeled items indicate Autofill |
| 80 // as opposed to Autocomplete. We're testing this distinction below with | 87 // as opposed to Autocomplete. We're testing this distinction below with |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 ProcessPendingMessages(); | 159 ProcessPendingMessages(); |
| 153 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( | 160 const IPC::Message* message2 = render_thread_.sink().GetUniqueMessageMatching( |
| 154 AutofillHostMsg_FillAutofillFormData::ID); | 161 AutofillHostMsg_FillAutofillFormData::ID); |
| 155 | 162 |
| 156 // No message should be sent in this case. |firstname| is filled directly. | 163 // No message should be sent in this case. |firstname| is filled directly. |
| 157 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); | 164 ASSERT_EQ(static_cast<IPC::Message*>(NULL), message2); |
| 158 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); | 165 EXPECT_EQ(firstname.value(), WebKit::WebString::fromUTF8("David")); |
| 159 } | 166 } |
| 160 | 167 |
| 161 } // namespace autofill | 168 } // namespace autofill |
| OLD | NEW |