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

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

Issue 2864493003: Deprecate CredentialRequestOptions.unmediated in favor mediation enum (Closed)
Patch Set: Rebase Created 3 years, 7 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
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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 EXPECT_TRUE(store_->IsEmpty()); 285 EXPECT_TRUE(store_->IsEmpty());
286 } 286 }
287 287
288 void TearDown() override { 288 void TearDown() override {
289 cm_service_impl_.reset(); 289 cm_service_impl_.reset();
290 290
291 store_->ShutdownOnUIThread(); 291 store_->ShutdownOnUIThread();
292 content::RenderViewHostTestHarness::TearDown(); 292 content::RenderViewHostTestHarness::TearDown();
293 } 293 }
294 294
295 void ExpectZeroClickSignInFailure(bool zero_click_only, 295 void ExpectZeroClickSignInFailure(CredentialMediationRequirement mediation,
296 bool include_passwords, 296 bool include_passwords,
297 const std::vector<GURL>& federations) { 297 const std::vector<GURL>& federations) {
298 bool called = false; 298 bool called = false;
299 mojom::CredentialManagerError error; 299 mojom::CredentialManagerError error;
300 base::Optional<CredentialInfo> credential; 300 base::Optional<CredentialInfo> credential;
301 CallGet(zero_click_only, include_passwords, federations,
302 base::Bind(&GetCredentialCallback, &called, &error, &credential));
303 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 301 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
304 .Times(testing::Exactly(0)); 302 .Times(testing::Exactly(0));
305 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 303 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
304 CallGet(mediation, include_passwords, federations,
305 base::Bind(&GetCredentialCallback, &called, &error, &credential));
306 306
307 RunAllPendingTasks(); 307 RunAllPendingTasks();
308 308
309 EXPECT_TRUE(called); 309 EXPECT_TRUE(called);
310 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); 310 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
311 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, credential->type); 311 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_EMPTY, credential->type);
312 } 312 }
313 313
314 void ExpectZeroClickSignInSuccess(bool zero_click_only, 314 void ExpectZeroClickSignInSuccess(CredentialMediationRequirement mediation,
315 bool include_passwords, 315 bool include_passwords,
316 const std::vector<GURL>& federations, 316 const std::vector<GURL>& federations,
317 CredentialType type) { 317 CredentialType type) {
318 bool called = false; 318 bool called = false;
319 mojom::CredentialManagerError error; 319 mojom::CredentialManagerError error;
320 base::Optional<CredentialInfo> credential; 320 base::Optional<CredentialInfo> credential;
321 CallGet(zero_click_only, include_passwords, federations,
322 base::Bind(&GetCredentialCallback, &called, &error, &credential));
323 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 321 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
324 .Times(testing::Exactly(0)); 322 .Times(testing::Exactly(0));
325 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(1)); 323 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(1));
324 CallGet(mediation, include_passwords, federations,
325 base::Bind(&GetCredentialCallback, &called, &error, &credential));
326 326
327 RunAllPendingTasks(); 327 RunAllPendingTasks();
328 328
329 EXPECT_TRUE(called); 329 EXPECT_TRUE(called);
330 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); 330 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
331 EXPECT_EQ(type, credential->type); 331 EXPECT_EQ(type, credential->type);
332 } 332 }
333 333
334 void ExpectCredentialType(bool zero_click_only, 334 void ExpectCredentialType(CredentialMediationRequirement mediation,
335 bool include_passwords, 335 bool include_passwords,
336 const std::vector<GURL>& federations, 336 const std::vector<GURL>& federations,
337 CredentialType type) { 337 CredentialType type) {
338 bool called = false; 338 bool called = false;
339 mojom::CredentialManagerError error; 339 mojom::CredentialManagerError error;
340 base::Optional<CredentialInfo> credential; 340 base::Optional<CredentialInfo> credential;
341 CallGet(zero_click_only, include_passwords, federations, 341 CallGet(mediation, include_passwords, federations,
342 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 342 base::Bind(&GetCredentialCallback, &called, &error, &credential));
343 343
344 RunAllPendingTasks(); 344 RunAllPendingTasks();
345 345
346 EXPECT_TRUE(called); 346 EXPECT_TRUE(called);
347 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); 347 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
348 EXPECT_EQ(type, credential->type); 348 EXPECT_EQ(type, credential->type);
349 } 349 }
350 350
351 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); } 351 CredentialManagerImpl* cm_service_impl() { return cm_service_impl_.get(); }
352 352
353 // Helpers for testing CredentialManagerImpl methods. 353 // Helpers for testing CredentialManagerImpl methods.
354 void CallStore(const CredentialInfo& info, 354 void CallStore(const CredentialInfo& info,
355 CredentialManagerImpl::StoreCallback callback) { 355 CredentialManagerImpl::StoreCallback callback) {
356 cm_service_impl_->Store(info, std::move(callback)); 356 cm_service_impl_->Store(info, std::move(callback));
357 } 357 }
358 358
359 void CallRequireUserMediation( 359 void CallRequireUserMediation(
360 CredentialManagerImpl::RequireUserMediationCallback callback) { 360 CredentialManagerImpl::RequireUserMediationCallback callback) {
361 cm_service_impl_->RequireUserMediation(std::move(callback)); 361 cm_service_impl_->RequireUserMediation(std::move(callback));
362 } 362 }
363 363
364 void CallGet(bool zero_click_only, 364 void CallGet(CredentialMediationRequirement mediation,
365 bool include_passwords, 365 bool include_passwords,
366 const std::vector<GURL>& federations, 366 const std::vector<GURL>& federations,
367 CredentialManagerImpl::GetCallback callback) { 367 CredentialManagerImpl::GetCallback callback) {
368 cm_service_impl_->Get(zero_click_only, include_passwords, federations, 368 cm_service_impl_->Get(mediation, include_passwords, federations,
369 std::move(callback)); 369 std::move(callback));
370 } 370 }
371 371
372 protected: 372 protected:
373 autofill::PasswordForm form_; 373 autofill::PasswordForm form_;
374 autofill::PasswordForm affiliated_form1_; 374 autofill::PasswordForm affiliated_form1_;
375 autofill::PasswordForm affiliated_form2_; 375 autofill::PasswordForm affiliated_form2_;
376 autofill::PasswordForm origin_path_form_; 376 autofill::PasswordForm origin_path_form_;
377 autofill::PasswordForm subdomain_form_; 377 autofill::PasswordForm subdomain_form_;
378 autofill::PasswordForm cross_origin_form_; 378 autofill::PasswordForm cross_origin_form_;
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 RunAllPendingTasks(); 673 RunAllPendingTasks();
674 674
675 std::vector<GURL> federations; 675 std::vector<GURL> federations;
676 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 676 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
677 .Times(testing::Exactly(1)); 677 .Times(testing::Exactly(1));
678 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 678 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
679 679
680 bool called = false; 680 bool called = false;
681 mojom::CredentialManagerError error; 681 mojom::CredentialManagerError error;
682 base::Optional<CredentialInfo> credential; 682 base::Optional<CredentialInfo> credential;
683 CallGet(false, true, federations, 683 CallGet(CredentialMediationRequirement::kOptional, true, federations,
684 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 684 base::Bind(&GetCredentialCallback, &called, &error, &credential));
685 685
686 RunAllPendingTasks(); 686 RunAllPendingTasks();
687 687
688 EXPECT_TRUE(called); 688 EXPECT_TRUE(called);
689 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); 689 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
690 690
691 // Verify that the update toggled the skip_zero_click flag. 691 // Verify that the update toggled the skip_zero_click flag.
692 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 692 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
693 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 693 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 806
807 TEST_F(CredentialManagerImplTest, 807 TEST_F(CredentialManagerImplTest,
808 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) { 808 CredentialManagerOnRequestCredentialWithEmptyPasswordStore) {
809 std::vector<GURL> federations; 809 std::vector<GURL> federations;
810 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) 810 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
811 .Times(testing::Exactly(0)); 811 .Times(testing::Exactly(0));
812 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 812 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
813 .Times(testing::Exactly(0)); 813 .Times(testing::Exactly(0));
814 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 814 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
815 815
816 ExpectCredentialType(false, true, federations, 816 ExpectCredentialType(CredentialMediationRequirement::kOptional, true,
817 CredentialType::CREDENTIAL_TYPE_EMPTY); 817 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
818 } 818 }
819 819
820 TEST_F(CredentialManagerImplTest, 820 TEST_F(CredentialManagerImplTest,
821 CredentialManagerOnRequestCredentialWithEmptyUsernames) { 821 CredentialManagerOnRequestCredentialWithEmptyUsernames) {
822 form_.username_value.clear(); 822 form_.username_value.clear();
823 store_->AddLogin(form_); 823 store_->AddLogin(form_);
824 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 824 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
825 .Times(testing::Exactly(0)); 825 .Times(testing::Exactly(0));
826 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 826 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
827 827
828 std::vector<GURL> federations; 828 std::vector<GURL> federations;
829 ExpectCredentialType(false, true, federations, 829 ExpectCredentialType(CredentialMediationRequirement::kOptional, true,
830 CredentialType::CREDENTIAL_TYPE_EMPTY); 830 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
831 } 831 }
832 832
833 TEST_F(CredentialManagerImplTest, 833 TEST_F(CredentialManagerImplTest,
834 CredentialManagerOnRequestCredentialWithPSLCredential) { 834 CredentialManagerOnRequestCredentialWithPSLCredential) {
835 store_->AddLogin(subdomain_form_); 835 store_->AddLogin(subdomain_form_);
836 subdomain_form_.is_public_suffix_match = true; 836 subdomain_form_.is_public_suffix_match = true;
837 EXPECT_CALL(*client_, 837 EXPECT_CALL(*client_,
838 PromptUserToChooseCredentialsPtr( 838 PromptUserToChooseCredentialsPtr(
839 UnorderedElementsAre(Pointee(subdomain_form_)), _, _)); 839 UnorderedElementsAre(Pointee(subdomain_form_)), _, _));
840 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(0); 840 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(0);
841 841
842 ExpectCredentialType(false, true, std::vector<GURL>(), 842 ExpectCredentialType(CredentialMediationRequirement::kOptional, true,
843 std::vector<GURL>(),
843 CredentialType::CREDENTIAL_TYPE_PASSWORD); 844 CredentialType::CREDENTIAL_TYPE_PASSWORD);
844 } 845 }
845 846
846 TEST_F(CredentialManagerImplTest, 847 TEST_F(CredentialManagerImplTest,
847 CredentialManagerOnRequestCredentialWithPSLAndNormalCredentials) { 848 CredentialManagerOnRequestCredentialWithPSLAndNormalCredentials) {
848 store_->AddLogin(form_); 849 store_->AddLogin(form_);
849 store_->AddLogin(origin_path_form_); 850 store_->AddLogin(origin_path_form_);
850 store_->AddLogin(subdomain_form_); 851 store_->AddLogin(subdomain_form_);
851 852
852 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr( 853 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(
853 UnorderedElementsAre(Pointee(origin_path_form_), 854 UnorderedElementsAre(Pointee(origin_path_form_),
854 Pointee(form_)), 855 Pointee(form_)),
855 _, _)); 856 _, _));
856 857
857 ExpectCredentialType(false, true, std::vector<GURL>(), 858 ExpectCredentialType(CredentialMediationRequirement::kOptional, true,
859 std::vector<GURL>(),
858 CredentialType::CREDENTIAL_TYPE_PASSWORD); 860 CredentialType::CREDENTIAL_TYPE_PASSWORD);
859 } 861 }
860 862
861 TEST_F(CredentialManagerImplTest, 863 TEST_F(CredentialManagerImplTest,
862 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) { 864 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) {
863 store_->AddLogin(form_); 865 store_->AddLogin(form_);
864 autofill::PasswordForm empty = form_; 866 autofill::PasswordForm empty = form_;
865 empty.username_value.clear(); 867 empty.username_value.clear();
866 store_->AddLogin(empty); 868 store_->AddLogin(empty);
867 autofill::PasswordForm duplicate = form_; 869 autofill::PasswordForm duplicate = form_;
868 duplicate.username_element = base::ASCIIToUTF16("different_username_element"); 870 duplicate.username_element = base::ASCIIToUTF16("different_username_element");
869 store_->AddLogin(duplicate); 871 store_->AddLogin(duplicate);
870 872
871 std::vector<GURL> federations; 873 std::vector<GURL> federations;
872 ExpectZeroClickSignInSuccess(false, true, federations, 874 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kOptional, true,
875 federations,
873 CredentialType::CREDENTIAL_TYPE_PASSWORD); 876 CredentialType::CREDENTIAL_TYPE_PASSWORD);
874 } 877 }
875 878
876 TEST_F(CredentialManagerImplTest, 879 TEST_F(CredentialManagerImplTest,
877 CredentialManagerOnRequestCredentialWithDuplicates) { 880 CredentialManagerOnRequestCredentialWithDuplicates) {
878 // Add 6 credentials. Two buckets of duplicates, one empty username and one 881 // Add 6 credentials. Two buckets of duplicates, one empty username and one
879 // federated one. There should be just 3 in the account chooser. 882 // federated one. There should be just 3 in the account chooser.
880 form_.preferred = true; 883 form_.preferred = true;
881 form_.username_element = base::ASCIIToUTF16("username_element"); 884 form_.username_element = base::ASCIIToUTF16("username_element");
882 store_->AddLogin(form_); 885 store_->AddLogin(form_);
(...skipping 22 matching lines...) Expand all
905 UnorderedElementsAre(Pointee(form_), 908 UnorderedElementsAre(Pointee(form_),
906 Pointee(origin_path_form_), 909 Pointee(origin_path_form_),
907 Pointee(federated)), 910 Pointee(federated)),
908 _, _)); 911 _, _));
909 912
910 bool called = false; 913 bool called = false;
911 mojom::CredentialManagerError error; 914 mojom::CredentialManagerError error;
912 base::Optional<CredentialInfo> credential; 915 base::Optional<CredentialInfo> credential;
913 std::vector<GURL> federations; 916 std::vector<GURL> federations;
914 federations.push_back(GURL("https://google.com/")); 917 federations.push_back(GURL("https://google.com/"));
915 CallGet(false, true, federations, 918 CallGet(CredentialMediationRequirement::kOptional, true, federations,
916 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 919 base::Bind(&GetCredentialCallback, &called, &error, &credential));
917 920
918 RunAllPendingTasks(); 921 RunAllPendingTasks();
919 } 922 }
920 923
921 TEST_F(CredentialManagerImplTest, 924 TEST_F(CredentialManagerImplTest,
922 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) { 925 CredentialManagerOnRequestCredentialWithCrossOriginPasswordStore) {
923 store_->AddLogin(cross_origin_form_); 926 store_->AddLogin(cross_origin_form_);
924 927
925 std::vector<GURL> federations; 928 std::vector<GURL> federations;
926 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)) 929 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_))
927 .Times(testing::Exactly(0)); 930 .Times(testing::Exactly(0));
928 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 931 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
929 .Times(testing::Exactly(0)); 932 .Times(testing::Exactly(0));
930 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 933 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
931 934
932 ExpectCredentialType(false, true, federations, 935 ExpectCredentialType(CredentialMediationRequirement::kOptional, true,
933 CredentialType::CREDENTIAL_TYPE_EMPTY); 936 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
934 } 937 }
935 938
936 TEST_F(CredentialManagerImplTest, 939 TEST_F(CredentialManagerImplTest,
937 CredentialManagerOnRequestCredentialWithFullPasswordStore) { 940 CredentialManagerOnRequestCredentialWithFullPasswordStore) {
938 client_->set_zero_click_enabled(false); 941 client_->set_zero_click_enabled(false);
939 store_->AddLogin(form_); 942 store_->AddLogin(form_);
940 943
941 std::vector<GURL> federations; 944 std::vector<GURL> federations;
942 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 945 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
943 .Times(testing::Exactly(1)); 946 .Times(testing::Exactly(1));
944 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 947 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
945 948
946 bool called = false; 949 bool called = false;
947 mojom::CredentialManagerError error; 950 mojom::CredentialManagerError error;
948 base::Optional<CredentialInfo> credential; 951 base::Optional<CredentialInfo> credential;
949 CallGet(false, true, federations, 952 CallGet(CredentialMediationRequirement::kOptional, true, federations,
950 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 953 base::Bind(&GetCredentialCallback, &called, &error, &credential));
951 954
952 RunAllPendingTasks(); 955 RunAllPendingTasks();
953 956
954 EXPECT_TRUE(called); 957 EXPECT_TRUE(called);
955 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error); 958 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
956 } 959 }
957 960
958 TEST_F( 961 TEST_F(
959 CredentialManagerImplTest, 962 CredentialManagerImplTest,
960 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { 963 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
961 std::vector<GURL> federations; 964 std::vector<GURL> federations;
962 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 965 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
963 .Times(testing::Exactly(0)); 966 .Times(testing::Exactly(0));
964 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 967 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
965 968
966 ExpectZeroClickSignInFailure(true, true, federations); 969 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
970 federations);
967 } 971 }
968 972
969 TEST_F(CredentialManagerImplTest, 973 TEST_F(CredentialManagerImplTest,
970 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 974 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
971 store_->AddLogin(form_); 975 store_->AddLogin(form_);
972 client_->set_first_run_seen(true); 976 client_->set_first_run_seen(true);
973 977
974 std::vector<GURL> federations; 978 std::vector<GURL> federations;
975 979
976 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 980 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
977 981
978 ExpectZeroClickSignInSuccess(true, true, federations, 982 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
983 federations,
979 CredentialType::CREDENTIAL_TYPE_PASSWORD); 984 CredentialType::CREDENTIAL_TYPE_PASSWORD);
980 } 985 }
981 986
982 TEST_F(CredentialManagerImplTest, 987 TEST_F(CredentialManagerImplTest,
983 CredentialManagerOnRequestCredentialWithoutPasswords) { 988 CredentialManagerOnRequestCredentialWithoutPasswords) {
984 store_->AddLogin(form_); 989 store_->AddLogin(form_);
985 client_->set_first_run_seen(true); 990 client_->set_first_run_seen(true);
986 991
987 std::vector<GURL> federations; 992 std::vector<GURL> federations;
988 993
989 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 994 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
990 995
991 ExpectZeroClickSignInFailure(true, false, federations); 996 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, false,
997 federations);
992 } 998 }
993 999
994 TEST_F(CredentialManagerImplTest, 1000 TEST_F(CredentialManagerImplTest,
995 CredentialManagerOnRequestCredentialFederatedMatch) { 1001 CredentialManagerOnRequestCredentialFederatedMatch) {
996 form_.federation_origin = url::Origin(GURL("https://example.com/")); 1002 form_.federation_origin = url::Origin(GURL("https://example.com/"));
997 form_.password_value = base::string16(); 1003 form_.password_value = base::string16();
998 store_->AddLogin(form_); 1004 store_->AddLogin(form_);
999 client_->set_first_run_seen(true); 1005 client_->set_first_run_seen(true);
1000 1006
1001 std::vector<GURL> federations; 1007 std::vector<GURL> federations;
1002 federations.push_back(GURL("https://example.com/")); 1008 federations.push_back(GURL("https://example.com/"));
1003 1009
1004 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 1010 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
1005 1011
1006 ExpectZeroClickSignInSuccess(true, true, federations, 1012 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1013 federations,
1007 CredentialType::CREDENTIAL_TYPE_FEDERATED); 1014 CredentialType::CREDENTIAL_TYPE_FEDERATED);
1008 } 1015 }
1009 1016
1010 TEST_F(CredentialManagerImplTest, 1017 TEST_F(CredentialManagerImplTest,
1011 CredentialManagerOnRequestCredentialFederatedNoMatch) { 1018 CredentialManagerOnRequestCredentialFederatedNoMatch) {
1012 form_.federation_origin = url::Origin(GURL("https://example.com/")); 1019 form_.federation_origin = url::Origin(GURL("https://example.com/"));
1013 form_.password_value = base::string16(); 1020 form_.password_value = base::string16();
1014 store_->AddLogin(form_); 1021 store_->AddLogin(form_);
1015 client_->set_first_run_seen(true); 1022 client_->set_first_run_seen(true);
1016 1023
1017 std::vector<GURL> federations; 1024 std::vector<GURL> federations;
1018 federations.push_back(GURL("https://not-example.com/")); 1025 federations.push_back(GURL("https://not-example.com/"));
1019 1026
1020 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 1027 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
1021 1028
1022 ExpectZeroClickSignInFailure(true, true, federations); 1029 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1030 federations);
1023 } 1031 }
1024 1032
1025 TEST_F(CredentialManagerImplTest, 1033 TEST_F(CredentialManagerImplTest,
1026 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) { 1034 CredentialManagerOnRequestCredentialAffiliatedPasswordMatch) {
1027 store_->AddLogin(affiliated_form1_); 1035 store_->AddLogin(affiliated_form1_);
1028 client_->set_first_run_seen(true); 1036 client_->set_first_run_seen(true);
1029 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1037 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1030 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1038 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1031 1039
1032 std::vector<GURL> federations; 1040 std::vector<GURL> federations;
1033 std::vector<std::string> affiliated_realms; 1041 std::vector<std::string> affiliated_realms;
1034 affiliated_realms.push_back(kTestAndroidRealm1); 1042 affiliated_realms.push_back(kTestAndroidRealm1);
1035 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1043 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1036 ->ExpectCallToGetAffiliatedAndroidRealms( 1044 ->ExpectCallToGetAffiliatedAndroidRealms(
1037 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1045 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1038 1046
1039 // We pass in 'true' for the 'include_passwords' argument to ensure that 1047 // We pass in 'true' for the 'include_passwords' argument to ensure that
1040 // password-type credentials are included as potential matches. 1048 // password-type credentials are included as potential matches.
1041 ExpectZeroClickSignInSuccess(true, true, federations, 1049 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1050 federations,
1042 CredentialType::CREDENTIAL_TYPE_PASSWORD); 1051 CredentialType::CREDENTIAL_TYPE_PASSWORD);
1043 } 1052 }
1044 1053
1045 TEST_F(CredentialManagerImplTest, 1054 TEST_F(CredentialManagerImplTest,
1046 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) { 1055 CredentialManagerOnRequestCredentialAffiliatedPasswordNoMatch) {
1047 store_->AddLogin(affiliated_form1_); 1056 store_->AddLogin(affiliated_form1_);
1048 client_->set_first_run_seen(true); 1057 client_->set_first_run_seen(true);
1049 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1058 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1050 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1059 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1051 1060
1052 std::vector<GURL> federations; 1061 std::vector<GURL> federations;
1053 std::vector<std::string> affiliated_realms; 1062 std::vector<std::string> affiliated_realms;
1054 affiliated_realms.push_back(kTestAndroidRealm1); 1063 affiliated_realms.push_back(kTestAndroidRealm1);
1055 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1064 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1056 ->ExpectCallToGetAffiliatedAndroidRealms( 1065 ->ExpectCallToGetAffiliatedAndroidRealms(
1057 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1066 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1058 1067
1059 // We pass in 'false' for the 'include_passwords' argument to ensure that 1068 // We pass in 'false' for the 'include_passwords' argument to ensure that
1060 // password-type credentials are excluded as potential matches. 1069 // password-type credentials are excluded as potential matches.
1061 ExpectZeroClickSignInFailure(true, false, federations); 1070 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, false,
1071 federations);
1062 } 1072 }
1063 1073
1064 TEST_F(CredentialManagerImplTest, 1074 TEST_F(CredentialManagerImplTest,
1065 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) { 1075 CredentialManagerOnRequestCredentialAffiliatedFederatedMatch) {
1066 affiliated_form1_.federation_origin = 1076 affiliated_form1_.federation_origin =
1067 url::Origin(GURL("https://example.com/")); 1077 url::Origin(GURL("https://example.com/"));
1068 affiliated_form1_.password_value = base::string16(); 1078 affiliated_form1_.password_value = base::string16();
1069 store_->AddLogin(affiliated_form1_); 1079 store_->AddLogin(affiliated_form1_);
1070 client_->set_first_run_seen(true); 1080 client_->set_first_run_seen(true);
1071 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1081 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1072 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1082 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1073 1083
1074 std::vector<GURL> federations; 1084 std::vector<GURL> federations;
1075 federations.push_back(GURL("https://example.com/")); 1085 federations.push_back(GURL("https://example.com/"));
1076 1086
1077 std::vector<std::string> affiliated_realms; 1087 std::vector<std::string> affiliated_realms;
1078 affiliated_realms.push_back(kTestAndroidRealm1); 1088 affiliated_realms.push_back(kTestAndroidRealm1);
1079 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1089 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1080 ->ExpectCallToGetAffiliatedAndroidRealms( 1090 ->ExpectCallToGetAffiliatedAndroidRealms(
1081 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1091 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1082 1092
1083 ExpectZeroClickSignInSuccess(true, true, federations, 1093 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1094 federations,
1084 CredentialType::CREDENTIAL_TYPE_FEDERATED); 1095 CredentialType::CREDENTIAL_TYPE_FEDERATED);
1085 } 1096 }
1086 1097
1087 TEST_F(CredentialManagerImplTest, 1098 TEST_F(CredentialManagerImplTest,
1088 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) { 1099 CredentialManagerOnRequestCredentialAffiliatedFederatedNoMatch) {
1089 affiliated_form1_.federation_origin = 1100 affiliated_form1_.federation_origin =
1090 url::Origin(GURL("https://example.com/")); 1101 url::Origin(GURL("https://example.com/"));
1091 affiliated_form1_.password_value = base::string16(); 1102 affiliated_form1_.password_value = base::string16();
1092 store_->AddLogin(affiliated_form1_); 1103 store_->AddLogin(affiliated_form1_);
1093 client_->set_first_run_seen(true); 1104 client_->set_first_run_seen(true);
1094 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1105 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1095 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1106 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1096 1107
1097 std::vector<GURL> federations; 1108 std::vector<GURL> federations;
1098 federations.push_back(GURL("https://not-example.com/")); 1109 federations.push_back(GURL("https://not-example.com/"));
1099 1110
1100 std::vector<std::string> affiliated_realms; 1111 std::vector<std::string> affiliated_realms;
1101 affiliated_realms.push_back(kTestAndroidRealm1); 1112 affiliated_realms.push_back(kTestAndroidRealm1);
1102 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1113 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1103 ->ExpectCallToGetAffiliatedAndroidRealms( 1114 ->ExpectCallToGetAffiliatedAndroidRealms(
1104 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1115 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1105 1116
1106 ExpectZeroClickSignInFailure(true, true, federations); 1117 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1118 federations);
1107 } 1119 }
1108 1120
1109 TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) { 1121 TEST_F(CredentialManagerImplTest, RequestCredentialWithoutFirstRun) {
1110 client_->set_first_run_seen(false); 1122 client_->set_first_run_seen(false);
1111 1123
1112 store_->AddLogin(form_); 1124 store_->AddLogin(form_);
1113 1125
1114 std::vector<GURL> federations; 1126 std::vector<GURL> federations;
1115 EXPECT_CALL(*client_, 1127 EXPECT_CALL(*client_,
1116 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) 1128 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
1117 .Times(1); 1129 .Times(1);
1118 1130
1119 ExpectZeroClickSignInFailure(true, true, federations); 1131 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1132 federations);
1120 } 1133 }
1121 1134
1122 TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) { 1135 TEST_F(CredentialManagerImplTest, RequestCredentialWithFirstRunAndSkip) {
1123 client_->set_first_run_seen(true); 1136 client_->set_first_run_seen(true);
1124 1137
1125 form_.skip_zero_click = true; 1138 form_.skip_zero_click = true;
1126 store_->AddLogin(form_); 1139 store_->AddLogin(form_);
1127 1140
1128 std::vector<GURL> federations; 1141 std::vector<GURL> federations;
1129 EXPECT_CALL(*client_, 1142 EXPECT_CALL(*client_,
1130 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) 1143 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
1131 .Times(1); 1144 .Times(1);
1132 1145
1133 ExpectZeroClickSignInFailure(true, true, federations); 1146 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1147 federations);
1134 } 1148 }
1135 1149
1136 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { 1150 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) {
1137 // If we encounter TLS errors, we won't return credentials. 1151 // If we encounter TLS errors, we won't return credentials.
1138 EXPECT_CALL(*client_, IsFillingEnabledForCurrentPage()) 1152 EXPECT_CALL(*client_, IsFillingEnabledForCurrentPage())
1139 .WillRepeatedly(testing::Return(false)); 1153 .WillRepeatedly(testing::Return(false));
1140 1154
1141 store_->AddLogin(form_); 1155 store_->AddLogin(form_);
1142 1156
1143 std::vector<GURL> federations; 1157 std::vector<GURL> federations;
1144 1158
1145 ExpectZeroClickSignInFailure(true, true, federations); 1159 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1160 federations);
1146 } 1161 }
1147 1162
1148 TEST_F(CredentialManagerImplTest, RequestCredentialWhilePrerendering) { 1163 TEST_F(CredentialManagerImplTest, RequestCredentialWhilePrerendering) {
1149 // The client disallows the credential manager for the current page. 1164 // The client disallows the credential manager for the current page.
1150 EXPECT_CALL(*client_, OnCredentialManagerUsed()) 1165 EXPECT_CALL(*client_, OnCredentialManagerUsed())
1151 .WillRepeatedly(testing::Return(false)); 1166 .WillRepeatedly(testing::Return(false));
1152 1167
1153 store_->AddLogin(form_); 1168 store_->AddLogin(form_);
1154 1169
1155 std::vector<GURL> federations; 1170 std::vector<GURL> federations;
1156 1171
1157 ExpectZeroClickSignInFailure(true, true, federations); 1172 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1173 federations);
1158 } 1174 }
1159 1175
1160 TEST_F(CredentialManagerImplTest, 1176 TEST_F(CredentialManagerImplTest,
1161 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { 1177 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
1162 store_->AddLogin(form_); 1178 store_->AddLogin(form_);
1163 store_->AddLogin(origin_path_form_); 1179 store_->AddLogin(origin_path_form_);
1164 1180
1165 std::vector<GURL> federations; 1181 std::vector<GURL> federations;
1166 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1182 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1167 .Times(testing::Exactly(0)); 1183 .Times(testing::Exactly(0));
1168 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1184 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1169 1185
1170 // With two items in the password store, we shouldn't get credentials back. 1186 // With two items in the password store, we shouldn't get credentials back.
1171 ExpectCredentialType(true, true, federations, 1187 ExpectCredentialType(CredentialMediationRequirement::kSilent, true,
1172 CredentialType::CREDENTIAL_TYPE_EMPTY); 1188 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
1173 } 1189 }
1174 1190
1175 TEST_F(CredentialManagerImplTest, 1191 TEST_F(CredentialManagerImplTest,
1176 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) { 1192 OnRequestCredentialWithZeroClickOnlyAndSkipZeroClickPasswordStore) {
1177 form_.skip_zero_click = true; 1193 form_.skip_zero_click = true;
1178 store_->AddLogin(form_); 1194 store_->AddLogin(form_);
1179 store_->AddLogin(origin_path_form_); 1195 store_->AddLogin(origin_path_form_);
1180 1196
1181 std::vector<GURL> federations; 1197 std::vector<GURL> federations;
1182 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1198 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1183 .Times(testing::Exactly(0)); 1199 .Times(testing::Exactly(0));
1184 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1200 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1185 1201
1186 // With two items in the password store, we shouldn't get credentials back, 1202 // With two items in the password store, we shouldn't get credentials back,
1187 // even though only one item has |skip_zero_click| set |false|. 1203 // even though only one item has |skip_zero_click| set |false|.
1188 ExpectCredentialType(true, true, federations, 1204 ExpectCredentialType(CredentialMediationRequirement::kSilent, true,
1189 CredentialType::CREDENTIAL_TYPE_EMPTY); 1205 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
1190 } 1206 }
1191 1207
1192 TEST_F(CredentialManagerImplTest, 1208 TEST_F(CredentialManagerImplTest,
1193 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) { 1209 OnRequestCredentialWithZeroClickOnlyCrossOriginPasswordStore) {
1194 store_->AddLogin(cross_origin_form_); 1210 store_->AddLogin(cross_origin_form_);
1195 1211
1196 form_.skip_zero_click = true; 1212 form_.skip_zero_click = true;
1197 store_->AddLogin(form_); 1213 store_->AddLogin(form_);
1198 1214
1199 std::vector<GURL> federations; 1215 std::vector<GURL> federations;
1200 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1216 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1201 .Times(testing::Exactly(0)); 1217 .Times(testing::Exactly(0));
1202 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1218 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1203 1219
1204 // We only have cross-origin zero-click credentials; they should not be 1220 // We only have cross-origin zero-click credentials; they should not be
1205 // returned. 1221 // returned.
1206 ExpectCredentialType(true, true, federations, 1222 ExpectCredentialType(CredentialMediationRequirement::kSilent, true,
1207 CredentialType::CREDENTIAL_TYPE_EMPTY); 1223 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
1208 } 1224 }
1209 1225
1210 TEST_F(CredentialManagerImplTest, 1226 TEST_F(CredentialManagerImplTest,
1211 CredentialManagerOnRequestCredentialWhileRequestPending) { 1227 CredentialManagerOnRequestCredentialWhileRequestPending) {
1212 client_->set_zero_click_enabled(false); 1228 client_->set_zero_click_enabled(false);
1213 store_->AddLogin(form_); 1229 store_->AddLogin(form_);
1214 1230
1215 std::vector<GURL> federations; 1231 std::vector<GURL> federations;
1216 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1232 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1217 .Times(testing::Exactly(0)); 1233 .Times(testing::Exactly(0));
1218 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1234 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1219 1235
1220 // 1st request. 1236 // 1st request.
1221 bool called_1 = false; 1237 bool called_1 = false;
1222 mojom::CredentialManagerError error_1; 1238 mojom::CredentialManagerError error_1;
1223 base::Optional<CredentialInfo> credential_1; 1239 base::Optional<CredentialInfo> credential_1;
1224 CallGet( 1240 CallGet(
1225 false, true, federations, 1241 CredentialMediationRequirement::kOptional, true, federations,
1226 base::Bind(&GetCredentialCallback, &called_1, &error_1, &credential_1)); 1242 base::Bind(&GetCredentialCallback, &called_1, &error_1, &credential_1));
1227 // 2nd request. 1243 // 2nd request.
1228 bool called_2 = false; 1244 bool called_2 = false;
1229 mojom::CredentialManagerError error_2; 1245 mojom::CredentialManagerError error_2;
1230 base::Optional<CredentialInfo> credential_2; 1246 base::Optional<CredentialInfo> credential_2;
1231 CallGet( 1247 CallGet(
1232 false, true, federations, 1248 CredentialMediationRequirement::kOptional, true, federations,
1233 base::Bind(&GetCredentialCallback, &called_2, &error_2, &credential_2)); 1249 base::Bind(&GetCredentialCallback, &called_2, &error_2, &credential_2));
1234 1250
1235 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1251 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1236 .Times(testing::Exactly(1)); 1252 .Times(testing::Exactly(1));
1237 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1253 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1238 1254
1239 // Execute the PasswordStore asynchronousness. 1255 // Execute the PasswordStore asynchronousness.
1240 RunAllPendingTasks(); 1256 RunAllPendingTasks();
1241 1257
1242 // Check that the second request triggered a rejection. 1258 // Check that the second request triggered a rejection.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 // MockPasswordManagerClient mocks a user choice, and when users choose a 1295 // MockPasswordManagerClient mocks a user choice, and when users choose a
1280 // credential (and have the global zero-click flag enabled), we make sure that 1296 // credential (and have the global zero-click flag enabled), we make sure that
1281 // they'll be logged in again next time. 1297 // they'll be logged in again next time.
1282 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1298 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1283 .Times(testing::Exactly(1)); 1299 .Times(testing::Exactly(1));
1284 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1300 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1285 1301
1286 bool called = false; 1302 bool called = false;
1287 mojom::CredentialManagerError error; 1303 mojom::CredentialManagerError error;
1288 base::Optional<CredentialInfo> credential; 1304 base::Optional<CredentialInfo> credential;
1289 CallGet(false, true, federations, 1305 CallGet(CredentialMediationRequirement::kOptional, true, federations,
1290 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 1306 base::Bind(&GetCredentialCallback, &called, &error, &credential));
1291 1307
1292 RunAllPendingTasks(); 1308 RunAllPendingTasks();
1293 1309
1294 passwords = store_->stored_passwords(); 1310 passwords = store_->stored_passwords();
1295 EXPECT_EQ(2U, passwords.size()); 1311 EXPECT_EQ(2U, passwords.size());
1296 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 1312 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
1297 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 1313 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
1298 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 1314 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
1299 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 1315 EXPECT_TRUE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
(...skipping 15 matching lines...) Expand all
1315 1331
1316 // Trigger a request which should return the credential found in |form_|, and 1332 // Trigger a request which should return the credential found in |form_|, and
1317 // wait for it to process. 1333 // wait for it to process.
1318 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1334 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1319 .Times(testing::Exactly(1)); 1335 .Times(testing::Exactly(1));
1320 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1336 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1321 1337
1322 bool called = false; 1338 bool called = false;
1323 mojom::CredentialManagerError error; 1339 mojom::CredentialManagerError error;
1324 base::Optional<CredentialInfo> credential; 1340 base::Optional<CredentialInfo> credential;
1325 CallGet(false, true, std::vector<GURL>(), 1341 CallGet(CredentialMediationRequirement::kOptional, true, std::vector<GURL>(),
1326 base::Bind(&GetCredentialCallback, &called, &error, &credential)); 1342 base::Bind(&GetCredentialCallback, &called, &error, &credential));
1327 1343
1328 RunAllPendingTasks(); 1344 RunAllPendingTasks();
1329 1345
1330 // The form shouldn't become a zero-click one. 1346 // The form shouldn't become a zero-click one.
1331 passwords = store_->stored_passwords(); 1347 passwords = store_->stored_passwords();
1332 ASSERT_EQ(1U, passwords.size()); 1348 ASSERT_EQ(1U, passwords.size());
1333 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 1349 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
1334 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 1350 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
1335 } 1351 }
1336 1352
1337 TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) { 1353 TEST_F(CredentialManagerImplTest, IncognitoZeroClickRequestCredential) {
1338 EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true)); 1354 EXPECT_CALL(*client_, IsIncognito()).WillRepeatedly(testing::Return(true));
1339 store_->AddLogin(form_); 1355 store_->AddLogin(form_);
1340 1356
1341 std::vector<GURL> federations; 1357 std::vector<GURL> federations;
1342 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 1358 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1343 .Times(testing::Exactly(0)); 1359 .Times(testing::Exactly(0));
1344 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 1360 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1345 1361
1346 ExpectCredentialType(true, true, federations, 1362 ExpectCredentialType(CredentialMediationRequirement::kSilent, true,
1347 CredentialType::CREDENTIAL_TYPE_EMPTY); 1363 federations, CredentialType::CREDENTIAL_TYPE_EMPTY);
1348 } 1364 }
1349 1365
1350 TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) { 1366 TEST_F(CredentialManagerImplTest, ZeroClickWithAffiliatedFormInPasswordStore) {
1351 // Insert the affiliated form into the store, and mock out the association 1367 // Insert the affiliated form into the store, and mock out the association
1352 // with the current origin. As it's the only form matching the origin, it 1368 // with the current origin. As it's the only form matching the origin, it
1353 // ought to be returned automagically. 1369 // ought to be returned automagically.
1354 store_->AddLogin(affiliated_form1_); 1370 store_->AddLogin(affiliated_form1_);
1355 1371
1356 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1372 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1357 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1373 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1358 1374
1359 std::vector<GURL> federations; 1375 std::vector<GURL> federations;
1360 std::vector<std::string> affiliated_realms; 1376 std::vector<std::string> affiliated_realms;
1361 affiliated_realms.push_back(kTestAndroidRealm1); 1377 affiliated_realms.push_back(kTestAndroidRealm1);
1362 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1378 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1363 ->ExpectCallToGetAffiliatedAndroidRealms( 1379 ->ExpectCallToGetAffiliatedAndroidRealms(
1364 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1380 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1365 1381
1366 ExpectZeroClickSignInSuccess(true, true, federations, 1382 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1383 federations,
1367 CredentialType::CREDENTIAL_TYPE_PASSWORD); 1384 CredentialType::CREDENTIAL_TYPE_PASSWORD);
1368 } 1385 }
1369 1386
1370 TEST_F(CredentialManagerImplTest, 1387 TEST_F(CredentialManagerImplTest,
1371 ZeroClickWithTwoAffiliatedFormsInPasswordStore) { 1388 ZeroClickWithTwoAffiliatedFormsInPasswordStore) {
1372 // Insert two affiliated forms into the store, and mock out the association 1389 // Insert two affiliated forms into the store, and mock out the association
1373 // with the current origin. Multiple forms === no zero-click sign in. 1390 // with the current origin. Multiple forms === no zero-click sign in.
1374 store_->AddLogin(affiliated_form1_); 1391 store_->AddLogin(affiliated_form1_);
1375 store_->AddLogin(affiliated_form2_); 1392 store_->AddLogin(affiliated_form2_);
1376 1393
1377 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1394 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1378 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1395 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1379 1396
1380 std::vector<GURL> federations; 1397 std::vector<GURL> federations;
1381 std::vector<std::string> affiliated_realms; 1398 std::vector<std::string> affiliated_realms;
1382 affiliated_realms.push_back(kTestAndroidRealm1); 1399 affiliated_realms.push_back(kTestAndroidRealm1);
1383 affiliated_realms.push_back(kTestAndroidRealm2); 1400 affiliated_realms.push_back(kTestAndroidRealm2);
1384 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1401 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1385 ->ExpectCallToGetAffiliatedAndroidRealms( 1402 ->ExpectCallToGetAffiliatedAndroidRealms(
1386 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1403 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1387 1404
1388 ExpectZeroClickSignInFailure(true, true, federations); 1405 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1406 federations);
1389 } 1407 }
1390 1408
1391 TEST_F(CredentialManagerImplTest, 1409 TEST_F(CredentialManagerImplTest,
1392 ZeroClickWithUnaffiliatedFormsInPasswordStore) { 1410 ZeroClickWithUnaffiliatedFormsInPasswordStore) {
1393 // Insert the affiliated form into the store, but don't mock out the 1411 // Insert the affiliated form into the store, but don't mock out the
1394 // association with the current origin. No association === no zero-click sign 1412 // association with the current origin. No association === no zero-click sign
1395 // in. 1413 // in.
1396 store_->AddLogin(affiliated_form1_); 1414 store_->AddLogin(affiliated_form1_);
1397 1415
1398 store_->SetAffiliatedMatchHelper( 1416 store_->SetAffiliatedMatchHelper(
1399 base::MakeUnique<MockAffiliatedMatchHelper>()); 1417 base::MakeUnique<MockAffiliatedMatchHelper>());
1400 1418
1401 std::vector<std::string> affiliated_realms; 1419 std::vector<std::string> affiliated_realms;
1402 PasswordStore::FormDigest digest = 1420 PasswordStore::FormDigest digest =
1403 cm_service_impl_->GetSynthesizedFormForOrigin(); 1421 cm_service_impl_->GetSynthesizedFormForOrigin();
1404 // First expect affiliations for the HTTPS domain. 1422 // First expect affiliations for the HTTPS domain.
1405 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1423 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1406 ->ExpectCallToGetAffiliatedAndroidRealms(digest, affiliated_realms); 1424 ->ExpectCallToGetAffiliatedAndroidRealms(digest, affiliated_realms);
1407 1425
1408 digest.origin = HttpURLFromHttps(digest.origin); 1426 digest.origin = HttpURLFromHttps(digest.origin);
1409 digest.signon_realm = digest.origin.spec(); 1427 digest.signon_realm = digest.origin.spec();
1410 // The second call happens for HTTP as the migration is triggered. 1428 // The second call happens for HTTP as the migration is triggered.
1411 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1429 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1412 ->ExpectCallToGetAffiliatedAndroidRealms(digest, affiliated_realms); 1430 ->ExpectCallToGetAffiliatedAndroidRealms(digest, affiliated_realms);
1413 1431
1414 std::vector<GURL> federations; 1432 std::vector<GURL> federations;
1415 ExpectZeroClickSignInFailure(true, true, federations); 1433 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1434 federations);
1416 } 1435 }
1417 1436
1418 TEST_F(CredentialManagerImplTest, 1437 TEST_F(CredentialManagerImplTest,
1419 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) { 1438 ZeroClickWithFormAndUnaffiliatedFormsInPasswordStore) {
1420 // Insert the affiliated form into the store, along with a real form for the 1439 // Insert the affiliated form into the store, along with a real form for the
1421 // origin, and don't mock out the association with the current origin. No 1440 // origin, and don't mock out the association with the current origin. No
1422 // association + existing form === zero-click sign in. 1441 // association + existing form === zero-click sign in.
1423 store_->AddLogin(form_); 1442 store_->AddLogin(form_);
1424 store_->AddLogin(affiliated_form1_); 1443 store_->AddLogin(affiliated_form1_);
1425 1444
1426 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper); 1445 auto mock_helper = base::WrapUnique(new MockAffiliatedMatchHelper);
1427 store_->SetAffiliatedMatchHelper(std::move(mock_helper)); 1446 store_->SetAffiliatedMatchHelper(std::move(mock_helper));
1428 1447
1429 std::vector<GURL> federations; 1448 std::vector<GURL> federations;
1430 std::vector<std::string> affiliated_realms; 1449 std::vector<std::string> affiliated_realms;
1431 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper()) 1450 static_cast<MockAffiliatedMatchHelper*>(store_->affiliated_match_helper())
1432 ->ExpectCallToGetAffiliatedAndroidRealms( 1451 ->ExpectCallToGetAffiliatedAndroidRealms(
1433 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms); 1452 cm_service_impl_->GetSynthesizedFormForOrigin(), affiliated_realms);
1434 1453
1435 ExpectZeroClickSignInSuccess(true, true, federations, 1454 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1455 federations,
1436 CredentialType::CREDENTIAL_TYPE_PASSWORD); 1456 CredentialType::CREDENTIAL_TYPE_PASSWORD);
1437 } 1457 }
1438 1458
1439 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) { 1459 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLCredential) {
1440 subdomain_form_.skip_zero_click = false; 1460 subdomain_form_.skip_zero_click = false;
1441 store_->AddLogin(subdomain_form_); 1461 store_->AddLogin(subdomain_form_);
1442 1462
1443 ExpectZeroClickSignInFailure(true, true, std::vector<GURL>()); 1463 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kSilent, true,
1464 std::vector<GURL>());
1444 } 1465 }
1445 1466
1446 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) { 1467 TEST_F(CredentialManagerImplTest, ZeroClickWithPSLAndNormalCredentials) {
1447 form_.password_value.clear(); 1468 form_.password_value.clear();
1448 form_.federation_origin = url::Origin(GURL("https://google.com/")); 1469 form_.federation_origin = url::Origin(GURL("https://google.com/"));
1449 form_.signon_realm = "federation://" + form_.origin.host() + "/google.com"; 1470 form_.signon_realm = "federation://" + form_.origin.host() + "/google.com";
1450 form_.skip_zero_click = false; 1471 form_.skip_zero_click = false;
1451 store_->AddLogin(form_); 1472 store_->AddLogin(form_);
1452 store_->AddLogin(subdomain_form_); 1473 store_->AddLogin(subdomain_form_);
1453 1474
1454 std::vector<GURL> federations = {GURL("https://google.com/")}; 1475 std::vector<GURL> federations = {GURL("https://google.com/")};
1455 ExpectZeroClickSignInSuccess(true, true, federations, 1476 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1477 federations,
1456 CredentialType::CREDENTIAL_TYPE_FEDERATED); 1478 CredentialType::CREDENTIAL_TYPE_FEDERATED);
1457 } 1479 }
1458 1480
1459 TEST_F(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) { 1481 TEST_F(CredentialManagerImplTest, ZeroClickAfterMigratingHttpCredential) {
1460 // There is an http credential saved. It should be migrated and used for auto 1482 // There is an http credential saved. It should be migrated and used for auto
1461 // sign-in. 1483 // sign-in.
1462 form_.origin = HttpURLFromHttps(form_.origin); 1484 form_.origin = HttpURLFromHttps(form_.origin);
1463 form_.signon_realm = form_.origin.GetOrigin().spec(); 1485 form_.signon_realm = form_.origin.GetOrigin().spec();
1464 // That is the default value for old credentials. 1486 // That is the default value for old credentials.
1465 form_.skip_zero_click = true; 1487 form_.skip_zero_click = true;
1466 store_->AddLogin(form_); 1488 store_->AddLogin(form_);
1467 1489
1468 std::vector<GURL> federations; 1490 std::vector<GURL> federations;
1469 ExpectZeroClickSignInSuccess(true, true, federations, 1491 ExpectZeroClickSignInSuccess(CredentialMediationRequirement::kSilent, true,
1492 federations,
1470 CredentialType::CREDENTIAL_TYPE_PASSWORD); 1493 CredentialType::CREDENTIAL_TYPE_PASSWORD);
1471 } 1494 }
1472 1495
1473 TEST_F(CredentialManagerImplTest, MigrateWithEmptyStore) { 1496 TEST_F(CredentialManagerImplTest, MigrateWithEmptyStore) {
1474 // HTTP scheme is valid for localhost. Nothing should crash. 1497 // HTTP scheme is valid for localhost. Nothing should crash.
1475 NavigateAndCommit(GURL("http://127.0.0.1:8000/")); 1498 NavigateAndCommit(GURL("http://127.0.0.1:8000/"));
1476 1499
1477 std::vector<GURL> federations; 1500 std::vector<GURL> federations;
1478 ExpectZeroClickSignInFailure(false, true, federations); 1501 ExpectZeroClickSignInFailure(CredentialMediationRequirement::kOptional, true,
1502 federations);
1503 }
1504
1505 TEST_F(CredentialManagerImplTest, MediationRequiredPreventsAutoSignIn) {
1506 form_.skip_zero_click = false;
1507 store_->AddLogin(form_);
1508
1509 std::vector<GURL> federations;
1510 bool called = false;
1511 mojom::CredentialManagerError error;
1512 base::Optional<CredentialInfo> credential;
1513
1514 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
1515 .Times(testing::Exactly(1));
1516 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
1517 CallGet(CredentialMediationRequirement::kRequired, true, federations,
1518 base::Bind(&GetCredentialCallback, &called, &error, &credential));
1519
1520 RunAllPendingTasks();
1521
1522 EXPECT_TRUE(called);
1523 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
1524 EXPECT_EQ(CredentialType::CREDENTIAL_TYPE_PASSWORD, credential->type);
1479 } 1525 }
1480 1526
1481 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) { 1527 TEST_F(CredentialManagerImplTest, GetSynthesizedFormForOrigin) {
1482 PasswordStore::FormDigest synthesized = 1528 PasswordStore::FormDigest synthesized =
1483 cm_service_impl_->GetSynthesizedFormForOrigin(); 1529 cm_service_impl_->GetSynthesizedFormForOrigin();
1484 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec()); 1530 EXPECT_EQ(kTestWebOrigin, synthesized.origin.spec());
1485 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm); 1531 EXPECT_EQ(kTestWebOrigin, synthesized.signon_realm);
1486 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme); 1532 EXPECT_EQ(autofill::PasswordForm::SCHEME_HTML, synthesized.scheme);
1487 } 1533 }
1488 1534
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_)); 1621 EXPECT_CALL(*client_, PromptUserToSavePasswordPtr(_));
1576 CallStore(info, base::Bind(&RespondCallback, &called)); 1622 CallStore(info, base::Bind(&RespondCallback, &called));
1577 // Allow the PasswordFormManager to talk to the password store 1623 // Allow the PasswordFormManager to talk to the password store
1578 RunAllPendingTasks(); 1624 RunAllPendingTasks();
1579 1625
1580 ASSERT_TRUE(client_->pending_manager()); 1626 ASSERT_TRUE(client_->pending_manager());
1581 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1627 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1582 } 1628 }
1583 1629
1584 } // namespace password_manager 1630 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698