OLD | NEW |
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" |
| 16 #include "components/password_manager/core/browser/password_manager_test_utils.h
" |
17 #include "components/password_manager/core/browser/stub_password_manager_client.
h" | 17 #include "components/password_manager/core/browser/stub_password_manager_client.
h" |
18 #include "components/password_manager/core/common/password_manager_switches.h" | 18 #include "components/password_manager/core/common/password_manager_features.h" |
19 #include "components/password_manager/sync/browser/sync_username_test_base.h" | 19 #include "components/password_manager/sync/browser/sync_username_test_base.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 using autofill::PasswordForm; | 22 using autofill::PasswordForm; |
23 | 23 |
24 namespace password_manager { | 24 namespace password_manager { |
25 | 25 |
26 namespace { | 26 namespace { |
27 | 27 |
28 class FakePasswordManagerClient : public StubPasswordManagerClient { | 28 class FakePasswordManagerClient : public StubPasswordManagerClient { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, | 128 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, |
129 }; | 129 }; |
130 | 130 |
131 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 131 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
132 SCOPED_TRACE(testing::Message() << "i=" << i); | 132 SCOPED_TRACE(testing::Message() << "i=" << i); |
133 CheckFilterResultsTestCase(kTestCases[i]); | 133 CheckFilterResultsTestCase(kTestCases[i]); |
134 } | 134 } |
135 } | 135 } |
136 | 136 |
137 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) { | 137 TEST_F(CredentialsFilterTest, FilterResults_DisallowSyncOnReauth) { |
138 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 138 // Only 'protect-sync-credential-on-reauth' feature is kept enabled, fill the |
139 command_line->AppendSwitch( | 139 // sync credential everywhere but on reauth. |
140 switches::kDisallowAutofillSyncCredentialForReauth); | 140 EnableFeature(features::kProtectSyncCredential, false, false); |
| 141 EnableFeature(features::kProtectSyncCredentialOnReauth, true, true); |
141 | 142 |
142 const TestCase kTestCases[] = { | 143 const TestCase kTestCases[] = { |
143 // Reauth URL, not sync username. | 144 // Reauth URL, not sync username. |
144 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), | 145 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), |
145 "another_user@example.org", | 146 "another_user@example.org", |
146 "https://accounts.google.com/login?rart=123&continue=blah", | 147 "https://accounts.google.com/login?rart=123&continue=blah", |
147 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, | 148 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, |
148 | 149 |
149 // Reauth URL, sync username. | 150 // Reauth URL, sync username. |
150 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), | 151 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), |
(...skipping 18 matching lines...) Expand all Loading... |
169 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, | 170 TestCase::FORM_NOT_FILTERED, TestCase::NO_HISTOGRAM}, |
170 }; | 171 }; |
171 | 172 |
172 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 173 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
173 SCOPED_TRACE(testing::Message() << "i=" << i); | 174 SCOPED_TRACE(testing::Message() << "i=" << i); |
174 CheckFilterResultsTestCase(kTestCases[i]); | 175 CheckFilterResultsTestCase(kTestCases[i]); |
175 } | 176 } |
176 } | 177 } |
177 | 178 |
178 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) { | 179 TEST_F(CredentialsFilterTest, FilterResults_DisallowSync) { |
179 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 180 // Both features are kept enabled, should cause sync credential to be |
180 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential); | 181 // filtered. |
| 182 EnableFeature(features::kProtectSyncCredential, true, false); |
| 183 EnableFeature(features::kProtectSyncCredentialOnReauth, true, true); |
181 | 184 |
182 const TestCase kTestCases[] = { | 185 const TestCase kTestCases[] = { |
183 // Reauth URL, not sync username. | 186 // Reauth URL, not sync username. |
184 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), | 187 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), |
185 "another_user@example.org", | 188 "another_user@example.org", |
186 "https://accounts.google.com/login?rart=123&continue=blah", | 189 "https://accounts.google.com/login?rart=123&continue=blah", |
187 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, | 190 TestCase::FORM_NOT_FILTERED, TestCase::HISTOGRAM_REPORTED}, |
188 | 191 |
189 // Reauth URL, sync username. | 192 // Reauth URL, sync username. |
190 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), | 193 {TestCase::SYNCING_PASSWORDS, SimpleGaiaForm("user@example.org"), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 244 |
242 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) { | 245 TEST_F(CredentialsFilterTest, ShouldSave_SyncCredential_NotSyncingPasswords) { |
243 PasswordForm form = SimpleGaiaForm("user@example.org"); | 246 PasswordForm form = SimpleGaiaForm("user@example.org"); |
244 | 247 |
245 FakeSigninAs("user@example.org"); | 248 FakeSigninAs("user@example.org"); |
246 SetSyncingPasswords(false); | 249 SetSyncingPasswords(false); |
247 EXPECT_TRUE(filter()->ShouldSave(form)); | 250 EXPECT_TRUE(filter()->ShouldSave(form)); |
248 } | 251 } |
249 | 252 |
250 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) { | 253 TEST_F(CredentialsFilterTest, ShouldFilterOneForm) { |
251 // Adding disallow switch should cause sync credential to be filtered. | 254 // Both features are kept enabled, should cause sync credential to be |
252 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 255 // filtered. |
253 command_line->AppendSwitch(switches::kDisallowAutofillSyncCredential); | 256 EnableFeature(features::kProtectSyncCredential, true, false); |
| 257 EnableFeature(features::kProtectSyncCredentialOnReauth, true, true); |
254 | 258 |
255 ScopedVector<autofill::PasswordForm> results; | 259 ScopedVector<autofill::PasswordForm> results; |
256 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com"))); | 260 results.push_back(new PasswordForm(SimpleGaiaForm("test1@gmail.com"))); |
257 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com"))); | 261 results.push_back(new PasswordForm(SimpleGaiaForm("test2@gmail.com"))); |
258 | 262 |
259 FakeSigninAs("test1@gmail.com"); | 263 FakeSigninAs("test1@gmail.com"); |
260 | 264 |
261 results = filter()->FilterResults(std::move(results)); | 265 results = filter()->FilterResults(std::move(results)); |
262 | 266 |
263 ASSERT_EQ(1u, results.size()); | 267 ASSERT_EQ(1u, results.size()); |
264 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); | 268 EXPECT_EQ(SimpleGaiaForm("test2@gmail.com"), *results[0]); |
265 } | 269 } |
266 | 270 |
267 } // namespace password_manager | 271 } // namespace password_manager |
OLD | NEW |