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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 MockPasswordManagerClient() { | 55 MockPasswordManagerClient() { |
| 56 EXPECT_CALL(*this, GetStoreResultFilter()) | 56 EXPECT_CALL(*this, GetStoreResultFilter()) |
| 57 .Times(AnyNumber()) | 57 .Times(AnyNumber()) |
| 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 and |
| 66 // the PasswordFormManager* argument. | 66 // ShowManualFallbackForSavingPtr owns the PasswordFormManager* argument. |
| 67 MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*)); | 67 MOCK_METHOD1(PromptUserToSaveOrUpdatePasswordPtr, void(PasswordFormManager*)); |
| 68 MOCK_METHOD3(ShowManualFallbackForSavingPtr, | |
| 69 void(PasswordFormManager*, bool, bool)); | |
| 70 MOCK_METHOD0(HideManualFallbackForSaving, void()); | |
| 68 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, | 71 MOCK_METHOD1(NotifySuccessfulLoginWithExistingPassword, |
| 69 void(const autofill::PasswordForm&)); | 72 void(const autofill::PasswordForm&)); |
| 70 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); | 73 MOCK_METHOD0(AutomaticPasswordSaveIndicator, void()); |
| 71 MOCK_METHOD0(GetPrefs, PrefService*()); | 74 MOCK_METHOD0(GetPrefs, PrefService*()); |
| 72 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&()); | 75 MOCK_CONST_METHOD0(GetMainFrameURL, const GURL&()); |
| 73 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); | 76 MOCK_METHOD0(GetDriver, PasswordManagerDriver*()); |
| 74 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*()); | 77 MOCK_CONST_METHOD0(GetStoreResultFilter, const MockStoreResultFilter*()); |
| 75 | 78 |
| 76 // Workaround for std::unique_ptr<> lacking a copy constructor. | 79 // Workaround for std::unique_ptr<> lacking a copy constructor. |
| 77 bool PromptUserToSaveOrUpdatePassword( | 80 bool PromptUserToSaveOrUpdatePassword( |
| 78 std::unique_ptr<PasswordFormManager> manager, | 81 std::unique_ptr<PasswordFormManager> manager, |
| 79 bool update_password) override { | 82 bool update_password) override { |
| 80 PromptUserToSaveOrUpdatePasswordPtr(manager.release()); | 83 PromptUserToSaveOrUpdatePasswordPtr(manager.release()); |
| 81 return false; | 84 return false; |
| 82 } | 85 } |
| 86 void ShowManualFallbackForSaving(std::unique_ptr<PasswordFormManager> manager, | |
| 87 bool has_generated_password, | |
| 88 bool is_update) override { | |
| 89 ShowManualFallbackForSavingPtr(manager.release(), has_generated_password, | |
| 90 is_update); | |
| 91 } | |
| 83 void AutomaticPasswordSave( | 92 void AutomaticPasswordSave( |
| 84 std::unique_ptr<PasswordFormManager> manager) override { | 93 std::unique_ptr<PasswordFormManager> manager) override { |
| 85 AutomaticPasswordSaveIndicator(); | 94 AutomaticPasswordSaveIndicator(); |
| 86 } | 95 } |
| 87 | 96 |
| 88 void FilterAllResultsForSaving() { | 97 void FilterAllResultsForSaving() { |
| 89 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); | 98 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); |
| 90 } | 99 } |
| 91 | 100 |
| 92 private: | 101 private: |
| (...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1802 std::unique_ptr<PasswordFormManager> form_manager_to_save; | 1811 std::unique_ptr<PasswordFormManager> form_manager_to_save; |
| 1803 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) | 1812 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) |
| 1804 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 1813 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| 1805 | 1814 |
| 1806 OnPasswordFormSubmitted(form); | 1815 OnPasswordFormSubmitted(form); |
| 1807 observed.clear(); | 1816 observed.clear(); |
| 1808 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1817 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
| 1809 } | 1818 } |
| 1810 #endif | 1819 #endif |
| 1811 | 1820 |
| 1821 TEST_F(PasswordManagerTest, ManualFallbackForSaving) { | |
| 1822 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1823 .WillRepeatedly(Return(true)); | |
| 1824 | |
| 1825 std::vector<PasswordForm> observed; | |
| 1826 PasswordForm form(MakeSimpleForm()); | |
| 1827 observed.push_back(form); | |
| 1828 PasswordForm stored_form = form; | |
| 1829 stored_form.password_value = ASCIIToUTF16("old_password"); | |
| 1830 EXPECT_CALL(*store_, GetLogins(_, _)) | |
| 1831 .WillOnce(WithArg<1>(InvokeConsumer(stored_form))); | |
| 1832 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | |
| 1833 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1834 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1835 | |
| 1836 // The username of the stored form is the same, there should be update bubble. | |
| 1837 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
| 1838 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false, true)) | |
| 1839 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1840 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1841 ASSERT_TRUE(form_manager_to_save); | |
| 1842 EXPECT_THAT(form_manager_to_save->pending_credentials(), FormMatches(form)); | |
| 1843 | |
| 1844 // The username of the stored form is different, there should be save bubble. | |
| 1845 PasswordForm new_form = form; | |
| 1846 new_form.username_value = ASCIIToUTF16("another_username"); | |
| 1847 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false, false)) | |
| 1848 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1849 manager()->ShowManualFallbackForSaving(&driver_, new_form); | |
| 1850 ASSERT_TRUE(form_manager_to_save); | |
| 1851 EXPECT_THAT(form_manager_to_save->pending_credentials(), | |
| 1852 FormMatches(new_form)); | |
| 1853 | |
| 1854 // Hide the manual fallback. | |
| 1855 EXPECT_CALL(client_, HideManualFallbackForSaving()); | |
| 1856 manager()->HideManualFallbackForSaving(); | |
| 1857 } | |
| 1858 | |
| 1859 // Tests that the manual fallback for saving isn't shown if there is no response | |
| 1860 // from the password storage. When crbug.com/741537 is fixed, change this test. | |
| 1861 TEST_F(PasswordManagerTest, ManualFallbackForSaving_SlowBackend) { | |
| 1862 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1863 .WillRepeatedly(Return(true)); | |
| 1864 | |
| 1865 std::vector<PasswordForm> observed; | |
| 1866 PasswordForm form(MakeSimpleForm()); | |
| 1867 observed.push_back(form); | |
| 1868 PasswordStoreConsumer* store_consumer = nullptr; | |
| 1869 EXPECT_CALL(*store_, GetLogins(_, _)).WillOnce(SaveArg<1>(&store_consumer)); | |
| 1870 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1871 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1872 | |
| 1873 // There is no response from the store. Don't show the fallback. | |
| 1874 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, _, _)).Times(0); | |
| 1875 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1876 | |
| 1877 // The storage responded. The fallback can be shown. | |
| 1878 ASSERT_TRUE(store_consumer); | |
| 1879 store_consumer->OnGetPasswordStoreResults( | |
| 1880 std::vector<std::unique_ptr<PasswordForm>>()); | |
| 1881 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
| 1882 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false, false)) | |
| 1883 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1884 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1885 } | |
| 1886 | |
|
vasilii
2017/08/03 10:46:37
How about a test for the generation scenario?
kolos1
2017/08/04 16:36:18
Done.
| |
| 1812 } // namespace password_manager | 1887 } // namespace password_manager |
| OLD | NEW |