OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browsing_data/core/counters/passwords_counter.h" | 5 #include "components/browsing_data/core/counters/passwords_counter.h" |
6 | 6 |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
10 #include "chrome/browser/sync/test/integration/passwords_helper.h" | 10 #include "chrome/browser/sync/test/integration/passwords_helper.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) { | 131 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) { |
132 AddLogin("https://www.google.com", "user1", false); | 132 AddLogin("https://www.google.com", "user1", false); |
133 AddLogin("https://www.google.com", "user2", false); | 133 AddLogin("https://www.google.com", "user2", false); |
134 AddLogin("https://www.google.com", "user3", false); | 134 AddLogin("https://www.google.com", "user3", false); |
135 AddLogin("https://www.chrome.com", "user1", false); | 135 AddLogin("https://www.chrome.com", "user1", false); |
136 AddLogin("https://www.chrome.com", "user2", false); | 136 AddLogin("https://www.chrome.com", "user2", false); |
137 | 137 |
138 Profile* profile = browser()->profile(); | 138 Profile* profile = browser()->profile(); |
139 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 139 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
140 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 140 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
141 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 141 counter.Init( |
142 base::Unretained(this))); | 142 profile->GetPrefs(), |
| 143 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 144 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
143 counter.Restart(); | 145 counter.Restart(); |
144 | 146 |
145 WaitForCounting(); | 147 WaitForCounting(); |
146 EXPECT_EQ(5u, GetResult()); | 148 EXPECT_EQ(5u, GetResult()); |
147 } | 149 } |
148 | 150 |
149 // Tests that the counter doesn't count blacklisted entries. | 151 // Tests that the counter doesn't count blacklisted entries. |
150 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { | 152 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { |
151 AddLogin("https://www.google.com", "user1", false); | 153 AddLogin("https://www.google.com", "user1", false); |
152 AddLogin("https://www.google.com", "user2", true); | 154 AddLogin("https://www.google.com", "user2", true); |
153 AddLogin("https://www.chrome.com", "user3", true); | 155 AddLogin("https://www.chrome.com", "user3", true); |
154 | 156 |
155 Profile* profile = browser()->profile(); | 157 Profile* profile = browser()->profile(); |
156 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 158 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
157 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 159 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
158 | 160 |
159 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 161 counter.Init( |
160 base::Unretained(this))); | 162 profile->GetPrefs(), |
| 163 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 164 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
161 counter.Restart(); | 165 counter.Restart(); |
162 | 166 |
163 WaitForCounting(); | 167 WaitForCounting(); |
164 EXPECT_EQ(1u, GetResult()); | 168 EXPECT_EQ(1u, GetResult()); |
165 } | 169 } |
166 | 170 |
167 // Tests that the counter starts counting automatically when the deletion | 171 // Tests that the counter starts counting automatically when the deletion |
168 // pref changes to true. | 172 // pref changes to true. |
169 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { | 173 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { |
170 SetPasswordsDeletionPref(false); | 174 SetPasswordsDeletionPref(false); |
171 AddLogin("https://www.google.com", "user", false); | 175 AddLogin("https://www.google.com", "user", false); |
172 AddLogin("https://www.chrome.com", "user", false); | 176 AddLogin("https://www.chrome.com", "user", false); |
173 | 177 |
174 Profile* profile = browser()->profile(); | 178 Profile* profile = browser()->profile(); |
175 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 179 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
176 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 180 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
177 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 181 counter.Init( |
178 base::Unretained(this))); | 182 profile->GetPrefs(), |
| 183 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 184 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
179 SetPasswordsDeletionPref(true); | 185 SetPasswordsDeletionPref(true); |
180 | 186 |
181 WaitForCounting(); | 187 WaitForCounting(); |
182 EXPECT_EQ(2u, GetResult()); | 188 EXPECT_EQ(2u, GetResult()); |
183 } | 189 } |
184 | 190 |
185 // Tests that the counter starts counting automatically when | 191 // Tests that the counter starts counting automatically when |
186 // the password store changes. | 192 // the password store changes. |
187 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { | 193 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { |
188 AddLogin("https://www.google.com", "user", false); | 194 AddLogin("https://www.google.com", "user", false); |
189 | 195 |
190 Profile* profile = browser()->profile(); | 196 Profile* profile = browser()->profile(); |
191 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 197 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
192 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 198 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
193 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 199 counter.Init( |
194 base::Unretained(this))); | 200 profile->GetPrefs(), |
| 201 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 202 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
195 counter.Restart(); | 203 counter.Restart(); |
196 | 204 |
197 WaitForCounting(); | 205 WaitForCounting(); |
198 EXPECT_EQ(1u, GetResult()); | 206 EXPECT_EQ(1u, GetResult()); |
199 | 207 |
200 AddLogin("https://www.chrome.com", "user", false); | 208 AddLogin("https://www.chrome.com", "user", false); |
201 WaitForCounting(); | 209 WaitForCounting(); |
202 EXPECT_EQ(2u, GetResult()); | 210 EXPECT_EQ(2u, GetResult()); |
203 | 211 |
204 RemoveLogin("https://www.chrome.com", "user", false); | 212 RemoveLogin("https://www.chrome.com", "user", false); |
205 WaitForCounting(); | 213 WaitForCounting(); |
206 EXPECT_EQ(1u, GetResult()); | 214 EXPECT_EQ(1u, GetResult()); |
207 } | 215 } |
208 | 216 |
209 // Tests that changing the deletion period restarts the counting, and that | 217 // Tests that changing the deletion period restarts the counting, and that |
210 // the result takes login creation dates into account. | 218 // the result takes login creation dates into account. |
211 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) { | 219 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) { |
212 AddLogin("https://www.google.com", "user", false); | 220 AddLogin("https://www.google.com", "user", false); |
213 RevertTimeInDays(2); | 221 RevertTimeInDays(2); |
214 AddLogin("https://example.com", "user1", false); | 222 AddLogin("https://example.com", "user1", false); |
215 RevertTimeInDays(3); | 223 RevertTimeInDays(3); |
216 AddLogin("https://example.com", "user2", false); | 224 AddLogin("https://example.com", "user2", false); |
217 RevertTimeInDays(30); | 225 RevertTimeInDays(30); |
218 AddLogin("https://www.chrome.com", "user", false); | 226 AddLogin("https://www.chrome.com", "user", false); |
219 | 227 |
220 Profile* profile = browser()->profile(); | 228 Profile* profile = browser()->profile(); |
221 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 229 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
222 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 230 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
223 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 231 counter.Init( |
224 base::Unretained(this))); | 232 profile->GetPrefs(), |
| 233 browsing_data::ClearBrowsingDataPreferenceType::DEFAULT, |
| 234 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
225 | 235 |
226 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 236 SetDeletionPeriodPref(browsing_data::LAST_HOUR); |
227 WaitForCounting(); | 237 WaitForCounting(); |
228 EXPECT_EQ(1u, GetResult()); | 238 EXPECT_EQ(1u, GetResult()); |
229 | 239 |
230 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 240 SetDeletionPeriodPref(browsing_data::LAST_DAY); |
231 WaitForCounting(); | 241 WaitForCounting(); |
232 EXPECT_EQ(1u, GetResult()); | 242 EXPECT_EQ(1u, GetResult()); |
233 | 243 |
234 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 244 SetDeletionPeriodPref(browsing_data::LAST_WEEK); |
235 WaitForCounting(); | 245 WaitForCounting(); |
236 EXPECT_EQ(3u, GetResult()); | 246 EXPECT_EQ(3u, GetResult()); |
237 | 247 |
238 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 248 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
239 WaitForCounting(); | 249 WaitForCounting(); |
240 EXPECT_EQ(3u, GetResult()); | 250 EXPECT_EQ(3u, GetResult()); |
241 | 251 |
242 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 252 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
243 WaitForCounting(); | 253 WaitForCounting(); |
244 EXPECT_EQ(4u, GetResult()); | 254 EXPECT_EQ(4u, GetResult()); |
245 } | 255 } |
246 | 256 |
247 } // namespace | 257 } // namespace |
OLD | NEW |