Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/core/browser/password_manager.h" | 5 #include "components/password_manager/core/browser/password_manager.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 .WillRepeatedly(Return(&filter_)); | 58 .WillRepeatedly(Return(&filter_)); |
| 59 ON_CALL(filter_, ShouldSave(_)).WillByDefault(Return(true)); | 59 ON_CALL(filter_, ShouldSave(_)).WillByDefault(Return(true)); |
| 60 } | 60 } |
| 61 | 61 |
| 62 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); | 62 MOCK_CONST_METHOD0(IsSavingAndFillingEnabledForCurrentPage, bool()); |
| 63 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); | 63 MOCK_CONST_METHOD0(DidLastPageLoadEncounterSSLErrors, bool()); |
| 64 MOCK_CONST_METHOD0(GetPasswordStore, PasswordStore*()); | 64 MOCK_CONST_METHOD0(GetPasswordStore, PasswordStore*()); |
| 65 // The code inside EXPECT_CALL for PromptUserToSaveOrUpdatePasswordPtr owns | 65 // The code inside EXPECT_CALL for PromptUserToSaveOrUpdatePasswordPtr owns |
| 66 // the PasswordFormManager* argument. | 66 // the PasswordFormManager* argument. |
| 67 MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*)); | 67 MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*)); |
| 68 MOCK_METHOD2(ShowManualFallbackPtr, void(PasswordFormManager*, bool)); | |
| 69 MOCK_METHOD0(HideManualFallback, void()); | |
| 68 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, | 70 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, |
| 69 void(const autofill::PasswordForm&)); | 71 void(const autofill::PasswordForm&)); |
| 70 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); | 72 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); |
| 71 MOCK_METHOD0(GetPrefs, PrefService*()); | 73 MOCK_METHOD0(GetPrefs, PrefService*()); |
| 72 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&()); | 74 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&()); |
| 73 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); | 75 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); |
| 74 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*()); | 76 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*()); |
| 75 | 77 |
| 76 // Workaround for std::unique_ptr<> lacking a copy constructor. | 78 // Workaround for std::unique_ptr<> lacking a copy constructor. |
| 77 bool PromptUserToSaveOrUpdatePassword( | 79 bool PromptUserToSaveOrUpdatePassword( |
| 78 std::unique_ptr<PasswordFormManager> manager, | 80 std::unique_ptr<PasswordFormManager> manager, |
| 79 bool update_password) override { | 81 bool update_password) override { |
| 80 PromptUserToSaveOrUpdatePasswordPtr(manager.release()); | 82 PromptUserToSaveOrUpdatePasswordPtr(manager.release()); |
| 81 return false; | 83 return false; |
| 82 } | 84 } |
| 85 void ShowManualFallback(std::unique_ptr<PasswordFormManager> manager, | |
| 86 bool is_update) override { | |
| 87 ShowManualFallbackPtr(manager.release(), is_update); | |
|
vasilii
2017/07/21 12:48:21
Memory leak here?
kolos1
2017/07/24 15:33:31
Fixed.
| |
| 88 } | |
| 83 void AutomaticPasswordSave( | 89 void AutomaticPasswordSave( |
| 84 std::unique_ptr<PasswordFormManager> manager) override { | 90 std::unique_ptr<PasswordFormManager> manager) override { |
| 85 AutomaticPasswordSaveIndicator(); | 91 AutomaticPasswordSaveIndicator(); |
| 86 } | 92 } |
| 87 | 93 |
| 88 void FilterAllResultsForSaving() { | 94 void FilterAllResultsForSaving() { |
| 89 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); | 95 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); |
| 90 } | 96 } |
| 91 | 97 |
| 92 private: | 98 private: |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 106 result.push_back(base::MakeUnique<PasswordForm>(form)); | 112 result.push_back(base::MakeUnique<PasswordForm>(form)); |
| 107 arg0->OnGetPasswordStoreResults(std::move(result)); | 113 arg0->OnGetPasswordStoreResults(std::move(result)); |
| 108 } | 114 } |
| 109 | 115 |
| 110 ACTION(InvokeEmptyConsumerWithForms) { | 116 ACTION(InvokeEmptyConsumerWithForms) { |
| 111 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); | 117 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); |
| 112 } | 118 } |
| 113 | 119 |
| 114 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } | 120 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
| 115 | 121 |
| 122 ACTION_P(SaveConsumerToList, list) { | |
| 123 list->push_back(arg0); | |
| 124 } | |
| 125 | |
| 116 } // namespace | 126 } // namespace |
| 117 | 127 |
| 118 class PasswordManagerTest : public testing::Test { | 128 class PasswordManagerTest : public testing::Test { |
| 119 protected: | 129 protected: |
| 120 void SetUp() override { | 130 void SetUp() override { |
| 121 store_ = new testing::StrictMock<MockPasswordStore>; | 131 store_ = new testing::StrictMock<MockPasswordStore>; |
| 122 EXPECT_CALL(*store_, ReportMetrics(_, _)).Times(AnyNumber()); | 132 EXPECT_CALL(*store_, ReportMetrics(_, _)).Times(AnyNumber()); |
| 123 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _)) | 133 EXPECT_CALL(*store_, GetLoginsForSameOrganizationName(_, _)) |
| 124 .Times(AnyNumber()); | 134 .Times(AnyNumber()); |
| 125 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), nullptr)); | 135 CHECK(store_->Init(syncer::SyncableService::StartSyncFlare(), nullptr)); |
| (...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1798 std::unique_ptr<PasswordFormManager> form_manager_to_save; | 1808 std::unique_ptr<PasswordFormManager> form_manager_to_save; |
| 1799 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) | 1809 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) |
| 1800 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 1810 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| 1801 | 1811 |
| 1802 OnPasswordFormSubmitted(form); | 1812 OnPasswordFormSubmitted(form); |
| 1803 observed.clear(); | 1813 observed.clear(); |
| 1804 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1814 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
| 1805 } | 1815 } |
| 1806 #endif | 1816 #endif |
| 1807 | 1817 |
| 1818 TEST_F(PasswordManagerTest, ManualFallbackForSaving) { | |
| 1819 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1820 .WillRepeatedly(Return(true)); | |
| 1821 | |
| 1822 std::vector<PasswordForm> observed; | |
| 1823 PasswordForm form(MakeSimpleForm()); | |
| 1824 observed.push_back(form); | |
| 1825 PasswordForm stored_form = form; | |
| 1826 stored_form.password_value = ASCIIToUTF16("old_password"); | |
| 1827 EXPECT_CALL(*store_, GetLogins(_, _)) | |
| 1828 .WillRepeatedly(WithArg<1>(InvokeConsumer(stored_form))); | |
|
vasilii
2017/07/21 12:48:21
I'm concerned if it happens more than once. Is it
kolos1
2017/07/24 15:33:30
Yes, it is called twice.
In tests above, WillRepe
vasilii
2017/07/25 11:17:46
Why is it called twice if the form is only one?
kolos1
2017/07/26 13:40:57
Investigated the case. Here it is called once actu
| |
| 1829 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | |
| 1830 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1831 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1832 | |
| 1833 // The username of the stored form is the same, there should be update bubble. | |
| 1834 EXPECT_CALL(client_, ShowManualFallbackPtr(_, true)); | |
|
vasilii
2017/07/21 12:48:21
Why don't we check anything about the form being p
kolos1
2017/07/24 15:33:31
Added some checks.
| |
| 1835 manager()->ShowManualFallback(&driver_, form); | |
| 1836 | |
| 1837 // The username of the stored form is different, there should be save bubble. | |
| 1838 PasswordForm new_form = form; | |
| 1839 new_form.username_value = ASCIIToUTF16("another_username"); | |
| 1840 EXPECT_CALL(client_, ShowManualFallbackPtr(_, false)); | |
| 1841 manager()->ShowManualFallback(&driver_, new_form); | |
| 1842 | |
| 1843 // Hide the manual fallback. | |
| 1844 EXPECT_CALL(client_, HideManualFallback()); | |
| 1845 manager()->HideManualFallback(); | |
| 1846 } | |
| 1847 | |
| 1848 // Tests that the manual fallback for saving isn't shown if there is no response | |
| 1849 // from the password storage. When crbug.com/741537 is fixed, change this test. | |
| 1850 TEST_F(PasswordManagerTest, ManualFallbackForSaving_SlowBackend) { | |
| 1851 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1852 .WillRepeatedly(Return(true)); | |
| 1853 | |
| 1854 std::vector<PasswordForm> observed; | |
| 1855 PasswordForm form(MakeSimpleForm()); | |
| 1856 observed.push_back(form); | |
| 1857 std::vector<PasswordStoreConsumer*> consumers; | |
| 1858 EXPECT_CALL(*store_, GetLogins(_, _)) | |
| 1859 .WillRepeatedly(WithArg<1>(SaveConsumerToList(&consumers))); | |
| 1860 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1861 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1862 | |
| 1863 // There is no response from the store. Don't show the fallback. | |
| 1864 EXPECT_CALL(client_, ShowManualFallbackPtr(_, _)).Times(0); | |
| 1865 manager()->ShowManualFallback(&driver_, form); | |
| 1866 | |
| 1867 // The storage responded. The fallback can be shown. | |
| 1868 EXPECT_CALL(client_, ShowManualFallbackPtr(_, false)); | |
|
vasilii
2017/07/21 12:48:21
Move down to ShowManualFallback. Do I understand r
kolos1
2017/07/24 15:33:31
Good point. Done.
| |
| 1869 for (PasswordStoreConsumer* consumer : consumers) { | |
| 1870 ASSERT_TRUE(consumer); | |
| 1871 consumer->OnGetPasswordStoreResults( | |
| 1872 std::vector<std::unique_ptr<PasswordForm>>()); | |
| 1873 } | |
| 1874 manager()->ShowManualFallback(&driver_, form); | |
| 1875 } | |
| 1876 | |
| 1808 } // namespace password_manager | 1877 } // namespace password_manager |
| OLD | NEW |