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 <stdarg.h> | 5 #include <stdarg.h> |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/stringprintf.h" | 10 #include "base/stringprintf.h" |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 element = g_list_next(element); | 250 element = g_list_next(element); |
251 } | 251 } |
252 g_list_free(results); | 252 g_list_free(results); |
253 return NULL; | 253 return NULL; |
254 } | 254 } |
255 | 255 |
256 const gchar* mock_gnome_keyring_result_to_message(GnomeKeyringResult res) { | 256 const gchar* mock_gnome_keyring_result_to_message(GnomeKeyringResult res) { |
257 return "mock keyring simulating failure"; | 257 return "mock keyring simulating failure"; |
258 } | 258 } |
259 | 259 |
260 // Inherit to get access to protected fields. | 260 } // namespace |
261 class MockGnomeKeyringLoader : public GnomeKeyringLoader { | |
262 public: | |
263 static bool LoadMockGnomeKeyring() { | |
264 #define GNOME_KEYRING_ASSIGN_POINTER(name) \ | |
265 gnome_keyring_##name = &mock_gnome_keyring_##name; | |
266 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER) | |
267 #undef GNOME_KEYRING_ASSIGN_POINTER | |
268 keyring_loaded = true; | |
269 // Reset the state of the mock library. | |
270 mock_keyring_items.clear(); | |
271 mock_keyring_reject_local_ids = false; | |
272 return true; | |
273 } | |
274 }; | |
275 | |
276 } // anonymous namespace | |
277 | 261 |
278 class NativeBackendGnomeTest : public testing::Test { | 262 class NativeBackendGnomeTest : public testing::Test { |
279 protected: | 263 protected: |
280 NativeBackendGnomeTest() | 264 NativeBackendGnomeTest() |
281 : ui_thread_(BrowserThread::UI, &message_loop_), | 265 : ui_thread_(BrowserThread::UI, &message_loop_), |
282 db_thread_(BrowserThread::DB) { | 266 db_thread_(BrowserThread::DB) { |
283 } | 267 } |
284 | 268 |
285 virtual void SetUp() { | 269 virtual void SetUp() { |
286 ASSERT_TRUE(db_thread_.Start()); | 270 ASSERT_TRUE(db_thread_.Start()); |
287 | 271 |
288 MockGnomeKeyringLoader::LoadMockGnomeKeyring(); | |
289 | |
290 form_google_.origin = GURL("http://www.google.com/"); | 272 form_google_.origin = GURL("http://www.google.com/"); |
291 form_google_.action = GURL("http://www.google.com/login"); | 273 form_google_.action = GURL("http://www.google.com/login"); |
292 form_google_.username_element = UTF8ToUTF16("user"); | 274 form_google_.username_element = UTF8ToUTF16("user"); |
293 form_google_.username_value = UTF8ToUTF16("joeschmoe"); | 275 form_google_.username_value = UTF8ToUTF16("joeschmoe"); |
294 form_google_.password_element = UTF8ToUTF16("pass"); | 276 form_google_.password_element = UTF8ToUTF16("pass"); |
295 form_google_.password_value = UTF8ToUTF16("seekrit"); | 277 form_google_.password_value = UTF8ToUTF16("seekrit"); |
296 form_google_.submit_element = UTF8ToUTF16("submit"); | 278 form_google_.submit_element = UTF8ToUTF16("submit"); |
297 form_google_.signon_realm = "Google"; | 279 form_google_.signon_realm = "Google"; |
298 | 280 |
299 form_isc_.origin = GURL("http://www.isc.org/"); | 281 form_isc_.origin = GURL("http://www.isc.org/"); |
300 form_isc_.action = GURL("http://www.isc.org/auth"); | 282 form_isc_.action = GURL("http://www.isc.org/auth"); |
301 form_isc_.username_element = UTF8ToUTF16("id"); | 283 form_isc_.username_element = UTF8ToUTF16("id"); |
302 form_isc_.username_value = UTF8ToUTF16("janedoe"); | 284 form_isc_.username_value = UTF8ToUTF16("janedoe"); |
303 form_isc_.password_element = UTF8ToUTF16("passwd"); | 285 form_isc_.password_element = UTF8ToUTF16("passwd"); |
304 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); | 286 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); |
305 form_isc_.submit_element = UTF8ToUTF16("login"); | 287 form_isc_.submit_element = UTF8ToUTF16("login"); |
306 form_isc_.signon_realm = "ISC"; | 288 form_isc_.signon_realm = "ISC"; |
307 } | 289 } |
308 | 290 |
309 virtual void TearDown() { | 291 virtual void TearDown() { |
310 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 292 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
311 MessageLoop::current()->Run(); | 293 MessageLoop::current()->Run(); |
312 db_thread_.Stop(); | 294 db_thread_.Stop(); |
313 } | 295 } |
314 | 296 |
| 297 static void SetUpMockKeyring(NativeBackendGnome* backend) { |
| 298 LibGnomeKeyringLoader* loader = backend->libgnome_keyring_loader(); |
| 299 loader->gnome_keyring_is_available = &mock_gnome_keyring_is_available; |
| 300 loader->gnome_keyring_store_password = &mock_gnome_keyring_store_password; |
| 301 loader->gnome_keyring_delete_password = &mock_gnome_keyring_delete_password; |
| 302 loader->gnome_keyring_find_itemsv = &mock_gnome_keyring_find_itemsv; |
| 303 loader->gnome_keyring_result_to_message = |
| 304 &mock_gnome_keyring_result_to_message; |
| 305 |
| 306 // Reset the state of the mock library. |
| 307 mock_keyring_items.clear(); |
| 308 mock_keyring_reject_local_ids = false; |
| 309 } |
| 310 |
315 void RunBothThreads() { | 311 void RunBothThreads() { |
316 // First we post a message to the DB thread that will run after all other | 312 // First we post a message to the DB thread that will run after all other |
317 // messages that have been posted to the DB thread (we don't expect more | 313 // messages that have been posted to the DB thread (we don't expect more |
318 // to be posted), which posts a message to the UI thread to quit the loop. | 314 // to be posted), which posts a message to the UI thread to quit the loop. |
319 // That way we can run both loops and be sure that the UI thread loop will | 315 // That way we can run both loops and be sure that the UI thread loop will |
320 // quit so we can get on with the rest of the test. | 316 // quit so we can get on with the rest of the test. |
321 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 317 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
322 base::Bind(&PostQuitTask, &message_loop_)); | 318 base::Bind(&PostQuitTask, &message_loop_)); |
323 MessageLoop::current()->Run(); | 319 MessageLoop::current()->Run(); |
324 } | 320 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 PasswordForm form_google_; | 384 PasswordForm form_google_; |
389 PasswordForm form_isc_; | 385 PasswordForm form_isc_; |
390 }; | 386 }; |
391 | 387 |
392 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { | 388 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { |
393 // Pretend that the migration has already taken place. | 389 // Pretend that the migration has already taken place. |
394 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 390 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
395 | 391 |
396 NativeBackendGnome backend(42, profile_.GetPrefs()); | 392 NativeBackendGnome backend(42, profile_.GetPrefs()); |
397 backend.Init(); | 393 backend.Init(); |
| 394 SetUpMockKeyring(&backend); |
398 | 395 |
399 BrowserThread::PostTask( | 396 BrowserThread::PostTask( |
400 BrowserThread::DB, FROM_HERE, | 397 BrowserThread::DB, FROM_HERE, |
401 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 398 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
402 base::Unretained(&backend), form_google_)); | 399 base::Unretained(&backend), form_google_)); |
403 | 400 |
404 RunBothThreads(); | 401 RunBothThreads(); |
405 | 402 |
406 EXPECT_EQ(1u, mock_keyring_items.size()); | 403 EXPECT_EQ(1u, mock_keyring_items.size()); |
407 if (mock_keyring_items.size() > 0) | 404 if (mock_keyring_items.size() > 0) |
408 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 405 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
409 } | 406 } |
410 | 407 |
411 TEST_F(NativeBackendGnomeTest, BasicListLogins) { | 408 TEST_F(NativeBackendGnomeTest, BasicListLogins) { |
412 // Pretend that the migration has already taken place. | 409 // Pretend that the migration has already taken place. |
413 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 410 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
414 | 411 |
415 NativeBackendGnome backend(42, profile_.GetPrefs()); | 412 NativeBackendGnome backend(42, profile_.GetPrefs()); |
416 backend.Init(); | 413 backend.Init(); |
| 414 SetUpMockKeyring(&backend); |
417 | 415 |
418 BrowserThread::PostTask( | 416 BrowserThread::PostTask( |
419 BrowserThread::DB, FROM_HERE, | 417 BrowserThread::DB, FROM_HERE, |
420 base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin), | 418 base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin), |
421 base::Unretained(&backend), form_google_)); | 419 base::Unretained(&backend), form_google_)); |
422 | 420 |
423 std::vector<PasswordForm*> form_list; | 421 std::vector<PasswordForm*> form_list; |
424 BrowserThread::PostTask( | 422 BrowserThread::PostTask( |
425 BrowserThread::DB, FROM_HERE, | 423 BrowserThread::DB, FROM_HERE, |
426 base::Bind( | 424 base::Bind( |
(...skipping 10 matching lines...) Expand all Loading... |
437 if (mock_keyring_items.size() > 0) | 435 if (mock_keyring_items.size() > 0) |
438 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 436 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
439 } | 437 } |
440 | 438 |
441 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { | 439 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { |
442 // Pretend that the migration has already taken place. | 440 // Pretend that the migration has already taken place. |
443 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 441 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
444 | 442 |
445 NativeBackendGnome backend(42, profile_.GetPrefs()); | 443 NativeBackendGnome backend(42, profile_.GetPrefs()); |
446 backend.Init(); | 444 backend.Init(); |
| 445 SetUpMockKeyring(&backend); |
447 | 446 |
448 BrowserThread::PostTask( | 447 BrowserThread::PostTask( |
449 BrowserThread::DB, FROM_HERE, | 448 BrowserThread::DB, FROM_HERE, |
450 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 449 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
451 base::Unretained(&backend), form_google_)); | 450 base::Unretained(&backend), form_google_)); |
452 | 451 |
453 RunBothThreads(); | 452 RunBothThreads(); |
454 | 453 |
455 EXPECT_EQ(1u, mock_keyring_items.size()); | 454 EXPECT_EQ(1u, mock_keyring_items.size()); |
456 if (mock_keyring_items.size() > 0) | 455 if (mock_keyring_items.size() > 0) |
457 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 456 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
458 | 457 |
459 BrowserThread::PostTask( | 458 BrowserThread::PostTask( |
460 BrowserThread::DB, FROM_HERE, | 459 BrowserThread::DB, FROM_HERE, |
461 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | 460 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), |
462 base::Unretained(&backend), form_google_)); | 461 base::Unretained(&backend), form_google_)); |
463 | 462 |
464 RunBothThreads(); | 463 RunBothThreads(); |
465 | 464 |
466 EXPECT_EQ(0u, mock_keyring_items.size()); | 465 EXPECT_EQ(0u, mock_keyring_items.size()); |
467 } | 466 } |
468 | 467 |
469 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { | 468 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { |
470 // Pretend that the migration has already taken place. | 469 // Pretend that the migration has already taken place. |
471 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 470 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
472 | 471 |
473 NativeBackendGnome backend(42, profile_.GetPrefs()); | 472 NativeBackendGnome backend(42, profile_.GetPrefs()); |
474 backend.Init(); | 473 backend.Init(); |
| 474 SetUpMockKeyring(&backend); |
475 | 475 |
476 // First add an unrelated login. | 476 // First add an unrelated login. |
477 BrowserThread::PostTask( | 477 BrowserThread::PostTask( |
478 BrowserThread::DB, FROM_HERE, | 478 BrowserThread::DB, FROM_HERE, |
479 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 479 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
480 base::Unretained(&backend), form_google_)); | 480 base::Unretained(&backend), form_google_)); |
481 | 481 |
482 RunBothThreads(); | 482 RunBothThreads(); |
483 | 483 |
484 EXPECT_EQ(1u, mock_keyring_items.size()); | 484 EXPECT_EQ(1u, mock_keyring_items.size()); |
(...skipping 24 matching lines...) Expand all Loading... |
509 if (mock_keyring_items.size() > 0) | 509 if (mock_keyring_items.size() > 0) |
510 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 510 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
511 } | 511 } |
512 | 512 |
513 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { | 513 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { |
514 // Pretend that the migration has already taken place. | 514 // Pretend that the migration has already taken place. |
515 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 515 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
516 | 516 |
517 NativeBackendGnome backend(42, profile_.GetPrefs()); | 517 NativeBackendGnome backend(42, profile_.GetPrefs()); |
518 backend.Init(); | 518 backend.Init(); |
| 519 SetUpMockKeyring(&backend); |
519 | 520 |
520 BrowserThread::PostTask( | 521 BrowserThread::PostTask( |
521 BrowserThread::DB, FROM_HERE, | 522 BrowserThread::DB, FROM_HERE, |
522 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 523 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
523 base::Unretained(&backend), form_google_)); | 524 base::Unretained(&backend), form_google_)); |
524 BrowserThread::PostTask( | 525 BrowserThread::PostTask( |
525 BrowserThread::DB, FROM_HERE, | 526 BrowserThread::DB, FROM_HERE, |
526 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 527 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
527 base::Unretained(&backend), form_google_)); | 528 base::Unretained(&backend), form_google_)); |
528 | 529 |
529 RunBothThreads(); | 530 RunBothThreads(); |
530 | 531 |
531 EXPECT_EQ(1u, mock_keyring_items.size()); | 532 EXPECT_EQ(1u, mock_keyring_items.size()); |
532 if (mock_keyring_items.size() > 0) | 533 if (mock_keyring_items.size() > 0) |
533 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 534 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
534 } | 535 } |
535 | 536 |
536 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { | 537 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { |
537 // Pretend that the migration has already taken place. | 538 // Pretend that the migration has already taken place. |
538 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 539 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
539 | 540 |
540 NativeBackendGnome backend(42, profile_.GetPrefs()); | 541 NativeBackendGnome backend(42, profile_.GetPrefs()); |
541 backend.Init(); | 542 backend.Init(); |
| 543 SetUpMockKeyring(&backend); |
542 | 544 |
543 BrowserThread::PostTask( | 545 BrowserThread::PostTask( |
544 BrowserThread::DB, FROM_HERE, | 546 BrowserThread::DB, FROM_HERE, |
545 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 547 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
546 base::Unretained(&backend), form_google_)); | 548 base::Unretained(&backend), form_google_)); |
547 | 549 |
548 // Send the same request twice with the same list both times. | 550 // Send the same request twice with the same list both times. |
549 std::vector<PasswordForm*> form_list; | 551 std::vector<PasswordForm*> form_list; |
550 BrowserThread::PostTask( | 552 BrowserThread::PostTask( |
551 BrowserThread::DB, FROM_HERE, | 553 BrowserThread::DB, FROM_HERE, |
(...skipping 19 matching lines...) Expand all Loading... |
571 | 573 |
572 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. | 574 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. |
573 | 575 |
574 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { | 576 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { |
575 // Reject attempts to migrate so we can populate the store. | 577 // Reject attempts to migrate so we can populate the store. |
576 mock_keyring_reject_local_ids = true; | 578 mock_keyring_reject_local_ids = true; |
577 | 579 |
578 { | 580 { |
579 NativeBackendGnome backend(42, profile_.GetPrefs()); | 581 NativeBackendGnome backend(42, profile_.GetPrefs()); |
580 backend.Init(); | 582 backend.Init(); |
| 583 SetUpMockKeyring(&backend); |
581 | 584 |
582 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 585 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
583 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 586 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
584 base::Unretained(&backend), form_google_)); | 587 base::Unretained(&backend), form_google_)); |
585 | 588 |
586 // Make sure we can get the form back even when migration is failing. | 589 // Make sure we can get the form back even when migration is failing. |
587 std::vector<PasswordForm*> form_list; | 590 std::vector<PasswordForm*> form_list; |
588 BrowserThread::PostTask( | 591 BrowserThread::PostTask( |
589 BrowserThread::DB, FROM_HERE, | 592 BrowserThread::DB, FROM_HERE, |
590 base::Bind( | 593 base::Bind( |
(...skipping 10 matching lines...) Expand all Loading... |
601 EXPECT_EQ(1u, mock_keyring_items.size()); | 604 EXPECT_EQ(1u, mock_keyring_items.size()); |
602 if (mock_keyring_items.size() > 0) | 605 if (mock_keyring_items.size() > 0) |
603 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 606 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
604 | 607 |
605 // Now allow the migration. | 608 // Now allow the migration. |
606 mock_keyring_reject_local_ids = false; | 609 mock_keyring_reject_local_ids = false; |
607 | 610 |
608 { | 611 { |
609 NativeBackendGnome backend(42, profile_.GetPrefs()); | 612 NativeBackendGnome backend(42, profile_.GetPrefs()); |
610 backend.Init(); | 613 backend.Init(); |
| 614 SetUpMockKeyring(&backend); |
611 | 615 |
612 // This should not trigger migration because there will be no results. | 616 // This should not trigger migration because there will be no results. |
613 std::vector<PasswordForm*> form_list; | 617 std::vector<PasswordForm*> form_list; |
614 BrowserThread::PostTask( | 618 BrowserThread::PostTask( |
615 BrowserThread::DB, FROM_HERE, | 619 BrowserThread::DB, FROM_HERE, |
616 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins), | 620 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins), |
617 base::Unretained(&backend), &form_list)); | 621 base::Unretained(&backend), &form_list)); |
618 | 622 |
619 RunBothThreads(); | 623 RunBothThreads(); |
620 | 624 |
621 // Check that we got nothing back. | 625 // Check that we got nothing back. |
622 EXPECT_EQ(0u, form_list.size()); | 626 EXPECT_EQ(0u, form_list.size()); |
623 STLDeleteElements(&form_list); | 627 STLDeleteElements(&form_list); |
624 } | 628 } |
625 | 629 |
626 // Check that the keyring is unmodified. | 630 // Check that the keyring is unmodified. |
627 EXPECT_EQ(1u, mock_keyring_items.size()); | 631 EXPECT_EQ(1u, mock_keyring_items.size()); |
628 if (mock_keyring_items.size() > 0) | 632 if (mock_keyring_items.size() > 0) |
629 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 633 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
630 | 634 |
631 // Check that we haven't set the persistent preference. | 635 // Check that we haven't set the persistent preference. |
632 EXPECT_FALSE( | 636 EXPECT_FALSE( |
633 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 637 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
634 | 638 |
635 { | 639 { |
636 NativeBackendGnome backend(42, profile_.GetPrefs()); | 640 NativeBackendGnome backend(42, profile_.GetPrefs()); |
637 backend.Init(); | 641 backend.Init(); |
| 642 SetUpMockKeyring(&backend); |
638 | 643 |
639 // Trigger the migration by looking something up. | 644 // Trigger the migration by looking something up. |
640 std::vector<PasswordForm*> form_list; | 645 std::vector<PasswordForm*> form_list; |
641 BrowserThread::PostTask( | 646 BrowserThread::PostTask( |
642 BrowserThread::DB, FROM_HERE, | 647 BrowserThread::DB, FROM_HERE, |
643 base::Bind( | 648 base::Bind( |
644 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 649 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
645 base::Unretained(&backend), &form_list)); | 650 base::Unretained(&backend), &form_list)); |
646 | 651 |
647 RunBothThreads(); | 652 RunBothThreads(); |
(...skipping 14 matching lines...) Expand all Loading... |
662 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 667 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
663 } | 668 } |
664 | 669 |
665 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { | 670 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { |
666 // Reject attempts to migrate so we can populate the store. | 671 // Reject attempts to migrate so we can populate the store. |
667 mock_keyring_reject_local_ids = true; | 672 mock_keyring_reject_local_ids = true; |
668 | 673 |
669 { | 674 { |
670 NativeBackendGnome backend(42, profile_.GetPrefs()); | 675 NativeBackendGnome backend(42, profile_.GetPrefs()); |
671 backend.Init(); | 676 backend.Init(); |
| 677 SetUpMockKeyring(&backend); |
672 | 678 |
673 BrowserThread::PostTask( | 679 BrowserThread::PostTask( |
674 BrowserThread::DB, FROM_HERE, | 680 BrowserThread::DB, FROM_HERE, |
675 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 681 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
676 base::Unretained(&backend), form_google_)); | 682 base::Unretained(&backend), form_google_)); |
677 | 683 |
678 RunBothThreads(); | 684 RunBothThreads(); |
679 } | 685 } |
680 | 686 |
681 EXPECT_EQ(1u, mock_keyring_items.size()); | 687 EXPECT_EQ(1u, mock_keyring_items.size()); |
682 if (mock_keyring_items.size() > 0) | 688 if (mock_keyring_items.size() > 0) |
683 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 689 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
684 | 690 |
685 // Now allow the migration. | 691 // Now allow the migration. |
686 mock_keyring_reject_local_ids = false; | 692 mock_keyring_reject_local_ids = false; |
687 | 693 |
688 { | 694 { |
689 NativeBackendGnome backend(42, profile_.GetPrefs()); | 695 NativeBackendGnome backend(42, profile_.GetPrefs()); |
690 backend.Init(); | 696 backend.Init(); |
| 697 SetUpMockKeyring(&backend); |
691 | 698 |
692 // Trigger the migration by looking something up. | 699 // Trigger the migration by looking something up. |
693 std::vector<PasswordForm*> form_list; | 700 std::vector<PasswordForm*> form_list; |
694 BrowserThread::PostTask( | 701 BrowserThread::PostTask( |
695 BrowserThread::DB, FROM_HERE, | 702 BrowserThread::DB, FROM_HERE, |
696 base::Bind( | 703 base::Bind( |
697 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 704 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
698 base::Unretained(&backend), &form_list)); | 705 base::Unretained(&backend), &form_list)); |
699 | 706 |
700 RunBothThreads(); | 707 RunBothThreads(); |
(...skipping 13 matching lines...) Expand all Loading... |
714 EXPECT_TRUE( | 721 EXPECT_TRUE( |
715 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 722 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
716 | 723 |
717 // Normally we'd actually have a different profile. But in the test just reset | 724 // Normally we'd actually have a different profile. But in the test just reset |
718 // the profile's persistent pref; we pass in the local profile id anyway. | 725 // the profile's persistent pref; we pass in the local profile id anyway. |
719 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | 726 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); |
720 | 727 |
721 { | 728 { |
722 NativeBackendGnome backend(24, profile_.GetPrefs()); | 729 NativeBackendGnome backend(24, profile_.GetPrefs()); |
723 backend.Init(); | 730 backend.Init(); |
| 731 SetUpMockKeyring(&backend); |
724 | 732 |
725 // Trigger the migration by looking something up. | 733 // Trigger the migration by looking something up. |
726 std::vector<PasswordForm*> form_list; | 734 std::vector<PasswordForm*> form_list; |
727 BrowserThread::PostTask( | 735 BrowserThread::PostTask( |
728 BrowserThread::DB, FROM_HERE, | 736 BrowserThread::DB, FROM_HERE, |
729 base::Bind( | 737 base::Bind( |
730 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 738 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
731 base::Unretained(&backend), &form_list)); | 739 base::Unretained(&backend), &form_list)); |
732 | 740 |
733 RunBothThreads(); | 741 RunBothThreads(); |
(...skipping 12 matching lines...) Expand all Loading... |
746 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); | 754 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); |
747 } | 755 } |
748 | 756 |
749 TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { | 757 TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { |
750 // Reject attempts to migrate so we can populate the store. | 758 // Reject attempts to migrate so we can populate the store. |
751 mock_keyring_reject_local_ids = true; | 759 mock_keyring_reject_local_ids = true; |
752 | 760 |
753 { | 761 { |
754 NativeBackendGnome backend(42, profile_.GetPrefs()); | 762 NativeBackendGnome backend(42, profile_.GetPrefs()); |
755 backend.Init(); | 763 backend.Init(); |
| 764 SetUpMockKeyring(&backend); |
756 | 765 |
757 BrowserThread::PostTask( | 766 BrowserThread::PostTask( |
758 BrowserThread::DB, FROM_HERE, | 767 BrowserThread::DB, FROM_HERE, |
759 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 768 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
760 base::Unretained(&backend), form_google_)); | 769 base::Unretained(&backend), form_google_)); |
761 | 770 |
762 RunBothThreads(); | 771 RunBothThreads(); |
763 } | 772 } |
764 | 773 |
765 EXPECT_EQ(1u, mock_keyring_items.size()); | 774 EXPECT_EQ(1u, mock_keyring_items.size()); |
766 if (mock_keyring_items.size() > 0) | 775 if (mock_keyring_items.size() > 0) |
767 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 776 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
768 | 777 |
769 // Now allow migration, but also pretend that the it has already taken place. | 778 // Now allow migration, but also pretend that the it has already taken place. |
770 mock_keyring_reject_local_ids = false; | 779 mock_keyring_reject_local_ids = false; |
771 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 780 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
772 | 781 |
773 { | 782 { |
774 NativeBackendGnome backend(42, profile_.GetPrefs()); | 783 NativeBackendGnome backend(42, profile_.GetPrefs()); |
775 backend.Init(); | 784 backend.Init(); |
| 785 SetUpMockKeyring(&backend); |
776 | 786 |
777 // Trigger the migration by adding a new login. | 787 // Trigger the migration by adding a new login. |
778 BrowserThread::PostTask( | 788 BrowserThread::PostTask( |
779 BrowserThread::DB, FROM_HERE, | 789 BrowserThread::DB, FROM_HERE, |
780 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 790 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
781 base::Unretained(&backend), form_isc_)); | 791 base::Unretained(&backend), form_isc_)); |
782 | 792 |
783 // Look up all logins; we expect only the one we added. | 793 // Look up all logins; we expect only the one we added. |
784 std::vector<PasswordForm*> form_list; | 794 std::vector<PasswordForm*> form_list; |
785 BrowserThread::PostTask( | 795 BrowserThread::PostTask( |
(...skipping 18 matching lines...) Expand all Loading... |
804 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); | 814 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); |
805 } | 815 } |
806 | 816 |
807 TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { | 817 TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { |
808 // Reject attempts to migrate so we can populate the store. | 818 // Reject attempts to migrate so we can populate the store. |
809 mock_keyring_reject_local_ids = true; | 819 mock_keyring_reject_local_ids = true; |
810 | 820 |
811 { | 821 { |
812 NativeBackendGnome backend(42, profile_.GetPrefs()); | 822 NativeBackendGnome backend(42, profile_.GetPrefs()); |
813 backend.Init(); | 823 backend.Init(); |
| 824 SetUpMockKeyring(&backend); |
814 | 825 |
815 BrowserThread::PostTask( | 826 BrowserThread::PostTask( |
816 BrowserThread::DB, FROM_HERE, | 827 BrowserThread::DB, FROM_HERE, |
817 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 828 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
818 base::Unretained(&backend), form_google_)); | 829 base::Unretained(&backend), form_google_)); |
819 | 830 |
820 RunBothThreads(); | 831 RunBothThreads(); |
821 } | 832 } |
822 | 833 |
823 EXPECT_EQ(1u, mock_keyring_items.size()); | 834 EXPECT_EQ(1u, mock_keyring_items.size()); |
824 if (mock_keyring_items.size() > 0) | 835 if (mock_keyring_items.size() > 0) |
825 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 836 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
826 | 837 |
827 // Now allow the migration. | 838 // Now allow the migration. |
828 mock_keyring_reject_local_ids = false; | 839 mock_keyring_reject_local_ids = false; |
829 | 840 |
830 { | 841 { |
831 NativeBackendGnome backend(42, profile_.GetPrefs()); | 842 NativeBackendGnome backend(42, profile_.GetPrefs()); |
832 backend.Init(); | 843 backend.Init(); |
| 844 SetUpMockKeyring(&backend); |
833 | 845 |
834 // Trigger the migration by looking something up. | 846 // Trigger the migration by looking something up. |
835 std::vector<PasswordForm*> form_list; | 847 std::vector<PasswordForm*> form_list; |
836 BrowserThread::PostTask( | 848 BrowserThread::PostTask( |
837 BrowserThread::DB, FROM_HERE, | 849 BrowserThread::DB, FROM_HERE, |
838 base::Bind( | 850 base::Bind( |
839 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 851 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
840 base::Unretained(&backend), &form_list)); | 852 base::Unretained(&backend), &form_list)); |
841 | 853 |
842 RunBothThreads(); | 854 RunBothThreads(); |
(...skipping 13 matching lines...) Expand all Loading... |
856 EXPECT_TRUE( | 868 EXPECT_TRUE( |
857 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 869 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
858 | 870 |
859 // Normally we'd actually have a different profile. But in the test just reset | 871 // Normally we'd actually have a different profile. But in the test just reset |
860 // the profile's persistent pref; we pass in the local profile id anyway. | 872 // the profile's persistent pref; we pass in the local profile id anyway. |
861 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | 873 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); |
862 | 874 |
863 { | 875 { |
864 NativeBackendGnome backend(24, profile_.GetPrefs()); | 876 NativeBackendGnome backend(24, profile_.GetPrefs()); |
865 backend.Init(); | 877 backend.Init(); |
| 878 SetUpMockKeyring(&backend); |
866 | 879 |
867 // Trigger the migration by looking something up. | 880 // Trigger the migration by looking something up. |
868 std::vector<PasswordForm*> form_list; | 881 std::vector<PasswordForm*> form_list; |
869 BrowserThread::PostTask( | 882 BrowserThread::PostTask( |
870 BrowserThread::DB, FROM_HERE, | 883 BrowserThread::DB, FROM_HERE, |
871 base::Bind( | 884 base::Bind( |
872 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 885 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
873 base::Unretained(&backend), &form_list)); | 886 base::Unretained(&backend), &form_list)); |
874 | 887 |
875 RunBothThreads(); | 888 RunBothThreads(); |
(...skipping 20 matching lines...) Expand all Loading... |
896 RunBothThreads(); | 909 RunBothThreads(); |
897 | 910 |
898 // The other two copies of the password in different profiles should remain. | 911 // The other two copies of the password in different profiles should remain. |
899 EXPECT_EQ(2u, mock_keyring_items.size()); | 912 EXPECT_EQ(2u, mock_keyring_items.size()); |
900 if (mock_keyring_items.size() > 0) | 913 if (mock_keyring_items.size() > 0) |
901 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 914 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
902 if (mock_keyring_items.size() > 1) | 915 if (mock_keyring_items.size() > 1) |
903 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 916 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
904 } | 917 } |
905 } | 918 } |
OLD | NEW |