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_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 13 matching lines...) Expand all Loading... | |
| 106 result.push_back(base::MakeUnique<PasswordForm>(form)); | 113 result.push_back(base::MakeUnique<PasswordForm>(form)); |
| 107 arg0->OnGetPasswordStoreResults(std::move(result)); | 114 arg0->OnGetPasswordStoreResults(std::move(result)); |
| 108 } | 115 } |
| 109 | 116 |
| 110 ACTION(InvokeEmptyConsumerWithForms) { | 117 ACTION(InvokeEmptyConsumerWithForms) { |
| 111 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); | 118 arg0->OnGetPasswordStoreResults(std::vector<std::unique_ptr<PasswordForm>>()); |
| 112 } | 119 } |
| 113 | 120 |
| 114 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } | 121 ACTION_P(SaveToScopedPtr, scoped) { scoped->reset(arg0); } |
| 115 | 122 |
| 123 ACTION_P(SaveConsumerToList, list) { | |
| 124 list->push_back(arg0); | |
| 125 } | |
| 126 | |
| 116 } // namespace | 127 } // namespace |
| 117 | 128 |
| 118 class PasswordManagerTest : public testing::Test { | 129 class PasswordManagerTest : public testing::Test { |
| 119 public: | 130 public: |
| 120 PasswordManagerTest() : test_url_("https://www.example.com") {} | 131 PasswordManagerTest() : test_url_("https://www.example.com") {} |
| 121 ~PasswordManagerTest() override = default; | 132 ~PasswordManagerTest() override = default; |
| 122 | 133 |
| 123 protected: | 134 protected: |
| 124 void SetUp() override { | 135 void SetUp() override { |
| 125 store_ = new testing::StrictMock<MockPasswordStore>; | 136 store_ = new testing::StrictMock<MockPasswordStore>; |
| (...skipping 1676 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1802 std::unique_ptr<PasswordFormManager> form_manager_to_save; | 1813 std::unique_ptr<PasswordFormManager> form_manager_to_save; |
| 1803 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) | 1814 EXPECT_CALL(client_, PromptUserToSaveOrUpdatePasswordPtr(_)) |
| 1804 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | 1815 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); |
| 1805 | 1816 |
| 1806 OnPasswordFormSubmitted(form); | 1817 OnPasswordFormSubmitted(form); |
| 1807 observed.clear(); | 1818 observed.clear(); |
| 1808 manager()->OnPasswordFormsRendered(&driver_, observed, true); | 1819 manager()->OnPasswordFormsRendered(&driver_, observed, true); |
| 1809 } | 1820 } |
| 1810 #endif | 1821 #endif |
| 1811 | 1822 |
| 1823 TEST_F(PasswordManagerTest, ManualFallbackForSaving) { | |
| 1824 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1825 .WillRepeatedly(Return(true)); | |
| 1826 | |
| 1827 std::vector<PasswordForm> observed; | |
| 1828 PasswordForm form(MakeSimpleForm()); | |
| 1829 observed.push_back(form); | |
| 1830 PasswordForm stored_form = form; | |
| 1831 stored_form.password_value = ASCIIToUTF16("old_password"); | |
| 1832 EXPECT_CALL(*store_, GetLogins(_, _)) | |
| 1833 .WillRepeatedly(WithArg<1>(InvokeConsumer(stored_form))); | |
| 1834 EXPECT_CALL(driver_, FillPasswordForm(_)).Times(2); | |
| 1835 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1836 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1837 | |
| 1838 // The username of the stored form is the same, there should be update bubble. | |
| 1839 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
| 1840 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, true)) | |
| 1841 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1842 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1843 ASSERT_TRUE(form_manager_to_save); | |
| 1844 EXPECT_THAT(form, FormMatches(*form_manager_to_save->submitted_form())); | |
| 1845 | |
| 1846 // The username of the stored form is different, there should be save bubble. | |
| 1847 PasswordForm new_form = form; | |
| 1848 new_form.username_value = ASCIIToUTF16("another_username"); | |
| 1849 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) | |
| 1850 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1851 manager()->ShowManualFallbackForSaving(&driver_, new_form); | |
| 1852 ASSERT_TRUE(form_manager_to_save); | |
| 1853 EXPECT_THAT(new_form, FormMatches(*form_manager_to_save->submitted_form())); | |
|
vasilii
2017/07/25 11:17:47
Check pending_credentials(). The UI is entirely ba
kolos1
2017/07/26 13:40:57
Done.
| |
| 1854 | |
| 1855 // Hide the manual fallback. | |
| 1856 EXPECT_CALL(client_, HideManualFallbackForSaving()); | |
| 1857 manager()->HideManualFallbackForSaving(); | |
| 1858 } | |
| 1859 | |
| 1860 // Tests that the manual fallback for saving isn't shown if there is no response | |
| 1861 // from the password storage. When crbug.com/741537 is fixed, change this test. | |
| 1862 TEST_F(PasswordManagerTest, ManualFallbackForSaving_SlowBackend) { | |
| 1863 EXPECT_CALL(client_, IsSavingAndFillingEnabledForCurrentPage()) | |
| 1864 .WillRepeatedly(Return(true)); | |
| 1865 | |
| 1866 std::vector<PasswordForm> observed; | |
| 1867 PasswordForm form(MakeSimpleForm()); | |
| 1868 observed.push_back(form); | |
| 1869 std::vector<PasswordStoreConsumer*> consumers; | |
| 1870 EXPECT_CALL(*store_, GetLogins(_, _)) | |
| 1871 .WillRepeatedly(WithArg<1>(SaveConsumerToList(&consumers))); | |
| 1872 manager()->OnPasswordFormsParsed(&driver_, observed); | |
| 1873 manager()->OnPasswordFormsRendered(&driver_, observed, true); | |
| 1874 | |
| 1875 // There is no response from the store. Don't show the fallback. | |
| 1876 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, _)).Times(0); | |
| 1877 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1878 | |
| 1879 // The storage responded. The fallback can be shown. | |
| 1880 for (PasswordStoreConsumer* consumer : consumers) { | |
| 1881 ASSERT_TRUE(consumer); | |
| 1882 consumer->OnGetPasswordStoreResults( | |
| 1883 std::vector<std::unique_ptr<PasswordForm>>()); | |
| 1884 } | |
| 1885 std::unique_ptr<PasswordFormManager> form_manager_to_save; | |
| 1886 EXPECT_CALL(client_, ShowManualFallbackForSavingPtr(_, false)) | |
| 1887 .WillOnce(WithArg<0>(SaveToScopedPtr(&form_manager_to_save))); | |
| 1888 manager()->ShowManualFallbackForSaving(&driver_, form); | |
| 1889 } | |
| 1890 | |
| 1812 } // namespace password_manager | 1891 } // namespace password_manager |
| OLD | NEW |