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

Side by Side Diff: chrome/browser/password_manager/password_manager_browsertest.cc

Issue 19705013: [password autofill] Remove references to PasswordForm from RenderViewImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 9 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 } 105 }
106 106
107 content::RenderViewHost* RenderViewHost() { 107 content::RenderViewHost* RenderViewHost() {
108 return WebContents()->GetRenderViewHost(); 108 return WebContents()->GetRenderViewHost();
109 } 109 }
110 110
111 private: 111 private:
112 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest); 112 DISALLOW_COPY_AND_ASSIGN(PasswordManagerBrowserTest);
113 }; 113 };
114 114
115 // Actual tests ---------------------------------------------------------------
116 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForNormalSubmit) {
117 ASSERT_TRUE(test_server()->Start());
115 118
116 // Actual tests --------------------------------------------------------------- 119 GURL url = test_server()->GetURL("files/password/password_form.html");
120 ui_test_utils::NavigateToURL(browser(), url);
121
122 // Fill a form and submit through a <input type="submit"> button. Nothing
123 // special.
124 NavigationObserver observer(WebContents());
125 std::string fill_and_submit =
126 "document.getElementById('username_field').value = 'temp';"
127 "document.getElementById('password_field').value = 'random';"
128 "document.getElementById('input_submit_button').click()";
129 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
130 observer.Wait();
131 EXPECT_TRUE(observer.infobar_shown());
132 }
133
134 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
135 PromptForSubmitUsingJavaScript) {
136 ASSERT_TRUE(test_server()->Start());
137
138 GURL url = test_server()->GetURL("files/password/password_form.html");
139 ui_test_utils::NavigateToURL(browser(), url);
140
141 // Fill a form and submit using <button> that calls submit() on the form.
142 // This should work regardless of the type of element, as long as submit() is
143 // called.
144 NavigationObserver observer(WebContents());
145 std::string fill_and_submit =
146 "document.getElementById('username_field').value = 'temp';"
147 "document.getElementById('password_field').value = 'random';"
148 "document.getElementById('submit_button').click()";
149 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
150 observer.Wait();
151 EXPECT_TRUE(observer.infobar_shown());
152 }
153
154 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) {
155 ASSERT_TRUE(test_server()->Start());
156
157 GURL url = test_server()->GetURL("files/password/password_form.html");
158 ui_test_utils::NavigateToURL(browser(), url);
159
160 // Don't fill the password form, just navigate away. Shouldn't prompt.
161 NavigationObserver observer(WebContents());
162 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
163 "window.location.href = 'done.html';"));
164 observer.Wait();
165 EXPECT_FALSE(observer.infobar_shown());
166 }
167
168 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
169 NoPromptForSubFrameNavigation) {
170 ASSERT_TRUE(test_server()->Start());
171
172 GURL url = test_server()->GetURL("files/password/multi_frames.html");
173 ui_test_utils::NavigateToURL(browser(), url);
174
175 // If you are filling out a password form in one frame and a different frame
176 // navigates, this should not trigger the infobar.
177 NavigationObserver observer(WebContents());
178 std::string fill =
179 "var first_frame = document.getElementById('first_frame');"
180 "var frame_doc = first_frame.contentDocument;"
181 "frame_doc.getElementById('username_field').value = 'temp';"
182 "frame_doc.getElementById('password_field').value = 'random';";
183 std::string navigate_frame =
184 "var second_iframe = document.getElementById('second_frame');"
185 "second_iframe.contentWindow.location.href = 'done.html';";
186
187 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
188 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
189 observer.Wait();
190 EXPECT_FALSE(observer.infobar_shown());
191 }
192
193 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
194 PromptAfterSubmitWithSubFrameNavigation) {
195 ASSERT_TRUE(test_server()->Start());
196
197 GURL url = test_server()->GetURL("files/password/multi_frames.html");
198 ui_test_utils::NavigateToURL(browser(), url);
199
200 // Make sure that we prompt to save password even if a sub-frame navigation
201 // happens first.
202 NavigationObserver observer(WebContents());
203 std::string navigate_frame =
204 "var second_iframe = document.getElementById('second_frame');"
205 "second_iframe.contentWindow.location.href = 'done.html';";
206 std::string fill_and_submit =
207 "var first_frame = document.getElementById('first_frame');"
208 "var frame_doc = first_frame.contentDocument;"
209 "frame_doc.getElementById('username_field').value = 'temp';"
210 "frame_doc.getElementById('password_field').value = 'random';"
211 "frame_doc.getElementById('input_submit_button').click();";
212
213 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
214 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
215 observer.Wait();
216 EXPECT_TRUE(observer.infobar_shown());
217 }
117 218
118 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { 219 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) {
119 #if defined(OS_WIN) && defined(USE_ASH) 220 #if defined(OS_WIN) && defined(USE_ASH)
120 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 221 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
121 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 222 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
122 return; 223 return;
123 #endif 224 #endif
124 225
125 ASSERT_TRUE(test_server()->Start()); 226 ASSERT_TRUE(test_server()->Start());
126 227
(...skipping 27 matching lines...) Expand all
154 // cases where the element that users click on isn't a submit button. 255 // cases where the element that users click on isn't a submit button.
155 NavigationObserver observer(WebContents()); 256 NavigationObserver observer(WebContents());
156 std::string fill_and_navigate = 257 std::string fill_and_navigate =
157 "document.getElementById('username_field').value = 'temp';" 258 "document.getElementById('username_field').value = 'temp';"
158 "document.getElementById('password_field').value = 'random';" 259 "document.getElementById('password_field').value = 'random';"
159 "send_xhr()"; 260 "send_xhr()";
160 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 261 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
161 observer.Wait(); 262 observer.Wait();
162 EXPECT_FALSE(observer.infobar_shown()); 263 EXPECT_FALSE(observer.infobar_shown());
163 } 264 }
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/password_manager.cc ('k') | chrome/browser/password_manager/password_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698