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

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

Issue 1850923004: Disable the autofill password manager when a credential is sent via CM API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "chrome/browser/password_manager/password_manager_test_base.h"
8 #include "chrome/browser/password_manager/password_store_factory.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/passwords/passwords_model_delegate.h"
12 #include "components/password_manager/core/browser/password_bubble_experiment.h"
13 #include "components/password_manager/core/browser/test_password_store.h"
14 #include "content/public/test/browser_test.h"
15 #include "content/public/test/browser_test_utils.h"
16
17 namespace {
18
19 class CredentialManagerBrowserTest : public PasswordManagerBrowserTestBase {
20 public:
21 CredentialManagerBrowserTest() = default;
22
23 bool IsShowingAccountChooser() {
24 return PasswordsModelDelegateFromWebContents(WebContents())->GetState() ==
25 password_manager::ui::CREDENTIAL_REQUEST_STATE;
26 }
27
28 private:
29 net::EmbeddedTestServer https_test_server_;
30
31 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest);
32 };
33
34 // Tests.
35
36 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
37 AccountChooserWithOldCredentialAndNavigation) {
38 // Save credentials with 'skip_zero_click'.
39 scoped_refptr<password_manager::TestPasswordStore> password_store =
40 static_cast<password_manager::TestPasswordStore*>(
41 PasswordStoreFactory::GetForProfile(
42 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
43 autofill::PasswordForm signin_form;
44 signin_form.signon_realm = embedded_test_server()->base_url().spec();
45 signin_form.password_value = base::ASCIIToUTF16("password");
46 signin_form.username_value = base::ASCIIToUTF16("user");
47 signin_form.origin = embedded_test_server()->base_url();
48 signin_form.skip_zero_click = true;
49 password_store->AddLogin(signin_form);
50
51 NavigateToFile("/password/password_form.html");
52 std::string fill_password =
53 "document.getElementById('username_field').value = 'user';"
54 "document.getElementById('password_field').value = 'password';";
55 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password));
56
57 // Call the API to trigger the notification to the client.
58 ASSERT_TRUE(content::ExecuteScript(
59 RenderViewHost(),
60 "navigator.credentials.get({password: true})"
61 ".then(cred => window.location = '/password/done.html')"));
62 ASSERT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
63 PasswordsModelDelegateFromWebContents(WebContents())->GetState());
64 PasswordsModelDelegateFromWebContents(WebContents())->ChooseCredential(
65 signin_form,
66 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
67
68 NavigationObserver observer(WebContents());
69 observer.SetPathToWaitFor("/password/done.html");
70 observer.Wait();
71
72 // Verify that the form's 'skip_zero_click' is updated and not overwritten
73 // by the autofill password manager on successful login.
74 auto& passwords_map = password_store->stored_passwords();
75 ASSERT_EQ(1u, passwords_map.size());
76 auto& passwords_vector = passwords_map.begin()->second;
77 ASSERT_EQ(1u, passwords_vector.size());
78 const autofill::PasswordForm& form = passwords_vector[0];
79 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value);
80 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value);
81 EXPECT_FALSE(form.skip_zero_click);
82 }
83
84 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
85 AutoSigninOldCredentialAndNavigation) {
86 // Save credentials with 'skip_zero_click' false.
87 scoped_refptr<password_manager::TestPasswordStore> password_store =
88 static_cast<password_manager::TestPasswordStore*>(
89 PasswordStoreFactory::GetForProfile(
90 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
91 autofill::PasswordForm signin_form;
92 signin_form.signon_realm = embedded_test_server()->base_url().spec();
93 signin_form.password_value = base::ASCIIToUTF16("password");
94 signin_form.username_value = base::ASCIIToUTF16("user");
95 signin_form.origin = embedded_test_server()->base_url();
96 signin_form.skip_zero_click = false;
97 password_store->AddLogin(signin_form);
98
99 // Enable 'auto signin' for the profile.
100 password_bubble_experiment::RecordAutoSignInPromptFirstRunExperienceWasShown(
101 browser()->profile()->GetPrefs());
102
103 NavigateToFile("/password/password_form.html");
104 std::string fill_password =
105 "document.getElementById('username_field').value = 'trash';"
106 "document.getElementById('password_field').value = 'trash';";
107 ASSERT_TRUE(content::ExecuteScript(RenderViewHost(), fill_password));
108
109 // Call the API to trigger the notification to the client.
110 ASSERT_TRUE(content::ExecuteScript(
111 RenderViewHost(),
112 "navigator.credentials.get({password: true})"
113 ".then(cred => window.location = '/password/done.html')"));
114
115 NavigationObserver observer(WebContents());
116 observer.SetPathToWaitFor("/password/done.html");
117 observer.Wait();
118
119 std::unique_ptr<PromptObserver> prompt_observer(
120 PromptObserver::Create(WebContents()));
121 // The autofill password manager shouldn't react to the successful login.
122 EXPECT_FALSE(prompt_observer->IsShowingPrompt());
123 }
124
125 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/password_manager/chrome_password_manager_client.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698