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

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

Issue 2523593006: Show PSL-matched credentials in the account chooser. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/content/browser/credential_manager_impl.h" 5 #include "components/password_manager/content/browser/credential_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 .WillByDefault(testing::Return(true)); 220 .WillByDefault(testing::Return(true));
221 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 221 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
222 222
223 NavigateAndCommit(GURL("https://example.com/test.html")); 223 NavigateAndCommit(GURL("https://example.com/test.html"));
224 224
225 form_.username_value = base::ASCIIToUTF16("Username"); 225 form_.username_value = base::ASCIIToUTF16("Username");
226 form_.display_name = base::ASCIIToUTF16("Display Name"); 226 form_.display_name = base::ASCIIToUTF16("Display Name");
227 form_.icon_url = GURL("https://example.com/icon.png"); 227 form_.icon_url = GURL("https://example.com/icon.png");
228 form_.password_value = base::ASCIIToUTF16("Password"); 228 form_.password_value = base::ASCIIToUTF16("Password");
229 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 229 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
230 form_.signon_realm = form_.origin.spec(); 230 form_.signon_realm = form_.origin.GetOrigin().spec();
231 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 231 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
232 form_.skip_zero_click = false; 232 form_.skip_zero_click = false;
233 233
234 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1"); 234 affiliated_form1_.username_value = base::ASCIIToUTF16("Affiliated 1");
235 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name"); 235 affiliated_form1_.display_name = base::ASCIIToUTF16("Display Name");
236 affiliated_form1_.password_value = base::ASCIIToUTF16("Password"); 236 affiliated_form1_.password_value = base::ASCIIToUTF16("Password");
237 affiliated_form1_.origin = GURL(); 237 affiliated_form1_.origin = GURL();
238 affiliated_form1_.signon_realm = kTestAndroidRealm1; 238 affiliated_form1_.signon_realm = kTestAndroidRealm1;
239 affiliated_form1_.scheme = autofill::PasswordForm::SCHEME_HTML; 239 affiliated_form1_.scheme = autofill::PasswordForm::SCHEME_HTML;
240 affiliated_form1_.skip_zero_click = false; 240 affiliated_form1_.skip_zero_click = false;
241 241
242 affiliated_form2_.username_value = base::ASCIIToUTF16("Affiliated 2"); 242 affiliated_form2_.username_value = base::ASCIIToUTF16("Affiliated 2");
243 affiliated_form2_.display_name = base::ASCIIToUTF16("Display Name"); 243 affiliated_form2_.display_name = base::ASCIIToUTF16("Display Name");
244 affiliated_form2_.password_value = base::ASCIIToUTF16("Password"); 244 affiliated_form2_.password_value = base::ASCIIToUTF16("Password");
245 affiliated_form2_.origin = GURL(); 245 affiliated_form2_.origin = GURL();
246 affiliated_form2_.signon_realm = kTestAndroidRealm2; 246 affiliated_form2_.signon_realm = kTestAndroidRealm2;
247 affiliated_form2_.scheme = autofill::PasswordForm::SCHEME_HTML; 247 affiliated_form2_.scheme = autofill::PasswordForm::SCHEME_HTML;
248 affiliated_form2_.skip_zero_click = false; 248 affiliated_form2_.skip_zero_click = false;
249 249
250 origin_path_form_.username_value = base::ASCIIToUTF16("Username 2"); 250 origin_path_form_.username_value = base::ASCIIToUTF16("Username 2");
251 origin_path_form_.display_name = base::ASCIIToUTF16("Display Name 2"); 251 origin_path_form_.display_name = base::ASCIIToUTF16("Display Name 2");
252 origin_path_form_.password_value = base::ASCIIToUTF16("Password 2"); 252 origin_path_form_.password_value = base::ASCIIToUTF16("Password 2");
253 origin_path_form_.origin = GURL("https://example.com/path"); 253 origin_path_form_.origin = GURL("https://example.com/path");
254 origin_path_form_.signon_realm = origin_path_form_.origin.spec(); 254 origin_path_form_.signon_realm =
255 origin_path_form_.origin.GetOrigin().spec();
255 origin_path_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 256 origin_path_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
256 origin_path_form_.skip_zero_click = false; 257 origin_path_form_.skip_zero_click = false;
257 258
258 subdomain_form_.username_value = base::ASCIIToUTF16("Username 2"); 259 subdomain_form_.username_value = base::ASCIIToUTF16("Username 2");
259 subdomain_form_.display_name = base::ASCIIToUTF16("Display Name 2"); 260 subdomain_form_.display_name = base::ASCIIToUTF16("Display Name 2");
260 subdomain_form_.password_value = base::ASCIIToUTF16("Password 2"); 261 subdomain_form_.password_value = base::ASCIIToUTF16("Password 2");
261 subdomain_form_.origin = GURL("https://subdomain.example.com/path"); 262 subdomain_form_.origin = GURL("https://subdomain.example.com/path");
262 subdomain_form_.signon_realm = subdomain_form_.origin.spec(); 263 subdomain_form_.signon_realm = subdomain_form_.origin.GetOrigin().spec();
263 subdomain_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 264 subdomain_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
264 subdomain_form_.skip_zero_click = false; 265 subdomain_form_.skip_zero_click = false;
265 266
266 cross_origin_form_.username_value = base::ASCIIToUTF16("Username"); 267 cross_origin_form_.username_value = base::ASCIIToUTF16("Username");
267 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name"); 268 cross_origin_form_.display_name = base::ASCIIToUTF16("Display Name");
268 cross_origin_form_.password_value = base::ASCIIToUTF16("Password"); 269 cross_origin_form_.password_value = base::ASCIIToUTF16("Password");
269 cross_origin_form_.origin = GURL("https://example.net/"); 270 cross_origin_form_.origin = GURL("https://example.net/");
270 cross_origin_form_.signon_realm = cross_origin_form_.origin.spec(); 271 cross_origin_form_.signon_realm =
272 cross_origin_form_.origin.GetOrigin().spec();
271 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML; 273 cross_origin_form_.scheme = autofill::PasswordForm::SCHEME_HTML;
272 cross_origin_form_.skip_zero_click = false; 274 cross_origin_form_.skip_zero_click = false;
273 275
274 store_->Clear(); 276 store_->Clear();
275 EXPECT_TRUE(store_->IsEmpty()); 277 EXPECT_TRUE(store_->IsEmpty());
276 } 278 }
277 279
278 void TearDown() override { 280 void TearDown() override {
279 cm_service_impl_.reset(); 281 cm_service_impl_.reset();
280 282
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 730 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
729 .Times(testing::Exactly(0)); 731 .Times(testing::Exactly(0));
730 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 732 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
731 733
732 std::vector<GURL> federations; 734 std::vector<GURL> federations;
733 ExpectCredentialType(false, true, federations, 735 ExpectCredentialType(false, true, federations,
734 CredentialType::CREDENTIAL_TYPE_EMPTY); 736 CredentialType::CREDENTIAL_TYPE_EMPTY);
735 } 737 }
736 738
737 TEST_F(CredentialManagerImplTest, 739 TEST_F(CredentialManagerImplTest,
740 CredentialManagerOnRequestCredentialWithPSLCredential) {
741 subdomain_form_.skip_zero_click = false;
vabr (Chromium) 2016/11/23 18:49:11 Is the skip_zero_click bit being false a part of t
vasilii 2016/11/24 12:44:10 It's the second. The test should pass with any val
vabr (Chromium) 2016/11/24 13:58:14 Acknowledged.
742 store_->AddLogin(subdomain_form_);
743 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _));
744 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(0);
745
746 ExpectCredentialType(false, true, std::vector<GURL>(),
747 CredentialType::CREDENTIAL_TYPE_PASSWORD);
748 }
749
750 TEST_F(CredentialManagerImplTest,
738 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) { 751 CredentialManagerOnRequestCredentialWithEmptyAndNonemptyUsernames) {
739 store_->AddLogin(form_); 752 store_->AddLogin(form_);
740 autofill::PasswordForm empty = form_; 753 autofill::PasswordForm empty = form_;
741 empty.username_value.clear(); 754 empty.username_value.clear();
742 store_->AddLogin(empty); 755 store_->AddLogin(empty);
743 autofill::PasswordForm duplicate = form_; 756 autofill::PasswordForm duplicate = form_;
744 duplicate.username_element = base::ASCIIToUTF16("different_username_element"); 757 duplicate.username_element = base::ASCIIToUTF16("different_username_element");
745 store_->AddLogin(duplicate); 758 store_->AddLogin(duplicate);
759 store_->AddLogin(subdomain_form_);
746 760
747 std::vector<GURL> federations; 761 std::vector<GURL> federations;
748 ExpectZeroClickSignInSuccess(false, true, federations, 762 ExpectZeroClickSignInSuccess(false, true, federations,
749 CredentialType::CREDENTIAL_TYPE_PASSWORD); 763 CredentialType::CREDENTIAL_TYPE_PASSWORD);
750 } 764 }
751 765
752 TEST_F(CredentialManagerImplTest, 766 TEST_F(CredentialManagerImplTest,
753 CredentialManagerOnRequestCredentialWithDuplicates) { 767 CredentialManagerOnRequestCredentialWithDuplicates) {
754 // Add 8 credentials. Two buckets of duplicates, one empty username and one 768 // Add 8 credentials. Two buckets of duplicates, one empty username and one
vabr (Chromium) 2016/11/23 18:49:11 I'm wondering if this particular test is trying to
vasilii 2016/11/24 12:44:10 Done. See CredentialManagerOnRequestCredentialWith
755 // federated one. There should be just 3 in the account chooser. 769 // federated one. There should be just 3 in the account chooser.
756 form_.preferred = true; 770 form_.preferred = true;
757 form_.username_element = base::ASCIIToUTF16("username_element"); 771 form_.username_element = base::ASCIIToUTF16("username_element");
758 store_->AddLogin(form_); 772 store_->AddLogin(form_);
759 autofill::PasswordForm empty = form_; 773 autofill::PasswordForm empty = form_;
760 empty.username_value.clear(); 774 empty.username_value.clear();
761 store_->AddLogin(empty); 775 store_->AddLogin(empty);
762 autofill::PasswordForm duplicate = form_; 776 autofill::PasswordForm duplicate = subdomain_form_;
763 duplicate.username_element = base::ASCIIToUTF16("username_element1"); 777 duplicate.username_value = form_.username_value;
764 duplicate.is_public_suffix_match = true;
765 store_->AddLogin(duplicate); 778 store_->AddLogin(duplicate);
766 duplicate = form_; 779 duplicate = form_;
767 duplicate.username_element = base::ASCIIToUTF16("username_element2"); 780 duplicate.username_element = base::ASCIIToUTF16("username_element2");
768 duplicate.preferred = false; 781 duplicate.preferred = false;
769 store_->AddLogin(duplicate); 782 store_->AddLogin(duplicate);
770 783
771 origin_path_form_.preferred = true; 784 origin_path_form_.preferred = true;
772 store_->AddLogin(origin_path_form_); 785 store_->AddLogin(origin_path_form_);
773 duplicate = origin_path_form_; 786 duplicate = subdomain_form_;
774 duplicate.username_element = base::ASCIIToUTF16("username_element3"); 787 duplicate.username_element = base::ASCIIToUTF16("username_element3");
775 duplicate.is_public_suffix_match = true; 788 duplicate.username_value = subdomain_form_.username_value;
776 store_->AddLogin(duplicate); 789 store_->AddLogin(duplicate);
777 duplicate = origin_path_form_; 790 duplicate = origin_path_form_;
778 duplicate.username_element = base::ASCIIToUTF16("username_element4"); 791 duplicate.username_element = base::ASCIIToUTF16("username_element4");
779 duplicate.preferred = false; 792 duplicate.preferred = false;
780 store_->AddLogin(duplicate); 793 store_->AddLogin(duplicate);
781 autofill::PasswordForm federated = origin_path_form_; 794 autofill::PasswordForm federated = origin_path_form_;
782 federated.password_value.clear(); 795 federated.password_value.clear();
783 federated.federation_origin = url::Origin(GURL("https://google.com/")); 796 federated.federation_origin = url::Origin(GURL("https://google.com/"));
784 federated.signon_realm = 797 federated.signon_realm =
785 "federation://" + federated.origin.host() + "/google.com"; 798 "federation://" + federated.origin.host() + "/google.com";
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 } 854 }
842 855
843 TEST_F( 856 TEST_F(
844 CredentialManagerImplTest, 857 CredentialManagerImplTest,
845 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) { 858 CredentialManagerOnRequestCredentialWithZeroClickOnlyEmptyPasswordStore) {
846 std::vector<GURL> federations; 859 std::vector<GURL> federations;
847 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) 860 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _))
848 .Times(testing::Exactly(0)); 861 .Times(testing::Exactly(0));
849 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); 862 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0));
850 863
851 bool called = false; 864 ExpectZeroClickSignInFailure(true, true, federations);
852 mojom::CredentialManagerError error;
853 base::Optional<CredentialInfo> credential;
854 CallGet(true, true, federations,
855 base::Bind(&GetCredentialCallback, &called, &error, &credential));
856
857 RunAllPendingTasks();
858
859 EXPECT_TRUE(called);
860 EXPECT_EQ(mojom::CredentialManagerError::SUCCESS, error);
861 } 865 }
862 866
863 TEST_F(CredentialManagerImplTest, 867 TEST_F(CredentialManagerImplTest,
864 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) { 868 CredentialManagerOnRequestCredentialWithZeroClickOnlyFullPasswordStore) {
865 store_->AddLogin(form_); 869 store_->AddLogin(form_);
866 client_->set_first_run_seen(true); 870 client_->set_first_run_seen(true);
867 871
868 std::vector<GURL> federations; 872 std::vector<GURL> federations;
869 873
870 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0); 874 EXPECT_CALL(*client_, NotifyUserCouldBeAutoSignedInPtr(_)).Times(0);
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1427 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1424 CallStore(info, base::Bind(&RespondCallback, &called)); 1428 CallStore(info, base::Bind(&RespondCallback, &called));
1425 // Allow the PasswordFormManager to talk to the password store 1429 // Allow the PasswordFormManager to talk to the password store
1426 RunAllPendingTasks(); 1430 RunAllPendingTasks();
1427 1431
1428 ASSERT_TRUE(client_->pending_manager()); 1432 ASSERT_TRUE(client_->pending_manager());
1429 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1433 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1430 } 1434 }
1431 1435
1432 } // namespace password_manager 1436 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698