| OLD | NEW |
| 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 Loading... |
| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); | 322 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD); |
| 323 | 323 |
| 324 NavigationObserver observer(WebContents()); | 324 NavigationObserver observer(WebContents()); |
| 325 observer.SetPathToWaitFor("/password/done.html"); | 325 observer.SetPathToWaitFor("/password/done.html"); |
| 326 observer.Wait(); | 326 observer.Wait(); |
| 327 | 327 |
| 328 // Wait for the password store before checking the prompt because it pops up | 328 // Wait for the password store before checking the prompt because it pops up |
| 329 // after the store replies. | 329 // after the store replies. |
| 330 WaitForPasswordStore(); | 330 WaitForPasswordStore(); |
| 331 BubbleObserver prompt_observer(WebContents()); | 331 BubbleObserver prompt_observer(WebContents()); |
| 332 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); | 332 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically()); |
| 333 EXPECT_FALSE(prompt_observer.IsShowingUpdatePrompt()); | 333 EXPECT_FALSE(prompt_observer.IsUpdatePromptShownAutomatically()); |
| 334 | 334 |
| 335 // There should be an entry for both psl.example.com and www.example.com. | 335 // There should be an entry for both psl.example.com and www.example.com. |
| 336 password_manager::TestPasswordStore::PasswordMap passwords = | 336 password_manager::TestPasswordStore::PasswordMap passwords = |
| 337 password_store->stored_passwords(); | 337 password_store->stored_passwords(); |
| 338 GURL www_url = https_test_server().GetURL("www.example.com", "/"); | 338 GURL www_url = https_test_server().GetURL("www.example.com", "/"); |
| 339 EXPECT_EQ(2U, passwords.size()); | 339 EXPECT_EQ(2U, passwords.size()); |
| 340 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); | 340 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec())); |
| 341 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); | 341 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec())); |
| 342 } | 342 } |
| 343 | 343 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 "navigator.credentials.get({password: true})" | 414 "navigator.credentials.get({password: true})" |
| 415 ".then(cred => window.location = '/password/done.html');")); | 415 ".then(cred => window.location = '/password/done.html');")); |
| 416 | 416 |
| 417 NavigationObserver observer(WebContents()); | 417 NavigationObserver observer(WebContents()); |
| 418 observer.SetPathToWaitFor("/password/done.html"); | 418 observer.SetPathToWaitFor("/password/done.html"); |
| 419 observer.Wait(); | 419 observer.Wait(); |
| 420 | 420 |
| 421 BubbleObserver prompt_observer(WebContents()); | 421 BubbleObserver prompt_observer(WebContents()); |
| 422 // The autofill password manager shouldn't react to the successful login | 422 // The autofill password manager shouldn't react to the successful login |
| 423 // because it was suppressed when the site got the credential back. | 423 // because it was suppressed when the site got the credential back. |
| 424 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); | 424 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically()); |
| 425 } | 425 } |
| 426 | 426 |
| 427 // Regression test for https://crbug.com/736357. | 427 // Regression test for https://crbug.com/736357. |
| 428 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, | 428 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, |
| 429 StoreInUnloadHandler_SameSite_OnDemandMojoPipe) { | 429 StoreInUnloadHandler_SameSite_OnDemandMojoPipe) { |
| 430 TestStoreInUnloadHandlerForSameSiteNavigation( | 430 TestStoreInUnloadHandlerForSameSiteNavigation( |
| 431 false /* preestablish_mojo_pipe */); | 431 false /* preestablish_mojo_pipe */); |
| 432 } | 432 } |
| 433 | 433 |
| 434 // Regression test for https://crbug.com/736357. | 434 // Regression test for https://crbug.com/736357. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 // Store a credential, and expect it to establish the Mojo connection. | 472 // Store a credential, and expect it to establish the Mojo connection. |
| 473 EXPECT_FALSE(client->has_binding_for_credential_manager()); | 473 EXPECT_FALSE(client->has_binding_for_credential_manager()); |
| 474 EXPECT_FALSE(client->was_store_ever_called()); | 474 EXPECT_FALSE(client->was_store_ever_called()); |
| 475 | 475 |
| 476 ASSERT_TRUE(content::ExecuteScript( | 476 ASSERT_TRUE(content::ExecuteScript( |
| 477 WebContents(), | 477 WebContents(), |
| 478 "var c = new PasswordCredential({ id: 'user', password: 'hunter2' });" | 478 "var c = new PasswordCredential({ id: 'user', password: 'hunter2' });" |
| 479 "navigator.credentials.store(c);")); | 479 "navigator.credentials.store(c);")); |
| 480 | 480 |
| 481 BubbleObserver prompt_observer(WebContents()); | 481 BubbleObserver prompt_observer(WebContents()); |
| 482 prompt_observer.WaitForSavePrompt(); | 482 prompt_observer.WaitForAutomaticSavePrompt(); |
| 483 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt()); | 483 ASSERT_TRUE(prompt_observer.IsSavePromptShownAutomatically()); |
| 484 prompt_observer.AcceptSavePrompt(); | 484 prompt_observer.AcceptSavePrompt(); |
| 485 WaitForPasswordStore(); | 485 WaitForPasswordStore(); |
| 486 | 486 |
| 487 EXPECT_TRUE(client->has_binding_for_credential_manager()); | 487 EXPECT_TRUE(client->has_binding_for_credential_manager()); |
| 488 EXPECT_TRUE(client->was_store_ever_called()); | 488 EXPECT_TRUE(client->was_store_ever_called()); |
| 489 | 489 |
| 490 // Trigger a same-site navigation. | 490 // Trigger a same-site navigation. |
| 491 content::RenderFrameHost* old_rfh = WebContents()->GetMainFrame(); | 491 content::RenderFrameHost* old_rfh = WebContents()->GetMainFrame(); |
| 492 ui_test_utils::NavigateToURL(browser(), a_url2); | 492 ui_test_utils::NavigateToURL(browser(), a_url2); |
| 493 ASSERT_EQ(old_rfh, WebContents()->GetMainFrame()); | 493 ASSERT_EQ(old_rfh, WebContents()->GetMainFrame()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 NavigationObserver form_submit_observer(WebContents()); | 539 NavigationObserver form_submit_observer(WebContents()); |
| 540 ASSERT_TRUE(content::ExecuteScript( | 540 ASSERT_TRUE(content::ExecuteScript( |
| 541 RenderViewHost(), | 541 RenderViewHost(), |
| 542 "document.getElementById('username_field').value = 'user';" | 542 "document.getElementById('username_field').value = 'user';" |
| 543 "document.getElementById('password_field').value = 'autofill';" | 543 "document.getElementById('password_field').value = 'autofill';" |
| 544 "document.getElementById('input_submit_button').click();")); | 544 "document.getElementById('input_submit_button').click();")); |
| 545 form_submit_observer.Wait(); | 545 form_submit_observer.Wait(); |
| 546 | 546 |
| 547 WaitForPasswordStore(); | 547 WaitForPasswordStore(); |
| 548 BubbleObserver prompt_observer(WebContents()); | 548 BubbleObserver prompt_observer(WebContents()); |
| 549 ASSERT_TRUE(prompt_observer.IsShowingSavePrompt()); | 549 ASSERT_TRUE(prompt_observer.IsSavePromptShownAutomatically()); |
| 550 prompt_observer.AcceptSavePrompt(); | 550 prompt_observer.AcceptSavePrompt(); |
| 551 | 551 |
| 552 WaitForPasswordStore(); | 552 WaitForPasswordStore(); |
| 553 password_manager::TestPasswordStore::PasswordMap stored = | 553 password_manager::TestPasswordStore::PasswordMap stored = |
| 554 static_cast<password_manager::TestPasswordStore*>( | 554 static_cast<password_manager::TestPasswordStore*>( |
| 555 PasswordStoreFactory::GetForProfile( | 555 PasswordStoreFactory::GetForProfile( |
| 556 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) | 556 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS) |
| 557 .get())->stored_passwords(); | 557 .get())->stored_passwords(); |
| 558 ASSERT_EQ(1u, stored.size()); | 558 ASSERT_EQ(1u, stored.size()); |
| 559 autofill::PasswordForm signin_form = stored.begin()->second[0]; | 559 autofill::PasswordForm signin_form = stored.begin()->second[0]; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 RenderViewHost(), | 597 RenderViewHost(), |
| 598 "document.getElementById('username_field').value = 'user';" | 598 "document.getElementById('username_field').value = 'user';" |
| 599 "document.getElementById('password_field').value = 'autofill';" | 599 "document.getElementById('password_field').value = 'autofill';" |
| 600 "document.getElementById('input_submit_button').click();")); | 600 "document.getElementById('input_submit_button').click();")); |
| 601 form_submit_observer.Wait(); | 601 form_submit_observer.Wait(); |
| 602 | 602 |
| 603 // Wait for the password store before checking the prompt because it pops up | 603 // Wait for the password store before checking the prompt because it pops up |
| 604 // after the store replies. | 604 // after the store replies. |
| 605 WaitForPasswordStore(); | 605 WaitForPasswordStore(); |
| 606 BubbleObserver prompt_observer(WebContents()); | 606 BubbleObserver prompt_observer(WebContents()); |
| 607 EXPECT_FALSE(prompt_observer.IsShowingSavePrompt()); | 607 EXPECT_FALSE(prompt_observer.IsSavePromptShownAutomatically()); |
| 608 EXPECT_FALSE(prompt_observer.IsShowingUpdatePrompt()); | 608 EXPECT_FALSE(prompt_observer.IsUpdatePromptShownAutomatically()); |
| 609 signin_form.skip_zero_click = false; | 609 signin_form.skip_zero_click = false; |
| 610 signin_form.times_used = 1; | 610 signin_form.times_used = 1; |
| 611 signin_form.password_value = base::ASCIIToUTF16("API"); | 611 signin_form.password_value = base::ASCIIToUTF16("API"); |
| 612 password_manager::TestPasswordStore::PasswordMap stored = | 612 password_manager::TestPasswordStore::PasswordMap stored = |
| 613 password_store->stored_passwords(); | 613 password_store->stored_passwords(); |
| 614 ASSERT_EQ(1u, stored.size()); | 614 ASSERT_EQ(1u, stored.size()); |
| 615 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); | 615 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); |
| 616 } | 616 } |
| 617 | 617 |
| 618 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, CredentialsAutofilled) { | 618 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, CredentialsAutofilled) { |
| 619 NavigateToFile("/password/password_form.html"); | 619 NavigateToFile("/password/password_form.html"); |
| 620 | 620 |
| 621 ASSERT_TRUE(content::ExecuteScript( | 621 ASSERT_TRUE(content::ExecuteScript( |
| 622 RenderFrameHost(), | 622 RenderFrameHost(), |
| 623 "var c = new PasswordCredential({ id: 'user', password: '12345' });" | 623 "var c = new PasswordCredential({ id: 'user', password: '12345' });" |
| 624 "navigator.credentials.store(c);")); | 624 "navigator.credentials.store(c);")); |
| 625 BubbleObserver bubble_observer(WebContents()); | 625 BubbleObserver bubble_observer(WebContents()); |
| 626 bubble_observer.WaitForSavePrompt(); | 626 bubble_observer.WaitForAutomaticSavePrompt(); |
| 627 bubble_observer.AcceptSavePrompt(); | 627 bubble_observer.AcceptSavePrompt(); |
| 628 | 628 |
| 629 // Reload the page and make sure it's autofilled. | 629 // Reload the page and make sure it's autofilled. |
| 630 NavigateToFile("/password/password_form.html"); | 630 NavigateToFile("/password/password_form.html"); |
| 631 WaitForElementValue("username_field", "user"); | 631 WaitForElementValue("username_field", "user"); |
| 632 content::SimulateMouseClickAt( | 632 content::SimulateMouseClickAt( |
| 633 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); | 633 WebContents(), 0, blink::WebMouseEvent::Button::kLeft, gfx::Point(1, 1)); |
| 634 WaitForElementValue("password_field", "12345"); | 634 WaitForElementValue("password_field", "12345"); |
| 635 } | 635 } |
| 636 | 636 |
| 637 } // namespace | 637 } // namespace |
| OLD | NEW |