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

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

Issue 2915763003: [Password Manager] Show omnibox icon and anchored prompt once user start typing password (Closed)
Patch Set: Introduced |has_generated_password| argument Created 3 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 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 #include <utility> 6 #include <utility>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 explicit ObservingAutofillClient(content::WebContents* web_contents) 159 explicit ObservingAutofillClient(content::WebContents* web_contents)
160 : run_loop_(nullptr), popup_shown_(false) {} 160 : run_loop_(nullptr), popup_shown_(false) {}
161 friend class content::WebContentsUserData<ObservingAutofillClient>; 161 friend class content::WebContentsUserData<ObservingAutofillClient>;
162 162
163 base::RunLoop* run_loop_; 163 base::RunLoop* run_loop_;
164 bool popup_shown_; 164 bool popup_shown_;
165 165
166 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient); 166 DISALLOW_COPY_AND_ASSIGN(ObservingAutofillClient);
167 }; 167 };
168 168
169 // For simplicity we assume that password store contains only 1 credential.
170 void CheckThatCredentialsStored(
171 password_manager::TestPasswordStore* password_store,
172 const base::string16& username,
173 const base::string16& password) {
174 auto& passwords_map = password_store->stored_passwords();
175 ASSERT_EQ(1u, passwords_map.size());
176 auto& passwords_vector = passwords_map.begin()->second;
177 ASSERT_EQ(1u, passwords_vector.size());
178 const autofill::PasswordForm& form = passwords_vector[0];
179 EXPECT_EQ(username, form.username_value);
180 EXPECT_EQ(password, form.password_value);
181 }
182
183 void TestPromptNotShown(const char* failure_message, 169 void TestPromptNotShown(const char* failure_message,
184 content::WebContents* web_contents, 170 content::WebContents* web_contents,
185 content::RenderViewHost* rvh) { 171 content::RenderViewHost* rvh) {
186 SCOPED_TRACE(testing::Message(failure_message)); 172 SCOPED_TRACE(testing::Message(failure_message));
187 173
188 NavigationObserver observer(web_contents); 174 NavigationObserver observer(web_contents);
189 std::string fill_and_submit = 175 std::string fill_and_submit =
190 "document.getElementById('username_failed').value = 'temp';" 176 "document.getElementById('username_failed').value = 'temp';"
191 "document.getElementById('password_failed').value = 'random';" 177 "document.getElementById('password_failed').value = 'random';"
192 "document.getElementById('failed_form').submit()"; 178 "document.getElementById('failed_form').submit()";
193 179
194 ASSERT_TRUE(content::ExecuteScript(rvh, fill_and_submit)); 180 ASSERT_TRUE(content::ExecuteScript(rvh, fill_and_submit));
195 observer.Wait(); 181 observer.Wait();
196 EXPECT_FALSE(BubbleObserver(web_contents).IsShowingSavePrompt()); 182 EXPECT_FALSE(BubbleObserver(web_contents).WasSavePromptShown());
197 } 183 }
198 184
199 } // namespace 185 } // namespace
200 186
201 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ObservingAutofillClient); 187 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ObservingAutofillClient);
202 188
203 namespace password_manager { 189 namespace password_manager {
204 190
205 // Actual tests --------------------------------------------------------------- 191 // Actual tests ---------------------------------------------------------------
206 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) { 192 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForNormalSubmit) {
207 NavigateToFile("/password/password_form.html"); 193 NavigateToFile("/password/password_form.html");
208 194
209 // Fill a form and submit through a <input type="submit"> button. Nothing 195 // Fill a form and submit through a <input type="submit"> button. Nothing
210 // special. 196 // special.
211 NavigationObserver observer(WebContents()); 197 NavigationObserver observer(WebContents());
212 std::string fill_and_submit = 198 std::string fill_and_submit =
213 "document.getElementById('username_field').value = 'temp';" 199 "document.getElementById('username_field').value = 'temp';"
214 "document.getElementById('password_field').value = 'random';" 200 "document.getElementById('password_field').value = 'random';"
215 "document.getElementById('input_submit_button').click()"; 201 "document.getElementById('input_submit_button').click()";
216 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 202 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
217 observer.Wait(); 203 observer.Wait();
218 204
219 // Save the password and check the store. 205 // Save the password and check the store.
220 BubbleObserver bubble_observer(WebContents()); 206 BubbleObserver bubble_observer(WebContents());
221 EXPECT_TRUE(bubble_observer.IsShowingSavePrompt()); 207 EXPECT_TRUE(bubble_observer.WasSavePromptShown());
222 bubble_observer.AcceptSavePrompt(); 208 bubble_observer.AcceptSavePrompt();
223 WaitForPasswordStore(); 209 WaitForPasswordStore();
224 210
225 scoped_refptr<password_manager::TestPasswordStore> password_store = 211 scoped_refptr<password_manager::TestPasswordStore> password_store =
226 static_cast<password_manager::TestPasswordStore*>( 212 static_cast<password_manager::TestPasswordStore*>(
227 PasswordStoreFactory::GetForProfile( 213 PasswordStoreFactory::GetForProfile(
228 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 214 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
229 .get()); 215 .get());
230 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 216 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
231 base::ASCIIToUTF16("random")); 217 base::ASCIIToUTF16("random"));
(...skipping 30 matching lines...) Expand all
262 // should not send "PasswordFormsParsed" messages after the page was loaded. 248 // should not send "PasswordFormsParsed" messages after the page was loaded.
263 NavigationObserver observer(WebContents()); 249 NavigationObserver observer(WebContents());
264 std::string fill_and_submit = 250 std::string fill_and_submit =
265 "document.getElementById('username_field').value = 'temp';" 251 "document.getElementById('username_field').value = 'temp';"
266 "document.getElementById('password_field').value = 'random';" 252 "document.getElementById('password_field').value = 'random';"
267 "document.getElementById('input_submit_button').click()"; 253 "document.getElementById('input_submit_button').click()";
268 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 254 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
269 observer.Wait(); 255 observer.Wait();
270 std::unique_ptr<BubbleObserver> prompt_observer( 256 std::unique_ptr<BubbleObserver> prompt_observer(
271 new BubbleObserver(WebContents())); 257 new BubbleObserver(WebContents()));
272 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 258 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
273 } 259 }
274 260
275 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 261 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
276 PromptForSubmitWithInPageNavigation) { 262 PromptForSubmitWithInPageNavigation) {
277 NavigateToFile("/password/password_navigate_before_submit.html"); 263 NavigateToFile("/password/password_navigate_before_submit.html");
278 264
279 // Fill a form and submit through a <input type="submit"> button. Nothing 265 // Fill a form and submit through a <input type="submit"> button. Nothing
280 // special. The form does an in-page navigation before submitting. 266 // special. The form does an in-page navigation before submitting.
281 NavigationObserver observer(WebContents()); 267 NavigationObserver observer(WebContents());
282 std::unique_ptr<BubbleObserver> prompt_observer( 268 std::unique_ptr<BubbleObserver> prompt_observer(
283 new BubbleObserver(WebContents())); 269 new BubbleObserver(WebContents()));
284 std::string fill_and_submit = 270 std::string fill_and_submit =
285 "document.getElementById('username_field').value = 'temp';" 271 "document.getElementById('username_field').value = 'temp';"
286 "document.getElementById('password_field').value = 'random';" 272 "document.getElementById('password_field').value = 'random';"
287 "document.getElementById('input_submit_button').click()"; 273 "document.getElementById('input_submit_button').click()";
288 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 274 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
289 observer.Wait(); 275 observer.Wait();
290 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 276 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
291 } 277 }
292 278
293 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 279 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
294 LoginSuccessWithUnrelatedForm) { 280 LoginSuccessWithUnrelatedForm) {
295 // Log in, see a form on the landing page. That form is not related to the 281 // Log in, see a form on the landing page. That form is not related to the
296 // login form (=has a different action), so we should offer saving the 282 // login form (=has a different action), so we should offer saving the
297 // password. 283 // password.
298 NavigateToFile("/password/password_form.html"); 284 NavigateToFile("/password/password_form.html");
299 285
300 NavigationObserver observer(WebContents()); 286 NavigationObserver observer(WebContents());
301 std::unique_ptr<BubbleObserver> prompt_observer( 287 std::unique_ptr<BubbleObserver> prompt_observer(
302 new BubbleObserver(WebContents())); 288 new BubbleObserver(WebContents()));
303 std::string fill_and_submit = 289 std::string fill_and_submit =
304 "document.getElementById('username_unrelated').value = 'temp';" 290 "document.getElementById('username_unrelated').value = 'temp';"
305 "document.getElementById('password_unrelated').value = 'random';" 291 "document.getElementById('password_unrelated').value = 'random';"
306 "document.getElementById('submit_unrelated').click()"; 292 "document.getElementById('submit_unrelated').click()";
307 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 293 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
308 observer.Wait(); 294 observer.Wait();
309 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 295 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
310 } 296 }
311 297
312 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, LoginFailed) { 298 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, LoginFailed) {
313 // Log in, see a form on the landing page. That form is not related to the 299 // Log in, see a form on the landing page. That form is not related to the
314 // login form (=has a different action), so we should offer saving the 300 // login form (=has a different action), so we should offer saving the
315 // password. 301 // password.
316 NavigateToFile("/password/password_form.html"); 302 NavigateToFile("/password/password_form.html");
317 303
318 NavigationObserver observer(WebContents()); 304 NavigationObserver observer(WebContents());
319 std::unique_ptr<BubbleObserver> prompt_observer( 305 std::unique_ptr<BubbleObserver> prompt_observer(
320 new BubbleObserver(WebContents())); 306 new BubbleObserver(WebContents()));
321 std::string fill_and_submit = 307 std::string fill_and_submit =
322 "document.getElementById('username_failed').value = 'temp';" 308 "document.getElementById('username_failed').value = 'temp';"
323 "document.getElementById('password_failed').value = 'random';" 309 "document.getElementById('password_failed').value = 'random';"
324 "document.getElementById('submit_failed').click()"; 310 "document.getElementById('submit_failed').click()";
325 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 311 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
326 observer.Wait(); 312 observer.Wait();
327 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 313 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
328 } 314 }
329 315
330 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, Redirects) { 316 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, Redirects) {
331 NavigateToFile("/password/password_form.html"); 317 NavigateToFile("/password/password_form.html");
332 318
333 // Fill a form and submit through a <input type="submit"> button. The form 319 // Fill a form and submit through a <input type="submit"> button. The form
334 // points to a redirection page. 320 // points to a redirection page.
335 NavigationObserver observer1(WebContents()); 321 NavigationObserver observer1(WebContents());
336 std::string fill_and_submit = 322 std::string fill_and_submit =
337 "document.getElementById('username_redirect').value = 'temp';" 323 "document.getElementById('username_redirect').value = 'temp';"
338 "document.getElementById('password_redirect').value = 'random';" 324 "document.getElementById('password_redirect').value = 'random';"
339 "document.getElementById('submit_redirect').click()"; 325 "document.getElementById('submit_redirect').click()";
340 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 326 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
341 observer1.Wait(); 327 observer1.Wait();
342 BubbleObserver bubble_observer(WebContents()); 328 BubbleObserver bubble_observer(WebContents());
343 EXPECT_TRUE(bubble_observer.IsShowingSavePrompt()); 329 EXPECT_TRUE(bubble_observer.WasSavePromptShown());
344 330
345 // The redirection page now redirects via Javascript. We check that the 331 // The redirection page now redirects via Javascript. We check that the
346 // bubble stays. 332 // bubble stays.
347 NavigationObserver observer2(WebContents()); 333 NavigationObserver observer2(WebContents());
348 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture( 334 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(
349 RenderFrameHost(), "window.location.href = 'done.html';")); 335 RenderFrameHost(), "window.location.href = 'done.html';"));
350 observer2.Wait(); 336 observer2.Wait();
351 EXPECT_TRUE(bubble_observer.IsShowingSavePrompt()); 337 EXPECT_TRUE(bubble_observer.WasSavePromptShown());
352 } 338 }
353 339
354 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 340 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
355 PromptForSubmitUsingJavaScript) { 341 PromptForSubmitUsingJavaScript) {
356 NavigateToFile("/password/password_form.html"); 342 NavigateToFile("/password/password_form.html");
357 343
358 // Fill a form and submit using <button> that calls submit() on the form. 344 // Fill a form and submit using <button> that calls submit() on the form.
359 // This should work regardless of the type of element, as long as submit() is 345 // This should work regardless of the type of element, as long as submit() is
360 // called. 346 // called.
361 NavigationObserver observer(WebContents()); 347 NavigationObserver observer(WebContents());
362 std::unique_ptr<BubbleObserver> prompt_observer( 348 std::unique_ptr<BubbleObserver> prompt_observer(
363 new BubbleObserver(WebContents())); 349 new BubbleObserver(WebContents()));
364 std::string fill_and_submit = 350 std::string fill_and_submit =
365 "document.getElementById('username_field').value = 'temp';" 351 "document.getElementById('username_field').value = 'temp';"
366 "document.getElementById('password_field').value = 'random';" 352 "document.getElementById('password_field').value = 'random';"
367 "document.getElementById('submit_button').click()"; 353 "document.getElementById('submit_button').click()";
368 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 354 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
369 observer.Wait(); 355 observer.Wait();
370 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 356 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
371 } 357 }
372 358
373 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForDynamicForm) { 359 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForDynamicForm) {
374 // Adding a PSL matching form is a workaround explained later. 360 // Adding a PSL matching form is a workaround explained later.
375 scoped_refptr<password_manager::TestPasswordStore> password_store = 361 scoped_refptr<password_manager::TestPasswordStore> password_store =
376 static_cast<password_manager::TestPasswordStore*>( 362 static_cast<password_manager::TestPasswordStore*>(
377 PasswordStoreFactory::GetForProfile( 363 PasswordStoreFactory::GetForProfile(
378 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 364 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
379 .get()); 365 .get());
380 autofill::PasswordForm signin_form; 366 autofill::PasswordForm signin_form;
(...skipping 20 matching lines...) Expand all
401 387
402 // Fill the dynamic password form and submit. 388 // Fill the dynamic password form and submit.
403 NavigationObserver observer(WebContents()); 389 NavigationObserver observer(WebContents());
404 std::string fill_and_submit = 390 std::string fill_and_submit =
405 "document.dynamic_form.username.value = 'tempro';" 391 "document.dynamic_form.username.value = 'tempro';"
406 "document.dynamic_form.password.value = 'random';" 392 "document.dynamic_form.password.value = 'random';"
407 "document.dynamic_form.submit()"; 393 "document.dynamic_form.submit()";
408 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 394 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
409 observer.Wait(); 395 observer.Wait();
410 396
411 EXPECT_TRUE(BubbleObserver(WebContents()).IsShowingSavePrompt()); 397 EXPECT_TRUE(BubbleObserver(WebContents()).WasSavePromptShown());
412 } 398 }
413 399
414 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptForNavigation) { 400 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptForNavigation) {
415 NavigateToFile("/password/password_form.html"); 401 NavigateToFile("/password/password_form.html");
416 402
417 // Don't fill the password form, just navigate away. Shouldn't prompt. 403 // Don't fill the password form, just navigate away. Shouldn't prompt.
418 NavigationObserver observer(WebContents()); 404 NavigationObserver observer(WebContents());
419 std::unique_ptr<BubbleObserver> prompt_observer( 405 std::unique_ptr<BubbleObserver> prompt_observer(
420 new BubbleObserver(WebContents())); 406 new BubbleObserver(WebContents()));
421 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture( 407 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(
422 RenderFrameHost(), "window.location.href = 'done.html';")); 408 RenderFrameHost(), "window.location.href = 'done.html';"));
423 observer.Wait(); 409 observer.Wait();
424 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 410 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
425 } 411 }
426 412
427 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 413 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
428 NoPromptForSubFrameNavigation) { 414 NoPromptForSubFrameNavigation) {
429 NavigateToFile("/password/multi_frames.html"); 415 NavigateToFile("/password/multi_frames.html");
430 416
431 // If you are filling out a password form in one frame and a different frame 417 // If you are filling out a password form in one frame and a different frame
432 // navigates, this should not trigger the infobar. 418 // navigates, this should not trigger the infobar.
433 NavigationObserver observer(WebContents()); 419 NavigationObserver observer(WebContents());
434 std::unique_ptr<BubbleObserver> prompt_observer( 420 std::unique_ptr<BubbleObserver> prompt_observer(
435 new BubbleObserver(WebContents())); 421 new BubbleObserver(WebContents()));
436 observer.SetPathToWaitFor("/password/done.html"); 422 observer.SetPathToWaitFor("/password/done.html");
437 std::string fill = 423 std::string fill =
438 "var first_frame = document.getElementById('first_frame');" 424 "var first_frame = document.getElementById('first_frame');"
439 "var frame_doc = first_frame.contentDocument;" 425 "var frame_doc = first_frame.contentDocument;"
440 "frame_doc.getElementById('username_field').value = 'temp';" 426 "frame_doc.getElementById('username_field').value = 'temp';"
441 "frame_doc.getElementById('password_field').value = 'random';"; 427 "frame_doc.getElementById('password_field').value = 'random';";
442 std::string navigate_frame = 428 std::string navigate_frame =
443 "var second_iframe = document.getElementById('second_frame');" 429 "var second_iframe = document.getElementById('second_frame');"
444 "second_iframe.contentWindow.location.href = 'done.html';"; 430 "second_iframe.contentWindow.location.href = 'done.html';";
445 431
446 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); 432 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
447 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); 433 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
448 observer.Wait(); 434 observer.Wait();
449 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 435 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
450 } 436 }
451 437
452 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 438 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
453 PromptAfterSubmitWithSubFrameNavigation) { 439 PromptAfterSubmitWithSubFrameNavigation) {
454 NavigateToFile("/password/multi_frames.html"); 440 NavigateToFile("/password/multi_frames.html");
455 441
456 // Make sure that we prompt to save password even if a sub-frame navigation 442 // Make sure that we prompt to save password even if a sub-frame navigation
457 // happens first. 443 // happens first.
458 NavigationObserver observer(WebContents()); 444 NavigationObserver observer(WebContents());
459 std::unique_ptr<BubbleObserver> prompt_observer( 445 std::unique_ptr<BubbleObserver> prompt_observer(
460 new BubbleObserver(WebContents())); 446 new BubbleObserver(WebContents()));
461 observer.SetPathToWaitFor("/password/done.html"); 447 observer.SetPathToWaitFor("/password/done.html");
462 std::string navigate_frame = 448 std::string navigate_frame =
463 "var second_iframe = document.getElementById('second_frame');" 449 "var second_iframe = document.getElementById('second_frame');"
464 "second_iframe.contentWindow.location.href = 'other.html';"; 450 "second_iframe.contentWindow.location.href = 'other.html';";
465 std::string fill_and_submit = 451 std::string fill_and_submit =
466 "var first_frame = document.getElementById('first_frame');" 452 "var first_frame = document.getElementById('first_frame');"
467 "var frame_doc = first_frame.contentDocument;" 453 "var frame_doc = first_frame.contentDocument;"
468 "frame_doc.getElementById('username_field').value = 'temp';" 454 "frame_doc.getElementById('username_field').value = 'temp';"
469 "frame_doc.getElementById('password_field').value = 'random';" 455 "frame_doc.getElementById('password_field').value = 'random';"
470 "frame_doc.getElementById('input_submit_button').click();"; 456 "frame_doc.getElementById('input_submit_button').click();";
471 457
472 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame)); 458 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), navigate_frame));
473 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 459 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
474 observer.Wait(); 460 observer.Wait();
475 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 461 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
476 } 462 }
477 463
478 IN_PROC_BROWSER_TEST_F( 464 IN_PROC_BROWSER_TEST_F(
479 PasswordManagerBrowserTestBase, 465 PasswordManagerBrowserTestBase,
480 NoPromptForFailedLoginFromMainFrameWithMultiFramesInPage) { 466 NoPromptForFailedLoginFromMainFrameWithMultiFramesInPage) {
481 NavigateToFile("/password/multi_frames.html"); 467 NavigateToFile("/password/multi_frames.html");
482 468
483 // Make sure that we don't prompt to save the password for a failed login 469 // Make sure that we don't prompt to save the password for a failed login
484 // from the main frame with multiple frames in the same page. 470 // from the main frame with multiple frames in the same page.
485 NavigationObserver observer(WebContents()); 471 NavigationObserver observer(WebContents());
486 std::unique_ptr<BubbleObserver> prompt_observer( 472 std::unique_ptr<BubbleObserver> prompt_observer(
487 new BubbleObserver(WebContents())); 473 new BubbleObserver(WebContents()));
488 std::string fill_and_submit = 474 std::string fill_and_submit =
489 "document.getElementById('username_failed').value = 'temp';" 475 "document.getElementById('username_failed').value = 'temp';"
490 "document.getElementById('password_failed').value = 'random';" 476 "document.getElementById('password_failed').value = 'random';"
491 "document.getElementById('submit_failed').click();"; 477 "document.getElementById('submit_failed').click();";
492 478
493 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 479 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
494 observer.Wait(); 480 observer.Wait();
495 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 481 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
496 } 482 }
497 483
498 IN_PROC_BROWSER_TEST_F( 484 IN_PROC_BROWSER_TEST_F(
499 PasswordManagerBrowserTestBase, 485 PasswordManagerBrowserTestBase,
500 NoPromptForFailedLoginFromSubFrameWithMultiFramesInPage) { 486 NoPromptForFailedLoginFromSubFrameWithMultiFramesInPage) {
501 NavigateToFile("/password/multi_frames.html"); 487 NavigateToFile("/password/multi_frames.html");
502 488
503 // Make sure that we don't prompt to save the password for a failed login 489 // Make sure that we don't prompt to save the password for a failed login
504 // from a sub-frame with multiple frames in the same page. 490 // from a sub-frame with multiple frames in the same page.
505 NavigationObserver observer(WebContents()); 491 NavigationObserver observer(WebContents());
506 std::unique_ptr<BubbleObserver> prompt_observer( 492 std::unique_ptr<BubbleObserver> prompt_observer(
507 new BubbleObserver(WebContents())); 493 new BubbleObserver(WebContents()));
508 std::string fill_and_submit = 494 std::string fill_and_submit =
509 "var first_frame = document.getElementById('first_frame');" 495 "var first_frame = document.getElementById('first_frame');"
510 "var frame_doc = first_frame.contentDocument;" 496 "var frame_doc = first_frame.contentDocument;"
511 "frame_doc.getElementById('username_failed').value = 'temp';" 497 "frame_doc.getElementById('username_failed').value = 'temp';"
512 "frame_doc.getElementById('password_failed').value = 'random';" 498 "frame_doc.getElementById('password_failed').value = 'random';"
513 "frame_doc.getElementById('submit_failed').click();"; 499 "frame_doc.getElementById('submit_failed').click();";
514 500
515 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 501 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
516 observer.SetPathToWaitFor("/password/failed.html"); 502 observer.SetPathToWaitFor("/password/failed.html");
517 observer.Wait(); 503 observer.Wait();
518 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 504 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
519 } 505 }
520 506
521 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForXHRSubmit) { 507 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForXHRSubmit) {
522 NavigateToFile("/password/password_xhr_submit.html"); 508 NavigateToFile("/password/password_xhr_submit.html");
523 509
524 // Verify that we show the save password prompt if a form returns false 510 // Verify that we show the save password prompt if a form returns false
525 // in its onsubmit handler but instead logs in/navigates via XHR. 511 // in its onsubmit handler but instead logs in/navigates via XHR.
526 // Note that calling 'submit()' on a form with javascript doesn't call 512 // Note that calling 'submit()' on a form with javascript doesn't call
527 // the onsubmit handler, so we click the submit button instead. 513 // the onsubmit handler, so we click the submit button instead.
528 NavigationObserver observer(WebContents()); 514 NavigationObserver observer(WebContents());
529 std::unique_ptr<BubbleObserver> prompt_observer( 515 std::unique_ptr<BubbleObserver> prompt_observer(
530 new BubbleObserver(WebContents())); 516 new BubbleObserver(WebContents()));
531 std::string fill_and_submit = 517 std::string fill_and_submit =
532 "document.getElementById('username_field').value = 'temp';" 518 "document.getElementById('username_field').value = 'temp';"
533 "document.getElementById('password_field').value = 'random';" 519 "document.getElementById('password_field').value = 'random';"
534 "document.getElementById('submit_button').click()"; 520 "document.getElementById('submit_button').click()";
535 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 521 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
536 observer.Wait(); 522 observer.Wait();
537 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 523 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
538 } 524 }
539 525
540 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 526 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
541 PromptForXHRWithoutOnSubmit) { 527 PromptForXHRWithoutOnSubmit) {
542 NavigateToFile("/password/password_xhr_submit.html"); 528 NavigateToFile("/password/password_xhr_submit.html");
543 529
544 // Verify that if XHR navigation occurs and the form is properly filled out, 530 // Verify that if XHR navigation occurs and the form is properly filled out,
545 // we try and save the password even though onsubmit hasn't been called. 531 // we try and save the password even though onsubmit hasn't been called.
546 NavigationObserver observer(WebContents()); 532 NavigationObserver observer(WebContents());
547 std::unique_ptr<BubbleObserver> prompt_observer( 533 std::unique_ptr<BubbleObserver> prompt_observer(
548 new BubbleObserver(WebContents())); 534 new BubbleObserver(WebContents()));
549 std::string fill_and_navigate = 535 std::string fill_and_navigate =
550 "document.getElementById('username_field').value = 'temp';" 536 "document.getElementById('username_field').value = 'temp';"
551 "document.getElementById('password_field').value = 'random';" 537 "document.getElementById('password_field').value = 'random';"
552 "send_xhr()"; 538 "send_xhr()";
553 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 539 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
554 observer.Wait(); 540 observer.Wait();
555 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 541 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
556 } 542 }
557 543
558 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 544 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
559 PromptForXHRWithNewPasswordsWithoutOnSubmit) { 545 PromptForXHRWithNewPasswordsWithoutOnSubmit) {
560 NavigateToFile("/password/password_xhr_submit.html"); 546 NavigateToFile("/password/password_xhr_submit.html");
561 547
562 // Verify that if XHR navigation occurs and the form is properly filled out, 548 // Verify that if XHR navigation occurs and the form is properly filled out,
563 // we try and save the password even though onsubmit hasn't been called. 549 // we try and save the password even though onsubmit hasn't been called.
564 // Specifically verify that the password form saving new passwords is treated 550 // Specifically verify that the password form saving new passwords is treated
565 // the same as a login form. 551 // the same as a login form.
566 NavigationObserver observer(WebContents()); 552 NavigationObserver observer(WebContents());
567 std::unique_ptr<BubbleObserver> prompt_observer( 553 std::unique_ptr<BubbleObserver> prompt_observer(
568 new BubbleObserver(WebContents())); 554 new BubbleObserver(WebContents()));
569 std::string fill_and_navigate = 555 std::string fill_and_navigate =
570 "document.getElementById('signup_username_field').value = 'temp';" 556 "document.getElementById('signup_username_field').value = 'temp';"
571 "document.getElementById('signup_password_field').value = 'random';" 557 "document.getElementById('signup_password_field').value = 'random';"
572 "document.getElementById('confirmation_password_field').value = 'random';" 558 "document.getElementById('confirmation_password_field').value = 'random';"
573 "send_xhr()"; 559 "send_xhr()";
574 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 560 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
575 observer.Wait(); 561 observer.Wait();
576 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 562 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
577 } 563 }
578 564
579 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 565 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
580 PromptForXHRSubmitWithoutNavigation) { 566 PromptForXHRSubmitWithoutNavigation) {
581 NavigateToFile("/password/password_xhr_submit.html"); 567 NavigateToFile("/password/password_xhr_submit.html");
582 568
583 // Need to pay attention for a message that XHR has finished since there 569 // Need to pay attention for a message that XHR has finished since there
584 // is no navigation to wait for. 570 // is no navigation to wait for.
585 content::DOMMessageQueue message_queue; 571 content::DOMMessageQueue message_queue;
586 572
587 // Verify that if XHR without navigation occurs and the form has been filled 573 // Verify that if XHR without navigation occurs and the form has been filled
588 // out we try and save the password. Note that in general the submission 574 // out we try and save the password. Note that in general the submission
589 // doesn't need to be via form.submit(), but for testing purposes it's 575 // doesn't need to be via form.submit(), but for testing purposes it's
590 // necessary since we otherwise ignore changes made to the value of these 576 // necessary since we otherwise ignore changes made to the value of these
591 // fields by script. 577 // fields by script.
592 std::unique_ptr<BubbleObserver> prompt_observer( 578 std::unique_ptr<BubbleObserver> prompt_observer(
593 new BubbleObserver(WebContents())); 579 new BubbleObserver(WebContents()));
594 std::string fill_and_submit = 580 std::string fill_and_submit =
595 "navigate = false;" 581 "navigate = false;"
596 "document.getElementById('username_field').value = 'temp';" 582 "document.getElementById('username_field').value = 'temp';"
597 "document.getElementById('password_field').value = 'random';" 583 "document.getElementById('password_field').value = 'random';"
598 "document.getElementById('submit_button').click();"; 584 "document.getElementById('submit_button').click();";
599 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 585 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
600 std::string message; 586 std::string message;
601 while (message_queue.WaitForMessage(&message)) { 587 while (message_queue.WaitForMessage(&message)) {
602 if (message == "\"XHR_FINISHED\"") 588 if (message == "\"XHR_FINISHED\"")
603 break; 589 break;
604 } 590 }
605 591
606 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 592 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
607 } 593 }
608 594
609 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 595 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
610 PromptForXHRSubmitWithoutNavigation_SignupForm) { 596 PromptForXHRSubmitWithoutNavigation_SignupForm) {
611 NavigateToFile("/password/password_xhr_submit.html"); 597 NavigateToFile("/password/password_xhr_submit.html");
612 598
613 // Need to pay attention for a message that XHR has finished since there 599 // Need to pay attention for a message that XHR has finished since there
614 // is no navigation to wait for. 600 // is no navigation to wait for.
615 content::DOMMessageQueue message_queue; 601 content::DOMMessageQueue message_queue;
616 602
(...skipping 10 matching lines...) Expand all
627 "document.getElementById('signup_password_field').value = 'random';" 613 "document.getElementById('signup_password_field').value = 'random';"
628 "document.getElementById('confirmation_password_field').value = 'random';" 614 "document.getElementById('confirmation_password_field').value = 'random';"
629 "document.getElementById('signup_submit_button').click();"; 615 "document.getElementById('signup_submit_button').click();";
630 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 616 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
631 std::string message; 617 std::string message;
632 while (message_queue.WaitForMessage(&message)) { 618 while (message_queue.WaitForMessage(&message)) {
633 if (message == "\"XHR_FINISHED\"") 619 if (message == "\"XHR_FINISHED\"")
634 break; 620 break;
635 } 621 }
636 622
637 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 623 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
638 } 624 }
639 625
640 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 626 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
641 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm) { 627 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm) {
642 NavigateToFile("/password/password_xhr_submit.html"); 628 NavigateToFile("/password/password_xhr_submit.html");
643 629
644 // Need to pay attention for a message that XHR has finished since there 630 // Need to pay attention for a message that XHR has finished since there
645 // is no navigation to wait for. 631 // is no navigation to wait for.
646 content::DOMMessageQueue message_queue; 632 content::DOMMessageQueue message_queue;
647 633
648 // Verify that if XHR without navigation occurs and the form has NOT been 634 // Verify that if XHR without navigation occurs and the form has NOT been
649 // filled out we don't prompt. 635 // filled out we don't prompt.
650 std::unique_ptr<BubbleObserver> prompt_observer( 636 std::unique_ptr<BubbleObserver> prompt_observer(
651 new BubbleObserver(WebContents())); 637 new BubbleObserver(WebContents()));
652 std::string fill_and_submit = 638 std::string fill_and_submit =
653 "navigate = false;" 639 "navigate = false;"
654 "document.getElementById('username_field').value = 'temp';" 640 "document.getElementById('username_field').value = 'temp';"
655 "document.getElementById('submit_button').click();"; 641 "document.getElementById('submit_button').click();";
656 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 642 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
657 std::string message; 643 std::string message;
658 while (message_queue.WaitForMessage(&message)) { 644 while (message_queue.WaitForMessage(&message)) {
659 if (message == "\"XHR_FINISHED\"") 645 if (message == "\"XHR_FINISHED\"")
660 break; 646 break;
661 } 647 }
662 648
663 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 649 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
664 } 650 }
665 651
666 IN_PROC_BROWSER_TEST_F( 652 IN_PROC_BROWSER_TEST_F(
667 PasswordManagerBrowserTestBase, 653 PasswordManagerBrowserTestBase,
668 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm_SignupForm) { 654 NoPromptForXHRSubmitWithoutNavigationWithUnfilledForm_SignupForm) {
669 NavigateToFile("/password/password_xhr_submit.html"); 655 NavigateToFile("/password/password_xhr_submit.html");
670 656
671 // Need to pay attention for a message that XHR has finished since there 657 // Need to pay attention for a message that XHR has finished since there
672 // is no navigation to wait for. 658 // is no navigation to wait for.
673 content::DOMMessageQueue message_queue; 659 content::DOMMessageQueue message_queue;
674 660
675 // Verify that if XHR without navigation occurs and the form has NOT been 661 // Verify that if XHR without navigation occurs and the form has NOT been
676 // filled out we don't prompt. 662 // filled out we don't prompt.
677 std::unique_ptr<BubbleObserver> prompt_observer( 663 std::unique_ptr<BubbleObserver> prompt_observer(
678 new BubbleObserver(WebContents())); 664 new BubbleObserver(WebContents()));
679 std::string fill_and_submit = 665 std::string fill_and_submit =
680 "navigate = false;" 666 "navigate = false;"
681 "document.getElementById('signup_username_field').value = 'temp';" 667 "document.getElementById('signup_username_field').value = 'temp';"
682 "document.getElementById('signup_submit_button').click();"; 668 "document.getElementById('signup_submit_button').click();";
683 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 669 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
684 std::string message; 670 std::string message;
685 while (message_queue.WaitForMessage(&message)) { 671 while (message_queue.WaitForMessage(&message)) {
686 if (message == "\"XHR_FINISHED\"") 672 if (message == "\"XHR_FINISHED\"")
687 break; 673 break;
688 } 674 }
689 675
690 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 676 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
691 } 677 }
692 678
693 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForFetchSubmit) { 679 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, PromptForFetchSubmit) {
694 NavigateToFile("/password/password_fetch_submit.html"); 680 NavigateToFile("/password/password_fetch_submit.html");
695 681
696 // Verify that we show the save password prompt if a form returns false 682 // Verify that we show the save password prompt if a form returns false
697 // in its onsubmit handler but instead logs in/navigates via Fetch. 683 // in its onsubmit handler but instead logs in/navigates via Fetch.
698 // Note that calling 'submit()' on a form with javascript doesn't call 684 // Note that calling 'submit()' on a form with javascript doesn't call
699 // the onsubmit handler, so we click the submit button instead. 685 // the onsubmit handler, so we click the submit button instead.
700 NavigationObserver observer(WebContents()); 686 NavigationObserver observer(WebContents());
701 std::unique_ptr<BubbleObserver> prompt_observer( 687 std::unique_ptr<BubbleObserver> prompt_observer(
702 new BubbleObserver(WebContents())); 688 new BubbleObserver(WebContents()));
703 std::string fill_and_submit = 689 std::string fill_and_submit =
704 "document.getElementById('username_field').value = 'temp';" 690 "document.getElementById('username_field').value = 'temp';"
705 "document.getElementById('password_field').value = 'random';" 691 "document.getElementById('password_field').value = 'random';"
706 "document.getElementById('submit_button').click()"; 692 "document.getElementById('submit_button').click()";
707 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 693 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
708 observer.Wait(); 694 observer.Wait();
709 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 695 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
710 } 696 }
711 697
712 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 698 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
713 PromptForFetchWithoutOnSubmit) { 699 PromptForFetchWithoutOnSubmit) {
714 NavigateToFile("/password/password_fetch_submit.html"); 700 NavigateToFile("/password/password_fetch_submit.html");
715 701
716 // Verify that if Fetch navigation occurs and the form is properly filled out, 702 // Verify that if Fetch navigation occurs and the form is properly filled out,
717 // we try and save the password even though onsubmit hasn't been called. 703 // we try and save the password even though onsubmit hasn't been called.
718 NavigationObserver observer(WebContents()); 704 NavigationObserver observer(WebContents());
719 std::unique_ptr<BubbleObserver> prompt_observer( 705 std::unique_ptr<BubbleObserver> prompt_observer(
720 new BubbleObserver(WebContents())); 706 new BubbleObserver(WebContents()));
721 std::string fill_and_navigate = 707 std::string fill_and_navigate =
722 "document.getElementById('username_field').value = 'temp';" 708 "document.getElementById('username_field').value = 'temp';"
723 "document.getElementById('password_field').value = 'random';" 709 "document.getElementById('password_field').value = 'random';"
724 "send_fetch()"; 710 "send_fetch()";
725 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 711 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
726 observer.Wait(); 712 observer.Wait();
727 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 713 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
728 } 714 }
729 715
730 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 716 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
731 PromptForFetchWithNewPasswordsWithoutOnSubmit) { 717 PromptForFetchWithNewPasswordsWithoutOnSubmit) {
732 NavigateToFile("/password/password_fetch_submit.html"); 718 NavigateToFile("/password/password_fetch_submit.html");
733 719
734 // Verify that if Fetch navigation occurs and the form is properly filled out, 720 // Verify that if Fetch navigation occurs and the form is properly filled out,
735 // we try and save the password even though onsubmit hasn't been called. 721 // we try and save the password even though onsubmit hasn't been called.
736 // Specifically verify that the password form saving new passwords is treated 722 // Specifically verify that the password form saving new passwords is treated
737 // the same as a login form. 723 // the same as a login form.
738 NavigationObserver observer(WebContents()); 724 NavigationObserver observer(WebContents());
739 std::unique_ptr<BubbleObserver> prompt_observer( 725 std::unique_ptr<BubbleObserver> prompt_observer(
740 new BubbleObserver(WebContents())); 726 new BubbleObserver(WebContents()));
741 std::string fill_and_navigate = 727 std::string fill_and_navigate =
742 "document.getElementById('signup_username_field').value = 'temp';" 728 "document.getElementById('signup_username_field').value = 'temp';"
743 "document.getElementById('signup_password_field').value = 'random';" 729 "document.getElementById('signup_password_field').value = 'random';"
744 "document.getElementById('confirmation_password_field').value = 'random';" 730 "document.getElementById('confirmation_password_field').value = 'random';"
745 "send_fetch()"; 731 "send_fetch()";
746 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate)); 732 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_navigate));
747 observer.Wait(); 733 observer.Wait();
748 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 734 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
749 } 735 }
750 736
751 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 737 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
752 PromptForFetchSubmitWithoutNavigation) { 738 PromptForFetchSubmitWithoutNavigation) {
753 NavigateToFile("/password/password_fetch_submit.html"); 739 NavigateToFile("/password/password_fetch_submit.html");
754 740
755 // Need to pay attention for a message that XHR has finished since there 741 // Need to pay attention for a message that XHR has finished since there
756 // is no navigation to wait for. 742 // is no navigation to wait for.
757 content::DOMMessageQueue message_queue; 743 content::DOMMessageQueue message_queue;
758 744
759 // Verify that if XHR without navigation occurs and the form has been filled 745 // Verify that if XHR without navigation occurs and the form has been filled
760 // out we try and save the password. Note that in general the submission 746 // out we try and save the password. Note that in general the submission
761 // doesn't need to be via form.submit(), but for testing purposes it's 747 // doesn't need to be via form.submit(), but for testing purposes it's
762 // necessary since we otherwise ignore changes made to the value of these 748 // necessary since we otherwise ignore changes made to the value of these
763 // fields by script. 749 // fields by script.
764 std::unique_ptr<BubbleObserver> prompt_observer( 750 std::unique_ptr<BubbleObserver> prompt_observer(
765 new BubbleObserver(WebContents())); 751 new BubbleObserver(WebContents()));
766 std::string fill_and_submit = 752 std::string fill_and_submit =
767 "navigate = false;" 753 "navigate = false;"
768 "document.getElementById('username_field').value = 'temp';" 754 "document.getElementById('username_field').value = 'temp';"
769 "document.getElementById('password_field').value = 'random';" 755 "document.getElementById('password_field').value = 'random';"
770 "document.getElementById('submit_button').click();"; 756 "document.getElementById('submit_button').click();";
771 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 757 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
772 std::string message; 758 std::string message;
773 while (message_queue.WaitForMessage(&message)) { 759 while (message_queue.WaitForMessage(&message)) {
774 if (message == "\"FETCH_FINISHED\"") 760 if (message == "\"FETCH_FINISHED\"")
775 break; 761 break;
776 } 762 }
777 763
778 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 764 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
779 } 765 }
780 766
781 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 767 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
782 PromptForFetchSubmitWithoutNavigation_SignupForm) { 768 PromptForFetchSubmitWithoutNavigation_SignupForm) {
783 NavigateToFile("/password/password_fetch_submit.html"); 769 NavigateToFile("/password/password_fetch_submit.html");
784 770
785 // Need to pay attention for a message that Fetch has finished since there 771 // Need to pay attention for a message that Fetch has finished since there
786 // is no navigation to wait for. 772 // is no navigation to wait for.
787 content::DOMMessageQueue message_queue; 773 content::DOMMessageQueue message_queue;
788 774
(...skipping 10 matching lines...) Expand all
799 "document.getElementById('signup_password_field').value = 'random';" 785 "document.getElementById('signup_password_field').value = 'random';"
800 "document.getElementById('confirmation_password_field').value = 'random';" 786 "document.getElementById('confirmation_password_field').value = 'random';"
801 "document.getElementById('signup_submit_button').click();"; 787 "document.getElementById('signup_submit_button').click();";
802 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 788 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
803 std::string message; 789 std::string message;
804 while (message_queue.WaitForMessage(&message)) { 790 while (message_queue.WaitForMessage(&message)) {
805 if (message == "\"FETCH_FINISHED\"") 791 if (message == "\"FETCH_FINISHED\"")
806 break; 792 break;
807 } 793 }
808 794
809 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 795 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
810 } 796 }
811 797
812 IN_PROC_BROWSER_TEST_F( 798 IN_PROC_BROWSER_TEST_F(
813 PasswordManagerBrowserTestBase, 799 PasswordManagerBrowserTestBase,
814 NoPromptForFetchSubmitWithoutNavigationWithUnfilledForm) { 800 NoPromptForFetchSubmitWithoutNavigationWithUnfilledForm) {
815 NavigateToFile("/password/password_fetch_submit.html"); 801 NavigateToFile("/password/password_fetch_submit.html");
816 802
817 // Need to pay attention for a message that Fetch has finished since there 803 // Need to pay attention for a message that Fetch has finished since there
818 // is no navigation to wait for. 804 // is no navigation to wait for.
819 content::DOMMessageQueue message_queue; 805 content::DOMMessageQueue message_queue;
820 806
821 // Verify that if Fetch without navigation occurs and the form has NOT been 807 // Verify that if Fetch without navigation occurs and the form has NOT been
822 // filled out we don't prompt. 808 // filled out we don't prompt.
823 std::unique_ptr<BubbleObserver> prompt_observer( 809 std::unique_ptr<BubbleObserver> prompt_observer(
824 new BubbleObserver(WebContents())); 810 new BubbleObserver(WebContents()));
825 std::string fill_and_submit = 811 std::string fill_and_submit =
826 "navigate = false;" 812 "navigate = false;"
827 "document.getElementById('username_field').value = 'temp';" 813 "document.getElementById('username_field').value = 'temp';"
828 "document.getElementById('submit_button').click();"; 814 "document.getElementById('submit_button').click();";
829 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 815 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
830 std::string message; 816 std::string message;
831 while (message_queue.WaitForMessage(&message)) { 817 while (message_queue.WaitForMessage(&message)) {
832 if (message == "\"FETCH_FINISHED\"") 818 if (message == "\"FETCH_FINISHED\"")
833 break; 819 break;
834 } 820 }
835 821
836 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 822 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
837 } 823 }
838 824
839 IN_PROC_BROWSER_TEST_F( 825 IN_PROC_BROWSER_TEST_F(
840 PasswordManagerBrowserTestBase, 826 PasswordManagerBrowserTestBase,
841 NoPromptForFetchSubmitWithoutNavigationWithUnfilledForm_SignupForm) { 827 NoPromptForFetchSubmitWithoutNavigationWithUnfilledForm_SignupForm) {
842 NavigateToFile("/password/password_fetch_submit.html"); 828 NavigateToFile("/password/password_fetch_submit.html");
843 829
844 // Need to pay attention for a message that Fetch has finished since there 830 // Need to pay attention for a message that Fetch has finished since there
845 // is no navigation to wait for. 831 // is no navigation to wait for.
846 content::DOMMessageQueue message_queue; 832 content::DOMMessageQueue message_queue;
847 833
848 // Verify that if Fetch without navigation occurs and the form has NOT been 834 // Verify that if Fetch without navigation occurs and the form has NOT been
849 // filled out we don't prompt. 835 // filled out we don't prompt.
850 std::unique_ptr<BubbleObserver> prompt_observer( 836 std::unique_ptr<BubbleObserver> prompt_observer(
851 new BubbleObserver(WebContents())); 837 new BubbleObserver(WebContents()));
852 std::string fill_and_submit = 838 std::string fill_and_submit =
853 "navigate = false;" 839 "navigate = false;"
854 "document.getElementById('signup_username_field').value = 'temp';" 840 "document.getElementById('signup_username_field').value = 'temp';"
855 "document.getElementById('signup_submit_button').click();"; 841 "document.getElementById('signup_submit_button').click();";
856 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 842 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
857 std::string message; 843 std::string message;
858 while (message_queue.WaitForMessage(&message)) { 844 while (message_queue.WaitForMessage(&message)) {
859 if (message == "\"FETCH_FINISHED\"") 845 if (message == "\"FETCH_FINISHED\"")
860 break; 846 break;
861 } 847 }
862 848
863 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 849 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
864 } 850 }
865 851
866 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptIfLinkClicked) { 852 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptIfLinkClicked) {
867 NavigateToFile("/password/password_form.html"); 853 NavigateToFile("/password/password_form.html");
868 854
869 // Verify that if the user takes a direct action to leave the page, we don't 855 // Verify that if the user takes a direct action to leave the page, we don't
870 // prompt to save the password even if the form is already filled out. 856 // prompt to save the password even if the form is already filled out.
871 NavigationObserver observer(WebContents()); 857 NavigationObserver observer(WebContents());
872 std::unique_ptr<BubbleObserver> prompt_observer( 858 std::unique_ptr<BubbleObserver> prompt_observer(
873 new BubbleObserver(WebContents())); 859 new BubbleObserver(WebContents()));
874 std::string fill_and_click_link = 860 std::string fill_and_click_link =
875 "document.getElementById('username_field').value = 'temp';" 861 "document.getElementById('username_field').value = 'temp';"
876 "document.getElementById('password_field').value = 'random';" 862 "document.getElementById('password_field').value = 'random';"
877 "document.getElementById('link').click();"; 863 "document.getElementById('link').click();";
878 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_click_link)); 864 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_click_link));
879 observer.Wait(); 865 observer.Wait();
880 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 866 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
881 } 867 }
882 868
883 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 869 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
884 VerifyPasswordGenerationUpload) { 870 VerifyPasswordGenerationUpload) {
885 // Prevent Autofill requests from actually going over the wire. 871 // Prevent Autofill requests from actually going over the wire.
886 net::TestURLFetcherFactory factory; 872 net::TestURLFetcherFactory factory;
887 // Disable Autofill requesting access to AddressBook data. This causes 873 // Disable Autofill requesting access to AddressBook data. This causes
888 // the test to hang on Mac. 874 // the test to hang on Mac.
889 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs()); 875 autofill::test::DisableSystemServices(browser()->profile()->GetPrefs());
890 876
891 // Visit a signup form. 877 // Visit a signup form.
892 NavigateToFile("/password/signup_form.html"); 878 NavigateToFile("/password/signup_form.html");
893 879
894 // Enter a password and save it. 880 // Enter a password and save it.
895 NavigationObserver first_observer(WebContents()); 881 NavigationObserver first_observer(WebContents());
896 std::unique_ptr<BubbleObserver> prompt_observer( 882 std::unique_ptr<BubbleObserver> prompt_observer(
897 new BubbleObserver(WebContents())); 883 new BubbleObserver(WebContents()));
898 std::string fill_and_submit = 884 std::string fill_and_submit =
899 "document.getElementById('other_info').value = 'stuff';" 885 "document.getElementById('other_info').value = 'stuff';"
900 "document.getElementById('username_field').value = 'my_username';" 886 "document.getElementById('username_field').value = 'my_username';"
901 "document.getElementById('password_field').value = 'password';" 887 "document.getElementById('password_field').value = 'password';"
902 "document.getElementById('input_submit_button').click()"; 888 "document.getElementById('input_submit_button').click()";
903 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 889 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
904 890
905 first_observer.Wait(); 891 first_observer.Wait();
906 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 892 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
907 prompt_observer->AcceptSavePrompt(); 893 prompt_observer->AcceptSavePrompt();
908 894
909 // Now navigate to a login form that has similar HTML markup. 895 // Now navigate to a login form that has similar HTML markup.
910 NavigateToFile("/password/password_form.html"); 896 NavigateToFile("/password/password_form.html");
911 897
912 // Simulate a user click to force an autofill of the form's DOM value, not 898 // Simulate a user click to force an autofill of the form's DOM value, not
913 // just the suggested value. 899 // just the suggested value.
914 content::SimulateMouseClick(WebContents(), 0, 900 content::SimulateMouseClick(WebContents(), 0,
915 blink::WebMouseEvent::Button::kLeft); 901 blink::WebMouseEvent::Button::kLeft);
916 902
917 // The form should be filled with the previously submitted username. 903 // The form should be filled with the previously submitted username.
918 CheckElementValue("username_field", "my_username"); 904 CheckElementValue("username_field", "my_username");
919 CheckElementValue("password_field", "password"); 905 CheckElementValue("password_field", "password");
920 906
921 // Submit the form and verify that there is no infobar (as the password 907 // Submit the form and verify that there is no infobar (as the password
922 // has already been saved). 908 // has already been saved).
923 NavigationObserver second_observer(WebContents()); 909 NavigationObserver second_observer(WebContents());
924 std::unique_ptr<BubbleObserver> second_prompt_observer( 910 std::unique_ptr<BubbleObserver> second_prompt_observer(
925 new BubbleObserver(WebContents())); 911 new BubbleObserver(WebContents()));
926 std::string submit_form = 912 std::string submit_form =
927 "document.getElementById('input_submit_button').click()"; 913 "document.getElementById('input_submit_button').click()";
928 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form)); 914 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit_form));
929 second_observer.Wait(); 915 second_observer.Wait();
930 EXPECT_FALSE(second_prompt_observer->IsShowingSavePrompt()); 916 EXPECT_FALSE(second_prompt_observer->WasSavePromptShown());
931 917
932 // Verify that we sent two pings to Autofill. One vote for of PASSWORD for 918 // Verify that we sent two pings to Autofill. One vote for of PASSWORD for
933 // the current form, and one vote for ACCOUNT_CREATION_PASSWORD on the 919 // the current form, and one vote for ACCOUNT_CREATION_PASSWORD on the
934 // original form since it has more than 2 text input fields and was used for 920 // original form since it has more than 2 text input fields and was used for
935 // the first time on a different form. 921 // the first time on a different form.
936 base::HistogramBase* upload_histogram = 922 base::HistogramBase* upload_histogram =
937 base::StatisticsRecorder::FindHistogram( 923 base::StatisticsRecorder::FindHistogram(
938 "PasswordGeneration.UploadStarted"); 924 "PasswordGeneration.UploadStarted");
939 ASSERT_TRUE(upload_histogram); 925 ASSERT_TRUE(upload_histogram);
940 std::unique_ptr<base::HistogramSamples> snapshot = 926 std::unique_ptr<base::HistogramSamples> snapshot =
(...skipping 16 matching lines...) Expand all
957 new BubbleObserver(WebContents())); 943 new BubbleObserver(WebContents()));
958 std::string fill_and_submit = 944 std::string fill_and_submit =
959 "var iframe = document.getElementById('test_iframe');" 945 "var iframe = document.getElementById('test_iframe');"
960 "var iframe_doc = iframe.contentDocument;" 946 "var iframe_doc = iframe.contentDocument;"
961 "iframe_doc.getElementById('username_field').value = 'temp';" 947 "iframe_doc.getElementById('username_field').value = 'temp';"
962 "iframe_doc.getElementById('password_field').value = 'random';" 948 "iframe_doc.getElementById('password_field').value = 'random';"
963 "iframe_doc.getElementById('submit_button').click()"; 949 "iframe_doc.getElementById('submit_button').click()";
964 950
965 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 951 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
966 observer.Wait(); 952 observer.Wait();
967 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 953 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
968 } 954 }
969 955
970 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 956 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
971 PromptForInputElementWithoutName) { 957 PromptForInputElementWithoutName) {
972 // Check that the prompt is shown for forms where input elements lack the 958 // Check that the prompt is shown for forms where input elements lack the
973 // "name" attribute but the "id" is present. 959 // "name" attribute but the "id" is present.
974 NavigateToFile("/password/password_form.html"); 960 NavigateToFile("/password/password_form.html");
975 961
976 NavigationObserver observer(WebContents()); 962 NavigationObserver observer(WebContents());
977 std::unique_ptr<BubbleObserver> prompt_observer( 963 std::unique_ptr<BubbleObserver> prompt_observer(
978 new BubbleObserver(WebContents())); 964 new BubbleObserver(WebContents()));
979 std::string fill_and_submit = 965 std::string fill_and_submit =
980 "document.getElementById('username_field_no_name').value = 'temp';" 966 "document.getElementById('username_field_no_name').value = 'temp';"
981 "document.getElementById('password_field_no_name').value = 'random';" 967 "document.getElementById('password_field_no_name').value = 'random';"
982 "document.getElementById('input_submit_button_no_name').click()"; 968 "document.getElementById('input_submit_button_no_name').click()";
983 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 969 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
984 observer.Wait(); 970 observer.Wait();
985 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 971 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
986 } 972 }
987 973
988 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 974 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
989 PromptForInputElementWithoutId) { 975 PromptForInputElementWithoutId) {
990 // Check that the prompt is shown for forms where input elements lack the 976 // Check that the prompt is shown for forms where input elements lack the
991 // "id" attribute but the "name" attribute is present. 977 // "id" attribute but the "name" attribute is present.
992 NavigateToFile("/password/password_form.html"); 978 NavigateToFile("/password/password_form.html");
993 979
994 NavigationObserver observer(WebContents()); 980 NavigationObserver observer(WebContents());
995 std::unique_ptr<BubbleObserver> prompt_observer( 981 std::unique_ptr<BubbleObserver> prompt_observer(
996 new BubbleObserver(WebContents())); 982 new BubbleObserver(WebContents()));
997 std::string fill_and_submit = 983 std::string fill_and_submit =
998 "document.getElementsByName('username_field_no_id')[0].value = 'temp';" 984 "document.getElementsByName('username_field_no_id')[0].value = 'temp';"
999 "document.getElementsByName('password_field_no_id')[0].value = 'random';" 985 "document.getElementsByName('password_field_no_id')[0].value = 'random';"
1000 "document.getElementsByName('input_submit_button_no_id')[0].click()"; 986 "document.getElementsByName('input_submit_button_no_id')[0].click()";
1001 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 987 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1002 observer.Wait(); 988 observer.Wait();
1003 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 989 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1004 } 990 }
1005 991
1006 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 992 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1007 PromptForInputElementWithoutIdAndName) { 993 PromptForInputElementWithoutIdAndName) {
1008 // Check that prompt is shown for forms where the input fields lack both 994 // Check that prompt is shown for forms where the input fields lack both
1009 // the "id" and the "name" attributes. 995 // the "id" and the "name" attributes.
1010 NavigateToFile("/password/password_form.html"); 996 NavigateToFile("/password/password_form.html");
1011 997
1012 NavigationObserver observer(WebContents()); 998 NavigationObserver observer(WebContents());
1013 std::unique_ptr<BubbleObserver> prompt_observer( 999 std::unique_ptr<BubbleObserver> prompt_observer(
1014 new BubbleObserver(WebContents())); 1000 new BubbleObserver(WebContents()));
1015 std::string fill_and_submit = 1001 std::string fill_and_submit =
1016 "var form = document.getElementById('testform_elements_no_id_no_name');" 1002 "var form = document.getElementById('testform_elements_no_id_no_name');"
1017 "var username = form.children[0];" 1003 "var username = form.children[0];"
1018 "username.value = 'temp';" 1004 "username.value = 'temp';"
1019 "var password = form.children[1];" 1005 "var password = form.children[1];"
1020 "password.value = 'random';" 1006 "password.value = 'random';"
1021 "form.children[2].click()"; // form.children[2] is the submit button. 1007 "form.children[2].click()"; // form.children[2] is the submit button.
1022 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1008 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1023 observer.Wait(); 1009 observer.Wait();
1024 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1010 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1025 prompt_observer->AcceptSavePrompt(); 1011 prompt_observer->AcceptSavePrompt();
1026 1012
1027 // Check that credentials are stored. 1013 // Check that credentials are stored.
1028 scoped_refptr<password_manager::TestPasswordStore> password_store = 1014 scoped_refptr<password_manager::TestPasswordStore> password_store =
1029 static_cast<password_manager::TestPasswordStore*>( 1015 static_cast<password_manager::TestPasswordStore*>(
1030 PasswordStoreFactory::GetForProfile( 1016 PasswordStoreFactory::GetForProfile(
1031 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 1017 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
1032 .get()); 1018 .get());
1033 1019
1034 WaitForPasswordStore(); 1020 WaitForPasswordStore();
(...skipping 11 matching lines...) Expand all
1046 1032
1047 NavigationObserver observer(WebContents()); 1033 NavigationObserver observer(WebContents());
1048 std::unique_ptr<BubbleObserver> prompt_observer( 1034 std::unique_ptr<BubbleObserver> prompt_observer(
1049 new BubbleObserver(WebContents())); 1035 new BubbleObserver(WebContents()));
1050 std::string fill_and_submit = 1036 std::string fill_and_submit =
1051 "document.getElementById('username_field').value = 'temp';" 1037 "document.getElementById('username_field').value = 'temp';"
1052 "document.getElementById('password_field').value = 'random';" 1038 "document.getElementById('password_field').value = 'random';"
1053 "document.getElementById('input_submit_button').click();"; 1039 "document.getElementById('input_submit_button').click();";
1054 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1040 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1055 observer.Wait(); 1041 observer.Wait();
1056 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1042 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1057 } 1043 }
1058 1044
1059 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1045 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1060 NoPromptForLandingPageWithHTTPErrorStatusCode) { 1046 NoPromptForLandingPageWithHTTPErrorStatusCode) {
1061 // Check that no prompt is shown for forms where the landing page has 1047 // Check that no prompt is shown for forms where the landing page has
1062 // HTTP status 404. 1048 // HTTP status 404.
1063 NavigateToFile("/password/password_form.html"); 1049 NavigateToFile("/password/password_form.html");
1064 1050
1065 NavigationObserver observer(WebContents()); 1051 NavigationObserver observer(WebContents());
1066 std::unique_ptr<BubbleObserver> prompt_observer( 1052 std::unique_ptr<BubbleObserver> prompt_observer(
1067 new BubbleObserver(WebContents())); 1053 new BubbleObserver(WebContents()));
1068 std::string fill_and_submit = 1054 std::string fill_and_submit =
1069 "document.getElementById('username_field_http_error').value = 'temp';" 1055 "document.getElementById('username_field_http_error').value = 'temp';"
1070 "document.getElementById('password_field_http_error').value = 'random';" 1056 "document.getElementById('password_field_http_error').value = 'random';"
1071 "document.getElementById('input_submit_button_http_error').click()"; 1057 "document.getElementById('input_submit_button_http_error').click()";
1072 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1058 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1073 observer.Wait(); 1059 observer.Wait();
1074 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1060 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1075 } 1061 }
1076 1062
1077 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1063 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1078 DeleteFrameBeforeSubmit) { 1064 DeleteFrameBeforeSubmit) {
1079 NavigateToFile("/password/multi_frames.html"); 1065 NavigateToFile("/password/multi_frames.html");
1080 1066
1081 NavigationObserver observer(WebContents()); 1067 NavigationObserver observer(WebContents());
1082 // Make sure we save some password info from an iframe and then destroy it. 1068 // Make sure we save some password info from an iframe and then destroy it.
1083 std::string save_and_remove = 1069 std::string save_and_remove =
1084 "var first_frame = document.getElementById('first_frame');" 1070 "var first_frame = document.getElementById('first_frame');"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 DontPromptForPasswordFormWithDefaultValue) { 1181 DontPromptForPasswordFormWithDefaultValue) {
1196 NavigateToFile("/password/password_form_with_default_value.html"); 1182 NavigateToFile("/password/password_form_with_default_value.html");
1197 1183
1198 // Don't prompt if we navigate away even if there is a password value since 1184 // Don't prompt if we navigate away even if there is a password value since
1199 // it's not coming from the user. 1185 // it's not coming from the user.
1200 NavigationObserver observer(WebContents()); 1186 NavigationObserver observer(WebContents());
1201 std::unique_ptr<BubbleObserver> prompt_observer( 1187 std::unique_ptr<BubbleObserver> prompt_observer(
1202 new BubbleObserver(WebContents())); 1188 new BubbleObserver(WebContents()));
1203 NavigateToFile("/password/done.html"); 1189 NavigateToFile("/password/done.html");
1204 observer.Wait(); 1190 observer.Wait();
1205 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1191 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1206 } 1192 }
1207 1193
1208 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1194 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1209 DontPromptForPasswordFormWithReadonlyPasswordField) { 1195 DontPromptForPasswordFormWithReadonlyPasswordField) {
1210 NavigateToFile("/password/password_form_with_password_readonly.html"); 1196 NavigateToFile("/password/password_form_with_password_readonly.html");
1211 1197
1212 // Fill a form and submit through a <input type="submit"> button. Nothing 1198 // Fill a form and submit through a <input type="submit"> button. Nothing
1213 // special. 1199 // special.
1214 NavigationObserver observer(WebContents()); 1200 NavigationObserver observer(WebContents());
1215 std::unique_ptr<BubbleObserver> prompt_observer( 1201 std::unique_ptr<BubbleObserver> prompt_observer(
1216 new BubbleObserver(WebContents())); 1202 new BubbleObserver(WebContents()));
1217 std::string fill_and_submit = 1203 std::string fill_and_submit =
1218 "document.getElementById('username_field').value = 'temp';" 1204 "document.getElementById('username_field').value = 'temp';"
1219 "document.getElementById('password_field').value = 'random';" 1205 "document.getElementById('password_field').value = 'random';"
1220 "document.getElementById('input_submit_button').click()"; 1206 "document.getElementById('input_submit_button').click()";
1221 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1207 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1222 observer.Wait(); 1208 observer.Wait();
1223 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1209 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1224 } 1210 }
1225 1211
1226 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1212 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1227 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) { 1213 PromptWhenEnableAutomaticPasswordSavingSwitchIsNotSet) {
1228 NavigateToFile("/password/password_form.html"); 1214 NavigateToFile("/password/password_form.html");
1229 1215
1230 // Fill a form and submit through a <input type="submit"> button. 1216 // Fill a form and submit through a <input type="submit"> button.
1231 NavigationObserver observer(WebContents()); 1217 NavigationObserver observer(WebContents());
1232 std::unique_ptr<BubbleObserver> prompt_observer( 1218 std::unique_ptr<BubbleObserver> prompt_observer(
1233 new BubbleObserver(WebContents())); 1219 new BubbleObserver(WebContents()));
1234 std::string fill_and_submit = 1220 std::string fill_and_submit =
1235 "document.getElementById('username_field').value = 'temp';" 1221 "document.getElementById('username_field').value = 'temp';"
1236 "document.getElementById('password_field').value = 'random';" 1222 "document.getElementById('password_field').value = 'random';"
1237 "document.getElementById('input_submit_button').click()"; 1223 "document.getElementById('input_submit_button').click()";
1238 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1224 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1239 observer.Wait(); 1225 observer.Wait();
1240 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1226 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1241 } 1227 }
1242 1228
1243 // Test fix for crbug.com/368690. 1229 // Test fix for crbug.com/368690.
1244 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptWhenReloading) { 1230 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptWhenReloading) {
1245 NavigateToFile("/password/password_form.html"); 1231 NavigateToFile("/password/password_form.html");
1246 1232
1247 std::string fill = 1233 std::string fill =
1248 "document.getElementById('username_redirect').value = 'temp';" 1234 "document.getElementById('username_redirect').value = 'temp';"
1249 "document.getElementById('password_redirect').value = 'random';"; 1235 "document.getElementById('password_redirect').value = 'random';";
1250 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill)); 1236 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill));
1251 1237
1252 NavigationObserver observer(WebContents()); 1238 NavigationObserver observer(WebContents());
1253 std::unique_ptr<BubbleObserver> prompt_observer( 1239 std::unique_ptr<BubbleObserver> prompt_observer(
1254 new BubbleObserver(WebContents())); 1240 new BubbleObserver(WebContents()));
1255 GURL url = embedded_test_server()->GetURL("/password/password_form.html"); 1241 GURL url = embedded_test_server()->GetURL("/password/password_form.html");
1256 chrome::NavigateParams params(browser(), url, ::ui::PAGE_TRANSITION_RELOAD); 1242 chrome::NavigateParams params(browser(), url, ::ui::PAGE_TRANSITION_RELOAD);
1257 ui_test_utils::NavigateToURL(&params); 1243 ui_test_utils::NavigateToURL(&params);
1258 observer.Wait(); 1244 observer.Wait();
1259 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1245 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1260 } 1246 }
1261 1247
1262 // Test that if a form gets dynamically added between the form parsing and 1248 // Test that if a form gets dynamically added between the form parsing and
1263 // rendering, and while the main frame still loads, it still is registered, and 1249 // rendering, and while the main frame still loads, it still is registered, and
1264 // thus saving passwords from it works. 1250 // thus saving passwords from it works.
1265 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1251 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1266 FormsAddedBetweenParsingAndRendering) { 1252 FormsAddedBetweenParsingAndRendering) {
1267 NavigateToFile("/password/between_parsing_and_rendering.html"); 1253 NavigateToFile("/password/between_parsing_and_rendering.html");
1268 1254
1269 NavigationObserver observer(WebContents()); 1255 NavigationObserver observer(WebContents());
1270 std::string submit = 1256 std::string submit =
1271 "document.getElementById('username').value = 'temp';" 1257 "document.getElementById('username').value = 'temp';"
1272 "document.getElementById('password').value = 'random';" 1258 "document.getElementById('password').value = 'random';"
1273 "document.getElementById('submit-button').click();"; 1259 "document.getElementById('submit-button').click();";
1274 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); 1260 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit));
1275 observer.Wait(); 1261 observer.Wait();
1276 1262
1277 EXPECT_TRUE(BubbleObserver(WebContents()).IsShowingSavePrompt()); 1263 EXPECT_TRUE(BubbleObserver(WebContents()).WasSavePromptShown());
1278 } 1264 }
1279 1265
1280 // Test that if a hidden form gets dynamically added between the form parsing 1266 // Test that if a hidden form gets dynamically added between the form parsing
1281 // and rendering, it still is registered, and autofilling works. 1267 // and rendering, it still is registered, and autofilling works.
1282 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1268 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1283 HiddenFormAddedBetweenParsingAndRendering) { 1269 HiddenFormAddedBetweenParsingAndRendering) {
1284 // At first let us save a credential to the password store. 1270 // At first let us save a credential to the password store.
1285 scoped_refptr<password_manager::TestPasswordStore> password_store = 1271 scoped_refptr<password_manager::TestPasswordStore> password_store =
1286 static_cast<password_manager::TestPasswordStore*>( 1272 static_cast<password_manager::TestPasswordStore*>(
1287 PasswordStoreFactory::GetForProfile( 1273 PasswordStoreFactory::GetForProfile(
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1370 static_cast<password_manager::TestPasswordStore*>( 1356 static_cast<password_manager::TestPasswordStore*>(
1371 PasswordStoreFactory::GetForProfile( 1357 PasswordStoreFactory::GetForProfile(
1372 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 1358 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
1373 ASSERT_TRUE(password_store->IsEmpty()); 1359 ASSERT_TRUE(password_store->IsEmpty());
1374 1360
1375 // Navigate to a page requiring HTTP auth. Wait for the tab to get the correct 1361 // Navigate to a page requiring HTTP auth. Wait for the tab to get the correct
1376 // WebContents, but don't wait for navigation, which only finishes after 1362 // WebContents, but don't wait for navigation, which only finishes after
1377 // authentication. 1363 // authentication.
1378 ui_test_utils::NavigateToURLWithDisposition( 1364 ui_test_utils::NavigateToURLWithDisposition(
1379 browser(), http_test_server.GetURL("/basic_auth"), 1365 browser(), http_test_server.GetURL("/basic_auth"),
1380 WindowOpenDisposition::NEW_FOREGROUND_TAB, 1366 WindowOpenDisposition::CURRENT_TAB, ui_test_utils::BROWSER_TEST_NONE);
1381 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
1382 1367
1383 content::WebContents* tab = 1368 content::NavigationController* nav_controller =
1384 browser()->tab_strip_model()->GetActiveWebContents(); 1369 &WebContents()->GetController();
1385 content::NavigationController* nav_controller = &tab->GetController(); 1370 NavigationObserver nav_observer(WebContents());
1386 NavigationObserver nav_observer(tab);
1387 WindowedAuthNeededObserver auth_needed_observer(nav_controller); 1371 WindowedAuthNeededObserver auth_needed_observer(nav_controller);
1388 auth_needed_observer.Wait(); 1372 auth_needed_observer.Wait();
1389 1373
1390 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller); 1374 WindowedAuthSuppliedObserver auth_supplied_observer(nav_controller);
1391 // Offer valid credentials on the auth challenge. 1375 // Offer valid credentials on the auth challenge.
1392 ASSERT_EQ(1u, login_observer.handlers().size()); 1376 ASSERT_EQ(1u, login_observer.handlers().size());
1393 LoginHandler* handler = *login_observer.handlers().begin(); 1377 LoginHandler* handler = *login_observer.handlers().begin();
1394 ASSERT_TRUE(handler); 1378 ASSERT_TRUE(handler);
1395 // Any username/password will work. 1379 // Any username/password will work.
1396 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd")); 1380 handler->SetAuth(base::UTF8ToUTF16("user"), base::UTF8ToUTF16("pwd"));
1397 auth_supplied_observer.Wait(); 1381 auth_supplied_observer.Wait();
1398 1382
1399 // The password manager should be working correctly. 1383 // The password manager should be working correctly.
1400 nav_observer.Wait(); 1384 nav_observer.Wait();
1401 WaitForPasswordStore(); 1385 WaitForPasswordStore();
1402 BubbleObserver bubble_observer(tab); 1386 BubbleObserver bubble_observer(WebContents());
1403 EXPECT_TRUE(bubble_observer.IsShowingSavePrompt()); 1387 EXPECT_TRUE(bubble_observer.WasSavePromptShown());
1404 bubble_observer.AcceptSavePrompt(); 1388 bubble_observer.AcceptSavePrompt();
1405 1389
1406 // Spin the message loop to make sure the password store had a chance to save 1390 // Spin the message loop to make sure the password store had a chance to save
1407 // the password. 1391 // the password.
1408 WaitForPasswordStore(); 1392 WaitForPasswordStore();
1409 EXPECT_FALSE(password_store->IsEmpty()); 1393 EXPECT_FALSE(password_store->IsEmpty());
1410 } 1394 }
1411 1395
1412 // Fill out a form and click a button. The Javascript removes the form, creates 1396 // Fill out a form and click a button. The Javascript removes the form, creates
1413 // a similar one with another action, fills it out and submits. Chrome can 1397 // a similar one with another action, fills it out and submits. Chrome can
1414 // manage to detect the new one and create a complete matching 1398 // manage to detect the new one and create a complete matching
1415 // PasswordFormManager. Otherwise, the all-but-action matching PFM should be 1399 // PasswordFormManager. Otherwise, the all-but-action matching PFM should be
1416 // used. Regardless of the internals the user sees the bubble in 100% cases. 1400 // used. Regardless of the internals the user sees the bubble in 100% cases.
1417 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1401 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1418 PreferPasswordFormManagerWhichFinishedMatching) { 1402 PreferPasswordFormManagerWhichFinishedMatching) {
1419 NavigateToFile("/password/create_form_copy_on_submit.html"); 1403 NavigateToFile("/password/create_form_copy_on_submit.html");
1420 1404
1421 NavigationObserver observer(WebContents()); 1405 NavigationObserver observer(WebContents());
1422 std::unique_ptr<BubbleObserver> prompt_observer( 1406 std::unique_ptr<BubbleObserver> prompt_observer(
1423 new BubbleObserver(WebContents())); 1407 new BubbleObserver(WebContents()));
1424 std::string submit = 1408 std::string submit =
1425 "document.getElementById('username').value = 'overwrite_me';" 1409 "document.getElementById('username').value = 'overwrite_me';"
1426 "document.getElementById('password').value = 'random';" 1410 "document.getElementById('password').value = 'random';"
1427 "document.getElementById('non-form-button').click();"; 1411 "document.getElementById('non-form-button').click();";
1428 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); 1412 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit));
1429 observer.Wait(); 1413 observer.Wait();
1430 1414
1431 WaitForPasswordStore(); 1415 WaitForPasswordStore();
1432 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1416 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1433 } 1417 }
1434 1418
1435 // Test that if login fails and content server pushes a different login form 1419 // Test that if login fails and content server pushes a different login form
1436 // with action URL having different schemes. Heuristic shall be able 1420 // with action URL having different schemes. Heuristic shall be able
1437 // identify such cases and *shall not* prompt to save incorrect password. 1421 // identify such cases and *shall not* prompt to save incorrect password.
1438 IN_PROC_BROWSER_TEST_F( 1422 IN_PROC_BROWSER_TEST_F(
1439 PasswordManagerBrowserTestBase, 1423 PasswordManagerBrowserTestBase,
1440 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpToHttps) { 1424 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpToHttps) {
1441 std::string path = 1425 std::string path =
1442 "/password/separate_login_form_with_onload_submit_script.html"; 1426 "/password/separate_login_form_with_onload_submit_script.html";
1443 GURL http_url(embedded_test_server()->GetURL(path)); 1427 GURL http_url(embedded_test_server()->GetURL(path));
1444 ASSERT_TRUE(http_url.SchemeIs(url::kHttpScheme)); 1428 ASSERT_TRUE(http_url.SchemeIs(url::kHttpScheme));
1445 1429
1446 NavigationObserver observer(WebContents()); 1430 NavigationObserver observer(WebContents());
1447 std::unique_ptr<BubbleObserver> prompt_observer( 1431 std::unique_ptr<BubbleObserver> prompt_observer(
1448 new BubbleObserver(WebContents())); 1432 new BubbleObserver(WebContents()));
1449 ui_test_utils::NavigateToURL(browser(), http_url); 1433 ui_test_utils::NavigateToURL(browser(), http_url);
1450 1434
1451 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); 1435 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html");
1452 observer.Wait(); 1436 observer.Wait();
1453 1437
1454 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1438 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1455 } 1439 }
1456 1440
1457 IN_PROC_BROWSER_TEST_F( 1441 IN_PROC_BROWSER_TEST_F(
1458 PasswordManagerBrowserTestBase, 1442 PasswordManagerBrowserTestBase,
1459 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpsToHttp) { 1443 NoPromptForLoginFailedAndServerPushSeperateLoginForm_HttpsToHttp) {
1460 // This test case cannot inject the scripts via content::ExecuteScript() in 1444 // This test case cannot inject the scripts via content::ExecuteScript() in
1461 // files served through HTTPS. Therefore the scripts are made part of the HTML 1445 // files served through HTTPS. Therefore the scripts are made part of the HTML
1462 // site and executed on load. 1446 // site and executed on load.
1463 std::string path = 1447 std::string path =
1464 "/password/separate_login_form_with_onload_submit_script.html"; 1448 "/password/separate_login_form_with_onload_submit_script.html";
1465 GURL https_url(https_test_server().GetURL(path)); 1449 GURL https_url(https_test_server().GetURL(path));
1466 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme)); 1450 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme));
1467 1451
1468 NavigationObserver observer(WebContents()); 1452 NavigationObserver observer(WebContents());
1469 std::unique_ptr<BubbleObserver> prompt_observer( 1453 std::unique_ptr<BubbleObserver> prompt_observer(
1470 new BubbleObserver(WebContents())); 1454 new BubbleObserver(WebContents()));
1471 ui_test_utils::NavigateToURL(browser(), https_url); 1455 ui_test_utils::NavigateToURL(browser(), https_url);
1472 1456
1473 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html"); 1457 observer.SetPathToWaitFor("/password/done_and_separate_login_form.html");
1474 observer.Wait(); 1458 observer.Wait();
1475 1459
1476 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1460 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1477 } 1461 }
1478 1462
1479 // Tests whether a attempted submission of a malicious credentials gets blocked. 1463 // Tests whether a attempted submission of a malicious credentials gets blocked.
1480 // This simulates a case which is described in http://crbug.com/571580. 1464 // This simulates a case which is described in http://crbug.com/571580.
1481 IN_PROC_BROWSER_TEST_F( 1465 IN_PROC_BROWSER_TEST_F(
1482 PasswordManagerBrowserTestBase, 1466 PasswordManagerBrowserTestBase,
1483 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) { 1467 NoPromptForSeperateLoginFormWhenSwitchingFromHttpsToHttp) {
1484 std::string path = "/password/password_form.html"; 1468 std::string path = "/password/password_form.html";
1485 GURL https_url(https_test_server().GetURL(path)); 1469 GURL https_url(https_test_server().GetURL(path));
1486 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme)); 1470 ASSERT_TRUE(https_url.SchemeIs(url::kHttpsScheme));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 "document.getElementById('input_submit_button').click()"; 1503 "document.getElementById('input_submit_button').click()";
1520 ASSERT_TRUE( 1504 ASSERT_TRUE(
1521 content::ExecuteScript(RenderViewHost(), fill_and_submit_attacker_form)); 1505 content::ExecuteScript(RenderViewHost(), fill_and_submit_attacker_form));
1522 1506
1523 NavigationObserver done_observer(WebContents()); 1507 NavigationObserver done_observer(WebContents());
1524 done_observer.SetPathToWaitFor("/password/done.html"); 1508 done_observer.SetPathToWaitFor("/password/done.html");
1525 done_observer.Wait(); 1509 done_observer.Wait();
1526 1510
1527 WaitForPasswordStore(); 1511 WaitForPasswordStore();
1528 BubbleObserver prompt_observer(WebContents()); 1512 BubbleObserver prompt_observer(WebContents());
1529 EXPECT_TRUE(prompt_observer.IsShowingSavePrompt()); 1513 EXPECT_TRUE(prompt_observer.WasSavePromptShown());
1530 prompt_observer.AcceptSavePrompt(); 1514 prompt_observer.AcceptSavePrompt();
1531 1515
1532 // Wait for password store and check that credentials are stored. 1516 // Wait for password store and check that credentials are stored.
1533 WaitForPasswordStore(); 1517 WaitForPasswordStore();
1534 scoped_refptr<password_manager::TestPasswordStore> password_store = 1518 scoped_refptr<password_manager::TestPasswordStore> password_store =
1535 static_cast<password_manager::TestPasswordStore*>( 1519 static_cast<password_manager::TestPasswordStore*>(
1536 PasswordStoreFactory::GetForProfile( 1520 PasswordStoreFactory::GetForProfile(
1537 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 1521 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
1538 .get()); 1522 .get());
1539 EXPECT_FALSE(password_store->IsEmpty()); 1523 EXPECT_FALSE(password_store->IsEmpty());
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 1633
1650 NavigationObserver observer(WebContents()); 1634 NavigationObserver observer(WebContents());
1651 std::unique_ptr<BubbleObserver> prompt_observer( 1635 std::unique_ptr<BubbleObserver> prompt_observer(
1652 new BubbleObserver(WebContents())); 1636 new BubbleObserver(WebContents()));
1653 std::string submit = 1637 std::string submit =
1654 "document.getElementById('password').value = 'password';" 1638 "document.getElementById('password').value = 'password';"
1655 "document.getElementById('submit-button').click();"; 1639 "document.getElementById('submit-button').click();";
1656 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); 1640 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit));
1657 observer.Wait(); 1641 observer.Wait();
1658 1642
1659 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1643 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1660 prompt_observer->AcceptSavePrompt(); 1644 prompt_observer->AcceptSavePrompt();
1661 1645
1662 WaitForPasswordStore(); 1646 WaitForPasswordStore();
1663 EXPECT_FALSE(password_store->IsEmpty()); 1647 EXPECT_FALSE(password_store->IsEmpty());
1664 } 1648 }
1665 1649
1666 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1650 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1667 AutofillSuggestionsForPasswordFormWithoutUsernameField) { 1651 AutofillSuggestionsForPasswordFormWithoutUsernameField) {
1668 std::string submit = 1652 std::string submit =
1669 "document.getElementById('password').value = 'mypassword';" 1653 "document.getElementById('password').value = 'mypassword';"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 NavigationObserver observer(WebContents()); 1705 NavigationObserver observer(WebContents());
1722 observer.set_quit_on_entry_committed(true); 1706 observer.set_quit_on_entry_committed(true);
1723 std::unique_ptr<BubbleObserver> prompt_observer( 1707 std::unique_ptr<BubbleObserver> prompt_observer(
1724 new BubbleObserver(WebContents())); 1708 new BubbleObserver(WebContents()));
1725 std::string fill_and_submit = 1709 std::string fill_and_submit =
1726 "document.getElementById('username_field').value = 'temp';" 1710 "document.getElementById('username_field').value = 'temp';"
1727 "document.getElementById('password_field').value = 'random';" 1711 "document.getElementById('password_field').value = 'random';"
1728 "document.getElementById('submit_button').click()"; 1712 "document.getElementById('submit_button').click()";
1729 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1713 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1730 observer.Wait(); 1714 observer.Wait();
1731 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1715 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1732 } 1716 }
1733 1717
1734 // Similar to the case above, but this time the form persists after 1718 // Similar to the case above, but this time the form persists after
1735 // 'history.pushState()'. And save password prompt should not show up 1719 // 'history.pushState()'. And save password prompt should not show up
1736 // in this case. 1720 // in this case.
1737 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1721 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1738 NoPromptForPushStateWhenFormPersists) { 1722 NoPromptForPushStateWhenFormPersists) {
1739 NavigateToFile("/password/password_push_state.html"); 1723 NavigateToFile("/password/password_push_state.html");
1740 1724
1741 // Set |should_delete_testform| to false to keep submitted form visible after 1725 // Set |should_delete_testform| to false to keep submitted form visible after
1742 // history.pushsTate(); 1726 // history.pushsTate();
1743 NavigationObserver observer(WebContents()); 1727 NavigationObserver observer(WebContents());
1744 observer.set_quit_on_entry_committed(true); 1728 observer.set_quit_on_entry_committed(true);
1745 std::unique_ptr<BubbleObserver> prompt_observer( 1729 std::unique_ptr<BubbleObserver> prompt_observer(
1746 new BubbleObserver(WebContents())); 1730 new BubbleObserver(WebContents()));
1747 std::string fill_and_submit = 1731 std::string fill_and_submit =
1748 "should_delete_testform = false;" 1732 "should_delete_testform = false;"
1749 "document.getElementById('username_field').value = 'temp';" 1733 "document.getElementById('username_field').value = 'temp';"
1750 "document.getElementById('password_field').value = 'random';" 1734 "document.getElementById('password_field').value = 'random';"
1751 "document.getElementById('submit_button').click()"; 1735 "document.getElementById('submit_button').click()";
1752 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1736 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1753 observer.Wait(); 1737 observer.Wait();
1754 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1738 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1755 } 1739 }
1756 1740
1757 // The password manager should distinguish forms with empty actions. After 1741 // The password manager should distinguish forms with empty actions. After
1758 // successful login, the login form disappears, but the another one shouldn't be 1742 // successful login, the login form disappears, but the another one shouldn't be
1759 // recognized as the login form. The save prompt should appear. 1743 // recognized as the login form. The save prompt should appear.
1760 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1744 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1761 PromptForPushStateWhenFormWithEmptyActionDisappears) { 1745 PromptForPushStateWhenFormWithEmptyActionDisappears) {
1762 NavigateToFile("/password/password_push_state.html"); 1746 NavigateToFile("/password/password_push_state.html");
1763 1747
1764 NavigationObserver observer(WebContents()); 1748 NavigationObserver observer(WebContents());
1765 observer.set_quit_on_entry_committed(true); 1749 observer.set_quit_on_entry_committed(true);
1766 std::unique_ptr<BubbleObserver> prompt_observer( 1750 std::unique_ptr<BubbleObserver> prompt_observer(
1767 new BubbleObserver(WebContents())); 1751 new BubbleObserver(WebContents()));
1768 std::string fill_and_submit = 1752 std::string fill_and_submit =
1769 "document.getElementById('ea_username_field').value = 'temp';" 1753 "document.getElementById('ea_username_field').value = 'temp';"
1770 "document.getElementById('ea_password_field').value = 'random';" 1754 "document.getElementById('ea_password_field').value = 'random';"
1771 "document.getElementById('ea_submit_button').click()"; 1755 "document.getElementById('ea_submit_button').click()";
1772 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1756 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1773 observer.Wait(); 1757 observer.Wait();
1774 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1758 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1775 } 1759 }
1776 1760
1777 // Similar to the case above, but this time the form persists after 1761 // Similar to the case above, but this time the form persists after
1778 // 'history.pushState()'. The password manager should find the login form even 1762 // 'history.pushState()'. The password manager should find the login form even
1779 // if the action of the form is empty. Save password prompt should not show up. 1763 // if the action of the form is empty. Save password prompt should not show up.
1780 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1764 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1781 PromptForPushStateWhenFormWithEmptyActionPersists) { 1765 PromptForPushStateWhenFormWithEmptyActionPersists) {
1782 NavigateToFile("/password/password_push_state.html"); 1766 NavigateToFile("/password/password_push_state.html");
1783 1767
1784 NavigationObserver observer(WebContents()); 1768 NavigationObserver observer(WebContents());
1785 observer.set_quit_on_entry_committed(true); 1769 observer.set_quit_on_entry_committed(true);
1786 std::unique_ptr<BubbleObserver> prompt_observer( 1770 std::unique_ptr<BubbleObserver> prompt_observer(
1787 new BubbleObserver(WebContents())); 1771 new BubbleObserver(WebContents()));
1788 std::string fill_and_submit = 1772 std::string fill_and_submit =
1789 "should_delete_testform = false;" 1773 "should_delete_testform = false;"
1790 "document.getElementById('ea_username_field').value = 'temp';" 1774 "document.getElementById('ea_username_field').value = 'temp';"
1791 "document.getElementById('ea_password_field').value = 'random';" 1775 "document.getElementById('ea_password_field').value = 'random';"
1792 "document.getElementById('ea_submit_button').click()"; 1776 "document.getElementById('ea_submit_button').click()";
1793 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1777 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1794 observer.Wait(); 1778 observer.Wait();
1795 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1779 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1796 } 1780 }
1797 1781
1798 // Current and target URLs contain different parameters and references. This 1782 // Current and target URLs contain different parameters and references. This
1799 // test checks that parameters and references in origins are ignored for 1783 // test checks that parameters and references in origins are ignored for
1800 // form origin comparison. 1784 // form origin comparison.
1801 IN_PROC_BROWSER_TEST_F( 1785 IN_PROC_BROWSER_TEST_F(
1802 PasswordManagerBrowserTestBase, 1786 PasswordManagerBrowserTestBase,
1803 PromptForPushStateWhenFormDisappears_ParametersInOrigins) { 1787 PromptForPushStateWhenFormDisappears_ParametersInOrigins) {
1804 NavigateToFile("/password/password_push_state.html?login#r"); 1788 NavigateToFile("/password/password_push_state.html?login#r");
1805 1789
1806 NavigationObserver observer(WebContents()); 1790 NavigationObserver observer(WebContents());
1807 observer.set_quit_on_entry_committed(true); 1791 observer.set_quit_on_entry_committed(true);
1808 std::unique_ptr<BubbleObserver> prompt_observer( 1792 std::unique_ptr<BubbleObserver> prompt_observer(
1809 new BubbleObserver(WebContents())); 1793 new BubbleObserver(WebContents()));
1810 std::string fill_and_submit = 1794 std::string fill_and_submit =
1811 "add_parameters_to_target_url = true;" 1795 "add_parameters_to_target_url = true;"
1812 "document.getElementById('pa_username_field').value = 'temp';" 1796 "document.getElementById('pa_username_field').value = 'temp';"
1813 "document.getElementById('pa_password_field').value = 'random';" 1797 "document.getElementById('pa_password_field').value = 'random';"
1814 "document.getElementById('pa_submit_button').click()"; 1798 "document.getElementById('pa_submit_button').click()";
1815 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1799 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1816 observer.Wait(); 1800 observer.Wait();
1817 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1801 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1818 } 1802 }
1819 1803
1820 // Similar to the case above, but this time the form persists after 1804 // Similar to the case above, but this time the form persists after
1821 // 'history.pushState()'. The password manager should find the login form even 1805 // 'history.pushState()'. The password manager should find the login form even
1822 // if target and current URLs contain different parameters or references. 1806 // if target and current URLs contain different parameters or references.
1823 // Save password prompt should not show up. 1807 // Save password prompt should not show up.
1824 IN_PROC_BROWSER_TEST_F( 1808 IN_PROC_BROWSER_TEST_F(
1825 PasswordManagerBrowserTestBase, 1809 PasswordManagerBrowserTestBase,
1826 PromptForPushStateWhenFormPersists_ParametersInOrigins) { 1810 PromptForPushStateWhenFormPersists_ParametersInOrigins) {
1827 NavigateToFile("/password/password_push_state.html?login#r"); 1811 NavigateToFile("/password/password_push_state.html?login#r");
1828 1812
1829 NavigationObserver observer(WebContents()); 1813 NavigationObserver observer(WebContents());
1830 observer.set_quit_on_entry_committed(true); 1814 observer.set_quit_on_entry_committed(true);
1831 std::unique_ptr<BubbleObserver> prompt_observer( 1815 std::unique_ptr<BubbleObserver> prompt_observer(
1832 new BubbleObserver(WebContents())); 1816 new BubbleObserver(WebContents()));
1833 std::string fill_and_submit = 1817 std::string fill_and_submit =
1834 "should_delete_testform = false;" 1818 "should_delete_testform = false;"
1835 "add_parameters_to_target_url = true;" 1819 "add_parameters_to_target_url = true;"
1836 "document.getElementById('pa_username_field').value = 'temp';" 1820 "document.getElementById('pa_username_field').value = 'temp';"
1837 "document.getElementById('pa_password_field').value = 'random';" 1821 "document.getElementById('pa_password_field').value = 'random';"
1838 "document.getElementById('pa_submit_button').click()"; 1822 "document.getElementById('pa_submit_button').click()";
1839 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1823 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1840 observer.Wait(); 1824 observer.Wait();
1841 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1825 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1842 } 1826 }
1843 1827
1844 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1828 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1845 InFrameNavigationDoesNotClearPopupState) { 1829 InFrameNavigationDoesNotClearPopupState) {
1846 scoped_refptr<password_manager::TestPasswordStore> password_store = 1830 scoped_refptr<password_manager::TestPasswordStore> password_store =
1847 static_cast<password_manager::TestPasswordStore*>( 1831 static_cast<password_manager::TestPasswordStore*>(
1848 PasswordStoreFactory::GetForProfile( 1832 PasswordStoreFactory::GetForProfile(
1849 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 1833 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
1850 .get()); 1834 .get());
1851 autofill::PasswordForm signin_form; 1835 autofill::PasswordForm signin_form;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 std::unique_ptr<BubbleObserver> prompt_observer( 1890 std::unique_ptr<BubbleObserver> prompt_observer(
1907 new BubbleObserver(WebContents())); 1891 new BubbleObserver(WebContents()));
1908 std::string fill_and_submit = 1892 std::string fill_and_submit =
1909 "document.getElementById('chg_username_field').value = 'temp';" 1893 "document.getElementById('chg_username_field').value = 'temp';"
1910 "document.getElementById('chg_password_field').value = 'random';" 1894 "document.getElementById('chg_password_field').value = 'random';"
1911 "document.getElementById('chg_new_password_1').value = 'random1';" 1895 "document.getElementById('chg_new_password_1').value = 'random1';"
1912 "document.getElementById('chg_new_password_2').value = 'random1';" 1896 "document.getElementById('chg_new_password_2').value = 'random1';"
1913 "document.getElementById('chg_submit_button').click()"; 1897 "document.getElementById('chg_submit_button').click()";
1914 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1898 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1915 observer.Wait(); 1899 observer.Wait();
1916 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1900 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1917 } 1901 }
1918 1902
1919 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1903 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1920 ChangePwdFormPushStateBubbleShown) { 1904 ChangePwdFormPushStateBubbleShown) {
1921 NavigateToFile("/password/password_push_state.html"); 1905 NavigateToFile("/password/password_push_state.html");
1922 1906
1923 NavigationObserver observer(WebContents()); 1907 NavigationObserver observer(WebContents());
1924 observer.set_quit_on_entry_committed(true); 1908 observer.set_quit_on_entry_committed(true);
1925 std::unique_ptr<BubbleObserver> prompt_observer( 1909 std::unique_ptr<BubbleObserver> prompt_observer(
1926 new BubbleObserver(WebContents())); 1910 new BubbleObserver(WebContents()));
1927 std::string fill_and_submit = 1911 std::string fill_and_submit =
1928 "document.getElementById('chg_username_field').value = 'temp';" 1912 "document.getElementById('chg_username_field').value = 'temp';"
1929 "document.getElementById('chg_password_field').value = 'random';" 1913 "document.getElementById('chg_password_field').value = 'random';"
1930 "document.getElementById('chg_new_password_1').value = 'random1';" 1914 "document.getElementById('chg_new_password_1').value = 'random1';"
1931 "document.getElementById('chg_new_password_2').value = 'random1';" 1915 "document.getElementById('chg_new_password_2').value = 'random1';"
1932 "document.getElementById('chg_submit_button').click()"; 1916 "document.getElementById('chg_submit_button').click()";
1933 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1917 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
1934 observer.Wait(); 1918 observer.Wait();
1935 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1919 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1936 } 1920 }
1937 1921
1938 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptOnBack) { 1922 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, NoPromptOnBack) {
1939 // Go to a successful landing page through submitting first, so that it is 1923 // Go to a successful landing page through submitting first, so that it is
1940 // reachable through going back, and the remembered page transition is form 1924 // reachable through going back, and the remembered page transition is form
1941 // submit. There is no need to submit non-empty strings. 1925 // submit. There is no need to submit non-empty strings.
1942 NavigateToFile("/password/password_form.html"); 1926 NavigateToFile("/password/password_form.html");
1943 1927
1944 NavigationObserver dummy_submit_observer(WebContents()); 1928 NavigationObserver dummy_submit_observer(WebContents());
1945 std::string just_submit = 1929 std::string just_submit =
(...skipping 11 matching lines...) Expand all
1957 // The (dummy) submit is necessary to provisionally save the typed password. A 1941 // The (dummy) submit is necessary to provisionally save the typed password. A
1958 // user typing in the password field would not need to submit to provisionally 1942 // user typing in the password field would not need to submit to provisionally
1959 // save it, but the script cannot trigger that just by assigning to the 1943 // save it, but the script cannot trigger that just by assigning to the
1960 // field's value. 1944 // field's value.
1961 std::string fill_and_back = 1945 std::string fill_and_back =
1962 "document.getElementById('password_field').value = 'random';" 1946 "document.getElementById('password_field').value = 'random';"
1963 "document.getElementById('input_submit_button').click();" 1947 "document.getElementById('input_submit_button').click();"
1964 "window.history.back();"; 1948 "window.history.back();";
1965 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_back)); 1949 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_back));
1966 observer.Wait(); 1950 observer.Wait();
1967 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 1951 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
1968 } 1952 }
1969 1953
1970 // Regression test for http://crbug.com/452306 1954 // Regression test for http://crbug.com/452306
1971 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1955 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1972 ChangingTextToPasswordFieldOnSignupForm) { 1956 ChangingTextToPasswordFieldOnSignupForm) {
1973 NavigateToFile("/password/signup_form.html"); 1957 NavigateToFile("/password/signup_form.html");
1974 1958
1975 // In this case, pretend that username_field is actually a password field 1959 // In this case, pretend that username_field is actually a password field
1976 // that starts as a text field to simulate placeholder. 1960 // that starts as a text field to simulate placeholder.
1977 NavigationObserver observer(WebContents()); 1961 NavigationObserver observer(WebContents());
1978 std::unique_ptr<BubbleObserver> prompt_observer( 1962 std::unique_ptr<BubbleObserver> prompt_observer(
1979 new BubbleObserver(WebContents())); 1963 new BubbleObserver(WebContents()));
1980 std::string change_and_submit = 1964 std::string change_and_submit =
1981 "document.getElementById('other_info').value = 'username';" 1965 "document.getElementById('other_info').value = 'username';"
1982 "document.getElementById('username_field').type = 'password';" 1966 "document.getElementById('username_field').type = 'password';"
1983 "document.getElementById('username_field').value = 'mypass';" 1967 "document.getElementById('username_field').value = 'mypass';"
1984 "document.getElementById('password_field').value = 'mypass';" 1968 "document.getElementById('password_field').value = 'mypass';"
1985 "document.getElementById('testform').submit();"; 1969 "document.getElementById('testform').submit();";
1986 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), change_and_submit)); 1970 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), change_and_submit));
1987 observer.Wait(); 1971 observer.Wait();
1988 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1972 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
1989 } 1973 }
1990 1974
1991 // Regression test for http://crbug.com/451631 1975 // Regression test for http://crbug.com/451631
1992 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1976 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
1993 SavingOnManyPasswordFieldsTest) { 1977 SavingOnManyPasswordFieldsTest) {
1994 // Simulate Macy's registration page, which contains the normal 2 password 1978 // Simulate Macy's registration page, which contains the normal 2 password
1995 // fields for confirming the new password plus 2 more fields for security 1979 // fields for confirming the new password plus 2 more fields for security
1996 // questions and credit card. Make sure that saving works correctly for such 1980 // questions and credit card. Make sure that saving works correctly for such
1997 // sites. 1981 // sites.
1998 NavigateToFile("/password/many_password_signup_form.html"); 1982 NavigateToFile("/password/many_password_signup_form.html");
1999 1983
2000 NavigationObserver observer(WebContents()); 1984 NavigationObserver observer(WebContents());
2001 std::unique_ptr<BubbleObserver> prompt_observer( 1985 std::unique_ptr<BubbleObserver> prompt_observer(
2002 new BubbleObserver(WebContents())); 1986 new BubbleObserver(WebContents()));
2003 std::string fill_and_submit = 1987 std::string fill_and_submit =
2004 "document.getElementById('username_field').value = 'username';" 1988 "document.getElementById('username_field').value = 'username';"
2005 "document.getElementById('password_field').value = 'mypass';" 1989 "document.getElementById('password_field').value = 'mypass';"
2006 "document.getElementById('confirm_field').value = 'mypass';" 1990 "document.getElementById('confirm_field').value = 'mypass';"
2007 "document.getElementById('security_answer').value = 'hometown';" 1991 "document.getElementById('security_answer').value = 'hometown';"
2008 "document.getElementById('SSN').value = '1234';" 1992 "document.getElementById('SSN').value = '1234';"
2009 "document.getElementById('testform').submit();"; 1993 "document.getElementById('testform').submit();";
2010 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 1994 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2011 observer.Wait(); 1995 observer.Wait();
2012 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 1996 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2013 } 1997 }
2014 1998
2015 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 1999 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2016 SaveWhenIFrameDestroyedOnFormSubmit) { 2000 SaveWhenIFrameDestroyedOnFormSubmit) {
2017 NavigateToFile("/password/frame_detached_on_submit.html"); 2001 NavigateToFile("/password/frame_detached_on_submit.html");
2018 2002
2019 // Need to pay attention for a message that XHR has finished since there 2003 // Need to pay attention for a message that XHR has finished since there
2020 // is no navigation to wait for. 2004 // is no navigation to wait for.
2021 content::DOMMessageQueue message_queue; 2005 content::DOMMessageQueue message_queue;
2022 2006
2023 std::unique_ptr<BubbleObserver> prompt_observer( 2007 std::unique_ptr<BubbleObserver> prompt_observer(
2024 new BubbleObserver(WebContents())); 2008 new BubbleObserver(WebContents()));
2025 std::string fill_and_submit = 2009 std::string fill_and_submit =
2026 "var iframe = document.getElementById('login_iframe');" 2010 "var iframe = document.getElementById('login_iframe');"
2027 "var frame_doc = iframe.contentDocument;" 2011 "var frame_doc = iframe.contentDocument;"
2028 "frame_doc.getElementById('username_field').value = 'temp';" 2012 "frame_doc.getElementById('username_field').value = 'temp';"
2029 "frame_doc.getElementById('password_field').value = 'random';" 2013 "frame_doc.getElementById('password_field').value = 'random';"
2030 "frame_doc.getElementById('submit_button').click();"; 2014 "frame_doc.getElementById('submit_button').click();";
2031 2015
2032 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2016 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2033 std::string message; 2017 std::string message;
2034 while (message_queue.WaitForMessage(&message)) { 2018 while (message_queue.WaitForMessage(&message)) {
2035 if (message == "\"SUBMISSION_FINISHED\"") 2019 if (message == "\"SUBMISSION_FINISHED\"")
2036 break; 2020 break;
2037 } 2021 }
2038 2022
2039 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 2023 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2040 } 2024 }
2041 2025
2042 // Tests that if a site embeds the login and signup forms into one <form>, the 2026 // Tests that if a site embeds the login and signup forms into one <form>, the
2043 // login form still gets autofilled. 2027 // login form still gets autofilled.
2044 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2028 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2045 AutofillSuggestionsForLoginSignupForm) { 2029 AutofillSuggestionsForLoginSignupForm) {
2046 std::string submit = 2030 std::string submit =
2047 "document.getElementById('username').value = 'myusername';" 2031 "document.getElementById('username').value = 'myusername';"
2048 "document.getElementById('password').value = 'mypassword';" 2032 "document.getElementById('password').value = 'mypassword';"
2049 "document.getElementById('submit').click();"; 2033 "document.getElementById('submit').click();";
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2082 ifrm_observer.Wait(); 2066 ifrm_observer.Wait();
2083 2067
2084 // Store a password for autofill later 2068 // Store a password for autofill later
2085 NavigationObserver init_observer(WebContents()); 2069 NavigationObserver init_observer(WebContents());
2086 init_observer.SetPathToWaitFor("/password/done.html"); 2070 init_observer.SetPathToWaitFor("/password/done.html");
2087 std::unique_ptr<BubbleObserver> prompt_observer( 2071 std::unique_ptr<BubbleObserver> prompt_observer(
2088 new BubbleObserver(WebContents())); 2072 new BubbleObserver(WebContents()));
2089 std::string init_form = "sendMessage('fill_and_submit');"; 2073 std::string init_form = "sendMessage('fill_and_submit');";
2090 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), init_form)); 2074 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), init_form));
2091 init_observer.Wait(); 2075 init_observer.Wait();
2092 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 2076 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2093 prompt_observer->AcceptSavePrompt(); 2077 prompt_observer->AcceptSavePrompt();
2094 2078
2095 // Visit the form again 2079 // Visit the form again
2096 NavigationObserver reload_observer(WebContents()); 2080 NavigationObserver reload_observer(WebContents());
2097 NavigateToFile("/password/password_form_in_crosssite_iframe.html"); 2081 NavigateToFile("/password/password_form_in_crosssite_iframe.html");
2098 reload_observer.Wait(); 2082 reload_observer.Wait();
2099 2083
2100 NavigationObserver ifrm_observer_2(WebContents()); 2084 NavigationObserver ifrm_observer_2(WebContents());
2101 ifrm_observer_2.SetPathToWaitFor("/password/crossite_iframe_content.html"); 2085 ifrm_observer_2.SetPathToWaitFor("/password/crossite_iframe_content.html");
2102 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(), 2086 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 std::unique_ptr<BubbleObserver> prompt_observer( 2139 std::unique_ptr<BubbleObserver> prompt_observer(
2156 new BubbleObserver(WebContents())); 2140 new BubbleObserver(WebContents()));
2157 2141
2158 std::string submit = 2142 std::string submit =
2159 "var ifrmDoc = document.getElementById('iframe').contentDocument;" 2143 "var ifrmDoc = document.getElementById('iframe').contentDocument;"
2160 "ifrmDoc.getElementById('username_field').value = 'temp';" 2144 "ifrmDoc.getElementById('username_field').value = 'temp';"
2161 "ifrmDoc.getElementById('password_field').value = 'pa55w0rd';" 2145 "ifrmDoc.getElementById('password_field').value = 'pa55w0rd';"
2162 "ifrmDoc.getElementById('input_submit_button').click();"; 2146 "ifrmDoc.getElementById('input_submit_button').click();";
2163 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit)); 2147 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), submit));
2164 observer.Wait(); 2148 observer.Wait();
2165 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 2149 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2166 prompt_observer->AcceptSavePrompt(); 2150 prompt_observer->AcceptSavePrompt();
2167 2151
2168 // Visit the form again 2152 // Visit the form again
2169 NavigationObserver reload_observer(WebContents()); 2153 NavigationObserver reload_observer(WebContents());
2170 NavigateToFile("/password/password_form_in_same_origin_iframe.html"); 2154 NavigateToFile("/password/password_form_in_same_origin_iframe.html");
2171 reload_observer.Wait(); 2155 reload_observer.Wait();
2172 2156
2173 // Verify username is autofilled 2157 // Verify username is autofilled
2174 CheckElementValue("iframe", "username_field", "temp"); 2158 CheckElementValue("iframe", "username_field", "temp");
2175 2159
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
2283 "document.getElementById('chg_password_wo_username_field').value = " 2267 "document.getElementById('chg_password_wo_username_field').value = "
2284 "'old_pw';" 2268 "'old_pw';"
2285 "document.getElementById('chg_new_password_wo_username_1').value = " 2269 "document.getElementById('chg_new_password_wo_username_1').value = "
2286 "'new_pw';" 2270 "'new_pw';"
2287 "document.getElementById('chg_new_password_wo_username_2').value = " 2271 "document.getElementById('chg_new_password_wo_username_2').value = "
2288 "'new_pw';" 2272 "'new_pw';"
2289 "document.getElementById('chg_submit_wo_username_button').click()"; 2273 "document.getElementById('chg_submit_wo_username_button').click()";
2290 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2274 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2291 observer.Wait(); 2275 observer.Wait();
2292 // No credentials stored before, so save bubble is shown. 2276 // No credentials stored before, so save bubble is shown.
2293 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 2277 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2294 prompt_observer->AcceptSavePrompt(); 2278 prompt_observer->AcceptSavePrompt();
2295 // Check that credentials are stored. 2279 // Check that credentials are stored.
2296 scoped_refptr<password_manager::TestPasswordStore> password_store = 2280 scoped_refptr<password_manager::TestPasswordStore> password_store =
2297 static_cast<password_manager::TestPasswordStore*>( 2281 static_cast<password_manager::TestPasswordStore*>(
2298 PasswordStoreFactory::GetForProfile( 2282 PasswordStoreFactory::GetForProfile(
2299 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 2283 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
2300 .get()); 2284 .get());
2301 WaitForPasswordStore(); 2285 WaitForPasswordStore();
2302 EXPECT_FALSE(password_store->IsEmpty()); 2286 EXPECT_FALSE(password_store->IsEmpty());
2303 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16(""), 2287 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16(""),
(...skipping 23 matching lines...) Expand all
2327 "document.getElementById('chg_password_wo_username_field').value = " 2311 "document.getElementById('chg_password_wo_username_field').value = "
2328 "'random';" 2312 "'random';"
2329 "document.getElementById('chg_new_password_wo_username_1').value = " 2313 "document.getElementById('chg_new_password_wo_username_1').value = "
2330 "'new_pw';" 2314 "'new_pw';"
2331 "document.getElementById('chg_new_password_wo_username_2').value = " 2315 "document.getElementById('chg_new_password_wo_username_2').value = "
2332 "'new_pw';" 2316 "'new_pw';"
2333 "document.getElementById('chg_submit_wo_username_button').click()"; 2317 "document.getElementById('chg_submit_wo_username_button').click()";
2334 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), 2318 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
2335 fill_and_submit_change_password)); 2319 fill_and_submit_change_password));
2336 observer.Wait(); 2320 observer.Wait();
2337 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); 2321 EXPECT_TRUE(prompt_observer->WasUpdatePromptShown());
2338 2322
2339 // We emulate that the user clicks "Update" button. 2323 // We emulate that the user clicks "Update" button.
2340 const autofill::PasswordForm& pending_credentials = 2324 const autofill::PasswordForm& pending_credentials =
2341 ManagePasswordsUIController::FromWebContents(WebContents()) 2325 ManagePasswordsUIController::FromWebContents(WebContents())
2342 ->GetPendingPassword(); 2326 ->GetPendingPassword();
2343 prompt_observer->AcceptUpdatePrompt(pending_credentials); 2327 prompt_observer->AcceptUpdatePrompt(pending_credentials);
2344 2328
2345 WaitForPasswordStore(); 2329 WaitForPasswordStore();
2346 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2330 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2347 base::ASCIIToUTF16("new_pw")); 2331 base::ASCIIToUTF16("new_pw"));
(...skipping 25 matching lines...) Expand all
2373 std::unique_ptr<BubbleObserver> prompt_observer( 2357 std::unique_ptr<BubbleObserver> prompt_observer(
2374 new BubbleObserver(WebContents())); 2358 new BubbleObserver(WebContents()));
2375 std::string fill_and_submit = 2359 std::string fill_and_submit =
2376 "document.getElementById('username_field').value = 'temp';" 2360 "document.getElementById('username_field').value = 'temp';"
2377 "document.getElementById('password_field').value = 'new_pw';" 2361 "document.getElementById('password_field').value = 'new_pw';"
2378 "document.getElementById('input_submit_button').click()"; 2362 "document.getElementById('input_submit_button').click()";
2379 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2363 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2380 observer.Wait(); 2364 observer.Wait();
2381 // The stored password "pw" was overriden with "new_pw", so update prompt is 2365 // The stored password "pw" was overriden with "new_pw", so update prompt is
2382 // expected. 2366 // expected.
2383 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); 2367 EXPECT_TRUE(prompt_observer->WasUpdatePromptShown());
2384 2368
2385 const autofill::PasswordForm stored_form = 2369 const autofill::PasswordForm stored_form =
2386 password_store->stored_passwords().begin()->second[0]; 2370 password_store->stored_passwords().begin()->second[0];
2387 prompt_observer->AcceptUpdatePrompt(stored_form); 2371 prompt_observer->AcceptUpdatePrompt(stored_form);
2388 WaitForPasswordStore(); 2372 WaitForPasswordStore();
2389 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2373 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2390 base::ASCIIToUTF16("new_pw")); 2374 base::ASCIIToUTF16("new_pw"));
2391 } 2375 }
2392 2376
2393 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2377 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
(...skipping 16 matching lines...) Expand all
2410 std::unique_ptr<BubbleObserver> prompt_observer( 2394 std::unique_ptr<BubbleObserver> prompt_observer(
2411 new BubbleObserver(WebContents())); 2395 new BubbleObserver(WebContents()));
2412 std::string fill_and_submit = 2396 std::string fill_and_submit =
2413 "document.getElementById('username_field').value = 'temp';" 2397 "document.getElementById('username_field').value = 'temp';"
2414 "document.getElementById('password_field').value = 'pw';" 2398 "document.getElementById('password_field').value = 'pw';"
2415 "document.getElementById('input_submit_button').click()"; 2399 "document.getElementById('input_submit_button').click()";
2416 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2400 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2417 observer.Wait(); 2401 observer.Wait();
2418 // The stored password "pw" was not overriden, so update prompt is not 2402 // The stored password "pw" was not overriden, so update prompt is not
2419 // expected. 2403 // expected.
2420 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 2404 EXPECT_FALSE(prompt_observer->WasUpdatePromptShown());
2421 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2405 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2422 base::ASCIIToUTF16("pw")); 2406 base::ASCIIToUTF16("pw"));
2423 } 2407 }
2424 2408
2425 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2409 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2426 ChangePwdWhenTheFormContainNotUsernameTextfield) { 2410 ChangePwdWhenTheFormContainNotUsernameTextfield) {
2427 // At first let us save credentials to the PasswordManager. 2411 // At first let us save credentials to the PasswordManager.
2428 scoped_refptr<password_manager::TestPasswordStore> password_store = 2412 scoped_refptr<password_manager::TestPasswordStore> password_store =
2429 static_cast<password_manager::TestPasswordStore*>( 2413 static_cast<password_manager::TestPasswordStore*>(
2430 PasswordStoreFactory::GetForProfile( 2414 PasswordStoreFactory::GetForProfile(
(...skipping 15 matching lines...) Expand all
2446 "document.getElementById('chg_password_withtext_field').value" 2430 "document.getElementById('chg_password_withtext_field').value"
2447 " = 'random';" 2431 " = 'random';"
2448 "document.getElementById('chg_new_password_withtext_username_1').value" 2432 "document.getElementById('chg_new_password_withtext_username_1').value"
2449 " = 'new_pw';" 2433 " = 'new_pw';"
2450 "document.getElementById('chg_new_password_withtext_username_2').value" 2434 "document.getElementById('chg_new_password_withtext_username_2').value"
2451 " = 'new_pw';" 2435 " = 'new_pw';"
2452 "document.getElementById('chg_submit_withtext_button').click()"; 2436 "document.getElementById('chg_submit_withtext_button').click()";
2453 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), 2437 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
2454 fill_and_submit_change_password)); 2438 fill_and_submit_change_password));
2455 observer.Wait(); 2439 observer.Wait();
2456 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); 2440 EXPECT_TRUE(prompt_observer->WasUpdatePromptShown());
2457 2441
2458 const autofill::PasswordForm stored_form = 2442 const autofill::PasswordForm stored_form =
2459 password_store->stored_passwords().begin()->second[0]; 2443 password_store->stored_passwords().begin()->second[0];
2460 prompt_observer->AcceptUpdatePrompt(stored_form); 2444 prompt_observer->AcceptUpdatePrompt(stored_form);
2461 WaitForPasswordStore(); 2445 WaitForPasswordStore();
2462 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 2446 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
2463 base::ASCIIToUTF16("new_pw")); 2447 base::ASCIIToUTF16("new_pw"));
2464 } 2448 }
2465 2449
2466 // Test whether the password form with the username and password fields having 2450 // Test whether the password form with the username and password fields having
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
2937 // Check that password save bubble is shown. 2921 // Check that password save bubble is shown.
2938 NavigateToFile("/password/password_form.html"); 2922 NavigateToFile("/password/password_form.html");
2939 NavigationObserver observer(WebContents()); 2923 NavigationObserver observer(WebContents());
2940 std::unique_ptr<BubbleObserver> prompt_observer( 2924 std::unique_ptr<BubbleObserver> prompt_observer(
2941 new BubbleObserver(WebContents())); 2925 new BubbleObserver(WebContents()));
2942 std::string fill_and_submit = 2926 std::string fill_and_submit =
2943 "document.getElementById('retry_password_field').value = 'pw';" 2927 "document.getElementById('retry_password_field').value = 'pw';"
2944 "document.getElementById('retry_submit_button').click()"; 2928 "document.getElementById('retry_submit_button').click()";
2945 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2929 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2946 observer.Wait(); 2930 observer.Wait();
2947 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 2931 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
2948 prompt_observer->AcceptSavePrompt(); 2932 prompt_observer->AcceptSavePrompt();
2949 2933
2950 WaitForPasswordStore(); 2934 WaitForPasswordStore();
2951 CheckThatCredentialsStored(password_store.get(), base::string16(), 2935 CheckThatCredentialsStored(password_store.get(), base::string16(),
2952 base::ASCIIToUTF16("pw")); 2936 base::ASCIIToUTF16("pw"));
2953 } 2937 }
2954 2938
2955 // Tests that no bubble shown when a password form without username submitted 2939 // Tests that no bubble shown when a password form without username submitted
2956 // and there is stored credentials with the same password. 2940 // and there is stored credentials with the same password.
2957 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2941 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
(...skipping 17 matching lines...) Expand all
2975 // same in one of the stored credentials. 2959 // same in one of the stored credentials.
2976 NavigateToFile("/password/password_form.html"); 2960 NavigateToFile("/password/password_form.html");
2977 NavigationObserver observer(WebContents()); 2961 NavigationObserver observer(WebContents());
2978 std::unique_ptr<BubbleObserver> prompt_observer( 2962 std::unique_ptr<BubbleObserver> prompt_observer(
2979 new BubbleObserver(WebContents())); 2963 new BubbleObserver(WebContents()));
2980 std::string fill_and_submit = 2964 std::string fill_and_submit =
2981 "document.getElementById('retry_password_field').value = 'pw';" 2965 "document.getElementById('retry_password_field').value = 'pw';"
2982 "document.getElementById('retry_submit_button').click()"; 2966 "document.getElementById('retry_submit_button').click()";
2983 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2967 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
2984 observer.Wait(); 2968 observer.Wait();
2985 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 2969 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
2986 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt()); 2970 EXPECT_FALSE(prompt_observer->WasUpdatePromptShown());
2987 } 2971 }
2988 2972
2989 // Tests that the update bubble shown when a password form without username is 2973 // Tests that the update bubble shown when a password form without username is
2990 // submitted and there are stored credentials but with different password. 2974 // submitted and there are stored credentials but with different password.
2991 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 2975 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
2992 PasswordRetryFormUpdateBubbleShown) { 2976 PasswordRetryFormUpdateBubbleShown) {
2993 // At first let us save credentials to the PasswordManager. 2977 // At first let us save credentials to the PasswordManager.
2994 scoped_refptr<password_manager::TestPasswordStore> password_store = 2978 scoped_refptr<password_manager::TestPasswordStore> password_store =
2995 static_cast<password_manager::TestPasswordStore*>( 2979 static_cast<password_manager::TestPasswordStore*>(
2996 PasswordStoreFactory::GetForProfile( 2980 PasswordStoreFactory::GetForProfile(
2997 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 2981 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
2998 .get()); 2982 .get());
2999 autofill::PasswordForm signin_form; 2983 autofill::PasswordForm signin_form;
3000 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 2984 signin_form.signon_realm = embedded_test_server()->base_url().spec();
3001 signin_form.username_value = base::ASCIIToUTF16("temp"); 2985 signin_form.username_value = base::ASCIIToUTF16("temp");
3002 signin_form.password_value = base::ASCIIToUTF16("pw"); 2986 signin_form.password_value = base::ASCIIToUTF16("pw");
3003 password_store->AddLogin(signin_form); 2987 password_store->AddLogin(signin_form);
3004 2988
3005 // Check that password update bubble is shown. 2989 // Check that password update bubble is shown.
3006 NavigateToFile("/password/password_form.html"); 2990 NavigateToFile("/password/password_form.html");
3007 NavigationObserver observer(WebContents()); 2991 NavigationObserver observer(WebContents());
3008 std::unique_ptr<BubbleObserver> prompt_observer( 2992 std::unique_ptr<BubbleObserver> prompt_observer(
3009 new BubbleObserver(WebContents())); 2993 new BubbleObserver(WebContents()));
3010 std::string fill_and_submit = 2994 std::string fill_and_submit =
3011 "document.getElementById('retry_password_field').value = 'new_pw';" 2995 "document.getElementById('retry_password_field').value = 'new_pw';"
3012 "document.getElementById('retry_submit_button').click()"; 2996 "document.getElementById('retry_submit_button').click()";
3013 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 2997 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
3014 observer.Wait(); 2998 observer.Wait();
3015 // The new password "new_pw" is used, so update prompt is expected. 2999 // The new password "new_pw" is used, so update prompt is expected.
3016 EXPECT_TRUE(prompt_observer->IsShowingUpdatePrompt()); 3000 EXPECT_TRUE(prompt_observer->WasUpdatePromptShown());
3017 3001
3018 const autofill::PasswordForm stored_form = 3002 const autofill::PasswordForm stored_form =
3019 password_store->stored_passwords().begin()->second[0]; 3003 password_store->stored_passwords().begin()->second[0];
3020 prompt_observer->AcceptUpdatePrompt(stored_form); 3004 prompt_observer->AcceptUpdatePrompt(stored_form);
3021 3005
3022 WaitForPasswordStore(); 3006 WaitForPasswordStore();
3023 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"), 3007 CheckThatCredentialsStored(password_store.get(), base::ASCIIToUTF16("temp"),
3024 base::ASCIIToUTF16("new_pw")); 3008 base::ASCIIToUTF16("new_pw"));
3025 } 3009 }
3026 3010
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3062 3046
3063 NavigationObserver observer(WebContents()); 3047 NavigationObserver observer(WebContents());
3064 std::unique_ptr<BubbleObserver> prompt_observer( 3048 std::unique_ptr<BubbleObserver> prompt_observer(
3065 new BubbleObserver(WebContents())); 3049 new BubbleObserver(WebContents()));
3066 std::string fill_and_submit = 3050 std::string fill_and_submit =
3067 "document.getElementById('username').value = 'temp';" 3051 "document.getElementById('username').value = 'temp';"
3068 "document.getElementById('password').value = 'random';" 3052 "document.getElementById('password').value = 'random';"
3069 "document.getElementById('submit').click()"; 3053 "document.getElementById('submit').click()";
3070 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit)); 3054 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_and_submit));
3071 observer.Wait(); 3055 observer.Wait();
3072 EXPECT_TRUE(prompt_observer->IsShowingSavePrompt()); 3056 EXPECT_TRUE(prompt_observer->WasSavePromptShown());
3073 } 3057 }
3074 3058
3075 // Tests that password suggestions still work if the fields have the 3059 // Tests that password suggestions still work if the fields have the
3076 // "autocomplete" attribute set to off. 3060 // "autocomplete" attribute set to off.
3077 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase, 3061 IN_PROC_BROWSER_TEST_F(PasswordManagerBrowserTestBase,
3078 AutofillSuggestionsForPasswordFormWithAutocompleteOff) { 3062 AutofillSuggestionsForPasswordFormWithAutocompleteOff) {
3079 std::string submit = 3063 std::string submit =
3080 "document.getElementById('username').value = 'temp';" 3064 "document.getElementById('username').value = 'temp';"
3081 "document.getElementById('password').value = 'mypassword';" 3065 "document.getElementById('password').value = 'mypassword';"
3082 "document.getElementById('submit').click();"; 3066 "document.getElementById('submit').click();";
(...skipping 29 matching lines...) Expand all
3112 NavigationObserver observer(WebContents()); 3096 NavigationObserver observer(WebContents());
3113 std::unique_ptr<BubbleObserver> prompt_observer( 3097 std::unique_ptr<BubbleObserver> prompt_observer(
3114 new BubbleObserver(WebContents())); 3098 new BubbleObserver(WebContents()));
3115 std::string fill_and_submit_change_password = 3099 std::string fill_and_submit_change_password =
3116 "document.getElementById('username_field').value = 'user';" 3100 "document.getElementById('username_field').value = 'user';"
3117 "document.getElementById('password_field').value = 'password';" 3101 "document.getElementById('password_field').value = 'password';"
3118 "document.getElementById('input_submit_button').click()"; 3102 "document.getElementById('input_submit_button').click()";
3119 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), 3103 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
3120 fill_and_submit_change_password)); 3104 fill_and_submit_change_password));
3121 observer.Wait(); 3105 observer.Wait();
3122 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 3106 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
3123 3107
3124 // Verify that the form's 'skip_zero_click' is not updated. 3108 // Verify that the form's 'skip_zero_click' is not updated.
3125 auto& passwords_map = password_store->stored_passwords(); 3109 auto& passwords_map = password_store->stored_passwords();
3126 ASSERT_EQ(1u, passwords_map.size()); 3110 ASSERT_EQ(1u, passwords_map.size());
3127 auto& passwords_vector = passwords_map.begin()->second; 3111 auto& passwords_vector = passwords_map.begin()->second;
3128 ASSERT_EQ(1u, passwords_vector.size()); 3112 ASSERT_EQ(1u, passwords_vector.size());
3129 const autofill::PasswordForm& form = passwords_vector[0]; 3113 const autofill::PasswordForm& form = passwords_vector[0];
3130 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); 3114 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value);
3131 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); 3115 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value);
3132 EXPECT_TRUE(form.skip_zero_click); 3116 EXPECT_TRUE(form.skip_zero_click);
(...skipping 22 matching lines...) Expand all
3155 NavigationObserver observer(WebContents()); 3139 NavigationObserver observer(WebContents());
3156 std::unique_ptr<BubbleObserver> prompt_observer( 3140 std::unique_ptr<BubbleObserver> prompt_observer(
3157 new BubbleObserver(WebContents())); 3141 new BubbleObserver(WebContents()));
3158 std::string fill_and_submit_change_password = 3142 std::string fill_and_submit_change_password =
3159 "document.getElementById('username_field').value = 'user';" 3143 "document.getElementById('username_field').value = 'user';"
3160 "document.getElementById('password_field').value = 'password';" 3144 "document.getElementById('password_field').value = 'password';"
3161 "document.getElementById('input_submit_button').click()"; 3145 "document.getElementById('input_submit_button').click()";
3162 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), 3146 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(),
3163 fill_and_submit_change_password)); 3147 fill_and_submit_change_password));
3164 observer.Wait(); 3148 observer.Wait();
3165 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt()); 3149 EXPECT_FALSE(prompt_observer->WasSavePromptShown());
3166 3150
3167 // Verify that the form's 'skip_zero_click' is not updated. 3151 // Verify that the form's 'skip_zero_click' is not updated.
3168 auto& passwords_map = password_store->stored_passwords(); 3152 auto& passwords_map = password_store->stored_passwords();
3169 ASSERT_EQ(1u, passwords_map.size()); 3153 ASSERT_EQ(1u, passwords_map.size());
3170 auto& passwords_vector = passwords_map.begin()->second; 3154 auto& passwords_vector = passwords_map.begin()->second;
3171 ASSERT_EQ(1u, passwords_vector.size()); 3155 ASSERT_EQ(1u, passwords_vector.size());
3172 const autofill::PasswordForm& form = passwords_vector[0]; 3156 const autofill::PasswordForm& form = passwords_vector[0];
3173 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); 3157 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value);
3174 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); 3158 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value);
3175 EXPECT_TRUE(form.skip_zero_click); 3159 EXPECT_TRUE(form.skip_zero_click);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
3306 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(), 3290 ASSERT_TRUE(content::ExecuteScriptWithoutUserGesture(RenderFrameHost(),
3307 "var noop = 'noop';")); 3291 "var noop = 'noop';"));
3308 // Ensure the warning was not triggered. 3292 // Ensure the warning was not triggered.
3309 content::RunAllBlockingPoolTasksUntilIdle(); 3293 content::RunAllBlockingPoolTasksUntilIdle();
3310 ASSERT_FALSE(observing_autofill_client->popup_shown()); 3294 ASSERT_FALSE(observing_autofill_client->popup_shown());
3311 // Ensure the histogram remains empty. 3295 // Ensure the histogram remains empty.
3312 histograms.ExpectTotalCount(kHistogram, 0); 3296 histograms.ExpectTotalCount(kHistogram, 0);
3313 } 3297 }
3314 3298
3315 } // namespace password_manager 3299 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698