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

Side by Side Diff: components/password_manager/content/browser/credential_manager_impl_unittest.cc

Issue 2523593006: Show PSL-matched credentials in the account chooser. (Closed)
Patch Set: nit 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/core/browser/credential_manager_pending_request_task.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/password_manager/content/browser/credential_manager_impl.h" 5 #include "components/password_manager/content/browser/credential_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 .WillByDefault(testing::Return(true)); 220 .WillByDefault(testing::Return(true));
221 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 221 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
222 222
223 NavigateAndCommit(GURL("https://example.com/test.html")); 223 NavigateAndCommit(GURL("https://example.com/test.html"));
224 224
225 form_.username_value = base::ASCIIToUTF16("Username"); 225 form_.username_value = base::ASCIIToUTF16("Username");
226 form_.display_name = base::ASCIIToUTF16("Display Name"); 226 form_.display_name = base::ASCIIToUTF16("Display Name");
227 form_.icon_url = GURL("https://example.com/icon.png"); 227 form_.icon_url = GURL("https://example.com/icon.png");
228 form_.password_value = base::ASCIIToUTF16("Password"); 228 form_.password_value = base::ASCIIToUTF16("Password");
229 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 229 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
230 form_.signon_realm = form_.origin.spec(); 230 form_.signon_realm = form_.origin.GetOrigin().spec();
231 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 231 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
232 form_.skip_zero_click = false; 232 form_.skip_zero_click = false;
233 233
234 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1"); 234 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1");
235 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name"); 235 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name");
236 affiliated_form1_.password_value = base::ASCIIToUTF16("Password"); 236 affiliated_form1_.password_value = base::ASCIIToUTF16("Password");
237 affiliated_form1_.origin = GURL(); 237 affiliated_form1_.origin = GURL();
238 affiliated_form1_.signon_realm = kTestAndroidRealm1; 238 affiliated_form1_.signon_realm = kTestAndroidRealm1;
239 affiliated_form1_.scheme = autofill::PasswordForm::SCHEME_HTML; 239 affiliated_form1_.scheme = autofill::PasswordForm::SCHEME_HTML;
240 affiliated_form1_.skip_zero_click = false; 240 affiliated_form1_.skip_zero_click = false;
241 241
242 affiliated_form2_.username_value = base::ASCIIToUTF16("Affiliated 2"); 242 affiliated_form2_.username_value = base::ASCIIToUTF16("Affiliated 2");
243 affiliated_form2_.display_name = base::ASCIIToUTF16("Display Name"); 243 affiliated_form2_.display_name = base::ASCIIToUTF16("Display Name");
244 affiliated_form2_.password_value = base::ASCIIToUTF16("Password"); 244 affiliated_form2_.password_value = base::ASCIIToUTF16("Password");
245 affiliated_form2_.origin = GURL(); 245 affiliated_form2_.origin = GURL();
246 affiliated_form2_.signon_realm = kTestAndroidRealm2; 246 affiliated_form2_.signon_realm = kTestAndroidRealm2;
247 affiliated_form2_.scheme = autofill::PasswordForm::SCHEME_HTML; 247 affiliated_form2_.scheme = autofill::PasswordForm::SCHEME_HTML;
248 affiliated_form2_.skip_zero_click = false; 248 affiliated_form2_.skip_zero_click = false;
249 249
250 origin_path_form_.username_value = base::ASCIIToUTF16("Username 2"); 250 origin_path_form_.username_value = base::ASCIIToUTF16("Username 2");
251 origin_path_form_.display_name = base::ASCIIToUTF16("Display Name 2"); 251 origin_path_form_.display_name = base::ASCIIToUTF16("Display Name 2");
252 origin_path_form_.password_value = base::ASCIIToUTF16("Password 2"); 252 origin_path_form_.password_value = base::ASCIIToUTF16("Password 2");
253 origin_path_form_.origin = GURL("https://example.com/path"); 253 origin_path_form_.origin = GURL("https://example.com/path");
254 origin_path_form_.signon_realm = origin_path_form_.origin.spec(); 254 origin_path_form_.signon_realm =
255 origin_path_form_.origin.GetOrigin().spec();
255 origin_path_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 256 origin_path_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
256 origin_path_form_.skip_zero_click = false; 257 origin_path_form_.skip_zero_click = false;
257 258
258 subdomain_form_.username_value = base::ASCIIToUTF16("Username 2"); 259 subdomain_form_.username_value = base::ASCIIToUTF16("Username 2");
259 subdomain_form_.display_name = base::ASCIIToUTF16("Display Name 2"); 260 subdomain_form_.display_name = base::ASCIIToUTF16("Display Name 2");
260 subdomain_form_.password_value = base::ASCIIToUTF16("Password 2"); 261 subdomain_form_.password_value = base::ASCIIToUTF16("Password 2");
261 subdomain_form_.origin = GURL("https://subdomain.example.com/path"); 262 subdomain_form_.origin = GURL("https://subdomain.example.com/path");
262 subdomain_form_.signon_realm = subdomain_form_.origin.spec(); 263 subdomain_form_.signon_realm = subdomain_form_.origin.GetOrigin().spec();
263 subdomain_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 264 subdomain_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
264 subdomain_form_.skip_zero_click = false; 265 subdomain_form_.skip_zero_click = false;
265 266
266 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); 267 cross_origin_form_.username_value = base::ASCIIToUTF16("Username");
267 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); 268 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name");
268 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); 269 cross_origin_form_.password_value = base::ASCIIToUTF16("Password");
269 cross_origin_form_.origin = GURL("https://example.net/"); 270 cross_origin_form_.origin = GURL("https://example.net/");
270 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); 271 cross_origin_form_.signon_realm =
272 cross_origin_form_.origin.GetOrigin().spec();
271 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 273 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
272 cross_origin_form_.skip_zero_click = false; 274 cross_origin_form_.skip_zero_click = false;
273 275
274 store_->Clear(); 276 store_->Clear();
275 EXPECT_TRUE(store_->IsEmpty()); 277 EXPECT_TRUE(store_->IsEmpty());
276 } 278 }
277 279
278 void TearDown() override { 280 void TearDown() override {
279 cm_service_impl_.reset(); 281 cm_service_impl_.reset();
280 282
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 730 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
729 .Times(testing::Exactly(0)); 731 .Times(testing::Exactly(0));
730 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 732 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
731 733
732 std::vector<GURL> federations; 734 std::vector<GURL> federations;
733 ExpectCredentialType(false, true, federations, 735 ExpectCredentialType(false, true, federations,
734 CredentialType::CREDENTIAL_TYPE_EMPTY); 736 CredentialType::CREDENTIAL_TYPE_EMPTY);
735 } 737 }
736 738
737 TEST_F(CredentialManagerImplTest, 739 TEST_F(CredentialManagerImplTest,
740 CredentialManagerOnRequestCredentialWithPSLCredential) {
741 store_->AddLogin(subdomain_form_);
742 subdomain_form_.is_public_suffix_match = true;
743 EXPECT_CALL(*client_,
744 PromptUserToChooseCredentialsPtr(
745 UnorderedElementsAre(Pointee(subdomain_form_)), _, _));
746 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(0);
747
748 ExpectCredentialType(false, true, std::vector<GURL>(),
749 CredentialType::CREDENTIAL_TYPE_PASSWORD);
750 }
751
752 TEST_F(CredentialManagerImplTest,
753 CredentialManagerOnRequestCredentialWithPSLAndNormalCredentials) {
754 store_->AddLogin(form_);
755 store_->AddLogin(origin_path_form_);
756 store_->AddLogin(subdomain_form_);
757
758 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(
759 UnorderedElementsAre(Pointee(origin_path_form_),
760 Pointee(form_)),
761 _, _));
762
763 ExpectCredentialType(false, true, std::vector<GURL>(),
764 CredentialType::CREDENTIAL_TYPE_PASSWORD);
765 }
766
767 TEST_F(CredentialManagerImplTest,
738 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) { 768 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) {
739 store_->AddLogin(form_); 769 store_->AddLogin(form_);
740 autofill::PasswordForm empty = form_; 770 autofill::PasswordForm empty = form_;
741 empty.username_value.clear(); 771 empty.username_value.clear();
742 store_->AddLogin(empty); 772 store_->AddLogin(empty);
743 autofill::PasswordForm duplicate = form_; 773 autofill::PasswordForm duplicate = form_;
744 duplicate.username_element = base::ASCIIToUTF16("different_username_element"); 774 duplicate.username_element = base::ASCIIToUTF16("different_username_element");
745 store_->AddLogin(duplicate); 775 store_->AddLogin(duplicate);
746 776
747 std::vector<GURL> federations; 777 std::vector<GURL> federations;
748 ExpectZeroClickSignInSuccess(false, true, federations, 778 ExpectZeroClickSignInSuccess(false, true, federations,
749 CredentialType::CREDENTIAL_TYPE_PASSWORD); 779 CredentialType::CREDENTIAL_TYPE_PASSWORD);
750 } 780 }
751 781
752 TEST_F(CredentialManagerImplTest, 782 TEST_F(CredentialManagerImplTest,
753 CredentialManagerOnRequestCredentialWithDuplicates) { 783 CredentialManagerOnRequestCredentialWithDuplicates) {
754 // Add 8 credentials. Two buckets of duplicates, one empty username and one 784 // Add 6 credentials. Two buckets of duplicates, one empty username and one
755 // federated one. There should be just 3 in the account chooser. 785 // federated one. There should be just 3 in the account chooser.
756 form_.preferred = true; 786 form_.preferred = true;
757 form_.username_element = base::ASCIIToUTF16("username_element"); 787 form_.username_element = base::ASCIIToUTF16("username_element");
758 store_->AddLogin(form_); 788 store_->AddLogin(form_);
759 autofill::PasswordForm empty = form_; 789 autofill::PasswordForm empty = form_;
760 empty.username_value.clear(); 790 empty.username_value.clear();
761 store_->AddLogin(empty); 791 store_->AddLogin(empty);
762 autofill::PasswordForm duplicate = form_; 792 autofill::PasswordForm duplicate = form_;
763 duplicate.username_element = base::ASCIIToUTF16("username_element1");
764 duplicate.is_public_suffix_match = true;
765 store_->AddLogin(duplicate);
766 duplicate = form_;
767 duplicate.username_element = base::ASCIIToUTF16("username_element2"); 793 duplicate.username_element = base::ASCIIToUTF16("username_element2");
768 duplicate.preferred = false; 794 duplicate.preferred = false;
769 store_->AddLogin(duplicate); 795 store_->AddLogin(duplicate);
770 796
771 origin_path_form_.preferred = true; 797 origin_path_form_.preferred = true;
772 store_->AddLogin(origin_path_form_); 798 store_->AddLogin(origin_path_form_);
773 duplicate = origin_path_form_; 799 duplicate = origin_path_form_;
774 duplicate.username_element = base::ASCIIToUTF16("username_element3");
775 duplicate.is_public_suffix_match = true;
776 store_->AddLogin(duplicate);
777 duplicate = origin_path_form_;
778 duplicate.username_element = base::ASCIIToUTF16("username_element4"); 800 duplicate.username_element = base::ASCIIToUTF16("username_element4");
779 duplicate.preferred = false; 801 duplicate.preferred = false;
780 store_->AddLogin(duplicate); 802 store_->AddLogin(duplicate);
781 autofill::PasswordForm federated = origin_path_form_; 803 autofill::PasswordForm federated = origin_path_form_;
782 federated.password_value.clear(); 804 federated.password_value.clear();
783 federated.federation_origin = url::Origin(GURL("https://google.com/")); 805 federated.federation_origin = url::Origin(GURL("https://google.com/"));
784 federated.signon_realm = 806 federated.signon_realm =
785 "federation://" + federated.origin.host() + "/google.com"; 807 "federation://" + federated.origin.host() + "/google.com";
786 store_->AddLogin(federated); 808 store_->AddLogin(federated);
787 809
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 863 }
842 864
843 TEST_F( 865 TEST_F(
844 CredentialManagerImplTest, 866 CredentialManagerImplTest,
845 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { 867 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
846 std::vector<GURL> federations; 868 std::vector<GURL> federations;
847 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 869 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
848 .Times(testing::Exactly(0)); 870 .Times(testing::Exactly(0));
849 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 871 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
850 872
851 bool called = false; 873 ExpectZeroClickSignInFailure(true, true, federations);
852 mojom::CredentialManagerError error;
853 base::Optional<CredentialInfo> credential;
854 CallGet(true, true, federations,
855 base::Bind(&GetCredentialCallback, &called, &error, &credential));
856
857 RunAllPendingTasks();
858
859 EXPECT_TRUE(called);
860 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
861 } 874 }
862 875
863 TEST_F(CredentialManagerImplTest, 876 TEST_F(CredentialManagerImplTest,
864 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 877 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
865 store_->AddLogin(form_); 878 store_->AddLogin(form_);
866 client_->set_first_run_seen(true); 879 client_->set_first_run_seen(true);
867 880
868 std::vector<GURL> federations; 881 std::vector<GURL> federations;
869 882
870 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 883 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
1315 std::vector<GURL> federations; 1328 std::vector<GURL> federations;
1316 std::vector<std::string> affiliated_realms; 1329 std::vector<std::string> affiliated_realms;
1317 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1330 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1318 ->ExpectCallToGetAffiliatedAndroidRealms( 1331 ->ExpectCallToGetAffiliatedAndroidRealms(
1319 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1332 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1320 1333
1321 ExpectZeroClickSignInSuccess(true, true, federations, 1334 ExpectZeroClickSignInSuccess(true, true, federations,
1322 CredentialType::CREDENTIAL_TYPE_PASSWORD); 1335 CredentialType::CREDENTIAL_TYPE_PASSWORD);
1323 } 1336 }
1324 1337
1338 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) {
1339 subdomain_form_.skip_zero_click = false;
1340 store_->AddLogin(subdomain_form_);
1341
1342 ExpectZeroClickSignInFailure(true, true, std::vector<GURL>());
1343 }
1344
1345 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) {
1346 form_.password_value.clear();
1347 form_.federation_origin = url::Origin(GURL("https://google.com/"));
1348 form_.signon_realm = "federation://" + form_.origin.host() + "/google.com";
1349 form_.skip_zero_click = false;
1350 store_->AddLogin(form_);
1351 store_->AddLogin(subdomain_form_);
1352
1353 std::vector<GURL> federations = {GURL("https://google.com/")};
1354 ExpectZeroClickSignInSuccess(true, true, federations,
1355 CredentialType::CREDENTIAL_TYPE_FEDERATED);
1356 }
1357
1325 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { 1358 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
1326 PasswordStore::FormDigest synthesized = 1359 PasswordStore::FormDigest synthesized =
1327 cm_service_impl_->GetSynthesizedFormForOrigin(); 1360 cm_service_impl_->GetSynthesizedFormForOrigin();
1328 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1361 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1329 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1362 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1330 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1363 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1331 } 1364 }
1332 1365
1333 TEST_F(CredentialManagerImplTest, BlacklistPasswordCredential) { 1366 TEST_F(CredentialManagerImplTest, BlacklistPasswordCredential) {
1334 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr( 1367 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1456 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1424 CallStore(info, base::Bind(&RespondCallback, &called)); 1457 CallStore(info, base::Bind(&RespondCallback, &called));
1425 // Allow the PasswordFormManager to talk to the password store 1458 // Allow the PasswordFormManager to talk to the password store
1426 RunAllPendingTasks(); 1459 RunAllPendingTasks();
1427 1460
1428 ASSERT_TRUE(client_->pending_manager()); 1461 ASSERT_TRUE(client_->pending_manager());
1429 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1462 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1430 } 1463 }
1431 1464
1432 } // namespace password_manager 1465 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | components/password_manager/core/browser/credential_manager_pending_request_task.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698