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/time.h" | 5 #include "base/time/time.h" |
6 #include "chrome/test/base/chrome_render_view_test.h" | 6 #include "chrome/test/base/chrome_render_view_test.h" |
7 #include "components/autofill/content/common/autofill_messages.h" | 7 #include "components/autofill/content/common/autofill_messages.h" |
8 #include "components/autofill/core/common/form_data.h" | 8 #include "components/autofill/core/common/form_data.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 | 42 |
43 FormFieldData& form_field = forms.a.fields[0]; | 43 FormFieldData& 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" generates a |
53 // FormSubmitted message. | 53 // FormSubmitted message. |
54 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { | 54 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { |
55 // Load a form. | 55 // Load a form. |
56 LoadHTML("<html><form id='myForm' autocomplete='off'>" | 56 LoadHTML("<html><form id='myForm' autocomplete='off'>" |
57 "<input name='fname' value='Rick'/>" | 57 "<input name='fname' value='Rick'/>" |
58 "<input name='lname' value='Deckard'/>" | 58 "<input name='lname' value='Deckard'/>" |
59 "</form></html>"); | 59 "</form></html>"); |
60 | 60 |
61 // Submit the form. | 61 // Submit the form. |
62 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 62 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
63 ProcessPendingMessages(); | 63 ProcessPendingMessages(); |
64 | 64 |
65 // No FormSubmitted message should have been sent. | 65 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
66 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 66 AutofillHostMsg_FormSubmitted::ID); |
67 AutofillHostMsg_FormSubmitted::ID)); | 67 ASSERT_TRUE(message != NULL); |
68 | |
69 // The tuple also includes a timestamp, which is ignored. | |
70 Tuple2<FormData, base::TimeTicks> forms; | |
71 AutofillHostMsg_FormSubmitted::Read(message, &forms); | |
72 ASSERT_EQ(2U, forms.a.fields.size()); | |
73 | |
74 FormFieldData& form_field = forms.a.fields[0]; | |
75 EXPECT_EQ(WebString("fname"), form_field.name); | |
76 EXPECT_EQ(WebString("Rick"), form_field.value); | |
77 | |
78 form_field = forms.a.fields[1]; | |
79 EXPECT_EQ(WebString("lname"), form_field.name); | |
80 EXPECT_EQ(WebString("Deckard"), form_field.value); | |
68 } | 81 } |
69 | 82 |
70 // Tests that fields with autocomplete off are not submitted. | 83 // Tests that fields with autocomplete off are submitted. |
71 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { | 84 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { |
72 // Load a form. | 85 // Load a form. |
73 LoadHTML("<html><form id='myForm'>" | 86 LoadHTML("<html><form id='myForm'>" |
74 "<input name='fname' value='Rick'/>" | 87 "<input name='fname' value='Rick'/>" |
75 "<input name='lname' value='Deckard' autocomplete='off'/>" | 88 "<input name='lname' value='Deckard' autocomplete='off'/>" |
76 "</form></html>"); | 89 "</form></html>"); |
77 | 90 |
78 // Submit the form. | 91 // Submit the form. |
79 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 92 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
80 ProcessPendingMessages(); | 93 ProcessPendingMessages(); |
81 | 94 |
82 // No FormSubmitted message should have been sent. | |
83 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( | 95 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
84 AutofillHostMsg_FormSubmitted::ID); | 96 AutofillHostMsg_FormSubmitted::ID); |
85 ASSERT_TRUE(message != NULL); | 97 ASSERT_TRUE(message != NULL); |
86 | 98 |
87 // The tuple also includes a timestamp, which is ignored. | 99 // The tuple also includes a timestamp, which is ignored. |
88 Tuple2<FormData, base::TimeTicks> forms; | 100 Tuple2<FormData, base::TimeTicks> forms; |
89 AutofillHostMsg_FormSubmitted::Read(message, &forms); | 101 AutofillHostMsg_FormSubmitted::Read(message, &forms); |
90 ASSERT_EQ(1U, forms.a.fields.size()); | 102 ASSERT_EQ(2U, forms.a.fields.size()); |
91 | 103 |
92 FormFieldData& form_field = forms.a.fields[0]; | 104 FormFieldData& form_field = forms.a.fields[0]; |
93 EXPECT_EQ(WebString("fname"), form_field.name); | 105 EXPECT_EQ(WebString("fname"), form_field.name); |
94 EXPECT_EQ(WebString("Rick"), form_field.value); | 106 EXPECT_EQ(WebString("Rick"), form_field.value); |
107 | |
108 form_field = forms.a.fields[1]; | |
109 EXPECT_EQ(WebString("lname"), form_field.name); | |
110 EXPECT_EQ(WebString("Deckard"), form_field.value); | |
95 } | 111 } |
96 | 112 |
97 // Tests that submitting a form that has been dynamically set as autocomplete | 113 // Tests that submitting a form that has been dynamically set as autocomplete |
98 // off does not generate a FormSubmitted message. | 114 // off generates a FormSubmitted message. |
99 // http://crbug.com/36520 | 115 // Note: We previously did the opposite, for bug http://crbug.com/36520 |
100 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { | 116 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { |
Evan Stade
2014/07/23 23:14:50
I question whether this test has any value any mor
| |
101 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" | 117 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" |
102 "<input name='lname' value='Deckard'/></form></html>"); | 118 "<input name='lname' value='Deckard'/></form></html>"); |
103 | 119 |
104 blink::WebElement element = | 120 blink::WebElement element = |
105 GetMainFrame()->document().getElementById(blink::WebString("myForm")); | 121 GetMainFrame()->document().getElementById(blink::WebString("myForm")); |
106 ASSERT_FALSE(element.isNull()); | 122 ASSERT_FALSE(element.isNull()); |
107 blink::WebFormElement form = element.to<blink::WebFormElement>(); | 123 blink::WebFormElement form = element.to<blink::WebFormElement>(); |
108 EXPECT_TRUE(form.autoComplete()); | 124 EXPECT_TRUE(form.autoComplete()); |
109 | 125 |
110 // Dynamically mark the form as autocomplete off. | 126 // Dynamically mark the form as autocomplete off. |
111 ExecuteJavaScript("document.getElementById('myForm')." | 127 ExecuteJavaScript("document.getElementById('myForm')." |
112 "setAttribute('autocomplete', 'off');"); | 128 "setAttribute('autocomplete', 'off');"); |
113 ProcessPendingMessages(); | 129 ProcessPendingMessages(); |
114 EXPECT_FALSE(form.autoComplete()); | 130 EXPECT_FALSE(form.autoComplete()); |
115 | 131 |
116 // Submit the form. | 132 // Submit the form. |
117 ExecuteJavaScript("document.getElementById('myForm').submit();"); | 133 ExecuteJavaScript("document.getElementById('myForm').submit();"); |
118 ProcessPendingMessages(); | 134 ProcessPendingMessages(); |
119 | 135 |
120 // No FormSubmitted message should have been sent. | 136 const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching( |
121 EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching( | 137 AutofillHostMsg_FormSubmitted::ID); |
122 AutofillHostMsg_FormSubmitted::ID)); | 138 ASSERT_TRUE(message != NULL); |
139 | |
140 // The tuple also includes a timestamp, which is ignored. | |
141 Tuple2<FormData, base::TimeTicks> forms; | |
142 AutofillHostMsg_FormSubmitted::Read(message, &forms); | |
143 ASSERT_EQ(2U, forms.a.fields.size()); | |
144 | |
145 FormFieldData& form_field = forms.a.fields[0]; | |
146 EXPECT_EQ(WebString("fname"), form_field.name); | |
147 EXPECT_EQ(WebString("Rick"), form_field.value); | |
148 | |
149 form_field = forms.a.fields[1]; | |
150 EXPECT_EQ(WebString("lname"), form_field.name); | |
151 EXPECT_EQ(WebString("Deckard"), form_field.value); | |
123 } | 152 } |
124 | 153 |
125 } // namespace autofill | 154 } // namespace autofill |
OLD | NEW |