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