| 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 175 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 176 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 176 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 177 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 177 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, |
| 178 base::Unretained(this))); | 178 base::Unretained(this))); |
| 179 SetPasswordsDeletionPref(true); | 179 SetPasswordsDeletionPref(true); |
| 180 | 180 |
| 181 WaitForCounting(); | 181 WaitForCounting(); |
| 182 EXPECT_EQ(2u, GetResult()); | 182 EXPECT_EQ(2u, GetResult()); |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Tests that the counter does not count passwords if the deletion | |
| 186 // preference is false. | |
| 187 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefIsFalse) { | |
| 188 SetPasswordsDeletionPref(false); | |
| 189 AddLogin("https://www.google.com", "user", false); | |
| 190 | |
| 191 Profile* profile = browser()->profile(); | |
| 192 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | |
| 193 profile, ServiceAccessType::EXPLICIT_ACCESS)); | |
| 194 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | |
| 195 base::Unretained(this))); | |
| 196 counter.Restart(); | |
| 197 | |
| 198 EXPECT_FALSE(counter.cancelable_task_tracker()->HasTrackedTasks()); | |
| 199 } | |
| 200 | |
| 201 // Tests that the counter starts counting automatically when | 185 // Tests that the counter starts counting automatically when |
| 202 // the password store changes. | 186 // the password store changes. |
| 203 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { | 187 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { |
| 204 AddLogin("https://www.google.com", "user", false); | 188 AddLogin("https://www.google.com", "user", false); |
| 205 | 189 |
| 206 Profile* profile = browser()->profile(); | 190 Profile* profile = browser()->profile(); |
| 207 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 191 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( |
| 208 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 192 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
| 209 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, | 193 counter.Init(profile->GetPrefs(), base::Bind(&PasswordsCounterTest::Callback, |
| 210 base::Unretained(this))); | 194 base::Unretained(this))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); | 238 SetDeletionPeriodPref(browsing_data::FOUR_WEEKS); |
| 255 WaitForCounting(); | 239 WaitForCounting(); |
| 256 EXPECT_EQ(3u, GetResult()); | 240 EXPECT_EQ(3u, GetResult()); |
| 257 | 241 |
| 258 SetDeletionPeriodPref(browsing_data::ALL_TIME); | 242 SetDeletionPeriodPref(browsing_data::ALL_TIME); |
| 259 WaitForCounting(); | 243 WaitForCounting(); |
| 260 EXPECT_EQ(4u, GetResult()); | 244 EXPECT_EQ(4u, GetResult()); |
| 261 } | 245 } |
| 262 | 246 |
| 263 } // namespace | 247 } // namespace |
| OLD | NEW |