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

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, 10 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 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/command_line.h"
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
15 #include "base/test/user_action_tester.h" 14 #include "base/test/user_action_tester.h"
16 #include "components/autofill/core/common/password_form.h" 15 #include "components/autofill/core/common/password_form.h"
17 #include "components/password_manager/core/browser/stub_password_manager_client. h" 16 #include "components/password_manager/core/browser/stub_password_manager_client. h"
18 #include "components/password_manager/core/common/password_manager_switches.h" 17 #include "components/password_manager/core/common/password_manager_features.h"
19 #include "components/password_manager/sync/browser/sync_username_test_base.h" 18 #include "components/password_manager/sync/browser/sync_username_test_base.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 20
22 using autofill::PasswordForm; 21 using autofill::PasswordForm;
23 22
24 namespace password_manager { 23 namespace password_manager {
25 24
26 namespace { 25 namespace {
27 26
28 class FakePasswordManagerClient : public StubPasswordManagerClient { 27 class FakePasswordManagerClient : public StubPasswordManagerClient {
(...skipping 12 matching lines...) Expand all
41 GURL last_committed_entry_url_; 40 GURL last_committed_entry_url_;
42 }; 41 };
43 42
44 bool IsFormFiltered(const CredentialsFilter* filter, const PasswordForm& form) { 43 bool IsFormFiltered(const CredentialsFilter* filter, const PasswordForm& form) {
45 ScopedVector<PasswordForm> vector; 44 ScopedVector<PasswordForm> vector;
46 vector.push_back(new PasswordForm(form)); 45 vector.push_back(new PasswordForm(form));
47 vector = filter->FilterResults(std::move(vector)); 46 vector = filter->FilterResults(std::move(vector));
48 return vector.empty(); 47 return vector.empty();
49 } 48 }
50 49
50 void EnableFeature(const base::Feature& feature) {
vabr (Chromium) 2016/02/08 14:16:49 optional: Instead of duplicating it here and in th
Pritam Nikam 2016/02/08 15:27:19 Done.
51 // Enable the command-line feature.
52 base::FeatureList::ClearInstanceForTesting();
53 scoped_ptr<base::FeatureList> feature_list(new base::FeatureList);
54 feature_list->InitializeFromCommandLine(feature.name, "");
55 base::FeatureList::SetInstance(std::move(feature_list));
56 }
57
51 } // namespace 58 } // namespace
52 59
53 class CredentialsFilterTest : public SyncUsernameTestBase { 60 class CredentialsFilterTest : public SyncUsernameTestBase {
54 public: 61 public:
55 struct TestCase { 62 struct TestCase {
56 enum { SYNCING_PASSWORDS, NOT_SYNCING_PASSWORDS } password_sync; 63 enum { SYNCING_PASSWORDS, NOT_SYNCING_PASSWORDS } password_sync;
57 PasswordForm form; 64 PasswordForm form;
58 std::string fake_sync_username; 65 std::string fake_sync_username;
59 const char* const last_committed_entry_url; 66 const char* const last_committed_entry_url;
60 enum { FORM_FILTERED, FORM_NOT_FILTERED } is_form_filtered; 67 enum { FORM_FILTERED, FORM_NOT_FILTERED } is_form_filtered;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, 135 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM},
129 }; 136 };
130 137
131 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 138 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
132 SCOPED_TRACE(testing::Message() << "i=" << i); 139 SCOPED_TRACE(testing::Message() << "i=" << i);
133 CheckFilterResultsTestCase(kTestCases[i]); 140 CheckFilterResultsTestCase(kTestCases[i]);
134 } 141 }
135 } 142 }
136 143
137 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) { 144 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) {
138 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 145 EnableFeature(features::kDisallowAutofillSyncCredentialForReauth);
139 command_line->AppendSwitch(
140 switches::kDisallowAutofillSyncCredentialForReauth);
141 146
142 const TestCase kTestCases[] = { 147 const TestCase kTestCases[] = {
143 // Reauth URL, not sync username. 148 // Reauth URL, not sync username.
144 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 149 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
145 "another_user@example.org", 150 "another_user@example.org",
146 "https://accounts.google.com/login?rart=123&continue=blah", 151 "https://accounts.google.com/login?rart=123&continue=blah",
147 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, 152 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED},
148 153
149 // Reauth URL, sync username. 154 // Reauth URL, sync username.
150 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 155 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
(...skipping 18 matching lines...) Expand all
169 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, 174 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM},
170 }; 175 };
171 176
172 for (size_t i = 0; i < arraysize(kTestCases); ++i) { 177 for (size_t i = 0; i < arraysize(kTestCases); ++i) {
173 SCOPED_TRACE(testing::Message() << "i=" << i); 178 SCOPED_TRACE(testing::Message() << "i=" << i);
174 CheckFilterResultsTestCase(kTestCases[i]); 179 CheckFilterResultsTestCase(kTestCases[i]);
175 } 180 }
176 } 181 }
177 182
178 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) { 183 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) {
179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 184 EnableFeature(features::kDisallowAutofillSyncCredential);
180 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential);
181 185
182 const TestCase kTestCases[] = { 186 const TestCase kTestCases[] = {
183 // Reauth URL, not sync username. 187 // Reauth URL, not sync username.
184 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 188 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
185 "another_user@example.org", 189 "another_user@example.org",
186 "https://accounts.google.com/login?rart=123&continue=blah", 190 "https://accounts.google.com/login?rart=123&continue=blah",
187 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, 191 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED},
188 192
189 // Reauth URL, sync username. 193 // Reauth URL, sync username.
190 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), 194 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) { 246 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) {
243 PasswordForm form = SimpleGaiaForm("user@example.org"); 247 PasswordForm form = SimpleGaiaForm("user@example.org");
244 248
245 FakeSigninAs("user@example.org"); 249 FakeSigninAs("user@example.org");
246 SetSyncingPasswords(false); 250 SetSyncingPasswords(false);
247 EXPECT_TRUE(filter()->ShouldSave(form)); 251 EXPECT_TRUE(filter()->ShouldSave(form));
248 } 252 }
249 253
250 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) { 254 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) {
251 // Adding disallow switch should cause sync credential to be filtered. 255 // Adding disallow switch should cause sync credential to be filtered.
252 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 256 EnableFeature(features::kDisallowAutofillSyncCredential);
253 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential);
254 257
255 ScopedVector<autofill::PasswordForm> results; 258 ScopedVector<autofill::PasswordForm> results;
256 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com"))); 259 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com")));
257 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com"))); 260 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com")));
258 261
259 FakeSigninAs("test1@gmail.com"); 262 FakeSigninAs("test1@gmail.com");
260 263
261 results = filter()->FilterResults(std::move(results)); 264 results = filter()->FilterResults(std::move(results));
262 265
263 ASSERT_EQ(1u, results.size()); 266 ASSERT_EQ(1u, results.size());
264 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); 267 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]);
265 } 268 }
266 269
267 } // namespace password_manager 270 } // 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