| 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(IsFillingEnabledForCurrentPage, bool()); |
| 59 MOCK_METHOD0(OnCredentialManagerUsed, bool()); |
| 59 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); | 60 MOCK_CONST_METHOD0(IsOffTheRecord, bool()); |
| 60 MOCK_METHOD0(NotifyUserAutoSigninPtr, bool()); | 61 MOCK_METHOD0(NotifyUserAutoSigninPtr, bool()); |
| 61 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, | 62 MOCK_METHOD1(NotifyUserCouldBeAutoSignedInPtr, |
| 62 bool(autofill::PasswordForm* form)); | 63 bool(autofill::PasswordForm* form)); |
| 63 MOCK_METHOD0(NotifyStorePasswordCalled, void()); | 64 MOCK_METHOD0(NotifyStorePasswordCalled, void()); |
| 64 MOCK_METHOD2(PromptUserToSavePasswordPtr, | 65 MOCK_METHOD2(PromptUserToSavePasswordPtr, |
| 65 void(PasswordFormManager*, CredentialSourceType type)); | 66 void(PasswordFormManager*, CredentialSourceType type)); |
| 66 MOCK_METHOD3(PromptUserToChooseCredentialsPtr, | 67 MOCK_METHOD3(PromptUserToChooseCredentialsPtr, |
| 67 bool(const std::vector<autofill::PasswordForm*>& local_forms, | 68 bool(const std::vector<autofill::PasswordForm*>& local_forms, |
| 68 const GURL& origin, | 69 const GURL& origin, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 client_.reset( | 209 client_.reset( |
| 209 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); | 210 new testing::NiceMock<MockPasswordManagerClient>(store_.get())); |
| 210 stub_driver_.reset( | 211 stub_driver_.reset( |
| 211 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); | 212 new SlightlyLessStubbyPasswordManagerDriver(client_.get())); |
| 212 cm_service_impl_.reset(new TestCredentialManagerImpl( | 213 cm_service_impl_.reset(new TestCredentialManagerImpl( |
| 213 web_contents(), client_.get(), stub_driver_.get())); | 214 web_contents(), client_.get(), stub_driver_.get())); |
| 214 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) | 215 ON_CALL(*client_, IsSavingAndFillingEnabledForCurrentPage()) |
| 215 .WillByDefault(testing::Return(true)); | 216 .WillByDefault(testing::Return(true)); |
| 216 ON_CALL(*client_, IsFillingEnabledForCurrentPage()) | 217 ON_CALL(*client_, IsFillingEnabledForCurrentPage()) |
| 217 .WillByDefault(testing::Return(true)); | 218 .WillByDefault(testing::Return(true)); |
| 219 ON_CALL(*client_, OnCredentialManagerUsed()) |
| 220 .WillByDefault(testing::Return(true)); |
| 218 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); | 221 ON_CALL(*client_, IsOffTheRecord()).WillByDefault(testing::Return(false)); |
| 219 | 222 |
| 220 NavigateAndCommit(GURL("https://example.com/test.html")); | 223 NavigateAndCommit(GURL("https://example.com/test.html")); |
| 221 | 224 |
| 222 form_.username_value = base::ASCIIToUTF16("Username"); | 225 form_.username_value = base::ASCIIToUTF16("Username"); |
| 223 form_.display_name = base::ASCIIToUTF16("Display Name"); | 226 form_.display_name = base::ASCIIToUTF16("Display Name"); |
| 224 form_.icon_url = GURL("https://example.com/icon.png"); | 227 form_.icon_url = GURL("https://example.com/icon.png"); |
| 225 form_.password_value = base::ASCIIToUTF16("Password"); | 228 form_.password_value = base::ASCIIToUTF16("Password"); |
| 226 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); | 229 form_.origin = web_contents()->GetLastCommittedURL().GetOrigin(); |
| 227 form_.signon_realm = form_.origin.spec(); | 230 form_.signon_realm = form_.origin.spec(); |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 EXPECT_CALL(*client_, IsFillingEnabledForCurrentPage()) | 1033 EXPECT_CALL(*client_, IsFillingEnabledForCurrentPage()) |
| 1031 .WillRepeatedly(testing::Return(false)); | 1034 .WillRepeatedly(testing::Return(false)); |
| 1032 | 1035 |
| 1033 store_->AddLogin(form_); | 1036 store_->AddLogin(form_); |
| 1034 | 1037 |
| 1035 std::vector<GURL> federations; | 1038 std::vector<GURL> federations; |
| 1036 | 1039 |
| 1037 ExpectZeroClickSignInFailure(true, true, federations); | 1040 ExpectZeroClickSignInFailure(true, true, federations); |
| 1038 } | 1041 } |
| 1039 | 1042 |
| 1043 TEST_F(CredentialManagerImplTest, RequestCredentialWhilePrerendering) { |
| 1044 // The client disallows the credential manager for the current page. |
| 1045 EXPECT_CALL(*client_, OnCredentialManagerUsed()) |
| 1046 .WillRepeatedly(testing::Return(false)); |
| 1047 |
| 1048 store_->AddLogin(form_); |
| 1049 |
| 1050 std::vector<GURL> federations; |
| 1051 |
| 1052 ExpectZeroClickSignInFailure(true, true, federations); |
| 1053 } |
| 1054 |
| 1040 TEST_F(CredentialManagerImplTest, | 1055 TEST_F(CredentialManagerImplTest, |
| 1041 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { | 1056 CredentialManagerOnRequestCredentialWithZeroClickOnlyTwoPasswordStore) { |
| 1042 store_->AddLogin(form_); | 1057 store_->AddLogin(form_); |
| 1043 store_->AddLogin(origin_path_form_); | 1058 store_->AddLogin(origin_path_form_); |
| 1044 | 1059 |
| 1045 std::vector<GURL> federations; | 1060 std::vector<GURL> federations; |
| 1046 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) | 1061 EXPECT_CALL(*client_, PromptUserToChooseCredentialsPtr(_, _, _)) |
| 1047 .Times(testing::Exactly(0)); | 1062 .Times(testing::Exactly(0)); |
| 1048 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); | 1063 EXPECT_CALL(*client_, NotifyUserAutoSigninPtr()).Times(testing::Exactly(0)); |
| 1049 | 1064 |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1409 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); | 1424 _, CredentialSourceType::CREDENTIAL_SOURCE_API)); |
| 1410 CallStore(info, base::Bind(&RespondCallback, &called)); | 1425 CallStore(info, base::Bind(&RespondCallback, &called)); |
| 1411 // Allow the PasswordFormManager to talk to the password store | 1426 // Allow the PasswordFormManager to talk to the password store |
| 1412 RunAllPendingTasks(); | 1427 RunAllPendingTasks(); |
| 1413 | 1428 |
| 1414 ASSERT_TRUE(client_->pending_manager()); | 1429 ASSERT_TRUE(client_->pending_manager()); |
| 1415 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); | 1430 EXPECT_TRUE(client_->pending_manager()->IsBlacklisted()); |
| 1416 } | 1431 } |
| 1417 | 1432 |
| 1418 } // namespace password_manager | 1433 } // namespace password_manager |
| OLD | NEW |