| 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/time.h" | 5 #include "base/time.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 "content/public/common/form_data.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 9 #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/WebDocument.h" |
| 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| 11 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" | 13 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" |
| 13 #include "webkit/forms/form_data.h" | |
| 14 #include "webkit/glue/web_io_operators.h" | 14 #include "webkit/glue/web_io_operators.h" |
| 15 | 15 |
| 16 using webkit::forms::FormData; | 16 using content::FormData; |
| 17 using WebKit::WebFrame; | 17 using WebKit::WebFrame; |
| 18 using WebKit::WebString; | 18 using WebKit::WebString; |
| 19 using WebKit::WebURLError; | 19 using WebKit::WebURLError; |
| 20 | 20 |
| 21 typedef ChromeRenderViewTest FormAutocompleteTest; | 21 typedef ChromeRenderViewTest FormAutocompleteTest; |
| 22 | 22 |
| 23 // Tests that submitting a form generates a FormSubmitted message | 23 // Tests that submitting a form generates a FormSubmitted message |
| 24 // with the form fields. | 24 // with the form fields. |
| 25 TEST_F(FormAutocompleteTest, NormalFormSubmit) { | 25 TEST_F(FormAutocompleteTest, NormalFormSubmit) { |
| 26 // Load a form. | 26 // Load a form. |
| 27 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 27 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" |
| 28 "<input name='lname' value='Deckard'/></form></html>"); | 28 "<input name='lname' value='Deckard'/></form></html>"); |
| 29 | 29 |
| 30 // Submit the form. | 30 // Submit the form. |
| 31 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 31 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
| 32 ProcessPendingMessages(); | 32 ProcessPendingMessages(); |
| 33 | 33 |
| 34 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 34 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 35 AutofillHostMsg_FormSubmitted::ID); | 35 AutofillHostMsg_FormSubmitted::ID); |
| 36 ASSERT_TRUE(message != NULL); | 36 ASSERT_TRUE(message != NULL); |
| 37 | 37 |
| 38 // The tuple also includes a timestamp, which is ignored. | 38 // The tuple also includes a timestamp, which is ignored. |
| 39 Tuple2<FormData, base::TimeTicks> forms; | 39 Tuple2<FormData, base::TimeTicks> forms; |
| 40 AutofillHostMsg_FormSubmitted::Read(message, &forms); | 40 AutofillHostMsg_FormSubmitted::Read(message, &forms); |
| 41 ASSERT_EQ(2U, forms.a.fields.size()); | 41 ASSERT_EQ(2U, forms.a.fields.size()); |
| 42 | 42 |
| 43 webkit::forms::FormField& form_field = forms.a.fields[0]; | 43 content::FormField& form_field = forms.a.fields[0]; |
| 44 EXPECT_EQ(WebString("fname"), form_field.name); | 44 EXPECT_EQ(WebString("fname"), form_field.name); |
| 45 EXPECT_EQ(WebString("Rick"), form_field.value); | 45 EXPECT_EQ(WebString("Rick"), form_field.value); |
| 46 | 46 |
| 47 form_field = forms.a.fields[1]; | 47 form_field = forms.a.fields[1]; |
| 48 EXPECT_EQ(WebString("lname"), form_field.name); | 48 EXPECT_EQ(WebString("lname"), form_field.name); |
| 49 EXPECT_EQ(WebString("Deckard"), form_field.value); | 49 EXPECT_EQ(WebString("Deckard"), form_field.value); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Tests that submitting a form that has autocomplete="off" does not generate a | 52 // Tests that submitting a form that has autocomplete="off" does not generate a |
| 53 // FormSubmitted message. | 53 // FormSubmitted message. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 82 // No FormSubmitted message should have been sent. | 82 // No FormSubmitted message should have been sent. |
| 83 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 83 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
| 84 AutofillHostMsg_FormSubmitted::ID); | 84 AutofillHostMsg_FormSubmitted::ID); |
| 85 ASSERT_TRUE(message != NULL); | 85 ASSERT_TRUE(message != NULL); |
| 86 | 86 |
| 87 // The tuple also includes a timestamp, which is ignored. | 87 // The tuple also includes a timestamp, which is ignored. |
| 88 Tuple2<FormData, base::TimeTicks> forms; | 88 Tuple2<FormData, base::TimeTicks> forms; |
| 89 AutofillHostMsg_FormSubmitted::Read(message, &forms); | 89 AutofillHostMsg_FormSubmitted::Read(message, &forms); |
| 90 ASSERT_EQ(1U, forms.a.fields.size()); | 90 ASSERT_EQ(1U, forms.a.fields.size()); |
| 91 | 91 |
| 92 webkit::forms::FormField& form_field = forms.a.fields[0]; | 92 content::FormField& form_field = forms.a.fields[0]; |
| 93 EXPECT_EQ(WebString("fname"), form_field.name); | 93 EXPECT_EQ(WebString("fname"), form_field.name); |
| 94 EXPECT_EQ(WebString("Rick"), form_field.value); | 94 EXPECT_EQ(WebString("Rick"), form_field.value); |
| 95 } | 95 } |
| 96 | 96 |
| 97 // Tests that submitting a form that has been dynamically set as autocomplete | 97 // Tests that submitting a form that has been dynamically set as autocomplete |
| 98 // off does not generate a FormSubmitted message. | 98 // off does not generate a FormSubmitted message. |
| 99 // http://crbug.com/36520 | 99 // http://crbug.com/36520 |
| 100 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { | 100 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { |
| 101 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 101 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" |
| 102 "<input name='lname' value='Deckard'/></form></html>"); | 102 "<input name='lname' value='Deckard'/></form></html>"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 114 EXPECT_FALSE(form.autoComplete()); | 114 EXPECT_FALSE(form.autoComplete()); |
| 115 | 115 |
| 116 // Submit the form. | 116 // Submit the form. |
| 117 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 117 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
| 118 ProcessPendingMessages(); | 118 ProcessPendingMessages(); |
| 119 | 119 |
| 120 // No FormSubmitted message should have been sent. | 120 // No FormSubmitted message should have been sent. |
| 121 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 121 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( |
| 122 AutofillHostMsg_FormSubmitted::ID)); | 122 AutofillHostMsg_FormSubmitted::ID)); |
| 123 } | 123 } |
| OLD | NEW |