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

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: Callback Created 7 years, 5 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 "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 8 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
9 #include "chrome/browser/infobars/infobar_service.h" 9 #include "chrome/browser/infobars/infobar_service.h"
10 #include "chrome/browser/password_manager/password_store_factory.h" 10 #include "chrome/browser/password_manager/password_store_factory.h"
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 protected: 94 protected:
95 content::WebContents* WebContents() { 95 content::WebContents* WebContents() {
96 return browser()->tab_strip_model()->GetActiveWebContents(); 96 return browser()->tab_strip_model()->GetActiveWebContents();
97 } 97 }
98 98
99 content::RenderViewHost* RenderViewHost() { 99 content::RenderViewHost* RenderViewHost() {
100 return WebContents()->GetRenderViewHost(); 100 return WebContents()->GetRenderViewHost();
101 } 101 }
102 }; 102 };
103 103
104 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForNormalSubmit) {
105 ASSERT_TRUE(test_server()->Start());
106
107 GURL url = test_server()->GetURL("files/password/password_form.html");
108 ui_test_utils::NavigateToURL(browser(), url);
109
110 // Fill a form and submit through a <input type="submit"> button. Nothing
111 // special.
112 NavigationObserver observer(WebContents());
113 std::string fill_and_submit =
114 "document.getElementById('username_field').value = 'temp';"
115 "document.getElementById('password_field').value = 'random';"
116 "document.getElementById('input_submit_button').click()";
117 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
118 observer.Wait();
119 EXPECT_TRUE(observer.InfoBarWasShown());
120 }
121
122 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
123 PromptForSubmitUsingJavaScript) {
124 ASSERT_TRUE(test_server()->Start());
125
126 GURL url = test_server()->GetURL("files/password/password_form.html");
127 ui_test_utils::NavigateToURL(browser(), url);
128
129 // Fill a form and submit using <button> that calls submit() on the form.
130 // This should work regardless of the type of element, as long as submit() is
131 // called.
132 NavigationObserver observer(WebContents());
133 std::string fill_and_submit =
134 "document.getElementById('username_field').value = 'temp';"
135 "document.getElementById('password_field').value = 'random';"
136 "document.getElementById('submit_button').click()";
137 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
138 observer.Wait();
139 EXPECT_TRUE(observer.InfoBarWasShown());
140 }
141
142 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, NoPromptForNavigation) {
143 ASSERT_TRUE(test_server()->Start());
144
145 GURL url = test_server()->GetURL("files/password/password_form.html");
146 ui_test_utils::NavigateToURL(browser(), url);
147
148 // Don't fill the password form, just navigate away. Shouldn't prompt.
149 NavigationObserver observer(WebContents());
150 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
151 "window.location.href = 'done.html';"));
152 observer.Wait();
153 EXPECT_FALSE(observer.InfoBarWasShown());
154 }
155
156 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
157 NoPromptForSubFrameNavigation) {
158 ASSERT_TRUE(test_server()->Start());
159
160 GURL url = test_server()->GetURL("files/password/multi_frames.html");
161 ui_test_utils::NavigateToURL(browser(), url);
162
163 // If you are filling out a password form in one frame and a different frame
164 // navigates, this should not trigger the infobar.
165 NavigationObserver observer(WebContents());
166 std::string fill =
167 "var first_frame = document.getElementById('first_frame');"
168 "var frame_doc = first_frame.contentDocument;"
169 "frame_doc.getElementById('username_field').value = 'temp';"
170 "frame_doc.getElementById('password_field').value = 'random';";
171 std::string navigate_frame =
172 "var second_iframe = document.getElementById('second_frame');"
173 "second_iframe.contentWindow.location.href = 'done.html';";
174
175 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
176 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
177 observer.Wait();
178 EXPECT_FALSE(observer.InfoBarWasShown());
179 }
180
181 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest,
182 PromptAfterSubmitWithSubFrameNavigation) {
183 ASSERT_TRUE(test_server()->Start());
184
185 GURL url = test_server()->GetURL("files/password/multi_frames.html");
186 ui_test_utils::NavigateToURL(browser(), url);
187
188 // Make sure that we prompt to save password even if a sub-frame navigation
189 // happens first.
190 NavigationObserver observer(WebContents());
191 std::string navigate_frame =
192 "var second_iframe = document.getElementById('second_frame');"
193 "second_iframe.contentWindow.location.href = 'done.html';";
194 std::string fill_and_submit =
195 "var first_frame = document.getElementById('first_frame');"
196 "var frame_doc = first_frame.contentDocument;"
197 "frame_doc.getElementById('username_field').value = 'temp';"
198 "frame_doc.getElementById('password_field').value = 'random';"
199 "frame_doc.getElementById('input_submit_button').click();";
200
201 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
202 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
203 observer.Wait();
204 EXPECT_TRUE(observer.InfoBarWasShown());
205 }
206
104 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) { 207 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTest, PromptForXHRSubmit) {
105 ASSERT_TRUE(test_server()->Start()); 208 ASSERT_TRUE(test_server()->Start());
106 209
107 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html"); 210 GURL url = test_server()->GetURL("files/password/password_xhr_submit.html");
108 ui_test_utils::NavigateToURL(browser(), url); 211 ui_test_utils::NavigateToURL(browser(), url);
109 212
110 // Verify that we show the save password prompt if a form returns false 213 // Verify that we show the save password prompt if a form returns false
111 // in its onsubmit handler but instead logs in/navigates via XHR. 214 // in its onsubmit handler but instead logs in/navigates via XHR.
112 // Note that calling 'submit()' on a form with javascript doesn't call 215 // Note that calling 'submit()' on a form with javascript doesn't call
113 // the onsubmit handler, so we click the submit button instead. 216 // the onsubmit handler, so we click the submit button instead.
(...skipping 20 matching lines...) Expand all
134 // cases where the element that users click on isn't a submit button. 237 // cases where the element that users click on isn't a submit button.
135 NavigationObserver observer(WebContents()); 238 NavigationObserver observer(WebContents());
136 std::string fill_and_navigate = 239 std::string fill_and_navigate =
137 "document.getElementById('username_field').value = 'temp';" 240 "document.getElementById('username_field').value = 'temp';"
138 "document.getElementById('password_field').value = 'random';" 241 "document.getElementById('password_field').value = 'random';"
139 "send_xhr()"; 242 "send_xhr()";
140 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 243 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
141 observer.Wait(); 244 observer.Wait();
142 EXPECT_FALSE(observer.InfoBarWasShown()); 245 EXPECT_FALSE(observer.InfoBarWasShown());
143 } 246 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698