| 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 "chrome/browser/browsing_data/passwords_counter.h" | 5 #include "chrome/browser/browsing_data/passwords_counter.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/password_manager/password_store_factory.h" | 10 #include "chrome/browser/password_manager/password_store_factory.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 AddLogin("https://www.google.com", "user1", false); | 123 AddLogin("https://www.google.com", "user1", false); |
| 124 AddLogin("https://www.google.com", "user2", false); | 124 AddLogin("https://www.google.com", "user2", false); |
| 125 AddLogin("https://www.google.com", "user3", false); | 125 AddLogin("https://www.google.com", "user3", false); |
| 126 AddLogin("https://www.chrome.com", "user1", false); | 126 AddLogin("https://www.chrome.com", "user1", false); |
| 127 AddLogin("https://www.chrome.com", "user2", false); | 127 AddLogin("https://www.chrome.com", "user2", false); |
| 128 | 128 |
| 129 PasswordsCounter counter; | 129 PasswordsCounter counter; |
| 130 counter.Init(browser()->profile(), | 130 counter.Init(browser()->profile(), |
| 131 base::Bind(&PasswordsCounterTest::Callback, | 131 base::Bind(&PasswordsCounterTest::Callback, |
| 132 base::Unretained(this))); | 132 base::Unretained(this))); |
| 133 counter.Restart(); |
| 133 | 134 |
| 134 WaitForCounting(); | 135 WaitForCounting(); |
| 135 EXPECT_EQ(5u, GetResult()); | 136 EXPECT_EQ(5u, GetResult()); |
| 136 } | 137 } |
| 137 | 138 |
| 138 // Tests that the counter doesn't count blacklisted entries. | 139 // Tests that the counter doesn't count blacklisted entries. |
| 139 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { | 140 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { |
| 140 AddLogin("https://www.google.com", "user1", false); | 141 AddLogin("https://www.google.com", "user1", false); |
| 141 AddLogin("https://www.google.com", "user2", true); | 142 AddLogin("https://www.google.com", "user2", true); |
| 142 AddLogin("https://www.chrome.com", "user3", true); | 143 AddLogin("https://www.chrome.com", "user3", true); |
| 143 | 144 |
| 144 PasswordsCounter counter; | 145 PasswordsCounter counter; |
| 145 counter.Init(browser()->profile(), | 146 counter.Init(browser()->profile(), |
| 146 base::Bind(&PasswordsCounterTest::Callback, | 147 base::Bind(&PasswordsCounterTest::Callback, |
| 147 base::Unretained(this))); | 148 base::Unretained(this))); |
| 149 counter.Restart(); |
| 148 | 150 |
| 149 WaitForCounting(); | 151 WaitForCounting(); |
| 150 EXPECT_EQ(1u, GetResult()); | 152 EXPECT_EQ(1u, GetResult()); |
| 151 } | 153 } |
| 152 | 154 |
| 153 // Tests that the counter starts counting automatically when the deletion | 155 // Tests that the counter starts counting automatically when the deletion |
| 154 // pref changes to true. | 156 // pref changes to true. |
| 155 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { | 157 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { |
| 156 SetPasswordsDeletionPref(false); | 158 SetPasswordsDeletionPref(false); |
| 157 AddLogin("https://www.google.com", "user", false); | 159 AddLogin("https://www.google.com", "user", false); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 170 // Tests that the counter does not count passwords if the deletion | 172 // Tests that the counter does not count passwords if the deletion |
| 171 // preference is false. | 173 // preference is false. |
| 172 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefIsFalse) { | 174 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefIsFalse) { |
| 173 SetPasswordsDeletionPref(false); | 175 SetPasswordsDeletionPref(false); |
| 174 AddLogin("https://www.google.com", "user", false); | 176 AddLogin("https://www.google.com", "user", false); |
| 175 | 177 |
| 176 PasswordsCounter counter; | 178 PasswordsCounter counter; |
| 177 counter.Init(browser()->profile(), | 179 counter.Init(browser()->profile(), |
| 178 base::Bind(&PasswordsCounterTest::Callback, | 180 base::Bind(&PasswordsCounterTest::Callback, |
| 179 base::Unretained(this))); | 181 base::Unretained(this))); |
| 182 counter.Restart(); |
| 180 | 183 |
| 181 EXPECT_FALSE(counter.cancelable_task_tracker()->HasTrackedTasks()); | 184 EXPECT_FALSE(counter.cancelable_task_tracker()->HasTrackedTasks()); |
| 182 } | 185 } |
| 183 | 186 |
| 184 // Tests that the counter starts counting automatically when | 187 // Tests that the counter starts counting automatically when |
| 185 // the password store changes. | 188 // the password store changes. |
| 186 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { | 189 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { |
| 187 AddLogin("https://www.google.com", "user", false); | 190 AddLogin("https://www.google.com", "user", false); |
| 188 | 191 |
| 189 PasswordsCounter counter; | 192 PasswordsCounter counter; |
| 190 counter.Init(browser()->profile(), | 193 counter.Init(browser()->profile(), |
| 191 base::Bind(&PasswordsCounterTest::Callback, | 194 base::Bind(&PasswordsCounterTest::Callback, |
| 192 base::Unretained(this))); | 195 base::Unretained(this))); |
| 196 counter.Restart(); |
| 193 | 197 |
| 194 WaitForCounting(); | 198 WaitForCounting(); |
| 195 EXPECT_EQ(1u, GetResult()); | 199 EXPECT_EQ(1u, GetResult()); |
| 196 | 200 |
| 197 AddLogin("https://www.chrome.com", "user", false); | 201 AddLogin("https://www.chrome.com", "user", false); |
| 198 WaitForCounting(); | 202 WaitForCounting(); |
| 199 EXPECT_EQ(2u, GetResult()); | 203 EXPECT_EQ(2u, GetResult()); |
| 200 | 204 |
| 201 RemoveLogin("https://www.chrome.com", "user", false); | 205 RemoveLogin("https://www.chrome.com", "user", false); |
| 202 WaitForCounting(); | 206 WaitForCounting(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 SetDeletionPeriodPref(BrowsingDataRemover::FOUR_WEEKS); | 238 SetDeletionPeriodPref(BrowsingDataRemover::FOUR_WEEKS); |
| 235 WaitForCounting(); | 239 WaitForCounting(); |
| 236 EXPECT_EQ(3u, GetResult()); | 240 EXPECT_EQ(3u, GetResult()); |
| 237 | 241 |
| 238 SetDeletionPeriodPref(BrowsingDataRemover::EVERYTHING); | 242 SetDeletionPeriodPref(BrowsingDataRemover::EVERYTHING); |
| 239 WaitForCounting(); | 243 WaitForCounting(); |
| 240 EXPECT_EQ(4u, GetResult()); | 244 EXPECT_EQ(4u, GetResult()); |
| 241 } | 245 } |
| 242 | 246 |
| 243 } // namespace | 247 } // namespace |
| OLD | NEW |