OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/common/render_messages.h" | 5 #include "chrome/common/autofill_messages.h" |
6 #include "chrome/test/render_view_test.h" | 6 #include "chrome/test/render_view_test.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 8 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" | 10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" |
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
12 #include "webkit/glue/form_data.h" | 12 #include "webkit/glue/form_data.h" |
13 #include "webkit/glue/web_io_operators.h" | 13 #include "webkit/glue/web_io_operators.h" |
14 | 14 |
15 using webkit_glue::FormData; | 15 using webkit_glue::FormData; |
16 using WebKit::WebFrame; | 16 using WebKit::WebFrame; |
17 using WebKit::WebString; | 17 using WebKit::WebString; |
18 using WebKit::WebTextDirection; | 18 using WebKit::WebTextDirection; |
19 using WebKit::WebURLError; | 19 using WebKit::WebURLError; |
20 | 20 |
21 typedef RenderViewTest FormAutocompleteTest; | 21 typedef RenderViewTest 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 ViewHostMsg_FormSubmitted::ID); | 35 AutoFillHostMsg_FormSubmitted::ID); |
36 ASSERT_TRUE(message != NULL); | 36 ASSERT_TRUE(message != NULL); |
37 | 37 |
38 Tuple1<FormData> forms; | 38 Tuple1<FormData> forms; |
39 ViewHostMsg_FormSubmitted::Read(message, &forms); | 39 AutoFillHostMsg_FormSubmitted::Read(message, &forms); |
40 ASSERT_EQ(2U, forms.a.fields.size()); | 40 ASSERT_EQ(2U, forms.a.fields.size()); |
41 | 41 |
42 webkit_glue::FormField& form_field = forms.a.fields[0]; | 42 webkit_glue::FormField& form_field = forms.a.fields[0]; |
43 EXPECT_EQ(WebString("fname"), form_field.name()); | 43 EXPECT_EQ(WebString("fname"), form_field.name()); |
44 EXPECT_EQ(WebString("Rick"), form_field.value()); | 44 EXPECT_EQ(WebString("Rick"), form_field.value()); |
45 | 45 |
46 form_field = forms.a.fields[1]; | 46 form_field = forms.a.fields[1]; |
47 EXPECT_EQ(WebString("lname"), form_field.name()); | 47 EXPECT_EQ(WebString("lname"), form_field.name()); |
48 EXPECT_EQ(WebString("Deckard"), form_field.value()); | 48 EXPECT_EQ(WebString("Deckard"), form_field.value()); |
49 } | 49 } |
50 | 50 |
51 // 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 |
52 // FormSubmitted message. | 52 // FormSubmitted message. |
53 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { | 53 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |
54 // Load a form. | 54 // Load a form. |
55 LoadHTML("<html><form id='myForm' autocomplete='off'>" | 55 LoadHTML("<html><form id='myForm' autocomplete='off'>" |
56 "<input name='fname' value='Rick'/>" | 56 "<input name='fname' value='Rick'/>" |
57 "<input name='lname' value='Deckard'/>" | 57 "<input name='lname' value='Deckard'/>" |
58 "</form></html>"); | 58 "</form></html>"); |
59 | 59 |
60 // Submit the form. | 60 // Submit the form. |
61 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 61 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
62 ProcessPendingMessages(); | 62 ProcessPendingMessages(); |
63 | 63 |
64 // No FormSubmitted message should have been sent. | 64 // No FormSubmitted message should have been sent. |
65 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( | 65 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( |
66 ViewHostMsg_FormSubmitted::ID)); | 66 AutoFillHostMsg_FormSubmitted::ID)); |
67 } | 67 } |
68 | 68 |
69 // Tests that fields with autocomplete off are not submitted. | 69 // Tests that fields with autocomplete off are not submitted. |
70 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { | 70 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { |
71 // Load a form. | 71 // Load a form. |
72 LoadHTML("<html><form id='myForm'>" | 72 LoadHTML("<html><form id='myForm'>" |
73 "<input name='fname' value='Rick'/>" | 73 "<input name='fname' value='Rick'/>" |
74 "<input name='lname' value='Deckard' autocomplete='off'/>" | 74 "<input name='lname' value='Deckard' autocomplete='off'/>" |
75 "</form></html>"); | 75 "</form></html>"); |
76 | 76 |
77 // Submit the form. | 77 // Submit the form. |
78 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 78 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
79 ProcessPendingMessages(); | 79 ProcessPendingMessages(); |
80 | 80 |
81 // No FormSubmitted message should have been sent. | 81 // No FormSubmitted message should have been sent. |
82 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( | 82 const IPC::Message* message = render_thread_.sink().GetFirstMessageMatching( |
83 ViewHostMsg_FormSubmitted::ID); | 83 AutoFillHostMsg_FormSubmitted::ID); |
84 ASSERT_TRUE(message != NULL); | 84 ASSERT_TRUE(message != NULL); |
85 | 85 |
86 Tuple1<FormData> forms; | 86 Tuple1<FormData> forms; |
87 ViewHostMsg_FormSubmitted::Read(message, &forms); | 87 AutoFillHostMsg_FormSubmitted::Read(message, &forms); |
88 ASSERT_EQ(1U, forms.a.fields.size()); | 88 ASSERT_EQ(1U, forms.a.fields.size()); |
89 | 89 |
90 webkit_glue::FormField& form_field = forms.a.fields[0]; | 90 webkit_glue::FormField& form_field = forms.a.fields[0]; |
91 EXPECT_EQ(WebString("fname"), form_field.name()); | 91 EXPECT_EQ(WebString("fname"), form_field.name()); |
92 EXPECT_EQ(WebString("Rick"), form_field.value()); | 92 EXPECT_EQ(WebString("Rick"), form_field.value()); |
93 } | 93 } |
94 | 94 |
95 // Tests that submitting a form that has been dynamically set as autocomplete | 95 // Tests that submitting a form that has been dynamically set as autocomplete |
96 // off does not generate a FormSubmitted message. | 96 // off does not generate a FormSubmitted message. |
97 // http://crbug.com/36520 | 97 // http://crbug.com/36520 |
(...skipping 12 matching lines...) Expand all Loading... |
110 ExecuteJavaScript("document.getElementById('myForm').autocomplete='off';"); | 110 ExecuteJavaScript("document.getElementById('myForm').autocomplete='off';"); |
111 ProcessPendingMessages(); | 111 ProcessPendingMessages(); |
112 EXPECT_FALSE(form.autoComplete()); | 112 EXPECT_FALSE(form.autoComplete()); |
113 | 113 |
114 // Submit the form. | 114 // Submit the form. |
115 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 115 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
116 ProcessPendingMessages(); | 116 ProcessPendingMessages(); |
117 | 117 |
118 // No FormSubmitted message should have been sent. | 118 // No FormSubmitted message should have been sent. |
119 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( | 119 EXPECT_FALSE(render_thread_.sink().GetFirstMessageMatching( |
120 ViewHostMsg_FormSubmitted::ID)); | 120 AutoFillHostMsg_FormSubmitted::ID)); |
121 } | 121 } |
OLD | NEW |