Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/renderer/autofill/form_autocomplete_browsertest.cc

Issue 1257603003: Revert of Add ExecuteJavaScriptForTest and make all tests use it (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/test/mock_render_thread.h" 9 #include "content/public/test/mock_render_thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 } // end namespace 67 } // end namespace
68 68
69 // Tests that submitting a form generates WillSubmitForm and FormSubmitted 69 // Tests that submitting a form generates WillSubmitForm and FormSubmitted
70 // messages with the form fields. 70 // messages with the form fields.
71 TEST_F(FormAutocompleteTest, NormalFormSubmit) { 71 TEST_F(FormAutocompleteTest, NormalFormSubmit) {
72 // Load a form. 72 // Load a form.
73 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" 73 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
74 "<input name='lname' value='Deckard'/></form></html>"); 74 "<input name='lname' value='Deckard'/></form></html>");
75 75
76 // Submit the form. 76 // Submit the form.
77 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 77 ExecuteJavaScript("document.getElementById('myForm').submit();");
78 ProcessPendingMessages(); 78 ProcessPendingMessages();
79 79
80 VerifyReceivedRendererMessages(render_thread_.get(), 80 VerifyReceivedRendererMessages(render_thread_.get(),
81 true /* expect_submitted_message */); 81 true /* expect_submitted_message */);
82 } 82 }
83 83
84 // Tests that submitting a form that prevents the submit event from propagating 84 // Tests that submitting a form that prevents the submit event from propagating
85 // will only send the WillSubmitForm message. 85 // will only send the WillSubmitForm message.
86 TEST_F(FormAutocompleteTest, SubmitEventPrevented) { 86 TEST_F(FormAutocompleteTest, SubmitEventPrevented) {
87 // Load a form. 87 // Load a form.
88 LoadHTML( 88 LoadHTML(
89 "<html><form id='myForm'><input name='fname' value='Rick'/>" 89 "<html><form id='myForm'><input name='fname' value='Rick'/>"
90 "<input name='lname' value='Deckard'/><input type=submit></form>" 90 "<input name='lname' value='Deckard'/><input type=submit></form>"
91 "</html>"); 91 "</html>");
92 92
93 // Submit the form. 93 // Submit the form.
94 ExecuteJavaScriptForTests( 94 ExecuteJavaScript(
95 "var form = document.forms[0];" 95 "var form = document.forms[0];"
96 "form.onsubmit = function(event) { event.preventDefault(); };" 96 "form.onsubmit = function(event) { event.preventDefault(); };"
97 "document.querySelector('input[type=submit]').click();"); 97 "document.querySelector('input[type=submit]').click();");
98 ProcessPendingMessages(); 98 ProcessPendingMessages();
99 99
100 VerifyReceivedRendererMessages(render_thread_.get(), 100 VerifyReceivedRendererMessages(render_thread_.get(),
101 false /* expect_submitted_message */); 101 false /* expect_submitted_message */);
102 } 102 }
103 103
104 // Tests that submitting a form that has autocomplete="off" generates 104 // Tests that submitting a form that has autocomplete="off" generates
105 // WillSubmitForm and FormSubmitted messages. 105 // WillSubmitForm and FormSubmitted messages.
106 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) { 106 TEST_F(FormAutocompleteTest, AutoCompleteOffFormSubmit) {
107 // Load a form. 107 // Load a form.
108 LoadHTML("<html><form id='myForm' autocomplete='off'>" 108 LoadHTML("<html><form id='myForm' autocomplete='off'>"
109 "<input name='fname' value='Rick'/>" 109 "<input name='fname' value='Rick'/>"
110 "<input name='lname' value='Deckard'/>" 110 "<input name='lname' value='Deckard'/>"
111 "</form></html>"); 111 "</form></html>");
112 112
113 // Submit the form. 113 // Submit the form.
114 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 114 ExecuteJavaScript("document.getElementById('myForm').submit();");
115 ProcessPendingMessages(); 115 ProcessPendingMessages();
116 116
117 VerifyReceivedRendererMessages(render_thread_.get(), 117 VerifyReceivedRendererMessages(render_thread_.get(),
118 true /* expect_submitted_message */); 118 true /* expect_submitted_message */);
119 } 119 }
120 120
121 // Tests that fields with autocomplete off are submitted. 121 // Tests that fields with autocomplete off are submitted.
122 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) { 122 TEST_F(FormAutocompleteTest, AutoCompleteOffInputSubmit) {
123 // Load a form. 123 // Load a form.
124 LoadHTML("<html><form id='myForm'>" 124 LoadHTML("<html><form id='myForm'>"
125 "<input name='fname' value='Rick'/>" 125 "<input name='fname' value='Rick'/>"
126 "<input name='lname' value='Deckard' autocomplete='off'/>" 126 "<input name='lname' value='Deckard' autocomplete='off'/>"
127 "</form></html>"); 127 "</form></html>");
128 128
129 // Submit the form. 129 // Submit the form.
130 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 130 ExecuteJavaScript("document.getElementById('myForm').submit();");
131 ProcessPendingMessages(); 131 ProcessPendingMessages();
132 132
133 VerifyReceivedRendererMessages(render_thread_.get(), 133 VerifyReceivedRendererMessages(render_thread_.get(),
134 true /* expect_submitted_message */); 134 true /* expect_submitted_message */);
135 } 135 }
136 136
137 // Tests that submitting a form that has been dynamically set as autocomplete 137 // Tests that submitting a form that has been dynamically set as autocomplete
138 // off generates WillSubmitForm and FormSubmitted messages. 138 // off generates WillSubmitForm and FormSubmitted messages.
139 // Note: We previously did the opposite, for bug http://crbug.com/36520 139 // Note: We previously did the opposite, for bug http://crbug.com/36520
140 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) { 140 TEST_F(FormAutocompleteTest, DynamicAutoCompleteOffFormSubmit) {
141 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>" 141 LoadHTML("<html><form id='myForm'><input name='fname' value='Rick'/>"
142 "<input name='lname' value='Deckard'/></form></html>"); 142 "<input name='lname' value='Deckard'/></form></html>");
143 143
144 blink::WebElement element = 144 blink::WebElement element =
145 GetMainFrame()->document().getElementById(blink::WebString("myForm")); 145 GetMainFrame()->document().getElementById(blink::WebString("myForm"));
146 ASSERT_FALSE(element.isNull()); 146 ASSERT_FALSE(element.isNull());
147 blink::WebFormElement form = element.to<blink::WebFormElement>(); 147 blink::WebFormElement form = element.to<blink::WebFormElement>();
148 EXPECT_TRUE(form.autoComplete()); 148 EXPECT_TRUE(form.autoComplete());
149 149
150 // Dynamically mark the form as autocomplete off. 150 // Dynamically mark the form as autocomplete off.
151 ExecuteJavaScriptForTests( 151 ExecuteJavaScript("document.getElementById('myForm')."
152 "document.getElementById('myForm')." 152 "setAttribute('autocomplete', 'off');");
153 "setAttribute('autocomplete', 'off');");
154 ProcessPendingMessages(); 153 ProcessPendingMessages();
155 EXPECT_FALSE(form.autoComplete()); 154 EXPECT_FALSE(form.autoComplete());
156 155
157 // Submit the form. 156 // Submit the form.
158 ExecuteJavaScriptForTests("document.getElementById('myForm').submit();"); 157 ExecuteJavaScript("document.getElementById('myForm').submit();");
159 ProcessPendingMessages(); 158 ProcessPendingMessages();
160 159
161 VerifyReceivedRendererMessages(render_thread_.get(), 160 VerifyReceivedRendererMessages(render_thread_.get(),
162 true /* expect_submitted_message */); 161 true /* expect_submitted_message */);
163 } 162 }
164 163
165 } // namespace autofill 164 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/renderer/autofill/autofill_renderer_browsertest.cc ('k') | chrome/renderer/autofill/form_autofill_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698