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" |
| 11 #include "chrome/browser/sync/profile_sync_service_factory.h" |
11 #include "chrome/browser/sync/test/integration/passwords_helper.h" | 12 #include "chrome/browser/sync/test/integration/passwords_helper.h" |
12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
14 #include "components/autofill/core/common/password_form.h" | 15 #include "components/autofill/core/common/password_form.h" |
| 16 #include "components/browser_sync/profile_sync_service_mock.h" |
15 #include "components/browsing_data/core/browsing_data_utils.h" | 17 #include "components/browsing_data/core/browsing_data_utils.h" |
16 #include "components/browsing_data/core/pref_names.h" | 18 #include "components/browsing_data/core/pref_names.h" |
17 #include "components/prefs/pref_service.h" | 19 #include "components/prefs/pref_service.h" |
18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
19 | 21 |
20 namespace { | 22 namespace { |
21 | 23 |
22 using autofill::PasswordForm; | 24 using autofill::PasswordForm; |
23 | 25 |
24 class PasswordsCounterTest : public InProcessBrowserTest { | 26 class PasswordsCounterTest : public InProcessBrowserTest { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // we get a finished result. | 79 // we get a finished result. |
78 run_loop_.reset(new base::RunLoop()); | 80 run_loop_.reset(new base::RunLoop()); |
79 run_loop_->Run(); | 81 run_loop_->Run(); |
80 } | 82 } |
81 | 83 |
82 browsing_data::BrowsingDataCounter::ResultInt GetResult() { | 84 browsing_data::BrowsingDataCounter::ResultInt GetResult() { |
83 DCHECK(finished_); | 85 DCHECK(finished_); |
84 return result_; | 86 return result_; |
85 } | 87 } |
86 | 88 |
| 89 bool HasSyncedPasswords() { |
| 90 DCHECK(finished_); |
| 91 return has_synced_passwords_; |
| 92 } |
| 93 |
87 void Callback( | 94 void Callback( |
88 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { | 95 std::unique_ptr<browsing_data::BrowsingDataCounter::Result> result) { |
89 finished_ = result->Finished(); | 96 finished_ = result->Finished(); |
90 | 97 |
91 if (finished_) { | 98 if (finished_) { |
92 result_ = | 99 auto* password_result = |
93 static_cast<browsing_data::BrowsingDataCounter::FinishedResult*>( | 100 static_cast<browsing_data::PasswordsCounter::PasswordResult*>( |
94 result.get()) | 101 result.get()); |
95 ->Value(); | 102 result_ = password_result->Value(); |
| 103 has_synced_passwords_ = password_result->has_synced_passwords(); |
96 } | 104 } |
97 | 105 |
98 if (finished_) | 106 if (finished_) |
99 run_loop_->Quit(); | 107 run_loop_->Quit(); |
100 } | 108 } |
101 | 109 |
102 void WaitForUICallbacksFromAddingLogins() { | 110 void WaitForUICallbacksFromAddingLogins() { |
103 base::RunLoop loop; | 111 base::RunLoop loop; |
104 loop.RunUntilIdle(); | 112 loop.RunUntilIdle(); |
105 } | 113 } |
(...skipping 12 matching lines...) Expand all Loading... |
118 return result; | 126 return result; |
119 } | 127 } |
120 | 128 |
121 scoped_refptr<password_manager::PasswordStore> store_; | 129 scoped_refptr<password_manager::PasswordStore> store_; |
122 | 130 |
123 std::unique_ptr<base::RunLoop> run_loop_; | 131 std::unique_ptr<base::RunLoop> run_loop_; |
124 base::Time time_; | 132 base::Time time_; |
125 | 133 |
126 bool finished_; | 134 bool finished_; |
127 browsing_data::BrowsingDataCounter::ResultInt result_; | 135 browsing_data::BrowsingDataCounter::ResultInt result_; |
| 136 bool has_synced_passwords_; |
128 }; | 137 }; |
129 | 138 |
130 // Tests that the counter correctly counts each individual credential on | 139 // Tests that the counter correctly counts each individual credential on |
131 // the same domain. | 140 // the same domain. |
132 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) { | 141 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, SameDomain) { |
133 AddLogin("https://www.google.com", "user1", false); | 142 AddLogin("https://www.google.com", "user1", false); |
134 AddLogin("https://www.google.com", "user2", false); | 143 AddLogin("https://www.google.com", "user2", false); |
135 AddLogin("https://www.google.com", "user3", false); | 144 AddLogin("https://www.google.com", "user3", false); |
136 AddLogin("https://www.chrome.com", "user1", false); | 145 AddLogin("https://www.chrome.com", "user1", false); |
137 AddLogin("https://www.chrome.com", "user2", false); | 146 AddLogin("https://www.chrome.com", "user2", false); |
138 WaitForUICallbacksFromAddingLogins(); | 147 WaitForUICallbacksFromAddingLogins(); |
139 | 148 |
140 Profile* profile = browser()->profile(); | 149 Profile* profile = browser()->profile(); |
141 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 150 browsing_data::PasswordsCounter counter( |
142 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 151 PasswordStoreFactory::GetForProfile(profile, |
| 152 ServiceAccessType::EXPLICIT_ACCESS), |
| 153 ProfileSyncServiceFactory::GetForProfile(profile)); |
143 counter.Init( | 154 counter.Init( |
144 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 155 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
145 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); | 156 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
146 counter.Restart(); | 157 counter.Restart(); |
147 | 158 |
148 WaitForCounting(); | 159 WaitForCounting(); |
149 EXPECT_EQ(5u, GetResult()); | 160 EXPECT_EQ(5u, GetResult()); |
| 161 EXPECT_EQ(false, HasSyncedPasswords()); |
150 } | 162 } |
151 | 163 |
152 // Tests that the counter doesn't count blacklisted entries. | 164 // Tests that the counter doesn't count blacklisted entries. |
153 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { | 165 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, Blacklisted) { |
154 AddLogin("https://www.google.com", "user1", false); | 166 AddLogin("https://www.google.com", "user1", false); |
155 AddLogin("https://www.google.com", "user2", true); | 167 AddLogin("https://www.google.com", "user2", true); |
156 AddLogin("https://www.chrome.com", "user3", true); | 168 AddLogin("https://www.chrome.com", "user3", true); |
157 WaitForUICallbacksFromAddingLogins(); | 169 WaitForUICallbacksFromAddingLogins(); |
158 | 170 |
159 Profile* profile = browser()->profile(); | 171 Profile* profile = browser()->profile(); |
160 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 172 browsing_data::PasswordsCounter counter( |
161 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 173 PasswordStoreFactory::GetForProfile(profile, |
| 174 ServiceAccessType::EXPLICIT_ACCESS), |
| 175 ProfileSyncServiceFactory::GetForProfile(profile)); |
162 | 176 |
163 counter.Init( | 177 counter.Init( |
164 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 178 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
165 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); | 179 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
166 counter.Restart(); | 180 counter.Restart(); |
167 | 181 |
168 WaitForCounting(); | 182 WaitForCounting(); |
169 EXPECT_EQ(1u, GetResult()); | 183 EXPECT_EQ(1u, GetResult()); |
| 184 EXPECT_EQ(false, HasSyncedPasswords()); |
170 } | 185 } |
171 | 186 |
172 // Tests that the counter starts counting automatically when the deletion | 187 // Tests that the counter starts counting automatically when the deletion |
173 // pref changes to true. | 188 // pref changes to true. |
174 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { | 189 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, PrefChanged) { |
175 SetPasswordsDeletionPref(false); | 190 SetPasswordsDeletionPref(false); |
176 AddLogin("https://www.google.com", "user", false); | 191 AddLogin("https://www.google.com", "user", false); |
177 AddLogin("https://www.chrome.com", "user", false); | 192 AddLogin("https://www.chrome.com", "user", false); |
178 WaitForUICallbacksFromAddingLogins(); | 193 WaitForUICallbacksFromAddingLogins(); |
179 | 194 |
180 Profile* profile = browser()->profile(); | 195 Profile* profile = browser()->profile(); |
181 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 196 browsing_data::PasswordsCounter counter( |
182 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 197 PasswordStoreFactory::GetForProfile(profile, |
| 198 ServiceAccessType::EXPLICIT_ACCESS), |
| 199 ProfileSyncServiceFactory::GetForProfile(profile)); |
183 counter.Init( | 200 counter.Init( |
184 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 201 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
185 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); | 202 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
186 SetPasswordsDeletionPref(true); | 203 SetPasswordsDeletionPref(true); |
187 | 204 |
188 WaitForCounting(); | 205 WaitForCounting(); |
189 EXPECT_EQ(2u, GetResult()); | 206 EXPECT_EQ(2u, GetResult()); |
| 207 EXPECT_EQ(false, HasSyncedPasswords()); |
190 } | 208 } |
191 | 209 |
192 // Tests that the counter starts counting automatically when | 210 // Tests that the counter starts counting automatically when |
193 // the password store changes. | 211 // the password store changes. |
194 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { | 212 IN_PROC_BROWSER_TEST_F(PasswordsCounterTest, StoreChanged) { |
195 AddLogin("https://www.google.com", "user", false); | 213 AddLogin("https://www.google.com", "user", false); |
196 WaitForUICallbacksFromAddingLogins(); | 214 WaitForUICallbacksFromAddingLogins(); |
197 | 215 |
198 Profile* profile = browser()->profile(); | 216 Profile* profile = browser()->profile(); |
199 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 217 browsing_data::PasswordsCounter counter( |
200 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 218 PasswordStoreFactory::GetForProfile(profile, |
| 219 ServiceAccessType::EXPLICIT_ACCESS), |
| 220 ProfileSyncServiceFactory::GetForProfile(profile)); |
201 counter.Init( | 221 counter.Init( |
202 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 222 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
203 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); | 223 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
204 counter.Restart(); | 224 counter.Restart(); |
205 | 225 |
206 WaitForCounting(); | 226 WaitForCounting(); |
207 EXPECT_EQ(1u, GetResult()); | 227 EXPECT_EQ(1u, GetResult()); |
208 | 228 |
209 AddLogin("https://www.chrome.com", "user", false); | 229 AddLogin("https://www.chrome.com", "user", false); |
210 WaitForCounting(); | 230 WaitForCounting(); |
(...skipping 10 matching lines...) Expand all Loading... |
221 AddLogin("https://www.google.com", "user", false); | 241 AddLogin("https://www.google.com", "user", false); |
222 RevertTimeInDays(2); | 242 RevertTimeInDays(2); |
223 AddLogin("https://example.com", "user1", false); | 243 AddLogin("https://example.com", "user1", false); |
224 RevertTimeInDays(3); | 244 RevertTimeInDays(3); |
225 AddLogin("https://example.com", "user2", false); | 245 AddLogin("https://example.com", "user2", false); |
226 RevertTimeInDays(30); | 246 RevertTimeInDays(30); |
227 AddLogin("https://www.chrome.com", "user", false); | 247 AddLogin("https://www.chrome.com", "user", false); |
228 WaitForUICallbacksFromAddingLogins(); | 248 WaitForUICallbacksFromAddingLogins(); |
229 | 249 |
230 Profile* profile = browser()->profile(); | 250 Profile* profile = browser()->profile(); |
231 browsing_data::PasswordsCounter counter(PasswordStoreFactory::GetForProfile( | 251 browsing_data::PasswordsCounter counter( |
232 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 252 PasswordStoreFactory::GetForProfile(profile, |
| 253 ServiceAccessType::EXPLICIT_ACCESS), |
| 254 ProfileSyncServiceFactory::GetForProfile(profile)); |
233 counter.Init( | 255 counter.Init( |
234 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, | 256 profile->GetPrefs(), browsing_data::ClearBrowsingDataTab::ADVANCED, |
235 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); | 257 base::Bind(&PasswordsCounterTest::Callback, base::Unretained(this))); |
236 | 258 |
237 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR); | 259 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_HOUR); |
238 WaitForCounting(); | 260 WaitForCounting(); |
239 EXPECT_EQ(1u, GetResult()); | 261 EXPECT_EQ(1u, GetResult()); |
240 | 262 |
241 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY); | 263 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_DAY); |
242 WaitForCounting(); | 264 WaitForCounting(); |
243 EXPECT_EQ(1u, GetResult()); | 265 EXPECT_EQ(1u, GetResult()); |
244 | 266 |
245 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK); | 267 SetDeletionPeriodPref(browsing_data::TimePeriod::LAST_WEEK); |
246 WaitForCounting(); | 268 WaitForCounting(); |
247 EXPECT_EQ(3u, GetResult()); | 269 EXPECT_EQ(3u, GetResult()); |
248 | 270 |
249 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS); | 271 SetDeletionPeriodPref(browsing_data::TimePeriod::FOUR_WEEKS); |
250 WaitForCounting(); | 272 WaitForCounting(); |
251 EXPECT_EQ(3u, GetResult()); | 273 EXPECT_EQ(3u, GetResult()); |
252 | 274 |
253 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); | 275 SetDeletionPeriodPref(browsing_data::TimePeriod::ALL_TIME); |
254 WaitForCounting(); | 276 WaitForCounting(); |
255 EXPECT_EQ(4u, GetResult()); | 277 EXPECT_EQ(4u, GetResult()); |
256 } | 278 } |
257 | 279 |
258 } // namespace | 280 } // namespace |
OLD | NEW |