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