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

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

Issue 2915763003: [Password Manager] Show omnibox icon and anchored prompt once user start typing password (Closed)
Patch Set: Rebase 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/macros.h" 5 #include "base/macros.h"
6 #include "base/stl_util.h" 6 #include "base/stl_util.h"
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/password_manager/chrome_password_manager_client.h" 9 #include "chrome/browser/password_manager/chrome_password_manager_client.h"
10 #include "chrome/browser/password_manager/password_manager_test_base.h" 10 #include "chrome/browser/password_manager/password_manager_test_base.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 // context of the old URL, |a_url|. 150 // context of the old URL, |a_url|.
151 // 151 //
152 // The CredentialManager Mojo interface is Channel-associated, so message 152 // The CredentialManager Mojo interface is Channel-associated, so message
153 // ordering with legacy IPC messages is preserved. Therefore, servicing the 153 // ordering with legacy IPC messages is preserved. Therefore, servicing the
154 // store() called from the `unload` handler, triggered from 154 // store() called from the `unload` handler, triggered from
155 // FrameLoader::PrepareForCommit, will be serviced before 155 // FrameLoader::PrepareForCommit, will be serviced before
156 // FrameHostMsg_DidCommitProvisionalLoad, thus before DidFinishNavigation, 156 // FrameHostMsg_DidCommitProvisionalLoad, thus before DidFinishNavigation,
157 ASSERT_TRUE(client->was_store_ever_called()); 157 ASSERT_TRUE(client->was_store_ever_called());
158 158
159 BubbleObserver prompt_observer(WebContents()); 159 BubbleObserver prompt_observer(WebContents());
160 prompt_observer.WaitForSavePrompt(); 160 prompt_observer.WaitForAutomaticSavePrompt();
161 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt()); 161 ASSERT_TRUE(prompt_observer.IsSavePromptShownAutomatically());
162 prompt_observer.AcceptSavePrompt(); 162 prompt_observer.AcceptSavePrompt();
163 163
164 WaitForPasswordStore(); 164 WaitForPasswordStore();
165 165
166 password_manager::TestPasswordStore* test_password_store = 166 password_manager::TestPasswordStore* test_password_store =
167 static_cast<password_manager::TestPasswordStore*>( 167 static_cast<password_manager::TestPasswordStore*>(
168 PasswordStoreFactory::GetForProfile( 168 PasswordStoreFactory::GetForProfile(
169 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 169 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
170 .get()); 170 .get());
171 171
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); 323 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
324 324
325 NavigationObserver observer(WebContents()); 325 NavigationObserver observer(WebContents());
326 observer.SetPathToWaitFor("/password/done.html"); 326 observer.SetPathToWaitFor("/password/done.html");
327 observer.Wait(); 327 observer.Wait();
328 328
329 // Wait for the password store before checking the prompt because it pops up 329 // Wait for the password store before checking the prompt because it pops up
330 // after the store replies. 330 // after the store replies.
331 WaitForPasswordStore(); 331 WaitForPasswordStore();
332 BubbleObserver prompt_observer(WebContents()); 332 BubbleObserver prompt_observer(WebContents());
333 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); 333 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically());
334 EXPECT_FALSE(prompt_observer.IsShowingUpdatePrompt()); 334 EXPECT_FALSE(prompt_observer.IsUpdatePromptShownAutomatically());
335 335
336 // There should be an entry for both psl.example.com and www.example.com. 336 // There should be an entry for both psl.example.com and www.example.com.
337 password_manager::TestPasswordStore::PasswordMap passwords = 337 password_manager::TestPasswordStore::PasswordMap passwords =
338 password_store->stored_passwords(); 338 password_store->stored_passwords();
339 GURL www_url = https_test_server().GetURL("www.example.com", "/"); 339 GURL www_url = https_test_server().GetURL("www.example.com", "/");
340 EXPECT_EQ(2U, passwords.size()); 340 EXPECT_EQ(2U, passwords.size());
341 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); 341 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec()));
342 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); 342 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec()));
343 } 343 }
344 344
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 "navigator.credentials.get({password: true})" 415 "navigator.credentials.get({password: true})"
416 ".then(cred => window.location = '/password/done.html');")); 416 ".then(cred => window.location = '/password/done.html');"));
417 417
418 NavigationObserver observer(WebContents()); 418 NavigationObserver observer(WebContents());
419 observer.SetPathToWaitFor("/password/done.html"); 419 observer.SetPathToWaitFor("/password/done.html");
420 observer.Wait(); 420 observer.Wait();
421 421
422 BubbleObserver prompt_observer(WebContents()); 422 BubbleObserver prompt_observer(WebContents());
423 // The autofill password manager shouldn't react to the successful login 423 // The autofill password manager shouldn't react to the successful login
424 // because it was suppressed when the site got the credential back. 424 // because it was suppressed when the site got the credential back.
425 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); 425 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically());
426 } 426 }
427 427
428 // Regression test for https://crbug.com/736357. 428 // Regression test for https://crbug.com/736357.
429 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 429 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
430 StoreInUnloadHandler_SameSite_OnDemandMojoPipe) { 430 StoreInUnloadHandler_SameSite_OnDemandMojoPipe) {
431 TestStoreInUnloadHandlerForSameSiteNavigation( 431 TestStoreInUnloadHandlerForSameSiteNavigation(
432 false /* preestablish_mojo_pipe */); 432 false /* preestablish_mojo_pipe */);
433 } 433 }
434 434
435 // Regression test for https://crbug.com/736357. 435 // Regression test for https://crbug.com/736357.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // Store a credential, and expect it to establish the Mojo connection. 473 // Store a credential, and expect it to establish the Mojo connection.
474 EXPECT_FALSE(client->has_binding_for_credential_manager()); 474 EXPECT_FALSE(client->has_binding_for_credential_manager());
475 EXPECT_FALSE(client->was_store_ever_called()); 475 EXPECT_FALSE(client->was_store_ever_called());
476 476
477 ASSERT_TRUE(content::ExecuteScript( 477 ASSERT_TRUE(content::ExecuteScript(
478 WebContents(), 478 WebContents(),
479 "var c = new PasswordCredential({ id: 'user', password: 'hunter2' });" 479 "var c = new PasswordCredential({ id: 'user', password: 'hunter2' });"
480 "navigator.credentials.store(c);")); 480 "navigator.credentials.store(c);"));
481 481
482 BubbleObserver prompt_observer(WebContents()); 482 BubbleObserver prompt_observer(WebContents());
483 prompt_observer.WaitForSavePrompt(); 483 prompt_observer.WaitForAutomaticSavePrompt();
484 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt()); 484 ASSERT_TRUE(prompt_observer.IsSavePromptShownAutomatically());
485 prompt_observer.AcceptSavePrompt(); 485 prompt_observer.AcceptSavePrompt();
486 WaitForPasswordStore(); 486 WaitForPasswordStore();
487 487
488 EXPECT_TRUE(client->has_binding_for_credential_manager()); 488 EXPECT_TRUE(client->has_binding_for_credential_manager());
489 EXPECT_TRUE(client->was_store_ever_called()); 489 EXPECT_TRUE(client->was_store_ever_called());
490 490
491 // Trigger a same-site navigation. 491 // Trigger a same-site navigation.
492 content::RenderFrameHost* old_rfh = WebContents()->GetMainFrame(); 492 content::RenderFrameHost* old_rfh = WebContents()->GetMainFrame();
493 ui_test_utils::NavigateToURL(browser(), a_url2); 493 ui_test_utils::NavigateToURL(browser(), a_url2);
494 ASSERT_EQ(old_rfh, WebContents()->GetMainFrame()); 494 ASSERT_EQ(old_rfh, WebContents()->GetMainFrame());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 NavigationObserver form_submit_observer(WebContents()); 540 NavigationObserver form_submit_observer(WebContents());
541 ASSERT_TRUE(content::ExecuteScript( 541 ASSERT_TRUE(content::ExecuteScript(
542 RenderViewHost(), 542 RenderViewHost(),
543 "document.getElementById('username_field').value = 'user';" 543 "document.getElementById('username_field').value = 'user';"
544 "document.getElementById('password_field').value = 'autofill';" 544 "document.getElementById('password_field').value = 'autofill';"
545 "document.getElementById('input_submit_button').click();")); 545 "document.getElementById('input_submit_button').click();"));
546 form_submit_observer.Wait(); 546 form_submit_observer.Wait();
547 547
548 WaitForPasswordStore(); 548 WaitForPasswordStore();
549 BubbleObserver prompt_observer(WebContents()); 549 BubbleObserver prompt_observer(WebContents());
550 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt()); 550 ASSERT_TRUE(prompt_observer.IsSavePromptShownAutomatically());
551 prompt_observer.AcceptSavePrompt(); 551 prompt_observer.AcceptSavePrompt();
552 552
553 WaitForPasswordStore(); 553 WaitForPasswordStore();
554 password_manager::TestPasswordStore::PasswordMap stored = 554 password_manager::TestPasswordStore::PasswordMap stored =
555 static_cast<password_manager::TestPasswordStore*>( 555 static_cast<password_manager::TestPasswordStore*>(
556 PasswordStoreFactory::GetForProfile( 556 PasswordStoreFactory::GetForProfile(
557 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) 557 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
558 .get())->stored_passwords(); 558 .get())->stored_passwords();
559 ASSERT_EQ(1u, stored.size()); 559 ASSERT_EQ(1u, stored.size());
560 autofill::PasswordForm signin_form = stored.begin()->second[0]; 560 autofill::PasswordForm signin_form = stored.begin()->second[0];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 RenderViewHost(), 598 RenderViewHost(),
599 "document.getElementById('username_field').value = 'user';" 599 "document.getElementById('username_field').value = 'user';"
600 "document.getElementById('password_field').value = 'autofill';" 600 "document.getElementById('password_field').value = 'autofill';"
601 "document.getElementById('input_submit_button').click();")); 601 "document.getElementById('input_submit_button').click();"));
602 form_submit_observer.Wait(); 602 form_submit_observer.Wait();
603 603
604 // Wait for the password store before checking the prompt because it pops up 604 // Wait for the password store before checking the prompt because it pops up
605 // after the store replies. 605 // after the store replies.
606 WaitForPasswordStore(); 606 WaitForPasswordStore();
607 BubbleObserver prompt_observer(WebContents()); 607 BubbleObserver prompt_observer(WebContents());
608 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); 608 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically());
609 EXPECT_FALSE(prompt_observer.IsShowingUpdatePrompt()); 609 EXPECT_FALSE(prompt_observer.IsUpdatePromptShownAutomatically());
610 signin_form.skip_zero_click = false; 610 signin_form.skip_zero_click = false;
611 signin_form.times_used = 1; 611 signin_form.times_used = 1;
612 signin_form.password_value = base::ASCIIToUTF16("API"); 612 signin_form.password_value = base::ASCIIToUTF16("API");
613 password_manager::TestPasswordStore::PasswordMap stored = 613 password_manager::TestPasswordStore::PasswordMap stored =
614 password_store->stored_passwords(); 614 password_store->stored_passwords();
615 ASSERT_EQ(1u, stored.size()); 615 ASSERT_EQ(1u, stored.size());
616 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 616 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
617 } 617 }
618 618
619 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, CredentialsAutofilled) { 619 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, CredentialsAutofilled) {
620 NavigateToFile("/password/password_form.html"); 620 NavigateToFile("/password/password_form.html");
621 621
622 ASSERT_TRUE(content::ExecuteScript( 622 ASSERT_TRUE(content::ExecuteScript(
623 RenderFrameHost(), 623 RenderFrameHost(),
624 "var c = new PasswordCredential({ id: 'user', password: '12345' });" 624 "var c = new PasswordCredential({ id: 'user', password: '12345' });"
625 "navigator.credentials.store(c);")); 625 "navigator.credentials.store(c);"));
626 BubbleObserver bubble_observer(WebContents()); 626 BubbleObserver bubble_observer(WebContents());
627 bubble_observer.WaitForSavePrompt(); 627 bubble_observer.WaitForAutomaticSavePrompt();
628 bubble_observer.AcceptSavePrompt(); 628 bubble_observer.AcceptSavePrompt();
629 629
630 // Reload the page and make sure it's autofilled. 630 // Reload the page and make sure it's autofilled.
631 NavigateToFile("/password/password_form.html"); 631 NavigateToFile("/password/password_form.html");
632 WaitForElementValue("username_field", "user"); 632 WaitForElementValue("username_field", "user");
633 content::SimulateMouseClickAt( 633 content::SimulateMouseClickAt(
634 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); 634 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1));
635 WaitForElementValue("password_field", "12345"); 635 WaitForElementValue("password_field", "12345");
636 } 636 }
637 637
638 } // namespace 638 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698