| 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 #include <string> | 6 #include <string> |
| 7 #include <vector> | 7 #include <vector> |
| 8 #include <wincrypt.h> | 8 #include <wincrypt.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // This IE7 password will be retrieved by the GetLogins call. | 166 // This IE7 password will be retrieved by the GetLogins call. |
| 167 wds_->AddIE7Login(password_info); | 167 wds_->AddIE7Login(password_info); |
| 168 | 168 |
| 169 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 169 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 170 // task to notify us that it's safe to carry on with the test. | 170 // task to notify us that it's safe to carry on with the test. |
| 171 WaitableEvent done(false, false); | 171 WaitableEvent done(false, false); |
| 172 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 172 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 173 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 173 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 174 done.Wait(); | 174 done.Wait(); |
| 175 | 175 |
| 176 // Prentend that the migration has already taken place. | |
| 177 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | |
| 178 true, | |
| 179 PrefService::UNSYNCABLE_PREF); | |
| 180 | |
| 181 // Initializing the PasswordStore shouldn't trigger a migration. | |
| 182 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 176 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), |
| 183 wds_.get()); | 177 wds_.get()); |
| 184 EXPECT_TRUE(store_->Init()); | 178 EXPECT_TRUE(store_->Init()); |
| 185 | 179 |
| 186 MockPasswordStoreConsumer consumer; | 180 MockPasswordStoreConsumer consumer; |
| 187 | 181 |
| 188 // Make sure we quit the MessageLoop even if the test fails. | 182 // Make sure we quit the MessageLoop even if the test fails. |
| 189 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | 183 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) |
| 190 .WillByDefault(QuitUIMessageLoop()); | 184 .WillByDefault(QuitUIMessageLoop()); |
| 191 | 185 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 .WillOnce(QuitUIMessageLoop()); | 219 .WillOnce(QuitUIMessageLoop()); |
| 226 | 220 |
| 227 store_->GetLogins(*form, &consumer); | 221 store_->GetLogins(*form, &consumer); |
| 228 MessageLoop::current()->Run(); | 222 MessageLoop::current()->Run(); |
| 229 | 223 |
| 230 STLDeleteElements(&forms); | 224 STLDeleteElements(&forms); |
| 231 } | 225 } |
| 232 | 226 |
| 233 // Crashy. http://crbug.com/86558 | 227 // Crashy. http://crbug.com/86558 |
| 234 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { | 228 TEST_F(PasswordStoreWinTest, DISABLED_OutstandingWDSQueries) { |
| 235 // Prentend that the migration has already taken place. | |
| 236 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | |
| 237 true, | |
| 238 PrefService::UNSYNCABLE_PREF); | |
| 239 | |
| 240 // Initializing the PasswordStore shouldn't trigger a migration. | |
| 241 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 229 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), |
| 242 wds_.get()); | 230 wds_.get()); |
| 243 EXPECT_TRUE(store_->Init()); | 231 EXPECT_TRUE(store_->Init()); |
| 244 | 232 |
| 245 PasswordFormData form_data = { | 233 PasswordFormData form_data = { |
| 246 PasswordForm::SCHEME_HTML, | 234 PasswordForm::SCHEME_HTML, |
| 247 "http://example.com/", | 235 "http://example.com/", |
| 248 "http://example.com/origin", | 236 "http://example.com/origin", |
| 249 "http://example.com/action", | 237 "http://example.com/action", |
| 250 L"submit_element", | 238 L"submit_element", |
| (...skipping 25 matching lines...) Expand all Loading... |
| 276 &password_info)); | 264 &password_info)); |
| 277 wds_->AddIE7Login(password_info); | 265 wds_->AddIE7Login(password_info); |
| 278 | 266 |
| 279 // The WDS schedules tasks to run on the DB thread so we schedule yet another | 267 // The WDS schedules tasks to run on the DB thread so we schedule yet another |
| 280 // task to notify us that it's safe to carry on with the test. | 268 // task to notify us that it's safe to carry on with the test. |
| 281 WaitableEvent done(false, false); | 269 WaitableEvent done(false, false); |
| 282 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 270 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 283 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | 271 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); |
| 284 done.Wait(); | 272 done.Wait(); |
| 285 | 273 |
| 286 // Prentend that the migration has already taken place. | |
| 287 profile_->GetPrefs()->RegisterBooleanPref(prefs::kLoginDatabaseMigrated, | |
| 288 true, | |
| 289 PrefService::UNSYNCABLE_PREF); | |
| 290 | |
| 291 // Initializing the PasswordStore shouldn't trigger a migration. | |
| 292 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 274 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), |
| 293 wds_.get()); | 275 wds_.get()); |
| 294 EXPECT_TRUE(store_->Init()); | 276 EXPECT_TRUE(store_->Init()); |
| 295 | 277 |
| 296 MockPasswordStoreConsumer password_consumer; | 278 MockPasswordStoreConsumer password_consumer; |
| 297 // Make sure we quit the MessageLoop even if the test fails. | 279 // Make sure we quit the MessageLoop even if the test fails. |
| 298 ON_CALL(password_consumer, OnPasswordStoreRequestDone(_, _)) | 280 ON_CALL(password_consumer, OnPasswordStoreRequestDone(_, _)) |
| 299 .WillByDefault(QuitUIMessageLoop()); | 281 .WillByDefault(QuitUIMessageLoop()); |
| 300 | 282 |
| 301 PasswordFormData form_data = { | 283 PasswordFormData form_data = { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 | 327 |
| 346 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin | 328 // Run the MessageLoop twice: once for the GetIE7Login that PasswordStoreWin |
| 347 // schedules on the DB thread and once for the one we just scheduled on the UI | 329 // schedules on the DB thread and once for the one we just scheduled on the UI |
| 348 // thread. | 330 // thread. |
| 349 MessageLoop::current()->Run(); | 331 MessageLoop::current()->Run(); |
| 350 MessageLoop::current()->Run(); | 332 MessageLoop::current()->Run(); |
| 351 | 333 |
| 352 STLDeleteElements(&forms); | 334 STLDeleteElements(&forms); |
| 353 } | 335 } |
| 354 | 336 |
| 355 TEST_F(PasswordStoreWinTest, Migration) { | |
| 356 PasswordFormData autofillable_data[] = { | |
| 357 { PasswordForm::SCHEME_HTML, | |
| 358 "http://foo.example.com", | |
| 359 "http://foo.example.com/origin", | |
| 360 "http://foo.example.com/action", | |
| 361 L"submit_element", | |
| 362 L"username_element", | |
| 363 L"password_element", | |
| 364 L"username_value", | |
| 365 L"password_value", | |
| 366 true, false, 1 }, | |
| 367 { PasswordForm::SCHEME_HTML, | |
| 368 "http://bar.example.com", | |
| 369 "http://bar.example.com/origin", | |
| 370 "http://bar.example.com/action", | |
| 371 L"submit_element", | |
| 372 L"username_element", | |
| 373 L"password_element", | |
| 374 L"username_value", | |
| 375 L"password_value", | |
| 376 true, false, 2 }, | |
| 377 { PasswordForm::SCHEME_HTML, | |
| 378 "http://baz.example.com", | |
| 379 "http://baz.example.com/origin", | |
| 380 "http://baz.example.com/action", | |
| 381 L"submit_element", | |
| 382 L"username_element", | |
| 383 L"password_element", | |
| 384 L"username_value", | |
| 385 L"password_value", | |
| 386 true, false, 3 }, | |
| 387 }; | |
| 388 PasswordFormData blacklisted_data[] = { | |
| 389 { PasswordForm::SCHEME_HTML, | |
| 390 "http://blacklisted.example.com", | |
| 391 "http://blacklisted.example.com/origin", | |
| 392 "http://blacklisted.example.com/action", | |
| 393 L"submit_element", | |
| 394 L"username_element", | |
| 395 L"password_element", | |
| 396 NULL, | |
| 397 NULL, | |
| 398 false, false, 1 }, | |
| 399 { PasswordForm::SCHEME_HTML, | |
| 400 "http://blacklisted2.example.com", | |
| 401 "http://blacklisted2.example.com/origin", | |
| 402 "http://blacklisted2.example.com/action", | |
| 403 L"submit_element", | |
| 404 L"username_element", | |
| 405 L"password_element", | |
| 406 NULL, | |
| 407 NULL, | |
| 408 false, false, 2 }, | |
| 409 }; | |
| 410 | |
| 411 VectorOfForms expected_autofillable; | |
| 412 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(autofillable_data); ++i) { | |
| 413 expected_autofillable.push_back( | |
| 414 CreatePasswordFormFromData(autofillable_data[i])); | |
| 415 } | |
| 416 | |
| 417 VectorOfForms expected_blacklisted; | |
| 418 for (unsigned int i = 0; i < ARRAYSIZE_UNSAFE(blacklisted_data); ++i) { | |
| 419 expected_blacklisted.push_back( | |
| 420 CreatePasswordFormFromData(blacklisted_data[i])); | |
| 421 } | |
| 422 | |
| 423 // Populate the WDS with logins that should be migrated. | |
| 424 for (VectorOfForms::iterator it = expected_autofillable.begin(); | |
| 425 it != expected_autofillable.end(); ++it) { | |
| 426 wds_->AddLogin(**it); | |
| 427 } | |
| 428 for (VectorOfForms::iterator it = expected_blacklisted.begin(); | |
| 429 it != expected_blacklisted.end(); ++it) { | |
| 430 wds_->AddLogin(**it); | |
| 431 } | |
| 432 | |
| 433 // The WDS schedules tasks to run on the DB thread so we schedule yet another | |
| 434 // task to notify us that it's safe to carry on with the test. | |
| 435 WaitableEvent done(false, false); | |
| 436 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 437 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | |
| 438 done.Wait(); | |
| 439 | |
| 440 // Initializing the PasswordStore should trigger a migration. | |
| 441 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | |
| 442 wds_.get()); | |
| 443 store_->Init(); | |
| 444 | |
| 445 // Check that the migration preference has not been initialized; | |
| 446 ASSERT_TRUE(NULL == profile_->GetPrefs()->FindPreference( | |
| 447 prefs::kLoginDatabaseMigrated)); | |
| 448 | |
| 449 // Again, the WDS schedules tasks to run on the DB thread, so schedule a task | |
| 450 // to signal us when it is safe to continue. | |
| 451 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 452 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | |
| 453 done.Wait(); | |
| 454 | |
| 455 // Let the WDS callbacks proceed so the logins can be migrated. | |
| 456 MessageLoop::current()->RunAllPending(); | |
| 457 | |
| 458 MockPasswordStoreConsumer consumer; | |
| 459 | |
| 460 // Make sure we quit the MessageLoop even if the test fails. | |
| 461 ON_CALL(consumer, OnPasswordStoreRequestDone(_, _)) | |
| 462 .WillByDefault(QuitUIMessageLoop()); | |
| 463 | |
| 464 // The autofillable forms should have been migrated from the WDS to the login | |
| 465 // database. | |
| 466 EXPECT_CALL(consumer, | |
| 467 OnPasswordStoreRequestDone(_, | |
| 468 ContainsAllPasswordForms(expected_autofillable))) | |
| 469 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | |
| 470 | |
| 471 store_->GetAutofillableLogins(&consumer); | |
| 472 MessageLoop::current()->Run(); | |
| 473 | |
| 474 // The blacklisted forms should have been migrated from the WDS to the login | |
| 475 // database. | |
| 476 EXPECT_CALL(consumer, | |
| 477 OnPasswordStoreRequestDone(_, | |
| 478 ContainsAllPasswordForms(expected_blacklisted))) | |
| 479 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | |
| 480 | |
| 481 store_->GetBlacklistLogins(&consumer); | |
| 482 MessageLoop::current()->Run(); | |
| 483 | |
| 484 // Check that the migration updated the migrated preference. | |
| 485 ASSERT_TRUE(profile_->GetPrefs()->GetBoolean(prefs::kLoginDatabaseMigrated)); | |
| 486 | |
| 487 MockWebDataServiceConsumer wds_consumer; | |
| 488 | |
| 489 // No autofillable logins should be left in the WDS. | |
| 490 EXPECT_CALL(wds_consumer, | |
| 491 OnWebDataServiceRequestDone(_, EmptyWDResult())); | |
| 492 | |
| 493 wds_->GetAutofillableLogins(&wds_consumer); | |
| 494 | |
| 495 // Wait for the WDS methods to execute on the DB thread. | |
| 496 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 497 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | |
| 498 done.Wait(); | |
| 499 | |
| 500 // Handle the callback from the WDS. | |
| 501 MessageLoop::current()->RunAllPending(); | |
| 502 | |
| 503 // Likewise, no blacklisted logins should be left in the WDS. | |
| 504 EXPECT_CALL(wds_consumer, | |
| 505 OnWebDataServiceRequestDone(_, EmptyWDResult())); | |
| 506 | |
| 507 wds_->GetBlacklistLogins(&wds_consumer); | |
| 508 | |
| 509 // Wait for the WDS methods to execute on the DB thread. | |
| 510 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 511 base::Bind(&WaitableEvent::Signal, base::Unretained(&done))); | |
| 512 done.Wait(); | |
| 513 | |
| 514 // Handle the callback from the WDS. | |
| 515 MessageLoop::current()->RunAllPending(); | |
| 516 | |
| 517 STLDeleteElements(&expected_autofillable); | |
| 518 STLDeleteElements(&expected_blacklisted); | |
| 519 } | |
| 520 | |
| 521 TEST_F(PasswordStoreWinTest, EmptyLogins) { | 337 TEST_F(PasswordStoreWinTest, EmptyLogins) { |
| 522 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), | 338 store_ = new PasswordStoreWin(login_db_.release(), profile_.get(), |
| 523 wds_.get()); | 339 wds_.get()); |
| 524 store_->Init(); | 340 store_->Init(); |
| 525 | 341 |
| 526 PasswordFormData form_data = { | 342 PasswordFormData form_data = { |
| 527 PasswordForm::SCHEME_HTML, | 343 PasswordForm::SCHEME_HTML, |
| 528 "http://example.com/", | 344 "http://example.com/", |
| 529 "http://example.com/origin", | 345 "http://example.com/origin", |
| 530 "http://example.com/action", | 346 "http://example.com/action", |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 403 |
| 588 VectorOfForms expect_none; | 404 VectorOfForms expect_none; |
| 589 // expect that we get no results; | 405 // expect that we get no results; |
| 590 EXPECT_CALL(consumer, OnPasswordStoreRequestDone( | 406 EXPECT_CALL(consumer, OnPasswordStoreRequestDone( |
| 591 _, ContainsAllPasswordForms(expect_none))) | 407 _, ContainsAllPasswordForms(expect_none))) |
| 592 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); | 408 .WillOnce(DoAll(WithArg<1>(STLDeleteElements0()), QuitUIMessageLoop())); |
| 593 | 409 |
| 594 store_->GetAutofillableLogins(&consumer); | 410 store_->GetAutofillableLogins(&consumer); |
| 595 MessageLoop::current()->Run(); | 411 MessageLoop::current()->Run(); |
| 596 } | 412 } |
| OLD | NEW |