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

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

Issue 2447813002: Strengthen the rules when the Credential Manager API is disabled. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/password_manager/content/browser/credential_manager_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/password_manager/content/browser/credential_manager_impl.h" 5 #include "components/password_manager/content/browser/credential_manager_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <string> 9 #include <string>
10 #include <tuple> 10 #include <tuple>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 48
49 namespace { 49 namespace {
50 50
51 const char kTestWebOrigin[] = "https://example.com/"; 51 const char kTestWebOrigin[] = "https://example.com/";
52 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/"; 52 const char kTestAndroidRealm1[] = "android://hash@com.example.one.android/";
53 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/"; 53 const char kTestAndroidRealm2[] = "android://hash@com.example.two.android/";
54 54
55 class MockPasswordManagerClient : public StubPasswordManagerClient { 55 class MockPasswordManagerClient : public StubPasswordManagerClient {
56 public: 56 public:
57 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); 57 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool());
58 MOCK_CONST_METHOD0(IsFillingEnabledForCurrentPage, bool());
58 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); 59 MOCK_CONST_METHOD0(IsOffTheRecord, bool());
59 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool());
60 MOCK_METHOD0(NotifyUserAutoSigninPtr, bool()); 60 MOCK_METHOD0(NotifyUserAutoSigninPtr, bool());
61 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, 61 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr,
62 bool(autofill::PasswordForm* form)); 62 bool(autofill::PasswordForm* form));
63 MOCK_METHOD0(NotifyStorePasswordCalled, void()); 63 MOCK_METHOD0(NotifyStorePasswordCalled, void());
64 MOCK_METHOD2(PromptUserToSavePasswordPtr, 64 MOCK_METHOD2(PromptUserToSavePasswordPtr,
65 void(PasswordFormManager*, CredentialSourceType type)); 65 void(PasswordFormManager*, CredentialSourceType type));
66 MOCK_METHOD3(PromptUserToChooseCredentialsPtr, 66 MOCK_METHOD3(PromptUserToChooseCredentialsPtr,
67 bool(const std::vector<autofill::PasswordForm*>& local_forms, 67 bool(const std::vector<autofill::PasswordForm*>& local_forms,
68 const GURL& origin, 68 const GURL& origin,
69 const CredentialsCallback& callback)); 69 const CredentialsCallback& callback));
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 content::RenderViewHostTestHarness::SetUp(); 206 content::RenderViewHostTestHarness::SetUp();
207 store_ = new TestPasswordStore; 207 store_ = new TestPasswordStore;
208 client_.reset( 208 client_.reset(
209 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); 209 new testing::NiceMock<MockPasswordManagerClient>(store_.get()));
210 stub_driver_.reset( 210 stub_driver_.reset(
211 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); 211 new SlightlyLessStubbyPasswordManagerDriver(client_.get()));
212 cm_service_impl_.reset(new TestCredentialManagerImpl( 212 cm_service_impl_.reset(new TestCredentialManagerImpl(
213 web_contents(), client_.get(), stub_driver_.get())); 213 web_contents(), client_.get(), stub_driver_.get()));
214 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) 214 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
215 .WillByDefault(testing::Return(true)); 215 .WillByDefault(testing::Return(true));
216 ON_CALL(*client_, IsFillingEnabledForCurrentPage())
217 .WillByDefault(testing::Return(true));
216 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); 218 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false));
217 ON_CALL(*client_, DidLastPageLoadEncounterSSLErrors())
218 .WillByDefault(testing::Return(false));
219 219
220 NavigateAndCommit(GURL("https://example.com/test.html")); 220 NavigateAndCommit(GURL("https://example.com/test.html"));
221 221
222 form_.username_value = base::ASCIIToUTF16("Username"); 222 form_.username_value = base::ASCIIToUTF16("Username");
223 form_.display_name = base::ASCIIToUTF16("Display Name"); 223 form_.display_name = base::ASCIIToUTF16("Display Name");
224 form_.icon_url = GURL("https://example.com/icon.png"); 224 form_.icon_url = GURL("https://example.com/icon.png");
225 form_.password_value = base::ASCIIToUTF16("Password"); 225 form_.password_value = base::ASCIIToUTF16("Password");
226 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); 226 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin();
227 form_.signon_realm = form_.origin.spec(); 227 form_.signon_realm = form_.origin.spec();
228 form_.scheme = autofill::PasswordForm::SCHEME_HTML; 228 form_.scheme = autofill::PasswordForm::SCHEME_HTML;
(...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 EXPECT_EQ(1U, passwords[form_.signon_realm].size()); 639 EXPECT_EQ(1U, passwords[form_.signon_realm].size());
640 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size()); 640 EXPECT_EQ(1U, passwords[subdomain_form_.signon_realm].size());
641 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size()); 641 EXPECT_EQ(1U, passwords[cross_origin_form_.signon_realm].size());
642 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click); 642 EXPECT_TRUE(passwords[form_.signon_realm][0].skip_zero_click);
643 EXPECT_TRUE(passwords[subdomain_form_.signon_realm][0].skip_zero_click); 643 EXPECT_TRUE(passwords[subdomain_form_.signon_realm][0].skip_zero_click);
644 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click); 644 EXPECT_FALSE(passwords[cross_origin_form_.signon_realm][0].skip_zero_click);
645 } 645 }
646 646
647 TEST_F(CredentialManagerImplTest, 647 TEST_F(CredentialManagerImplTest,
648 CredentialManagerOnRequireUserMediationIncognito) { 648 CredentialManagerOnRequireUserMediationIncognito) {
649 EXPECT_CALL(*client_, IsOffTheRecord()).WillRepeatedly(testing::Return(true)); 649 EXPECT_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage())
650 .WillRepeatedly(testing::Return(false));
650 store_->AddLogin(form_); 651 store_->AddLogin(form_);
651 RunAllPendingTasks(); 652 RunAllPendingTasks();
652 653
653 TestPasswordStore::PasswordMap passwords = store_->stored_passwords(); 654 TestPasswordStore::PasswordMap passwords = store_->stored_passwords();
654 ASSERT_EQ(1U, passwords.size()); 655 ASSERT_EQ(1U, passwords.size());
655 ASSERT_EQ(1U, passwords[form_.signon_realm].size()); 656 ASSERT_EQ(1U, passwords[form_.signon_realm].size());
656 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click); 657 EXPECT_FALSE(passwords[form_.signon_realm][0].skip_zero_click);
657 658
658 bool called = false; 659 bool called = false;
659 CallRequireUserMediation(base::Bind(&RespondCallback, &called)); 660 CallRequireUserMediation(base::Bind(&RespondCallback, &called));
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
1019 std::vector<GURL> federations; 1020 std::vector<GURL> federations;
1020 EXPECT_CALL(*client_, 1021 EXPECT_CALL(*client_,
1021 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_))) 1022 NotifyUserCouldBeAutoSignedInPtr(testing::Pointee(form_)))
1022 .Times(1); 1023 .Times(1);
1023 1024
1024 ExpectZeroClickSignInFailure(true, true, federations); 1025 ExpectZeroClickSignInFailure(true, true, federations);
1025 } 1026 }
1026 1027
1027 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) { 1028 TEST_F(CredentialManagerImplTest, RequestCredentialWithTLSErrors) {
1028 // If we encounter TLS errors, we won't return credentials. 1029 // If we encounter TLS errors, we won't return credentials.
1029 EXPECT_CALL(*client_, DidLastPageLoadEncounterSSLErrors()) 1030 EXPECT_CALL(*client_, IsFillingEnabledForCurrentPage())
1030 .WillRepeatedly(testing::Return(true)); 1031 .WillRepeatedly(testing::Return(false));
1031 1032
1032 store_->AddLogin(form_); 1033 store_->AddLogin(form_);
1033 1034
1034 std::vector<GURL> federations; 1035 std::vector<GURL> federations;
1035 1036
1036 ExpectZeroClickSignInFailure(true, true, federations); 1037 ExpectZeroClickSignInFailure(true, true, federations);
1037 } 1038 }
1038 1039
1039 TEST_F(CredentialManagerImplTest, 1040 TEST_F(CredentialManagerImplTest,
1040 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { 1041 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) {
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); 1409 _, CredentialSourceType::CREDENTIAL_SOURCE_API));
1409 CallStore(info, base::Bind(&RespondCallback, &called)); 1410 CallStore(info, base::Bind(&RespondCallback, &called));
1410 // Allow the PasswordFormManager to talk to the password store 1411 // Allow the PasswordFormManager to talk to the password store
1411 RunAllPendingTasks(); 1412 RunAllPendingTasks();
1412 1413
1413 ASSERT_TRUE(client_->pending_manager()); 1414 ASSERT_TRUE(client_->pending_manager());
1414 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); 1415 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted());
1415 } 1416 }
1416 1417
1417 } // namespace password_manager 1418 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/content/browser/credential_manager_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698