OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 #include "components/password_manager/core/common/password_manager_pref_names.h" | 26 #include "components/password_manager/core/common/password_manager_pref_names.h" |
27 #include "components/webdata/common/web_database_service.h" | 27 #include "components/webdata/common/web_database_service.h" |
28 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
29 #include "crypto/wincrypt_shim.h" | 29 #include "crypto/wincrypt_shim.h" |
30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 using autofill::PasswordForm; | 33 using autofill::PasswordForm; |
34 using base::WaitableEvent; | 34 using base::WaitableEvent; |
35 using content::BrowserThread; | 35 using content::BrowserThread; |
36 using password_manager::ContainsSamePasswordForms; | |
36 using password_manager::LoginDatabase; | 37 using password_manager::LoginDatabase; |
37 using password_manager::ContainsAllPasswordForms; | |
38 using password_manager::PasswordFormData; | 38 using password_manager::PasswordFormData; |
39 using password_manager::PasswordStore; | 39 using password_manager::PasswordStore; |
40 using password_manager::PasswordStoreConsumer; | 40 using password_manager::PasswordStoreConsumer; |
41 using testing::_; | 41 using testing::_; |
42 using testing::DoAll; | 42 using testing::DoAll; |
43 using testing::IsEmpty; | |
43 using testing::WithArg; | 44 using testing::WithArg; |
44 | 45 |
45 namespace { | 46 namespace { |
46 | 47 |
47 class MockPasswordStoreConsumer : public PasswordStoreConsumer { | 48 class MockPasswordStoreConsumer : public PasswordStoreConsumer { |
48 public: | 49 public: |
49 MOCK_METHOD1(OnGetPasswordStoreResults, | 50 MOCK_METHOD1(OnGetPasswordStoreResultsConstRef, |
50 void(const std::vector<autofill::PasswordForm*>&)); | 51 void(const std::vector<PasswordForm*>&)); |
52 | |
53 // GMock cannot mock methods with move-only args. | |
54 void OnGetPasswordStoreResults(ScopedVector<PasswordForm> results) override { | |
55 OnGetPasswordStoreResultsConstRef(results.get()); | |
56 } | |
51 }; | 57 }; |
52 | 58 |
53 class MockWebDataServiceConsumer : public WebDataServiceConsumer { | 59 class MockWebDataServiceConsumer : public WebDataServiceConsumer { |
54 public: | 60 public: |
55 MOCK_METHOD2(OnWebDataServiceRequestDone, | 61 MOCK_METHOD2(OnWebDataServiceRequestDone, |
56 void(PasswordWebDataService::Handle, const WDTypedResult*)); | 62 void(PasswordWebDataService::Handle, const WDTypedResult*)); |
57 }; | 63 }; |
58 | 64 |
59 } // anonymous namespace | 65 } // anonymous namespace |
60 | 66 |
61 typedef std::vector<PasswordForm*> VectorOfForms; | |
62 | |
63 class PasswordStoreWinTest : public testing::Test { | 67 class PasswordStoreWinTest : public testing::Test { |
64 protected: | 68 protected: |
65 PasswordStoreWinTest() | 69 PasswordStoreWinTest() |
66 : ui_thread_(BrowserThread::UI, &message_loop_), | 70 : ui_thread_(BrowserThread::UI, &message_loop_), |
67 db_thread_(BrowserThread::DB) { | 71 db_thread_(BrowserThread::DB) { |
68 } | 72 } |
69 | 73 |
70 bool CreateIE7PasswordInfo(const std::wstring& url, const base::Time& created, | 74 bool CreateIE7PasswordInfo(const std::wstring& url, const base::Time& created, |
71 IE7PasswordInfo* info) { | 75 IE7PasswordInfo* info) { |
72 // Copied from chrome/browser/importer/importer_unittest.cc | 76 // Copied from chrome/browser/importer/importer_unittest.cc |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 208 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
205 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 209 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
206 done.Wait(); | 210 done.Wait(); |
207 | 211 |
208 store_ = CreatePasswordStore(); | 212 store_ = CreatePasswordStore(); |
209 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 213 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
210 | 214 |
211 MockPasswordStoreConsumer consumer; | 215 MockPasswordStoreConsumer consumer; |
212 | 216 |
213 // Make sure we quit the MessageLoop even if the test fails. | 217 // Make sure we quit the MessageLoop even if the test fails. |
214 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 218 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
215 .WillByDefault(QuitUIMessageLoop()); | 219 .WillByDefault(QuitUIMessageLoop()); |
216 | 220 |
217 PasswordFormData form_data = { | 221 PasswordFormData form_data = { |
218 PasswordForm::SCHEME_HTML, | 222 PasswordForm::SCHEME_HTML, |
219 "http://example.com/", | 223 "http://example.com/", |
220 "http://example.com/origin", | 224 "http://example.com/origin", |
221 "http://example.com/action", | 225 "http://example.com/action", |
222 L"submit_element", | 226 L"submit_element", |
223 L"username_element", | 227 L"username_element", |
224 L"password_element", | 228 L"password_element", |
225 L"", | 229 L"", |
226 L"", | 230 L"", |
227 true, false, 1, | 231 true, false, 1, |
228 }; | 232 }; |
229 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 233 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); |
230 | 234 |
231 // The returned form will not have 'action' or '*_element' fields set. This | 235 // The returned form will not have 'action' or '*_element' fields set. This |
232 // is because credentials imported from IE don't have this information. | 236 // is because credentials imported from IE don't have this information. |
233 PasswordFormData expected_form_data = { | 237 PasswordFormData expected_form_data = { |
234 PasswordForm::SCHEME_HTML, | 238 PasswordForm::SCHEME_HTML, |
235 "http://example.com/", | 239 "http://example.com/", |
236 "http://example.com/origin", | 240 "http://example.com/origin", |
237 "", | 241 "", |
238 L"", | 242 L"", |
239 L"", | 243 L"", |
240 L"", | 244 L"", |
241 L"abcdefgh", | 245 L"abcdefgh", |
242 L"abcdefghijkl", | 246 L"abcdefghijkl", |
243 true, false, 1, | 247 true, false, 1, |
244 }; | 248 }; |
245 std::vector<PasswordForm*> forms; | 249 ScopedVector<autofill::PasswordForm> expected_forms; |
246 forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 250 expected_forms.push_back(CreatePasswordFormFromData(expected_form_data)); |
247 | 251 |
248 // The IE7 password should be returned. | 252 // The IE7 password should be returned. |
249 EXPECT_CALL(consumer, | 253 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef( |
250 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms))) | 254 ContainsSamePasswordForms(expected_forms.get()))) |
251 .WillOnce(QuitUIMessageLoop()); | 255 .WillOnce(QuitUIMessageLoop()); |
vasilii
2015/02/09 10:08:35
Not needed given the line #219
vabr (Chromium)
2015/02/09 11:36:06
Done.
| |
252 | 256 |
253 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 257 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
254 base::MessageLoop::current()->Run(); | 258 base::MessageLoop::current()->Run(); |
255 | |
256 STLDeleteElements(&forms); | |
257 } | 259 } |
258 | 260 |
259 // Crashy. http://crbug.com/86558 | 261 // Crashy. http://crbug.com/86558 |
260 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 262 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
261 store_ = CreatePasswordStore(); | 263 store_ = CreatePasswordStore(); |
262 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 264 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
263 | 265 |
264 PasswordFormData form_data = { | 266 PasswordFormData form_data = { |
265 PasswordForm::SCHEME_HTML, | 267 PasswordForm::SCHEME_HTML, |
266 "http://example.com/", | 268 "http://example.com/", |
267 "http://example.com/origin", | 269 "http://example.com/origin", |
268 "http://example.com/action", | 270 "http://example.com/action", |
269 L"submit_element", | 271 L"submit_element", |
270 L"username_element", | 272 L"username_element", |
271 L"password_element", | 273 L"password_element", |
272 L"", | 274 L"", |
273 L"", | 275 L"", |
274 true, false, 1, | 276 true, false, 1, |
275 }; | 277 }; |
276 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 278 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); |
277 | 279 |
278 MockPasswordStoreConsumer consumer; | 280 MockPasswordStoreConsumer consumer; |
279 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 281 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
280 | 282 |
281 // Release the PSW and the WDS before the query can return. | 283 // Release the PSW and the WDS before the query can return. |
282 store_->Shutdown(); | 284 store_->Shutdown(); |
283 store_ = NULL; | 285 store_ = NULL; |
284 wds_ = NULL; | 286 wds_ = NULL; |
285 | 287 |
286 base::MessageLoop::current()->RunUntilIdle(); | 288 base::MessageLoop::current()->RunUntilIdle(); |
(...skipping 12 matching lines...) Expand all Loading... | |
299 WaitableEvent done(false, false); | 301 WaitableEvent done(false, false); |
300 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 302 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
301 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 303 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
302 done.Wait(); | 304 done.Wait(); |
303 | 305 |
304 store_ = CreatePasswordStore(); | 306 store_ = CreatePasswordStore(); |
305 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); | 307 EXPECT_TRUE(store_->Init(syncer::SyncableService::StartSyncFlare())); |
306 | 308 |
307 MockPasswordStoreConsumer password_consumer; | 309 MockPasswordStoreConsumer password_consumer; |
308 // Make sure we quit the MessageLoop even if the test fails. | 310 // Make sure we quit the MessageLoop even if the test fails. |
309 ON_CALL(password_consumer, OnGetPasswordStoreResults(_)) | 311 ON_CALL(password_consumer, OnGetPasswordStoreResultsConstRef(_)) |
310 .WillByDefault(QuitUIMessageLoop()); | 312 .WillByDefault(QuitUIMessageLoop()); |
311 | 313 |
312 PasswordFormData form_data = { | 314 PasswordFormData form_data = { |
313 PasswordForm::SCHEME_HTML, | 315 PasswordForm::SCHEME_HTML, |
314 "http://example.com/", | 316 "http://example.com/", |
315 "http://example.com/origin", | 317 "http://example.com/origin", |
316 "http://example.com/action", | 318 "http://example.com/action", |
317 L"submit_element", | 319 L"submit_element", |
318 L"username_element", | 320 L"username_element", |
319 L"password_element", | 321 L"password_element", |
320 L"", | 322 L"", |
321 L"", | 323 L"", |
322 true, false, 1, | 324 true, false, 1, |
323 }; | 325 }; |
324 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 326 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); |
325 | 327 |
326 PasswordFormData expected_form_data = { | 328 PasswordFormData expected_form_data = { |
327 PasswordForm::SCHEME_HTML, | 329 PasswordForm::SCHEME_HTML, |
328 "http://example.com/", | 330 "http://example.com/", |
329 "http://example.com/origin", | 331 "http://example.com/origin", |
330 "http://example.com/action", | 332 "http://example.com/action", |
331 L"submit_element", | 333 L"submit_element", |
332 L"username_element", | 334 L"username_element", |
333 L"password_element", | 335 L"password_element", |
334 L"abcdefgh", | 336 L"abcdefgh", |
335 L"abcdefghijkl", | 337 L"abcdefghijkl", |
336 true, false, 1, | 338 true, false, 1, |
337 }; | 339 }; |
338 std::vector<PasswordForm*> forms; | 340 ScopedVector<autofill::PasswordForm> expected_forms; |
339 forms.push_back(CreatePasswordFormFromData(expected_form_data)); | 341 expected_forms.push_back(CreatePasswordFormFromData(expected_form_data)); |
340 | 342 |
341 // The IE7 password should be returned. | 343 // The IE7 password should be returned. |
342 EXPECT_CALL(password_consumer, | 344 EXPECT_CALL(password_consumer, |
343 OnGetPasswordStoreResults(ContainsAllPasswordForms(forms))) | 345 OnGetPasswordStoreResultsConstRef(ContainsSamePasswordForms( |
344 .WillOnce(QuitUIMessageLoop()); | 346 expected_forms.get()))).WillOnce(QuitUIMessageLoop()); |
vasilii
2015/02/09 10:08:35
QuitUIMessageLoop() not needed
vabr (Chromium)
2015/02/09 11:36:06
Done.
| |
345 | 347 |
346 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); | 348 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &password_consumer); |
347 | 349 |
348 MockWebDataServiceConsumer wds_consumer; | 350 MockWebDataServiceConsumer wds_consumer; |
349 | 351 |
350 EXPECT_CALL(wds_consumer, | 352 EXPECT_CALL(wds_consumer, |
351 OnWebDataServiceRequestDone(_, _)) | 353 OnWebDataServiceRequestDone(_, _)) |
352 .WillOnce(QuitUIMessageLoop()); | 354 .WillOnce(QuitUIMessageLoop()); |
353 | 355 |
354 wds_->GetIE7Login(password_info, &wds_consumer); | 356 wds_->GetIE7Login(password_info, &wds_consumer); |
355 | 357 |
356 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin | 358 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin |
357 // schedules on the DB thread and once for the one we just scheduled on the UI | 359 // schedules on the DB thread and once for the one we just scheduled on the UI |
358 // thread. | 360 // thread. |
359 base::MessageLoop::current()->Run(); | 361 base::MessageLoop::current()->Run(); |
360 base::MessageLoop::current()->Run(); | 362 base::MessageLoop::current()->Run(); |
361 | |
362 STLDeleteElements(&forms); | |
363 } | 363 } |
364 | 364 |
365 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 365 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
366 store_ = CreatePasswordStore(); | 366 store_ = CreatePasswordStore(); |
367 store_->Init(syncer::SyncableService::StartSyncFlare()); | 367 store_->Init(syncer::SyncableService::StartSyncFlare()); |
368 | 368 |
369 PasswordFormData form_data = { | 369 PasswordFormData form_data = { |
370 PasswordForm::SCHEME_HTML, | 370 PasswordForm::SCHEME_HTML, |
371 "http://example.com/", | 371 "http://example.com/", |
372 "http://example.com/origin", | 372 "http://example.com/origin", |
373 "http://example.com/action", | 373 "http://example.com/action", |
374 L"submit_element", | 374 L"submit_element", |
375 L"username_element", | 375 L"username_element", |
376 L"password_element", | 376 L"password_element", |
377 L"", | 377 L"", |
378 L"", | 378 L"", |
379 true, false, 1, | 379 true, false, 1, |
380 }; | 380 }; |
381 scoped_ptr<PasswordForm> form(CreatePasswordFormFromData(form_data)); | 381 scoped_ptr<PasswordForm> form = CreatePasswordFormFromData(form_data); |
382 | 382 |
383 MockPasswordStoreConsumer consumer; | 383 MockPasswordStoreConsumer consumer; |
384 | 384 |
385 // Make sure we quit the MessageLoop even if the test fails. | 385 // Make sure we quit the MessageLoop even if the test fails. |
386 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 386 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
387 .WillByDefault(QuitUIMessageLoop()); | 387 .WillByDefault(QuitUIMessageLoop()); |
388 | 388 |
389 VectorOfForms expect_none; | 389 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
390 // expect that we get no results; | |
391 EXPECT_CALL(consumer, | |
392 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
393 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
394 | 390 |
395 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); | 391 store_->GetLogins(*form, PasswordStore::DISALLOW_PROMPT, &consumer); |
396 base::MessageLoop::current()->Run(); | 392 base::MessageLoop::current()->Run(); |
397 } | 393 } |
398 | 394 |
399 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { | 395 TEST_F(PasswordStoreWinTest, EmptyBlacklistLogins) { |
400 store_ = CreatePasswordStore(); | 396 store_ = CreatePasswordStore(); |
401 store_->Init(syncer::SyncableService::StartSyncFlare()); | 397 store_->Init(syncer::SyncableService::StartSyncFlare()); |
402 | 398 |
403 MockPasswordStoreConsumer consumer; | 399 MockPasswordStoreConsumer consumer; |
404 | 400 |
405 // Make sure we quit the MessageLoop even if the test fails. | 401 // Make sure we quit the MessageLoop even if the test fails. |
406 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 402 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
407 .WillByDefault(QuitUIMessageLoop()); | 403 .WillByDefault(QuitUIMessageLoop()); |
408 | 404 |
409 VectorOfForms expect_none; | 405 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
410 // expect that we get no results; | |
411 EXPECT_CALL( | |
412 consumer, | |
413 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
414 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
415 | 406 |
416 store_->GetBlacklistLogins(&consumer); | 407 store_->GetBlacklistLogins(&consumer); |
417 base::MessageLoop::current()->Run(); | 408 base::MessageLoop::current()->Run(); |
418 } | 409 } |
419 | 410 |
420 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { | 411 TEST_F(PasswordStoreWinTest, EmptyAutofillableLogins) { |
421 store_ = CreatePasswordStore(); | 412 store_ = CreatePasswordStore(); |
422 store_->Init(syncer::SyncableService::StartSyncFlare()); | 413 store_->Init(syncer::SyncableService::StartSyncFlare()); |
423 | 414 |
424 MockPasswordStoreConsumer consumer; | 415 MockPasswordStoreConsumer consumer; |
425 | 416 |
426 // Make sure we quit the MessageLoop even if the test fails. | 417 // Make sure we quit the MessageLoop even if the test fails. |
427 ON_CALL(consumer, OnGetPasswordStoreResults(_)) | 418 ON_CALL(consumer, OnGetPasswordStoreResultsConstRef(_)) |
428 .WillByDefault(QuitUIMessageLoop()); | 419 .WillByDefault(QuitUIMessageLoop()); |
429 | 420 |
430 VectorOfForms expect_none; | 421 EXPECT_CALL(consumer, OnGetPasswordStoreResultsConstRef(IsEmpty())); |
431 // expect that we get no results; | |
432 EXPECT_CALL( | |
433 consumer, | |
434 OnGetPasswordStoreResults(ContainsAllPasswordForms(expect_none))) | |
435 .WillOnce(DoAll(WithArg<0>(STLDeleteElements0()), QuitUIMessageLoop())); | |
436 | 422 |
437 store_->GetAutofillableLogins(&consumer); | 423 store_->GetAutofillableLogins(&consumer); |
438 base::MessageLoop::current()->Run(); | 424 base::MessageLoop::current()->Run(); |
439 } | 425 } |
OLD | NEW |