| 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 "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "chrome/browser/password_manager/password_store_factory.h" | 10 #include "chrome/browser/password_manager/password_store_factory.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 using autofill::PasswordForm; | 22 using autofill::PasswordForm; |
| 23 | 23 |
| 24 class PasswordsCounterTest : public InProcessBrowserTest { | 24 class PasswordsCounterTest : public InProcessBrowserTest { |
| 25 public: | 25 public: |
| 26 void SetUpOnMainThread() override { | 26 void SetUpOnMainThread() override { |
| 27 time_ = base::Time::Now(); | 27 time_ = base::Time::Now(); |
| 28 store_ = PasswordStoreFactory::GetForProfile( | 28 store_ = PasswordStoreFactory::GetForProfile( |
| 29 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); | 29 browser()->profile(), ServiceAccessType::IMPLICIT_ACCESS); |
| 30 SetPasswordsDeletionPref(true); | 30 SetPasswordsDeletionPref(true); |
| 31 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 31 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
| 32 } | 32 } |
| 33 | 33 |
| 34 void AddLogin(const std::string& origin, | 34 void AddLogin(const std::string& origin, |
| 35 const std::string& username, | 35 const std::string& username, |
| 36 bool blacklisted) { | 36 bool blacklisted) { |
| 37 // Add login and wait until the password store actually changes. | 37 // Add login and wait until the password store actually changes. |
| 38 // on the database thread. | 38 // on the database thread. |
| 39 passwords_helper::AddLogin( | 39 passwords_helper::AddLogin( |
| 40 store_.get(), CreateCredentials(origin, username, blacklisted)); | 40 store_.get(), CreateCredentials(origin, username, blacklisted)); |
| 41 } | 41 } |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 AddLogin("https://www.google.com", "user1", false); | 133 AddLogin("https://www.google.com", "user1", false); |
| 134 AddLogin("https://www.google.com", "user2", false); | 134 AddLogin("https://www.google.com", "user2", false); |
| 135 AddLogin("https://www.google.com", "user3", false); | 135 AddLogin("https://www.google.com", "user3", false); |
| 136 AddLogin("https://www.chrome.com", "user1", false); | 136 AddLogin("https://www.chrome.com", "user1", false); |
| 137 AddLogin("https://www.chrome.com", "user2", false); | 137 AddLogin("https://www.chrome.com", "user2", false); |
| 138 WaitForUICallbacksFromAddingLogins(); | 138 WaitForUICallbacksFromAddingLogins(); |
| 139 | 139 |
| 140 Profile* profile = browser()->profile(); | 140 Profile* profile = browser()->profile(); |
| 141 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 141 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 142 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 142 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 143 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 143 counter.Init( |
| 144 base::Unretained(this))); | 144 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 145 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
| 145 counter.Restart(); | 146 counter.Restart(); |
| 146 | 147 |
| 147 WaitForCounting(); | 148 WaitForCounting(); |
| 148 EXPECT_EQ(5u, GetResult()); | 149 EXPECT_EQ(5u, GetResult()); |
| 149 } | 150 } |
| 150 | 151 |
| 151 // Tests that the counter doesn't count blacklisted entries. | 152 // Tests that the counter doesn't count blacklisted entries. |
| 152 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { | 153 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { |
| 153 AddLogin("https://www.google.com", "user1", false); | 154 AddLogin("https://www.google.com", "user1", false); |
| 154 AddLogin("https://www.google.com", "user2", true); | 155 AddLogin("https://www.google.com", "user2", true); |
| 155 AddLogin("https://www.chrome.com", "user3", true); | 156 AddLogin("https://www.chrome.com", "user3", true); |
| 156 WaitForUICallbacksFromAddingLogins(); | 157 WaitForUICallbacksFromAddingLogins(); |
| 157 | 158 |
| 158 Profile* profile = browser()->profile(); | 159 Profile* profile = browser()->profile(); |
| 159 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 160 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 160 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 161 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 161 | 162 |
| 162 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 163 counter.Init( |
| 163 base::Unretained(this))); | 164 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 165 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
| 164 counter.Restart(); | 166 counter.Restart(); |
| 165 | 167 |
| 166 WaitForCounting(); | 168 WaitForCounting(); |
| 167 EXPECT_EQ(1u, GetResult()); | 169 EXPECT_EQ(1u, GetResult()); |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Tests that the counter starts counting automatically when the deletion | 172 // Tests that the counter starts counting automatically when the deletion |
| 171 // pref changes to true. | 173 // pref changes to true. |
| 172 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { | 174 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { |
| 173 SetPasswordsDeletionPref(false); | 175 SetPasswordsDeletionPref(false); |
| 174 AddLogin("https://www.google.com", "user", false); | 176 AddLogin("https://www.google.com", "user", false); |
| 175 AddLogin("https://www.chrome.com", "user", false); | 177 AddLogin("https://www.chrome.com", "user", false); |
| 176 WaitForUICallbacksFromAddingLogins(); | 178 WaitForUICallbacksFromAddingLogins(); |
| 177 | 179 |
| 178 Profile* profile = browser()->profile(); | 180 Profile* profile = browser()->profile(); |
| 179 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 181 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 180 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 182 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 181 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 183 counter.Init( |
| 182 base::Unretained(this))); | 184 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 185 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
| 183 SetPasswordsDeletionPref(true); | 186 SetPasswordsDeletionPref(true); |
| 184 | 187 |
| 185 WaitForCounting(); | 188 WaitForCounting(); |
| 186 EXPECT_EQ(2u, GetResult()); | 189 EXPECT_EQ(2u, GetResult()); |
| 187 } | 190 } |
| 188 | 191 |
| 189 // Tests that the counter starts counting automatically when | 192 // Tests that the counter starts counting automatically when |
| 190 // the password store changes. | 193 // the password store changes. |
| 191 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { | 194 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { |
| 192 AddLogin("https://www.google.com", "user", false); | 195 AddLogin("https://www.google.com", "user", false); |
| 193 WaitForUICallbacksFromAddingLogins(); | 196 WaitForUICallbacksFromAddingLogins(); |
| 194 | 197 |
| 195 Profile* profile = browser()->profile(); | 198 Profile* profile = browser()->profile(); |
| 196 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 199 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 197 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 200 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 198 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 201 counter.Init( |
| 199 base::Unretained(this))); | 202 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 203 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
| 200 counter.Restart(); | 204 counter.Restart(); |
| 201 | 205 |
| 202 WaitForCounting(); | 206 WaitForCounting(); |
| 203 EXPECT_EQ(1u, GetResult()); | 207 EXPECT_EQ(1u, GetResult()); |
| 204 | 208 |
| 205 AddLogin("https://www.chrome.com", "user", false); | 209 AddLogin("https://www.chrome.com", "user", false); |
| 206 WaitForCounting(); | 210 WaitForCounting(); |
| 207 EXPECT_EQ(2u, GetResult()); | 211 EXPECT_EQ(2u, GetResult()); |
| 208 | 212 |
| 209 RemoveLogin("https://www.chrome.com", "user", false); | 213 RemoveLogin("https://www.chrome.com", "user", false); |
| 210 WaitForCounting(); | 214 WaitForCounting(); |
| 211 EXPECT_EQ(1u, GetResult()); | 215 EXPECT_EQ(1u, GetResult()); |
| 212 } | 216 } |
| 213 | 217 |
| 214 // Tests that changing the deletion period restarts the counting, and that | 218 // Tests that changing the deletion period restarts the counting, and that |
| 215 // the result takes login creation dates into account. | 219 // the result takes login creation dates into account. |
| 216 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) { | 220 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PeriodChanged) { |
| 217 AddLogin("https://www.google.com", "user", false); | 221 AddLogin("https://www.google.com", "user", false); |
| 218 RevertTimeInDays(2); | 222 RevertTimeInDays(2); |
| 219 AddLogin("https://example.com", "user1", false); | 223 AddLogin("https://example.com", "user1", false); |
| 220 RevertTimeInDays(3); | 224 RevertTimeInDays(3); |
| 221 AddLogin("https://example.com", "user2", false); | 225 AddLogin("https://example.com", "user2", false); |
| 222 RevertTimeInDays(30); | 226 RevertTimeInDays(30); |
| 223 AddLogin("https://www.chrome.com", "user", false); | 227 AddLogin("https://www.chrome.com", "user", false); |
| 224 WaitForUICallbacksFromAddingLogins(); | 228 WaitForUICallbacksFromAddingLogins(); |
| 225 | 229 |
| 226 Profile* profile = browser()->profile(); | 230 Profile* profile = browser()->profile(); |
| 227 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 231 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 228 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 232 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 229 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 233 counter.Init( |
| 230 base::Unretained(this))); | 234 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
| 235 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
| 231 | 236 |
| 232 SetDeletionPeriodPref(browsing_data::LAST_HOUR); | 237 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR); |
| 233 WaitForCounting(); | 238 WaitForCounting(); |
| 234 EXPECT_EQ(1u, GetResult()); | 239 EXPECT_EQ(1u, GetResult()); |
| 235 | 240 |
| 236 SetDeletionPeriodPref(browsing_data::LAST_DAY); | 241 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY); |
| 237 WaitForCounting(); | 242 WaitForCounting(); |
| 238 EXPECT_EQ(1u, GetResult()); | 243 EXPECT_EQ(1u, GetResult()); |
| 239 | 244 |
| 240 SetDeletionPeriodPref(browsing_data::LAST_WEEK); | 245 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK); |
| 241 WaitForCounting(); | 246 WaitForCounting(); |
| 242 EXPECT_EQ(3u, GetResult()); | 247 EXPECT_EQ(3u, GetResult()); |
| 243 | 248 |
| 244 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 249 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS); |
| 245 WaitForCounting(); | 250 WaitForCounting(); |
| 246 EXPECT_EQ(3u, GetResult()); | 251 EXPECT_EQ(3u, GetResult()); |
| 247 | 252 |
| 248 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 253 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
| 249 WaitForCounting(); | 254 WaitForCounting(); |
| 250 EXPECT_EQ(4u, GetResult()); | 255 EXPECT_EQ(4u, GetResult()); |
| 251 } | 256 } |
| 252 | 257 |
| 253 } // namespace | 258 } // namespace |
| OLD | NEW |