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

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