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

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

Issue 2598003002: Suppress save and update bubbles when storing a PSL matched credential (Closed)
Patch Set: Addressed comments. Created 4 years 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
« no previous file with comments | « no previous file | components/password_manager/content/browser/credential_manager_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/utf_string_conversions.h" 7 #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_manager_test_base.h"
8 #include "chrome/browser/password_manager/password_store_factory.h" 9 #include "chrome/browser/password_manager/password_store_factory.h"
9 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_io_data.h"
10 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/passwords/passwords_model_delegate.h" 13 #include "chrome/browser/ui/passwords/passwords_model_delegate.h"
14 #include "chrome/test/base/ui_test_utils.h"
12 #include "components/password_manager/core/browser/password_bubble_experiment.h" 15 #include "components/password_manager/core/browser/password_bubble_experiment.h"
13 #include "components/password_manager/core/browser/password_store_consumer.h" 16 #include "components/password_manager/core/browser/password_store_consumer.h"
14 #include "components/password_manager/core/browser/test_password_store.h" 17 #include "components/password_manager/core/browser/test_password_store.h"
15 #include "content/public/test/browser_test.h" 18 #include "content/public/test/browser_test.h"
16 #include "content/public/test/browser_test_utils.h" 19 #include "content/public/test/browser_test_utils.h"
20 #include "net/cert/cert_verify_result.h"
21 #include "net/cert/mock_cert_verifier.h"
22 #include "net/dns/mock_host_resolver.h"
17 23
18 namespace { 24 namespace {
19 25
20 // A helper class that synchronously waits until the password store handles a 26 // A helper class that synchronously waits until the password store handles a
21 // GetLogins() request. 27 // GetLogins() request.
22 class PasswordStoreResultsObserver 28 class PasswordStoreResultsObserver
23 : public password_manager::PasswordStoreConsumer { 29 : public password_manager::PasswordStoreConsumer {
24 public: 30 public:
25 PasswordStoreResultsObserver() = default; 31 PasswordStoreResultsObserver() = default;
26 32
(...skipping 25 matching lines...) Expand all
52 // are executed on another thread. 58 // are executed on another thread.
53 void WaitForPasswordStore() { 59 void WaitForPasswordStore() {
54 scoped_refptr<password_manager::PasswordStore> password_store = 60 scoped_refptr<password_manager::PasswordStore> password_store =
55 PasswordStoreFactory::GetForProfile( 61 PasswordStoreFactory::GetForProfile(
56 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); 62 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS);
57 PasswordStoreResultsObserver syncer; 63 PasswordStoreResultsObserver syncer;
58 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer); 64 password_store->GetAutofillableLoginsWithAffiliatedRealms(&syncer);
59 syncer.Wait(); 65 syncer.Wait();
60 } 66 }
61 67
68 // Similarly to PasswordManagerBrowserTestBase::NavigateToFile this is a
69 // wrapper around ui_test_utils::NavigateURL that waits until DidFinishLoad()
70 // fires. Different to NavigateToFile this method allows passing a test_server
71 // and modifications to the hostname.
72 void NavigateToURL(const net::EmbeddedTestServer& test_server,
73 const std::string& hostname,
74 const std::string& relative_url) {
75 NavigationObserver observer(WebContents());
76 GURL url = test_server.GetURL(hostname, relative_url);
77 ui_test_utils::NavigateToURL(browser(), url);
78 observer.Wait();
79 }
80
81 void SetUpInProcessBrowserTestFixture() override {
82 ProfileIOData::SetCertVerifierForTesting(&mock_cert_verifier_);
83 }
84
85 void TearDownInProcessBrowserTestFixture() override {
86 ProfileIOData::SetCertVerifierForTesting(nullptr);
87 }
88
89 net::MockCertVerifier& mock_cert_verifier() {
90 return mock_cert_verifier_;
91 }
92
62 private: 93 private:
63 94 net::MockCertVerifier mock_cert_verifier_;
64 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest); 95 DISALLOW_COPY_AND_ASSIGN(CredentialManagerBrowserTest);
65 }; 96 };
66 97
67 // Tests. 98 // Tests.
68 99
69 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 100 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
70 AccountChooserWithOldCredentialAndNavigation) { 101 AccountChooserWithOldCredentialAndNavigation) {
71 // Save credentials with 'skip_zero_click'. 102 // Save credentials with 'skip_zero_click'.
72 scoped_refptr<password_manager::TestPasswordStore> password_store = 103 scoped_refptr<password_manager::TestPasswordStore> password_store =
73 static_cast<password_manager::TestPasswordStore*>( 104 static_cast<password_manager::TestPasswordStore*>(
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 ASSERT_EQ(1u, passwords_map.size()); 143 ASSERT_EQ(1u, passwords_map.size());
113 const std::vector<autofill::PasswordForm>& passwords_vector = 144 const std::vector<autofill::PasswordForm>& passwords_vector =
114 passwords_map.begin()->second; 145 passwords_map.begin()->second;
115 ASSERT_EQ(1u, passwords_vector.size()); 146 ASSERT_EQ(1u, passwords_vector.size());
116 const autofill::PasswordForm& form = passwords_vector[0]; 147 const autofill::PasswordForm& form = passwords_vector[0];
117 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value); 148 EXPECT_EQ(base::ASCIIToUTF16("user"), form.username_value);
118 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value); 149 EXPECT_EQ(base::ASCIIToUTF16("password"), form.password_value);
119 EXPECT_FALSE(form.skip_zero_click); 150 EXPECT_FALSE(form.skip_zero_click);
120 } 151 }
121 152
153 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
154 StoreSavesPSLMatchedCredential) {
155 // Setup HTTPS server serving files from standard test directory.
156 static constexpr base::FilePath::CharType kDocRoot[] =
157 FILE_PATH_LITERAL("chrome/test/data");
158 net::EmbeddedTestServer https_test_server(
159 net::EmbeddedTestServer::TYPE_HTTPS);
160 https_test_server.ServeFilesFromSourceDirectory(base::FilePath(kDocRoot));
161 ASSERT_TRUE(https_test_server.Start());
162
163 // Setup mock certificate for all origins.
164 auto cert = https_test_server.GetCertificate();
165 net::CertVerifyResult verify_result;
166 verify_result.cert_status = 0;
167 verify_result.is_issued_by_known_root = true;
168 verify_result.verified_cert = cert;
169 mock_cert_verifier().AddResultForCert(cert.get(), verify_result, net::OK);
170
171 // Redirect all requests to localhost.
172 host_resolver()->AddRule("*", "127.0.0.1");
173
174 scoped_refptr<password_manager::TestPasswordStore> password_store =
175 static_cast<password_manager::TestPasswordStore*>(
176 PasswordStoreFactory::GetForProfile(
177 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS)
178 .get());
179
180 // The call to |GetURL| is needed to get the correct port.
181 GURL psl_url = https_test_server.GetURL("psl.example.com", "/");
182
183 autofill::PasswordForm signin_form;
184 signin_form.signon_realm = psl_url.spec();
185 signin_form.password_value = base::ASCIIToUTF16("password");
186 signin_form.username_value = base::ASCIIToUTF16("user");
187 signin_form.origin = psl_url;
188 password_store->AddLogin(signin_form);
189
190 NavigateToURL(https_test_server, "www.example.com",
191 "/password/password_form.html");
192
193 // Call the API to trigger |get| and |store| and redirect.
194 ASSERT_TRUE(
195 content::ExecuteScript(RenderViewHost(),
196 "navigator.credentials.get({password: true})"
197 ".then(cred => "
198 "navigator.credentials.store(cred)"
199 ".then(cred => "
200 "window.location = '/password/done.html'))"));
201
202 WaitForPasswordStore();
203 ASSERT_EQ(password_manager::ui::CREDENTIAL_REQUEST_STATE,
204 PasswordsModelDelegateFromWebContents(WebContents())->GetState());
205 PasswordsModelDelegateFromWebContents(WebContents())
206 ->ChooseCredential(
207 signin_form,
208 password_manager::CredentialType::CREDENTIAL_TYPE_PASSWORD);
209
210 NavigationObserver observer(WebContents());
211 observer.SetPathToWaitFor("/password/done.html");
212 observer.Wait();
213
214 // Wait for the password store before checking the prompt because it pops up
215 // after the store replies.
216 WaitForPasswordStore();
217 std::unique_ptr<BubbleObserver> prompt_observer(
218 new BubbleObserver(WebContents()));
219 EXPECT_FALSE(prompt_observer->IsShowingSavePrompt());
220 EXPECT_FALSE(prompt_observer->IsShowingUpdatePrompt());
221
222 // There should be an entry for both psl.example.com and www.example.com.
223 password_manager::TestPasswordStore::PasswordMap passwords =
224 password_store->stored_passwords();
225 GURL www_url = https_test_server.GetURL("www.example.com", "/");
226 EXPECT_EQ(2U, passwords.size());
227 EXPECT_TRUE(base::ContainsKey(passwords, psl_url.spec()));
228 EXPECT_TRUE(base::ContainsKey(passwords, www_url.spec()));
229 }
122 230
123 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest, 231 IN_PROC_BROWSER_TEST_F(CredentialManagerBrowserTest,
124 AutoSigninOldCredentialAndNavigation) { 232 AutoSigninOldCredentialAndNavigation) {
125 // Save credentials with 'skip_zero_click' false. 233 // Save credentials with 'skip_zero_click' false.
126 scoped_refptr<password_manager::TestPasswordStore> password_store = 234 scoped_refptr<password_manager::TestPasswordStore> password_store =
127 static_cast<password_manager::TestPasswordStore*>( 235 static_cast<password_manager::TestPasswordStore*>(
128 PasswordStoreFactory::GetForProfile( 236 PasswordStoreFactory::GetForProfile(
129 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get()); 237 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS).get());
130 autofill::PasswordForm signin_form; 238 autofill::PasswordForm signin_form;
131 signin_form.signon_realm = embedded_test_server()->base_url().spec(); 239 signin_form.signon_realm = embedded_test_server()->base_url().spec();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 signin_form.skip_zero_click = false; 357 signin_form.skip_zero_click = false;
250 signin_form.times_used = 1; 358 signin_form.times_used = 1;
251 signin_form.password_value = base::ASCIIToUTF16("API"); 359 signin_form.password_value = base::ASCIIToUTF16("API");
252 password_manager::TestPasswordStore::PasswordMap stored = 360 password_manager::TestPasswordStore::PasswordMap stored =
253 password_store->stored_passwords(); 361 password_store->stored_passwords();
254 ASSERT_EQ(1u, stored.size()); 362 ASSERT_EQ(1u, stored.size());
255 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]); 363 EXPECT_EQ(signin_form, stored[signin_form.signon_realm][0]);
256 } 364 }
257 365
258 } // namespace 366 } // namespace
OLDNEW
« no previous file with comments | « no previous file | components/password_manager/content/browser/credential_manager_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698