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

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: Address comments 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 protected: 96 protected:
97 content::WebContents* WebContents() { 97 content::WebContents* WebContents() {
98 return browser()->tab_strip_model()->GetActiveWebContents(); 98 return browser()->tab_strip_model()->GetActiveWebContents();
99 } 99 }
100 100
101 content::RenderViewHost* RenderViewHost() { 101 content::RenderViewHost* RenderViewHost() {
102 return WebContents()->GetRenderViewHost(); 102 return WebContents()->GetRenderViewHost();
103 } 103 }
104 }; 104 };
105 105
106 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForNormalSubmit) {
107 ASSERT_TRUE(test_server()->Start());
108
109 GURL url = test_server()->GetURL("files/password/password_form.html");
110 ui_test_utils::NavigateToURL(browser(), url);
111
112 // Fill a form and submit through a <input type="submit"> button. Nothing
113 // special.
114 NavigationObserver observer(WebContents());
115 std::string fill_and_submit =
116 "document.getElementById('username_field').value = 'temp';"
117 "document.getElementById('password_field').value = 'random';"
118 "document.getElementById('input_submit_button').click()";
119 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
120 observer.Wait();
121 EXPECT_TRUE(observer.InfoBarWasShown());
122 }
123
124 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
125 PromptForSubmitUsingJavaScript) {
126 ASSERT_TRUE(test_server()->Start());
127
128 GURL url = test_server()->GetURL("files/password/password_form.html");
129 ui_test_utils::NavigateToURL(browser(), url);
130
131 // Fill a form and submit using <button> that calls submit() on the form.
132 // This should work regardless of the type of element, as long as submit() is
133 // called.
134 NavigationObserver observer(WebContents());
135 std::string fill_and_submit =
136 "document.getElementById('username_field').value = 'temp';"
137 "document.getElementById('password_field').value = 'random';"
138 "document.getElementById('submit_button').click()";
139 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
140 observer.Wait();
141 EXPECT_TRUE(observer.InfoBarWasShown());
142 }
143
144 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) {
145 ASSERT_TRUE(test_server()->Start());
146
147 GURL url = test_server()->GetURL("files/password/password_form.html");
148 ui_test_utils::NavigateToURL(browser(), url);
149
150 // Don't fill the password form, just navigate away. Shouldn't prompt.
151 NavigationObserver observer(WebContents());
152 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
153 "window.location.href = 'done.html';"));
154 observer.Wait();
155 EXPECT_FALSE(observer.InfoBarWasShown());
156 }
157
158 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
159 NoPromptForSubFrameNavigation) {
160 ASSERT_TRUE(test_server()->Start());
161
162 GURL url = test_server()->GetURL("files/password/multi_frames.html");
163 ui_test_utils::NavigateToURL(browser(), url);
164
165 // If you are filling out a password form in one frame and a different frame
166 // navigates, this should not trigger the infobar.
167 NavigationObserver observer(WebContents());
168 std::string fill =
169 "var first_frame = document.getElementById('first_frame');"
170 "var frame_doc = first_frame.contentDocument;"
171 "frame_doc.getElementById('username_field').value = 'temp';"
172 "frame_doc.getElementById('password_field').value = 'random';";
173 std::string navigate_frame =
174 "var second_iframe = document.getElementById('second_frame');"
175 "second_iframe.contentWindow.location.href = 'done.html';";
176
177 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
178 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
179 observer.Wait();
180 EXPECT_FALSE(observer.InfoBarWasShown());
181 }
182
183 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
184 PromptAfterSubmitWithSubFrameNavigation) {
185 ASSERT_TRUE(test_server()->Start());
186
187 GURL url = test_server()->GetURL("files/password/multi_frames.html");
188 ui_test_utils::NavigateToURL(browser(), url);
189
190 // Make sure that we prompt to save password even if a sub-frame navigation
191 // happens first.
192 NavigationObserver observer(WebContents());
193 std::string navigate_frame =
194 "var second_iframe = document.getElementById('second_frame');"
195 "second_iframe.contentWindow.location.href = 'done.html';";
196 std::string fill_and_submit =
197 "var first_frame = document.getElementById('first_frame');"
198 "var frame_doc = first_frame.contentDocument;"
199 "frame_doc.getElementById('username_field').value = 'temp';"
200 "frame_doc.getElementById('password_field').value = 'random';"
201 "frame_doc.getElementById('input_submit_button').click();";
202
203 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
204 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
205 observer.Wait();
206 EXPECT_TRUE(observer.InfoBarWasShown());
207 }
208
106 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { 209 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) {
107 #if defined(OS_WIN) && defined(USE_ASH) 210 #if defined(OS_WIN) && defined(USE_ASH)
Ilya Sherman 2013/08/06 09:34:11 nit: IMO it's slightly better to mark the test as
108 // Disable this test in Metro+Ash for now (http://crbug.com/262796). 211 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
109 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) 212 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests))
110 return; 213 return;
111 #endif 214 #endif
112 215
113 ASSERT_TRUE(test_server()->Start()); 216 ASSERT_TRUE(test_server()->Start());
114 217
115 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html"); 218 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html");
116 ui_test_utils::NavigateToURL(browser(), url); 219 ui_test_utils::NavigateToURL(browser(), url);
117 220
(...skipping 24 matching lines...) Expand all
142 // cases where the element that users click on isn't a submit button. 245 // cases where the element that users click on isn't a submit button.
143 NavigationObserver observer(WebContents()); 246 NavigationObserver observer(WebContents());
144 std::string fill_and_navigate = 247 std::string fill_and_navigate =
145 "document.getElementById('username_field').value = 'temp';" 248 "document.getElementById('username_field').value = 'temp';"
146 "document.getElementById('password_field').value = 'random';" 249 "document.getElementById('password_field').value = 'random';"
147 "send_xhr()"; 250 "send_xhr()";
148 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 251 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
149 observer.Wait(); 252 observer.Wait();
150 EXPECT_FALSE(observer.InfoBarWasShown()); 253 EXPECT_FALSE(observer.InfoBarWasShown());
151 } 254 }
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