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_METHOD2(ShowManualFallbackForSavingPtr, | |
69 void(PasswordFormManager*, 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 is_update) override { | |
88 ShowManualFallbackForSavingPtr(manager.release(), is_update); | |
89 } | |
83 void AutomaticPasswordSave( | 90 void AutomaticPasswordSave( |
84 std::unique_ptr<PasswordFormManager> manager) override { | 91 std::unique_ptr<PasswordFormManager> manager) override { |
85 AutomaticPasswordSaveIndicator(); | 92 AutomaticPasswordSaveIndicator(); |
86 } | 93 } |
87 | 94 |
88 void FilterAllResultsForSaving() { | 95 void FilterAllResultsForSaving() { |
89 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); | 96 EXPECT_CALL(filter_, ShouldSave(_)).WillRepeatedly(Return(false)); |
90 } | 97 } |
91 | 98 |
92 private: | 99 private: |
(...skipping 1709 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1802 std::unique_ptr<PasswordFormManager> form_manager_to_save; | 1809 std::unique_ptr<PasswordFormManager> form_manager_to_save; |
1803 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) | 1810 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) |
1804 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 1811 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
1805 | 1812 |
1806 OnPasswordFormSubmitted(form); | 1813 OnPasswordFormSubmitted(form); |
1807 observed.clear(); | 1814 observed.clear(); |
1808 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1815 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
1809 } | 1816 } |
1810 #endif | 1817 #endif |
1811 | 1818 |
1819 TEST_F(PasswordManagerTest, ManualFallbackForSaving) { | |
1820 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
1821 .WillRepeatedly(Return(true)); | |
1822 | |
1823 std::vector<PasswordForm> observed; | |
1824 PasswordForm form(MakeSimpleForm()); | |
1825 observed.push_back(form); | |
1826 PasswordForm stored_form = form; | |
1827 stored_form.password_value = ASCIIToUTF16("old_password"); | |
1828 EXPECT_CALL(*store_, GetLogins(_, _)) | |
1829 .WillOnce(WithArg<1>(InvokeConsumer(stored_form))); | |
1830 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | |
1831 manager()->OnPasswordFormsParsed(&driver_, observed); | |
1832 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
1833 | |
1834 // The username of the stored form is the same, there should be update bubble. | |
1835 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
1836 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, true)) | |
1837 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
1838 manager()->ShowManualFallbackForSaving(&driver_, form); | |
1839 ASSERT_TRUE(form_manager_to_save); | |
1840 EXPECT_THAT(form_manager_to_save->pending_credentials(), FormMatches(form)); | |
1841 | |
1842 // The username of the stored form is different, there should be save bubble. | |
1843 PasswordForm new_form = form; | |
1844 new_form.username_value = ASCIIToUTF16("another_username"); | |
1845 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) | |
1846 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
1847 manager()->ShowManualFallbackForSaving(&driver_, new_form); | |
1848 ASSERT_TRUE(form_manager_to_save); | |
1849 EXPECT_THAT(form_manager_to_save->pending_credentials(), | |
1850 FormMatches(new_form)); | |
1851 | |
1852 // Hide the manual fallback. | |
1853 EXPECT_CALL(client_, HideManualFallbackForSaving()); | |
1854 manager()->HideManualFallbackForSaving(); | |
1855 } | |
1856 | |
1857 // Tests that the manual fallback for saving isn't shown if there is no response | |
1858 // from the password storage. When crbug.com/741537 is fixed, change this test. | |
1859 TEST_F(PasswordManagerTest, ManualFallbackForSaving_SlowBackend) { | |
1860 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
1861 .WillRepeatedly(Return(true)); | |
1862 | |
1863 std::vector<PasswordForm> observed; | |
1864 PasswordForm form(MakeSimpleForm()); | |
1865 observed.push_back(form); | |
1866 PasswordStoreConsumer* store_consumer = nullptr; | |
1867 EXPECT_CALL(*store_, GetLogins(_, _)).WillOnce(SaveArg<1>(&store_consumer)); | |
1868 manager()->OnPasswordFormsParsed(&driver_, observed); | |
1869 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
1870 | |
1871 // There is no response from the store. Don't show the fallback. | |
1872 // GetLogins is called second time because of cloning PasswordFormManager for | |
1873 // showing the fallback. It clones FormFetcher too. Since the original | |
1874 // FormFetcher is still waiting for credentials, the clone will fetch | |
1875 // credentials too. | |
vasilii
2017/07/26 14:59:33
I'm confused about the comment. The test and the i
kolos1
2017/08/01 11:04:34
The issue fixed. The comment is not needed anymore
| |
1876 EXPECT_CALL(*store_, GetLogins(_, _)); | |
1877 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, _)).Times(0); | |
1878 manager()->ShowManualFallbackForSaving(&driver_, form); | |
1879 | |
1880 // The storage responded. The fallback can be shown. | |
1881 ASSERT_TRUE(store_consumer); | |
1882 store_consumer->OnGetPasswordStoreResults( | |
1883 std::vector<std::unique_ptr<PasswordForm>>()); | |
1884 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
1885 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) | |
1886 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
1887 manager()->ShowManualFallbackForSaving(&driver_, form); | |
1888 } | |
1889 | |
1812 } // namespace password_manager | 1890 } // namespace password_manager |
OLD | NEW |