| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
| 10 #include "base/platform_file.h" | 10 #include "base/platform_file.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 ASSERT_TRUE(db_thread_.Start()); | 278 ASSERT_TRUE(db_thread_.Start()); |
| 279 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 279 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 280 | 280 |
| 281 profile_.reset(new TestingProfile()); | 281 profile_.reset(new TestingProfile()); |
| 282 | 282 |
| 283 login_db_.reset(new LoginDatabase()); | 283 login_db_.reset(new LoginDatabase()); |
| 284 ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append("login_test"))); | 284 ASSERT_TRUE(login_db_->Init(temp_dir_.path().Append("login_test"))); |
| 285 } | 285 } |
| 286 | 286 |
| 287 virtual void TearDown() { | 287 virtual void TearDown() { |
| 288 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 288 base::MessageLoop::current()->PostTask(FROM_HERE, |
| 289 MessageLoop::current()->Run(); | 289 base::MessageLoop::QuitClosure()); |
| 290 base::MessageLoop::current()->Run(); |
| 290 db_thread_.Stop(); | 291 db_thread_.Stop(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 PasswordStoreX::NativeBackend* GetBackend() { | 294 PasswordStoreX::NativeBackend* GetBackend() { |
| 294 switch (GetParam()) { | 295 switch (GetParam()) { |
| 295 case FAILING_BACKEND: | 296 case FAILING_BACKEND: |
| 296 return new FailingBackend(); | 297 return new FailingBackend(); |
| 297 case WORKING_BACKEND: | 298 case WORKING_BACKEND: |
| 298 return new MockBackend(); | 299 return new MockBackend(); |
| 299 default: | 300 default: |
| 300 return NULL; | 301 return NULL; |
| 301 } | 302 } |
| 302 } | 303 } |
| 303 | 304 |
| 304 MessageLoopForUI message_loop_; | 305 base::MessageLoopForUI message_loop_; |
| 305 content::TestBrowserThread ui_thread_; | 306 content::TestBrowserThread ui_thread_; |
| 306 // PasswordStore, WDS schedule work on this thread. | 307 // PasswordStore, WDS schedule work on this thread. |
| 307 content::TestBrowserThread db_thread_; | 308 content::TestBrowserThread db_thread_; |
| 308 | 309 |
| 309 scoped_ptr<LoginDatabase> login_db_; | 310 scoped_ptr<LoginDatabase> login_db_; |
| 310 scoped_ptr<TestingProfile> profile_; | 311 scoped_ptr<TestingProfile> profile_; |
| 311 base::ScopedTempDir temp_dir_; | 312 base::ScopedTempDir temp_dir_; |
| 312 }; | 313 }; |
| 313 | 314 |
| 314 ACTION(STLDeleteElements0) { | 315 ACTION(STLDeleteElements0) { |
| 315 STLDeleteContainerPointers(arg0.begin(), arg0.end()); | 316 STLDeleteContainerPointers(arg0.begin(), arg0.end()); |
| 316 } | 317 } |
| 317 | 318 |
| 318 ACTION(QuitUIMessageLoop) { | 319 ACTION(QuitUIMessageLoop) { |
| 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 320 MessageLoop::current()->Quit(); | 321 base::MessageLoop::current()->Quit(); |
| 321 } | 322 } |
| 322 | 323 |
| 323 TEST_P(PasswordStoreXTest, Notifications) { | 324 TEST_P(PasswordStoreXTest, Notifications) { |
| 324 scoped_refptr<PasswordStoreX> store( | 325 scoped_refptr<PasswordStoreX> store( |
| 325 new PasswordStoreX(login_db_.release(), | 326 new PasswordStoreX(login_db_.release(), |
| 326 profile_.get(), | 327 profile_.get(), |
| 327 GetBackend())); | 328 GetBackend())); |
| 328 store->Init(); | 329 store->Init(); |
| 329 | 330 |
| 330 PasswordFormData form_data = | 331 PasswordFormData form_data = |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | 466 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) |
| 466 .WillByDefault(QuitUIMessageLoop()); | 467 .WillByDefault(QuitUIMessageLoop()); |
| 467 | 468 |
| 468 // The autofillable forms should have been migrated to the native backend. | 469 // The autofillable forms should have been migrated to the native backend. |
| 469 EXPECT_CALL(consumer, | 470 EXPECT_CALL(consumer, |
| 470 OnPasswordStoreRequestDone(_, | 471 OnPasswordStoreRequestDone(_, |
| 471 ContainsAllPasswordForms(expected_autofillable))) | 472 ContainsAllPasswordForms(expected_autofillable))) |
| 472 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | 473 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 473 | 474 |
| 474 store->GetAutofillableLogins(&consumer); | 475 store->GetAutofillableLogins(&consumer); |
| 475 MessageLoop::current()->Run(); | 476 base::MessageLoop::current()->Run(); |
| 476 | 477 |
| 477 // The blacklisted forms should have been migrated to the native backend. | 478 // The blacklisted forms should have been migrated to the native backend. |
| 478 EXPECT_CALL(consumer, | 479 EXPECT_CALL(consumer, |
| 479 OnPasswordStoreRequestDone(_, | 480 OnPasswordStoreRequestDone(_, |
| 480 ContainsAllPasswordForms(expected_blacklisted))) | 481 ContainsAllPasswordForms(expected_blacklisted))) |
| 481 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | 482 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 482 | 483 |
| 483 store->GetBlacklistLogins(&consumer); | 484 store->GetBlacklistLogins(&consumer); |
| 484 MessageLoop::current()->Run(); | 485 base::MessageLoop::current()->Run(); |
| 485 | 486 |
| 486 VectorOfForms empty; | 487 VectorOfForms empty; |
| 487 MockLoginDatabaseReturn ld_return; | 488 MockLoginDatabaseReturn ld_return; |
| 488 | 489 |
| 489 if (GetParam() == WORKING_BACKEND) { | 490 if (GetParam() == WORKING_BACKEND) { |
| 490 // No autofillable logins should be left in the login DB. | 491 // No autofillable logins should be left in the login DB. |
| 491 EXPECT_CALL(ld_return, | 492 EXPECT_CALL(ld_return, |
| 492 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); | 493 OnLoginDatabaseQueryDone(ContainsAllPasswordForms(empty))); |
| 493 } else { | 494 } else { |
| 494 // The autofillable logins should still be in the login DB. | 495 // The autofillable logins should still be in the login DB. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 | 549 |
| 549 INSTANTIATE_TEST_CASE_P(NoBackend, | 550 INSTANTIATE_TEST_CASE_P(NoBackend, |
| 550 PasswordStoreXTest, | 551 PasswordStoreXTest, |
| 551 testing::Values(NO_BACKEND)); | 552 testing::Values(NO_BACKEND)); |
| 552 INSTANTIATE_TEST_CASE_P(FailingBackend, | 553 INSTANTIATE_TEST_CASE_P(FailingBackend, |
| 553 PasswordStoreXTest, | 554 PasswordStoreXTest, |
| 554 testing::Values(FAILING_BACKEND)); | 555 testing::Values(FAILING_BACKEND)); |
| 555 INSTANTIATE_TEST_CASE_P(WorkingBackend, | 556 INSTANTIATE_TEST_CASE_P(WorkingBackend, |
| 556 PasswordStoreXTest, | 557 PasswordStoreXTest, |
| 557 testing::Values(WORKING_BACKEND)); | 558 testing::Values(WORKING_BACKEND)); |
| OLD | NEW |