| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/prefs/pref_registry_simple.h" | 7 #include "base/prefs/pref_registry_simple.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/prefs/testing_pref_service.h" | 9 #include "base/prefs/testing_pref_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 class TestPasswordManagerClient : public StubPasswordManagerClient { | 55 class TestPasswordManagerClient : public StubPasswordManagerClient { |
| 56 public: | 56 public: |
| 57 explicit TestPasswordManagerClient(PasswordStore* password_store) | 57 explicit TestPasswordManagerClient(PasswordStore* password_store) |
| 58 : password_store_(password_store) { | 58 : password_store_(password_store) { |
| 59 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, | 59 prefs_.registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
| 60 true); | 60 true); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual bool ShouldFilterAutofillResult( | 63 virtual bool ShouldFilterAutofillResult( |
| 64 const autofill::PasswordForm& form) override { | 64 const autofill::PasswordForm& form) OVERRIDE { |
| 65 if (form == form_to_filter_) | 65 if (form == form_to_filter_) |
| 66 return true; | 66 return true; |
| 67 return false; | 67 return false; |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual PrefService* GetPrefs() override { return &prefs_; } | 70 virtual PrefService* GetPrefs() OVERRIDE { return &prefs_; } |
| 71 virtual PasswordStore* GetPasswordStore() override { return password_store_; } | 71 virtual PasswordStore* GetPasswordStore() OVERRIDE { return password_store_; } |
| 72 virtual PasswordManagerDriver* GetDriver() override { return &driver_; } | 72 virtual PasswordManagerDriver* GetDriver() OVERRIDE { return &driver_; } |
| 73 virtual void AuthenticateAutofillAndFillForm( | 73 virtual void AuthenticateAutofillAndFillForm( |
| 74 scoped_ptr<autofill::PasswordFormFillData> fill_data) override { | 74 scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE { |
| 75 driver_.FillPasswordForm(*fill_data.get()); | 75 driver_.FillPasswordForm(*fill_data.get()); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void SetFormToFilter(const autofill::PasswordForm& form) { | 78 void SetFormToFilter(const autofill::PasswordForm& form) { |
| 79 form_to_filter_ = form; | 79 form_to_filter_ = form; |
| 80 } | 80 } |
| 81 | 81 |
| 82 MockPasswordManagerDriver* GetMockDriver() { return &driver_; } | 82 MockPasswordManagerDriver* GetMockDriver() { return &driver_; } |
| 83 | 83 |
| 84 private: | 84 private: |
| 85 autofill::PasswordForm form_to_filter_; | 85 autofill::PasswordForm form_to_filter_; |
| 86 | 86 |
| 87 TestingPrefServiceSimple prefs_; | 87 TestingPrefServiceSimple prefs_; |
| 88 PasswordStore* password_store_; | 88 PasswordStore* password_store_; |
| 89 testing::NiceMock<MockPasswordManagerDriver> driver_; | 89 testing::NiceMock<MockPasswordManagerDriver> driver_; |
| 90 }; | 90 }; |
| 91 | 91 |
| 92 class TestPasswordManager : public PasswordManager { | 92 class TestPasswordManager : public PasswordManager { |
| 93 public: | 93 public: |
| 94 explicit TestPasswordManager(PasswordManagerClient* client) | 94 explicit TestPasswordManager(PasswordManagerClient* client) |
| 95 : PasswordManager(client) {} | 95 : PasswordManager(client) {} |
| 96 | 96 |
| 97 virtual void Autofill(const autofill::PasswordForm& form_for_autofill, | 97 virtual void Autofill(const autofill::PasswordForm& form_for_autofill, |
| 98 const autofill::PasswordFormMap& best_matches, | 98 const autofill::PasswordFormMap& best_matches, |
| 99 const autofill::PasswordForm& preferred_match, | 99 const autofill::PasswordForm& preferred_match, |
| 100 bool wait_for_username) const override { | 100 bool wait_for_username) const OVERRIDE { |
| 101 best_matches_ = best_matches; | 101 best_matches_ = best_matches; |
| 102 } | 102 } |
| 103 | 103 |
| 104 const autofill::PasswordFormMap& GetLatestBestMatches() { | 104 const autofill::PasswordFormMap& GetLatestBestMatches() { |
| 105 return best_matches_; | 105 return best_matches_; |
| 106 } | 106 } |
| 107 | 107 |
| 108 private: | 108 private: |
| 109 // Marked mutable to get around constness of Autofill(). | 109 // Marked mutable to get around constness of Autofill(). |
| 110 mutable autofill::PasswordFormMap best_matches_; | 110 mutable autofill::PasswordFormMap best_matches_; |
| (...skipping 1173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1284 PasswordStore::ALLOW_PROMPT); | 1284 PasswordStore::ALLOW_PROMPT); |
| 1285 RunAllPendingTasks(); | 1285 RunAllPendingTasks(); |
| 1286 | 1286 |
| 1287 // Make sure that the preferred match is updated appropriately. | 1287 // Make sure that the preferred match is updated appropriately. |
| 1288 EXPECT_EQ(ASCIIToUTF16("password"), | 1288 EXPECT_EQ(ASCIIToUTF16("password"), |
| 1289 retrieving_manager.preferred_match()->password_value); | 1289 retrieving_manager.preferred_match()->password_value); |
| 1290 password_store->Shutdown(); | 1290 password_store->Shutdown(); |
| 1291 } | 1291 } |
| 1292 | 1292 |
| 1293 } // namespace password_manager | 1293 } // namespace password_manager |
| OLD | NEW |