Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: components/password_manager/sync/browser/sync_credentials_filter_unittest.cc

Issue 1668523002: [Password Manager] Switch password manager code to use the Feature framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/password_manager/sync/browser/sync_credentials_filter.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/sync/browser/sync_credentials_filter.h" 5 #include "components/password_manager/sync/browser/sync_credentials_filter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <utility> 8 #include <utility>
9 #include <vector>
9 10
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/test/histogram_tester.h" 14 #include "base/test/histogram_tester.h"
15 #include "base/test/user_action_tester.h" 15 #include "base/test/user_action_tester.h"
16 #include "components/autofill/core/common/password_form.h" 16 #include "components/autofill/core/common/password_form.h"
17 #include "components/password_manager/core/browser/password_manager_test_utils.h "
17 #include "components/password_manager/core/browser/stub_password_manager_client. h" 18 #include "components/password_manager/core/browser/stub_password_manager_client. h"
18 #include "components/password_manager/core/common/password_manager_switches.h" 19 #include "components/password_manager/core/common/password_manager_features.h"
19 #include "components/password_manager/sync/browser/sync_username_test_base.h" 20 #include "components/password_manager/sync/browser/sync_username_test_base.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using autofill::PasswordForm; 23 using autofill::PasswordForm;
23 24
24 namespace password_manager { 25 namespace password_manager {
25 26
26 namespace { 27 namespace {
27 28
28 class FakePasswordManagerClient : public StubPasswordManagerClient { 29 class FakePasswordManagerClient : public StubPasswordManagerClient {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, 129 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM},
129 }; 130 };
130 131
131 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 132 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
132 SCOPED_TRACE(testing::Message() << "i=" << i); 133 SCOPED_TRACE(testing::Message() << "i=" << i);
133 CheckFilterResultsTestCase(kTestCases[i]); 134 CheckFilterResultsTestCase(kTestCases[i]);
134 } 135 }
135 } 136 }
136 137
137 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) { 138 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) {
138 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 139 // Only 'protect-sync-credential-on-reauth' feature is kept enabled, fill the
139 command_line->AppendSwitch( 140 // sync credential everywhere but on reauth.
140 switches::kDisallowAutofillSyncCredentialForReauth); 141 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
142 std::vector<const base::Feature*> enabled_features;
143 std::vector<const base::Feature*> disabled_features;
144 disabled_features.push_back(&features::kProtectSyncCredential);
145 enabled_features.push_back(&features::kProtectSyncCredentialOnReauth);
146 SetFeatures(enabled_features, disabled_features, std::move(feature_list));
141 147
142 const TestCase kTestCases[] = { 148 const TestCase kTestCases[] = {
143 // Reauth URL, not sync username. 149 // Reauth URL, not sync username.
144 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 150 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
145 "another_user@example.org", 151 "another_user@example.org",
146 "https://accounts.google.com/login?rart=123&continue=blah", 152 "https://accounts.google.com/login?rart=123&continue=blah",
147 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, 153 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED},
148 154
149 // Reauth URL, sync username. 155 // Reauth URL, sync username.
150 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 156 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
(...skipping 18 matching lines...) Expand all
169 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, 175 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM},
170 }; 176 };
171 177
172 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 178 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
173 SCOPED_TRACE(testing::Message() << "i=" << i); 179 SCOPED_TRACE(testing::Message() << "i=" << i);
174 CheckFilterResultsTestCase(kTestCases[i]); 180 CheckFilterResultsTestCase(kTestCases[i]);
175 } 181 }
176 } 182 }
177 183
178 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) { 184 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) {
179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 185 // Both features are kept enabled, should cause sync credential to be
180 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential); 186 // filtered.
187 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
188 std::vector<const base::Feature*> enabled_features;
189 std::vector<const base::Feature*> disabled_features;
190 enabled_features.push_back(&features::kProtectSyncCredential);
191 enabled_features.push_back(&features::kProtectSyncCredentialOnReauth);
192 SetFeatures(enabled_features, disabled_features, std::move(feature_list));
181 193
182 const TestCase kTestCases[] = { 194 const TestCase kTestCases[] = {
183 // Reauth URL, not sync username. 195 // Reauth URL, not sync username.
184 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 196 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
185 "another_user@example.org", 197 "another_user@example.org",
186 "https://accounts.google.com/login?rart=123&continue=blah", 198 "https://accounts.google.com/login?rart=123&continue=blah",
187 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, 199 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED},
188 200
189 // Reauth URL, sync username. 201 // Reauth URL, sync username.
190 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 202 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 253
242 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) { 254 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) {
243 PasswordForm form = SimpleGaiaForm("user@example.org"); 255 PasswordForm form = SimpleGaiaForm("user@example.org");
244 256
245 FakeSigninAs("user@example.org"); 257 FakeSigninAs("user@example.org");
246 SetSyncingPasswords(false); 258 SetSyncingPasswords(false);
247 EXPECT_TRUE(filter()->ShouldSave(form)); 259 EXPECT_TRUE(filter()->ShouldSave(form));
248 } 260 }
249 261
250 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) { 262 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) {
251 // Adding disallow switch should cause sync credential to be filtered. 263 // Both features are kept enabled, should cause sync credential to be
252 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 264 // filtered.
253 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential); 265 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
266 std::vector<const base::Feature*> enabled_features;
267 std::vector<const base::Feature*> disabled_features;
268 enabled_features.push_back(&features::kProtectSyncCredential);
269 enabled_features.push_back(&features::kProtectSyncCredentialOnReauth);
270 SetFeatures(enabled_features, disabled_features, std::move(feature_list));
254 271
255 ScopedVector<autofill::PasswordForm> results; 272 ScopedVector<autofill::PasswordForm> results;
256 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com"))); 273 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com")));
257 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com"))); 274 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com")));
258 275
259 FakeSigninAs("test1@gmail.com"); 276 FakeSigninAs("test1@gmail.com");
260 277
261 results = filter()->FilterResults(std::move(results)); 278 results = filter()->FilterResults(std::move(results));
262 279
263 ASSERT_EQ(1u, results.size()); 280 ASSERT_EQ(1u, results.size());
264 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); 281 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]);
265 } 282 }
266 283
267 } // namespace password_manager 284 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/sync/browser/sync_credentials_filter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698