OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <vector> | 5 #include <vector> |
6 | 6 |
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/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 class TestPasswordManagerDriver : public StubPasswordManagerDriver { | 31 class TestPasswordManagerDriver : public StubPasswordManagerDriver { |
32 public: | 32 public: |
33 TestPasswordManagerDriver(PasswordManagerClient* client) | 33 TestPasswordManagerDriver(PasswordManagerClient* client) |
34 : password_manager_(client), | 34 : password_manager_(client), |
35 password_generation_manager_(client), | 35 password_generation_manager_(client), |
36 password_autofill_manager_(client, NULL), | 36 password_autofill_manager_(client, NULL), |
37 is_off_the_record_(false) {} | 37 is_off_the_record_(false) {} |
38 virtual ~TestPasswordManagerDriver() {} | 38 virtual ~TestPasswordManagerDriver() {} |
39 | 39 |
40 // PasswordManagerDriver implementation. | 40 // PasswordManagerDriver implementation. |
41 virtual bool IsOffTheRecord() OVERRIDE { return is_off_the_record_; } | 41 virtual bool IsOffTheRecord() override { return is_off_the_record_; } |
42 virtual PasswordGenerationManager* GetPasswordGenerationManager() OVERRIDE { | 42 virtual PasswordGenerationManager* GetPasswordGenerationManager() override { |
43 return &password_generation_manager_; | 43 return &password_generation_manager_; |
44 } | 44 } |
45 virtual PasswordManager* GetPasswordManager() OVERRIDE { | 45 virtual PasswordManager* GetPasswordManager() override { |
46 return &password_manager_; | 46 return &password_manager_; |
47 } | 47 } |
48 virtual PasswordAutofillManager* GetPasswordAutofillManager() OVERRIDE { | 48 virtual PasswordAutofillManager* GetPasswordAutofillManager() override { |
49 return &password_autofill_manager_; | 49 return &password_autofill_manager_; |
50 } | 50 } |
51 virtual void AccountCreationFormsFound( | 51 virtual void AccountCreationFormsFound( |
52 const std::vector<autofill::FormData>& forms) OVERRIDE { | 52 const std::vector<autofill::FormData>& forms) override { |
53 found_account_creation_forms_.insert( | 53 found_account_creation_forms_.insert( |
54 found_account_creation_forms_.begin(), forms.begin(), forms.end()); | 54 found_account_creation_forms_.begin(), forms.begin(), forms.end()); |
55 } | 55 } |
56 | 56 |
57 const std::vector<autofill::FormData>& GetFoundAccountCreationForms() { | 57 const std::vector<autofill::FormData>& GetFoundAccountCreationForms() { |
58 return found_account_creation_forms_; | 58 return found_account_creation_forms_; |
59 } | 59 } |
60 void set_is_off_the_record(bool is_off_the_record) { | 60 void set_is_off_the_record(bool is_off_the_record) { |
61 is_off_the_record_ = is_off_the_record; | 61 is_off_the_record_ = is_off_the_record; |
62 } | 62 } |
63 | 63 |
64 private: | 64 private: |
65 PasswordManager password_manager_; | 65 PasswordManager password_manager_; |
66 PasswordGenerationManager password_generation_manager_; | 66 PasswordGenerationManager password_generation_manager_; |
67 PasswordAutofillManager password_autofill_manager_; | 67 PasswordAutofillManager password_autofill_manager_; |
68 std::vector<autofill::FormData> found_account_creation_forms_; | 68 std::vector<autofill::FormData> found_account_creation_forms_; |
69 bool is_off_the_record_; | 69 bool is_off_the_record_; |
70 }; | 70 }; |
71 | 71 |
72 class TestPasswordManagerClient : public StubPasswordManagerClient { | 72 class TestPasswordManagerClient : public StubPasswordManagerClient { |
73 public: | 73 public: |
74 TestPasswordManagerClient(scoped_ptr<PrefService> prefs) | 74 TestPasswordManagerClient(scoped_ptr<PrefService> prefs) |
75 : prefs_(prefs.Pass()), driver_(this), is_sync_enabled_(false) {} | 75 : prefs_(prefs.Pass()), driver_(this), is_sync_enabled_(false) {} |
76 | 76 |
77 virtual PasswordStore* GetPasswordStore() OVERRIDE { return NULL; } | 77 virtual PasswordStore* GetPasswordStore() override { return NULL; } |
78 virtual PrefService* GetPrefs() OVERRIDE { return prefs_.get(); } | 78 virtual PrefService* GetPrefs() override { return prefs_.get(); } |
79 virtual PasswordManagerDriver* GetDriver() OVERRIDE { return &driver_; } | 79 virtual PasswordManagerDriver* GetDriver() override { return &driver_; } |
80 virtual void AuthenticateAutofillAndFillForm( | 80 virtual void AuthenticateAutofillAndFillForm( |
81 scoped_ptr<autofill::PasswordFormFillData> fill_data) OVERRIDE {} | 81 scoped_ptr<autofill::PasswordFormFillData> fill_data) override {} |
82 virtual bool IsPasswordSyncEnabled() OVERRIDE { return is_sync_enabled_; } | 82 virtual bool IsPasswordSyncEnabled() override { return is_sync_enabled_; } |
83 | 83 |
84 void set_is_password_sync_enabled(bool enabled) { | 84 void set_is_password_sync_enabled(bool enabled) { |
85 is_sync_enabled_ = enabled; | 85 is_sync_enabled_ = enabled; |
86 } | 86 } |
87 | 87 |
88 private: | 88 private: |
89 scoped_ptr<PrefService> prefs_; | 89 scoped_ptr<PrefService> prefs_; |
90 TestPasswordManagerDriver driver_; | 90 TestPasswordManagerDriver driver_; |
91 bool is_sync_enabled_; | 91 bool is_sync_enabled_; |
92 }; | 92 }; |
93 | 93 |
94 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, | 94 // Unlike the base AutofillMetrics, exposes copy and assignment constructors, |
95 // which are handy for briefer test code. The AutofillMetrics class is | 95 // which are handy for briefer test code. The AutofillMetrics class is |
96 // stateless, so this is safe. | 96 // stateless, so this is safe. |
97 class TestAutofillMetrics : public autofill::AutofillMetrics { | 97 class TestAutofillMetrics : public autofill::AutofillMetrics { |
98 public: | 98 public: |
99 TestAutofillMetrics() {} | 99 TestAutofillMetrics() {} |
100 virtual ~TestAutofillMetrics() {} | 100 virtual ~TestAutofillMetrics() {} |
101 }; | 101 }; |
102 | 102 |
103 } // anonymous namespace | 103 } // anonymous namespace |
104 | 104 |
105 class PasswordGenerationManagerTest : public testing::Test { | 105 class PasswordGenerationManagerTest : public testing::Test { |
106 protected: | 106 protected: |
107 virtual void SetUp() OVERRIDE { | 107 virtual void SetUp() override { |
108 // Construct a PrefService and register all necessary prefs before handing | 108 // Construct a PrefService and register all necessary prefs before handing |
109 // it off to |client_|, as the initialization flow of |client_| will | 109 // it off to |client_|, as the initialization flow of |client_| will |
110 // indirectly cause those prefs to be immediately accessed. | 110 // indirectly cause those prefs to be immediately accessed. |
111 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); | 111 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); |
112 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, | 112 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
113 true); | 113 true); |
114 client_.reset(new TestPasswordManagerClient(prefs.PassAs<PrefService>())); | 114 client_.reset(new TestPasswordManagerClient(prefs.PassAs<PrefService>())); |
115 } | 115 } |
116 | 116 |
117 virtual void TearDown() OVERRIDE { client_.reset(); } | 117 virtual void TearDown() override { client_.reset(); } |
118 | 118 |
119 PasswordGenerationManager* GetGenerationManager() { | 119 PasswordGenerationManager* GetGenerationManager() { |
120 return client_->GetDriver()->GetPasswordGenerationManager(); | 120 return client_->GetDriver()->GetPasswordGenerationManager(); |
121 } | 121 } |
122 | 122 |
123 TestPasswordManagerDriver* GetTestDriver() { | 123 TestPasswordManagerDriver* GetTestDriver() { |
124 return static_cast<TestPasswordManagerDriver*>(client_->GetDriver()); | 124 return static_cast<TestPasswordManagerDriver*>(client_->GetDriver()); |
125 } | 125 } |
126 | 126 |
127 bool IsGenerationEnabled() { | 127 bool IsGenerationEnabled() { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 // be disabled. | 212 // be disabled. |
213 GetTestDriver()->set_is_off_the_record(true); | 213 GetTestDriver()->set_is_off_the_record(true); |
214 PrefService* prefs = client_->GetPrefs(); | 214 PrefService* prefs = client_->GetPrefs(); |
215 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); | 215 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
216 client_->set_is_password_sync_enabled(true); | 216 client_->set_is_password_sync_enabled(true); |
217 | 217 |
218 EXPECT_FALSE(IsGenerationEnabled()); | 218 EXPECT_FALSE(IsGenerationEnabled()); |
219 } | 219 } |
220 | 220 |
221 } // namespace password_manager | 221 } // namespace password_manager |
OLD | NEW |