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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 104 |
105 } // anonymous namespace | 105 } // anonymous namespace |
106 | 106 |
107 class PasswordGenerationManagerTest : public testing::Test { | 107 class PasswordGenerationManagerTest : public testing::Test { |
108 protected: | 108 protected: |
109 virtual void SetUp() OVERRIDE { | 109 virtual void SetUp() OVERRIDE { |
110 // Construct a PrefService and register all necessary prefs before handing | 110 // Construct a PrefService and register all necessary prefs before handing |
111 // it off to |client_|, as the initialization flow of |client_| will | 111 // it off to |client_|, as the initialization flow of |client_| will |
112 // indirectly cause those prefs to be immediately accessed. | 112 // indirectly cause those prefs to be immediately accessed. |
113 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); | 113 scoped_ptr<TestingPrefServiceSimple> prefs(new TestingPrefServiceSimple()); |
114 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerEnabled, | 114 prefs->registry()->RegisterBooleanPref(prefs::kPasswordManagerSavingEnabled, |
115 true); | 115 true); |
116 client_.reset(new TestPasswordManagerClient(prefs.PassAs<PrefService>())); | 116 client_.reset(new TestPasswordManagerClient(prefs.PassAs<PrefService>())); |
117 } | 117 } |
118 | 118 |
119 virtual void TearDown() OVERRIDE { client_.reset(); } | 119 virtual void TearDown() OVERRIDE { client_.reset(); } |
120 | 120 |
121 PasswordGenerationManager* GetGenerationManager() { | 121 PasswordGenerationManager* GetGenerationManager() { |
122 return client_->GetDriver()->GetPasswordGenerationManager(); | 122 return client_->GetDriver()->GetPasswordGenerationManager(); |
123 } | 123 } |
124 | 124 |
(...skipping 10 matching lines...) Expand all Loading... |
135 GetGenerationManager()->DetectAccountCreationForms(forms); | 135 GetGenerationManager()->DetectAccountCreationForms(forms); |
136 } | 136 } |
137 | 137 |
138 scoped_ptr<TestPasswordManagerClient> client_; | 138 scoped_ptr<TestPasswordManagerClient> client_; |
139 }; | 139 }; |
140 | 140 |
141 TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { | 141 TEST_F(PasswordGenerationManagerTest, IsGenerationEnabled) { |
142 // Enabling the PasswordManager and password sync should cause generation to | 142 // Enabling the PasswordManager and password sync should cause generation to |
143 // be enabled. | 143 // be enabled. |
144 PrefService* prefs = client_->GetPrefs(); | 144 PrefService* prefs = client_->GetPrefs(); |
145 prefs->SetBoolean(prefs::kPasswordManagerEnabled, true); | 145 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
146 client_->set_is_password_sync_enabled(true); | 146 client_->set_is_password_sync_enabled(true); |
147 EXPECT_TRUE(IsGenerationEnabled()); | 147 EXPECT_TRUE(IsGenerationEnabled()); |
148 | 148 |
149 // Disabling password syncing should cause generation to be disabled. | 149 // Disabling password syncing should cause generation to be disabled. |
150 client_->set_is_password_sync_enabled(false); | 150 client_->set_is_password_sync_enabled(false); |
151 EXPECT_FALSE(IsGenerationEnabled()); | 151 EXPECT_FALSE(IsGenerationEnabled()); |
152 | 152 |
153 // Disabling the PasswordManager should cause generation to be disabled even | 153 // Disabling the PasswordManager should cause generation to be disabled even |
154 // if syncing is enabled. | 154 // if syncing is enabled. |
155 prefs->SetBoolean(prefs::kPasswordManagerEnabled, false); | 155 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, false); |
156 client_->set_is_password_sync_enabled(true); | 156 client_->set_is_password_sync_enabled(true); |
157 EXPECT_FALSE(IsGenerationEnabled()); | 157 EXPECT_FALSE(IsGenerationEnabled()); |
158 } | 158 } |
159 | 159 |
160 TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { | 160 TEST_F(PasswordGenerationManagerTest, DetectAccountCreationForms) { |
161 // Setup so that IsGenerationEnabled() returns true. | 161 // Setup so that IsGenerationEnabled() returns true. |
162 PrefService* prefs = client_->GetPrefs(); | 162 PrefService* prefs = client_->GetPrefs(); |
163 prefs->SetBoolean(prefs::kPasswordManagerEnabled, true); | 163 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
164 client_->set_is_password_sync_enabled(true); | 164 client_->set_is_password_sync_enabled(true); |
165 | 165 |
166 autofill::FormData login_form; | 166 autofill::FormData login_form; |
167 login_form.origin = GURL("http://www.yahoo.com/login/"); | 167 login_form.origin = GURL("http://www.yahoo.com/login/"); |
168 autofill::FormFieldData username; | 168 autofill::FormFieldData username; |
169 username.label = ASCIIToUTF16("username"); | 169 username.label = ASCIIToUTF16("username"); |
170 username.name = ASCIIToUTF16("login"); | 170 username.name = ASCIIToUTF16("login"); |
171 username.form_control_type = "text"; | 171 username.form_control_type = "text"; |
172 login_form.fields.push_back(username); | 172 login_form.fields.push_back(username); |
173 autofill::FormFieldData password; | 173 autofill::FormFieldData password; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 EXPECT_EQ(GURL("http://accounts.yahoo.com/"), | 207 EXPECT_EQ(GURL("http://accounts.yahoo.com/"), |
208 GetTestDriver()->GetFoundAccountCreationForms()[0].origin); | 208 GetTestDriver()->GetFoundAccountCreationForms()[0].origin); |
209 } | 209 } |
210 | 210 |
211 TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncStateIncognito) { | 211 TEST_F(PasswordGenerationManagerTest, UpdatePasswordSyncStateIncognito) { |
212 // Disable password manager by going incognito. Even though password | 212 // Disable password manager by going incognito. Even though password |
213 // syncing is enabled, generation should still | 213 // syncing is enabled, generation should still |
214 // be disabled. | 214 // be disabled. |
215 GetTestDriver()->set_is_off_the_record(true); | 215 GetTestDriver()->set_is_off_the_record(true); |
216 PrefService* prefs = client_->GetPrefs(); | 216 PrefService* prefs = client_->GetPrefs(); |
217 prefs->SetBoolean(prefs::kPasswordManagerEnabled, true); | 217 prefs->SetBoolean(prefs::kPasswordManagerSavingEnabled, true); |
218 client_->set_is_password_sync_enabled(true); | 218 client_->set_is_password_sync_enabled(true); |
219 | 219 |
220 EXPECT_FALSE(IsGenerationEnabled()); | 220 EXPECT_FALSE(IsGenerationEnabled()); |
221 } | 221 } |
222 | 222 |
223 } // namespace password_manager | 223 } // namespace password_manager |
OLD | NEW |