Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/password_manager/native_backend_gnome_x_unittest.cc

Issue 8509038: Linux: split GNOME Keyring integration into a separate process. Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: everything works Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <sys/socket.h>
6 7
7 #include "base/basictypes.h" 8 #include "base/basictypes.h"
8 #include "base/stl_util.h" 9 #include "base/stl_util.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
11 #include "base/time.h" 12 #include "base/time.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/password_manager/native_backend_gnome_x.h" 14 #include "chrome/browser/password_manager/native_backend_gnome_x.h"
15 #include "chrome/browser/password_manager/proxy/chrome_keyring_proxy.h"
16 #include "chrome/browser/password_manager/proxy/chrome_keyring_proxy_client.h"
17 #include "chrome/browser/password_manager/proxy/keyring_loader.h"
14 #include "chrome/browser/prefs/pref_service.h" 18 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
16 #include "chrome/test/base/testing_profile.h" 20 #include "chrome/test/base/testing_profile.h"
17 #include "content/test/test_browser_thread.h" 21 #include "content/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
19 23
20 using webkit_glue::PasswordForm; 24 using webkit_glue::PasswordForm;
21 25
22 namespace { 26 namespace {
23 27
24 // What follows is a very simple implementation of the subset of the GNOME 28 // What follows is a very simple implementation of the subset of the GNOME
25 // Keyring API that we actually use. It gets substituted for the real one by 29 // Keyring API that we actually use. It gets substituted for the real one by
26 // MockGnomeKeyringLoader, which hooks into the facility normally used to load 30 // MockGnomeKeyringLoader, which hooks into the facility normally used to load
27 // the GNOME Keyring library at runtime to avoid a static dependency on it. 31 // the GNOME Keyring library at runtime to avoid a static dependency on it.
32 // We also use some special glue code to link directly with the main keyring
33 // proxy code and thus call into the mock implementation in this process,
34 // rather than in a separate proxy process. (See below.)
28 35
29 struct MockKeyringItem { 36 struct MockKeyringItem {
30 MockKeyringItem() {} 37 MockKeyringItem() {}
31 MockKeyringItem(const char* keyring, 38 MockKeyringItem(const char* keyring,
32 const std::string& display_name, 39 const std::string& display_name,
33 const std::string& password) 40 const std::string& password)
34 : keyring(keyring ? keyring : "login"), 41 : keyring(keyring ? keyring : "login"),
35 display_name(display_name), 42 display_name(display_name),
36 password(password) {} 43 password(password) {}
37 44
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER) 272 GNOME_KEYRING_FOR_EACH_FUNC(GNOME_KEYRING_ASSIGN_POINTER)
266 #undef GNOME_KEYRING_ASSIGN_POINTER 273 #undef GNOME_KEYRING_ASSIGN_POINTER
267 keyring_loaded = true; 274 keyring_loaded = true;
268 // Reset the state of the mock library. 275 // Reset the state of the mock library.
269 mock_keyring_items.clear(); 276 mock_keyring_items.clear();
270 mock_keyring_reject_local_ids = false; 277 mock_keyring_reject_local_ids = false;
271 return true; 278 return true;
272 } 279 }
273 }; 280 };
274 281
282 // Now that we can inject a mock GNOME Keyring API, we need to glue the keyring
283 // proxy client directly to the proxy code, which is linked into the unit test
284 // directly. We do this by creating a socket and giving one end to each, but we
285 // need some slightly adapted proxy and proxy client classes to make that work.
286
287 class TestChromeKeyringProxy : public ChromeKeyringProxy {
288 public:
289 explicit TestChromeKeyringProxy(int fd)
290 : ChromeKeyringProxy(fd, CreateOutput(fd)) {}
291 ~TestChromeKeyringProxy() { fclose(output_); }
292
293 private:
294 // This is a bit of a hack. We need to do this before calling the constructor
295 // for ChromeKeyringProxy, since it needs a FILE*. So we have a member method
296 // that fills in output_ for us before the body of our constructor even runs.
297 // It's safe since there's nothing virtual involved.
298 FILE* CreateOutput(int fd) {
299 int dup_fd = dup(fd);
300 CHECK_GE(dup_fd, 0);
301 output_ = fdopen(dup_fd, "r+");
302 CHECK(output_);
303 return output_;
304 }
305
306 FILE* output_;
307 };
308
309 class TestChromeKeyringProxyClient : public ChromeKeyringProxyClient {
310 public:
311 using ChromeKeyringProxyClient::ConnectForTesting;
312 };
313
314 class TestNativeBackendGnome : public NativeBackendGnome {
315 public:
316 using NativeBackendGnome::InitForTesting;
317 };
318
275 } // anonymous namespace 319 } // anonymous namespace
276 320
277 class NativeBackendGnomeTest : public testing::Test { 321 class NativeBackendGnomeTest : public testing::Test {
278 protected: 322 protected:
279 NativeBackendGnomeTest() 323 NativeBackendGnomeTest()
280 : ui_thread_(BrowserThread::UI, &message_loop_), 324 : ui_thread_(BrowserThread::UI, &message_loop_),
281 db_thread_(BrowserThread::DB) { 325 db_thread_(BrowserThread::DB),
326 file_thread_(BrowserThread::FILE) {
282 } 327 }
283 328
284 virtual void SetUp() { 329 virtual void SetUp() {
285 ASSERT_TRUE(db_thread_.Start()); 330 ASSERT_TRUE(db_thread_.Start());
331 base::Thread::Options options(MessageLoop::TYPE_IO, 0);
332 ASSERT_TRUE(file_thread_.StartWithOptions(options));
286 333
287 MockGnomeKeyringLoader::LoadMockGnomeKeyring(); 334 MockGnomeKeyringLoader::LoadMockGnomeKeyring();
288 335
336 int fds[2];
337 ASSERT_TRUE(socketpair(AF_LOCAL, SOCK_STREAM, 0, fds) >= 0);
338 // Give one side to the proxy itself, which is linked into the unit test.
339 // We won't call its Run() method, but its events will run from the UI
340 // thread's GMainContext automatically. Its Stop() method won't work.
341 proxy_.reset(new TestChromeKeyringProxy(fds[0]));
342 // Save the other side for test proxy clients.
343 proxy_fd_ = fds[1];
344
289 form_google_.origin = GURL("http://www.google.com/"); 345 form_google_.origin = GURL("http://www.google.com/");
290 form_google_.action = GURL("http://www.google.com/login"); 346 form_google_.action = GURL("http://www.google.com/login");
291 form_google_.username_element = UTF8ToUTF16("user"); 347 form_google_.username_element = UTF8ToUTF16("user");
292 form_google_.username_value = UTF8ToUTF16("joeschmoe"); 348 form_google_.username_value = UTF8ToUTF16("joeschmoe");
293 form_google_.password_element = UTF8ToUTF16("pass"); 349 form_google_.password_element = UTF8ToUTF16("pass");
294 form_google_.password_value = UTF8ToUTF16("seekrit"); 350 form_google_.password_value = UTF8ToUTF16("seekrit");
295 form_google_.submit_element = UTF8ToUTF16("submit"); 351 form_google_.submit_element = UTF8ToUTF16("submit");
296 form_google_.signon_realm = "Google"; 352 form_google_.signon_realm = "Google";
297 353
298 form_isc_.origin = GURL("http://www.isc.org/"); 354 form_isc_.origin = GURL("http://www.isc.org/");
299 form_isc_.action = GURL("http://www.isc.org/auth"); 355 form_isc_.action = GURL("http://www.isc.org/auth");
300 form_isc_.username_element = UTF8ToUTF16("id"); 356 form_isc_.username_element = UTF8ToUTF16("id");
301 form_isc_.username_value = UTF8ToUTF16("janedoe"); 357 form_isc_.username_value = UTF8ToUTF16("janedoe");
302 form_isc_.password_element = UTF8ToUTF16("passwd"); 358 form_isc_.password_element = UTF8ToUTF16("passwd");
303 form_isc_.password_value = UTF8ToUTF16("ihazabukkit"); 359 form_isc_.password_value = UTF8ToUTF16("ihazabukkit");
304 form_isc_.submit_element = UTF8ToUTF16("login"); 360 form_isc_.submit_element = UTF8ToUTF16("login");
305 form_isc_.signon_realm = "ISC"; 361 form_isc_.signon_realm = "ISC";
306 } 362 }
307 363
308 virtual void TearDown() { 364 virtual void TearDown() {
309 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); 365 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
310 MessageLoop::current()->Run(); 366 MessageLoop::current()->Run();
367 // It is important to close this file descriptor only after finishing
368 // running the UI thread's message loop, or else it will get into an
369 // infinite loop due to the proxy's Stop() method not working with the
370 // way we've linked it directly with the unit test.
371 close(proxy_fd_);
372 file_thread_.Stop();
311 db_thread_.Stop(); 373 db_thread_.Stop();
312 } 374 }
313 375
314 void RunBothThreads() { 376 void InitNativeBackend(NativeBackendGnome* backend) {
377 int fd = dup(proxy_fd_);
378 ASSERT_GE(fd, 0);
379 TestChromeKeyringProxyClient* client = new TestChromeKeyringProxyClient;
380 client->ConnectForTesting(fd, true);
381 // The cast is safe because all it does is change protection.
382 static_cast<TestNativeBackendGnome*>(backend)->InitForTesting(client);
383 }
384
385 void RunAllThreads() {
315 // First we post a message to the DB thread that will run after all other 386 // First we post a message to the DB thread that will run after all other
316 // messages that have been posted to the DB thread (we don't expect more 387 // messages that have been posted to the DB thread (we don't expect more
317 // to be posted), which posts a message to the UI thread to quit the loop. 388 // to be posted), which posts a message to the UI thread to quit the loop.
318 // That way we can run both loops and be sure that the UI thread loop will 389 // That way we can run both loops and be sure that the UI thread loop will
319 // quit so we can get on with the rest of the test. 390 // quit so we can get on with the rest of the test.
320 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 391 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
321 base::Bind(&PostQuitTask, &message_loop_)); 392 base::Bind(&PostQuitTask, &message_loop_));
322 MessageLoop::current()->Run(); 393 MessageLoop::current()->Run();
323 } 394 }
324 395
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 CheckUint32Attribute(item, "preferred", form.preferred); 444 CheckUint32Attribute(item, "preferred", form.preferred);
374 // We don't check the date created. It varies. 445 // We don't check the date created. It varies.
375 CheckUint32Attribute(item, "blacklisted_by_user", form.blacklisted_by_user); 446 CheckUint32Attribute(item, "blacklisted_by_user", form.blacklisted_by_user);
376 CheckUint32Attribute(item, "scheme", form.scheme); 447 CheckUint32Attribute(item, "scheme", form.scheme);
377 CheckStringAttribute(item, "application", app_string); 448 CheckStringAttribute(item, "application", app_string);
378 } 449 }
379 450
380 MessageLoopForUI message_loop_; 451 MessageLoopForUI message_loop_;
381 content::TestBrowserThread ui_thread_; 452 content::TestBrowserThread ui_thread_;
382 content::TestBrowserThread db_thread_; 453 content::TestBrowserThread db_thread_;
454 content::TestBrowserThread file_thread_;
383 455
384 TestingProfile profile_; 456 TestingProfile profile_;
385 457
458 // By its very existence, the test proxy integrates with the UI thread's
459 // message loop (via GMainContext). We don't need to access it explicitly.
460 scoped_ptr<TestChromeKeyringProxy> proxy_;
461 // This is the file descriptor connected to the proxy, suitable for dup()ing
462 // and using to construct TestChromeKeyringProxyClients.
463 int proxy_fd_;
464
386 // Provide some test forms to avoid having to set them up in each test. 465 // Provide some test forms to avoid having to set them up in each test.
387 PasswordForm form_google_; 466 PasswordForm form_google_;
388 PasswordForm form_isc_; 467 PasswordForm form_isc_;
389 }; 468 };
390 469
391 TEST_F(NativeBackendGnomeTest, BasicAddLogin) { 470 TEST_F(NativeBackendGnomeTest, BasicAddLogin) {
392 // Pretend that the migration has already taken place. 471 // Pretend that the migration has already taken place.
393 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 472 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
394 473
395 NativeBackendGnome backend(42, profile_.GetPrefs()); 474 NativeBackendGnome backend(42, profile_.GetPrefs());
396 backend.Init(); 475 InitNativeBackend(&backend);
397 476
398 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 477 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
399 base::IgnoreReturn<bool>(base::Bind( 478 base::IgnoreReturn<bool>(base::Bind(
400 &NativeBackendGnome::AddLogin, 479 &NativeBackendGnome::AddLogin,
401 base::Unretained(&backend), form_google_))); 480 base::Unretained(&backend), form_google_)));
402 481
403 RunBothThreads(); 482 RunAllThreads();
404 483
405 EXPECT_EQ(1u, mock_keyring_items.size()); 484 EXPECT_EQ(1u, mock_keyring_items.size());
406 if (mock_keyring_items.size() > 0) 485 if (mock_keyring_items.size() > 0)
407 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 486 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
408 } 487 }
409 488
410 TEST_F(NativeBackendGnomeTest, BasicListLogins) { 489 TEST_F(NativeBackendGnomeTest, BasicListLogins) {
411 // Pretend that the migration has already taken place. 490 // Pretend that the migration has already taken place.
412 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 491 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
413 492
414 NativeBackendGnome backend(42, profile_.GetPrefs()); 493 NativeBackendGnome backend(42, profile_.GetPrefs());
415 backend.Init(); 494 InitNativeBackend(&backend);
416 495
417 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 496 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
418 base::IgnoreReturn<bool>(base::Bind( 497 base::IgnoreReturn<bool>(base::Bind(
419 &NativeBackendGnome::AddLogin, 498 &NativeBackendGnome::AddLogin,
420 base::Unretained(&backend), form_google_))); 499 base::Unretained(&backend), form_google_)));
421 500
422 std::vector<PasswordForm*> form_list; 501 std::vector<PasswordForm*> form_list;
423 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 502 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
424 base::IgnoreReturn<bool>(base::Bind( 503 base::IgnoreReturn<bool>(base::Bind(
425 &NativeBackendGnome::GetAutofillableLogins, 504 &NativeBackendGnome::GetAutofillableLogins,
426 base::Unretained(&backend), &form_list))); 505 base::Unretained(&backend), &form_list)));
427 506
428 RunBothThreads(); 507 RunAllThreads();
429 508
430 // Quick check that we got something back. 509 // Quick check that we got something back.
431 EXPECT_EQ(1u, form_list.size()); 510 EXPECT_EQ(1u, form_list.size());
432 STLDeleteElements(&form_list); 511 STLDeleteElements(&form_list);
433 512
434 EXPECT_EQ(1u, mock_keyring_items.size()); 513 EXPECT_EQ(1u, mock_keyring_items.size());
435 if (mock_keyring_items.size() > 0) 514 if (mock_keyring_items.size() > 0)
436 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 515 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
437 } 516 }
438 517
439 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { 518 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) {
440 // Pretend that the migration has already taken place. 519 // Pretend that the migration has already taken place.
441 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 520 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
442 521
443 NativeBackendGnome backend(42, profile_.GetPrefs()); 522 NativeBackendGnome backend(42, profile_.GetPrefs());
444 backend.Init(); 523 InitNativeBackend(&backend);
445 524
446 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 525 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
447 base::IgnoreReturn<bool>(base::Bind( 526 base::IgnoreReturn<bool>(base::Bind(
448 &NativeBackendGnome::AddLogin, 527 &NativeBackendGnome::AddLogin,
449 base::Unretained(&backend), form_google_))); 528 base::Unretained(&backend), form_google_)));
450 529
451 RunBothThreads(); 530 RunAllThreads();
452 531
453 EXPECT_EQ(1u, mock_keyring_items.size()); 532 EXPECT_EQ(1u, mock_keyring_items.size());
454 if (mock_keyring_items.size() > 0) 533 if (mock_keyring_items.size() > 0)
455 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 534 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
456 535
457 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 536 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
458 base::IgnoreReturn<bool>(base::Bind( 537 base::IgnoreReturn<bool>(base::Bind(
459 &NativeBackendGnome::RemoveLogin, 538 &NativeBackendGnome::RemoveLogin,
460 base::Unretained(&backend), form_google_))); 539 base::Unretained(&backend), form_google_)));
461 540
462 RunBothThreads(); 541 RunAllThreads();
463 542
464 EXPECT_EQ(0u, mock_keyring_items.size()); 543 EXPECT_EQ(0u, mock_keyring_items.size());
465 } 544 }
466 545
467 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { 546 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) {
468 // Pretend that the migration has already taken place. 547 // Pretend that the migration has already taken place.
469 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 548 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
470 549
471 NativeBackendGnome backend(42, profile_.GetPrefs()); 550 NativeBackendGnome backend(42, profile_.GetPrefs());
472 backend.Init(); 551 InitNativeBackend(&backend);
473 552
474 // First add an unrelated login. 553 // First add an unrelated login.
475 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 554 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
476 base::IgnoreReturn<bool>(base::Bind( 555 base::IgnoreReturn<bool>(base::Bind(
477 &NativeBackendGnome::AddLogin, 556 &NativeBackendGnome::AddLogin,
478 base::Unretained(&backend), form_google_))); 557 base::Unretained(&backend), form_google_)));
479 558
480 RunBothThreads(); 559 RunAllThreads();
481 560
482 EXPECT_EQ(1u, mock_keyring_items.size()); 561 EXPECT_EQ(1u, mock_keyring_items.size());
483 if (mock_keyring_items.size() > 0) 562 if (mock_keyring_items.size() > 0)
484 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 563 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
485 564
486 // Attempt to remove a login that doesn't exist. 565 // Attempt to remove a login that doesn't exist.
487 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 566 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
488 base::IgnoreReturn<bool>(base::Bind( 567 base::IgnoreReturn<bool>(base::Bind(
489 &NativeBackendGnome::RemoveLogin, 568 &NativeBackendGnome::RemoveLogin,
490 base::Unretained(&backend), form_isc_))); 569 base::Unretained(&backend), form_isc_)));
491 570
492 // Make sure we can still get the first form back. 571 // Make sure we can still get the first form back.
493 std::vector<PasswordForm*> form_list; 572 std::vector<PasswordForm*> form_list;
494 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 573 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
495 base::IgnoreReturn<bool>(base::Bind( 574 base::IgnoreReturn<bool>(base::Bind(
496 &NativeBackendGnome::GetAutofillableLogins, 575 &NativeBackendGnome::GetAutofillableLogins,
497 base::Unretained(&backend), &form_list))); 576 base::Unretained(&backend), &form_list)));
498 577
499 RunBothThreads(); 578 RunAllThreads();
500 579
501 // Quick check that we got something back. 580 // Quick check that we got something back.
502 EXPECT_EQ(1u, form_list.size()); 581 EXPECT_EQ(1u, form_list.size());
503 STLDeleteElements(&form_list); 582 STLDeleteElements(&form_list);
504 583
505 EXPECT_EQ(1u, mock_keyring_items.size()); 584 EXPECT_EQ(1u, mock_keyring_items.size());
506 if (mock_keyring_items.size() > 0) 585 if (mock_keyring_items.size() > 0)
507 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 586 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
508 } 587 }
509 588
510 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { 589 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) {
511 // Pretend that the migration has already taken place. 590 // Pretend that the migration has already taken place.
512 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 591 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
513 592
514 NativeBackendGnome backend(42, profile_.GetPrefs()); 593 NativeBackendGnome backend(42, profile_.GetPrefs());
515 backend.Init(); 594 InitNativeBackend(&backend);
516 595
517 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 596 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
518 base::IgnoreReturn<bool>(base::Bind( 597 base::IgnoreReturn<bool>(base::Bind(
519 &NativeBackendGnome::AddLogin, 598 &NativeBackendGnome::AddLogin,
520 base::Unretained(&backend), form_google_))); 599 base::Unretained(&backend), form_google_)));
521 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 600 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
522 base::IgnoreReturn<bool>(base::Bind( 601 base::IgnoreReturn<bool>(base::Bind(
523 &NativeBackendGnome::AddLogin, 602 &NativeBackendGnome::AddLogin,
524 base::Unretained(&backend), form_google_))); 603 base::Unretained(&backend), form_google_)));
525 604
526 RunBothThreads(); 605 RunAllThreads();
527 606
528 EXPECT_EQ(1u, mock_keyring_items.size()); 607 EXPECT_EQ(1u, mock_keyring_items.size());
529 if (mock_keyring_items.size() > 0) 608 if (mock_keyring_items.size() > 0)
530 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 609 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
531 } 610 }
532 611
533 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { 612 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) {
534 // Pretend that the migration has already taken place. 613 // Pretend that the migration has already taken place.
535 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 614 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
536 615
537 NativeBackendGnome backend(42, profile_.GetPrefs()); 616 NativeBackendGnome backend(42, profile_.GetPrefs());
538 backend.Init(); 617 InitNativeBackend(&backend);
539 618
540 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 619 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
541 base::IgnoreReturn<bool>(base::Bind( 620 base::IgnoreReturn<bool>(base::Bind(
542 &NativeBackendGnome::AddLogin, 621 &NativeBackendGnome::AddLogin,
543 base::Unretained(&backend), form_google_))); 622 base::Unretained(&backend), form_google_)));
544 623
545 // Send the same request twice with the same list both times. 624 // Send the same request twice with the same list both times.
546 std::vector<PasswordForm*> form_list; 625 std::vector<PasswordForm*> form_list;
547 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 626 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
548 base::IgnoreReturn<bool>(base::Bind( 627 base::IgnoreReturn<bool>(base::Bind(
549 &NativeBackendGnome::GetAutofillableLogins, 628 &NativeBackendGnome::GetAutofillableLogins,
550 base::Unretained(&backend), &form_list))); 629 base::Unretained(&backend), &form_list)));
551 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 630 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
552 base::IgnoreReturn<bool>(base::Bind( 631 base::IgnoreReturn<bool>(base::Bind(
553 &NativeBackendGnome::GetAutofillableLogins, 632 &NativeBackendGnome::GetAutofillableLogins,
554 base::Unretained(&backend), &form_list))); 633 base::Unretained(&backend), &form_list)));
555 634
556 RunBothThreads(); 635 RunAllThreads();
557 636
558 // Quick check that we got two results back. 637 // Quick check that we got two results back.
559 EXPECT_EQ(2u, form_list.size()); 638 EXPECT_EQ(2u, form_list.size());
560 STLDeleteElements(&form_list); 639 STLDeleteElements(&form_list);
561 640
562 EXPECT_EQ(1u, mock_keyring_items.size()); 641 EXPECT_EQ(1u, mock_keyring_items.size());
563 if (mock_keyring_items.size() > 0) 642 if (mock_keyring_items.size() > 0)
564 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); 643 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42");
565 } 644 }
566 645
567 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. 646 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point.
568 647
569 TEST_F(NativeBackendGnomeTest, MigrateOneLogin) { 648 TEST_F(NativeBackendGnomeTest, MigrateOneLogin) {
570 // Reject attempts to migrate so we can populate the store. 649 // Reject attempts to migrate so we can populate the store.
571 mock_keyring_reject_local_ids = true; 650 mock_keyring_reject_local_ids = true;
572 651
573 { 652 {
574 NativeBackendGnome backend(42, profile_.GetPrefs()); 653 NativeBackendGnome backend(42, profile_.GetPrefs());
575 backend.Init(); 654 InitNativeBackend(&backend);
576 655
577 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 656 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
578 base::IgnoreReturn<bool>(base::Bind( 657 base::IgnoreReturn<bool>(base::Bind(
579 &NativeBackendGnome::AddLogin, 658 &NativeBackendGnome::AddLogin,
580 base::Unretained(&backend), form_google_))); 659 base::Unretained(&backend), form_google_)));
581 660
582 // Make sure we can get the form back even when migration is failing. 661 // Make sure we can get the form back even when migration is failing.
583 std::vector<PasswordForm*> form_list; 662 std::vector<PasswordForm*> form_list;
584 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 663 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
585 base::IgnoreReturn<bool>(base::Bind( 664 base::IgnoreReturn<bool>(base::Bind(
586 &NativeBackendGnome::GetAutofillableLogins, 665 &NativeBackendGnome::GetAutofillableLogins,
587 base::Unretained(&backend), &form_list))); 666 base::Unretained(&backend), &form_list)));
588 667
589 RunBothThreads(); 668 RunAllThreads();
590 669
591 // Quick check that we got something back. 670 // Quick check that we got something back.
592 EXPECT_EQ(1u, form_list.size()); 671 EXPECT_EQ(1u, form_list.size());
593 STLDeleteElements(&form_list); 672 STLDeleteElements(&form_list);
594 } 673 }
595 674
596 EXPECT_EQ(1u, mock_keyring_items.size()); 675 EXPECT_EQ(1u, mock_keyring_items.size());
597 if (mock_keyring_items.size() > 0) 676 if (mock_keyring_items.size() > 0)
598 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 677 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
599 678
600 // Now allow the migration. 679 // Now allow the migration.
601 mock_keyring_reject_local_ids = false; 680 mock_keyring_reject_local_ids = false;
602 681
603 { 682 {
604 NativeBackendGnome backend(42, profile_.GetPrefs()); 683 NativeBackendGnome backend(42, profile_.GetPrefs());
605 backend.Init(); 684 InitNativeBackend(&backend);
606 685
607 // This should not trigger migration because there will be no results. 686 // This should not trigger migration because there will be no results.
608 std::vector<PasswordForm*> form_list; 687 std::vector<PasswordForm*> form_list;
609 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 688 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
610 base::IgnoreReturn<bool>(base::Bind( 689 base::IgnoreReturn<bool>(base::Bind(
611 &NativeBackendGnome::GetBlacklistLogins, 690 &NativeBackendGnome::GetBlacklistLogins,
612 base::Unretained(&backend), &form_list))); 691 base::Unretained(&backend), &form_list)));
613 692
614 RunBothThreads(); 693 RunAllThreads();
615 694
616 // Check that we got nothing back. 695 // Check that we got nothing back.
617 EXPECT_EQ(0u, form_list.size()); 696 EXPECT_EQ(0u, form_list.size());
618 STLDeleteElements(&form_list); 697 STLDeleteElements(&form_list);
619 } 698 }
620 699
621 // Check that the keyring is unmodified. 700 // Check that the keyring is unmodified.
622 EXPECT_EQ(1u, mock_keyring_items.size()); 701 EXPECT_EQ(1u, mock_keyring_items.size());
623 if (mock_keyring_items.size() > 0) 702 if (mock_keyring_items.size() > 0)
624 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 703 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
625 704
626 // Check that we haven't set the persistent preference. 705 // Check that we haven't set the persistent preference.
627 EXPECT_FALSE( 706 EXPECT_FALSE(
628 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 707 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
629 708
630 { 709 {
631 NativeBackendGnome backend(42, profile_.GetPrefs()); 710 NativeBackendGnome backend(42, profile_.GetPrefs());
632 backend.Init(); 711 InitNativeBackend(&backend);
633 712
634 // Trigger the migration by looking something up. 713 // Trigger the migration by looking something up.
635 std::vector<PasswordForm*> form_list; 714 std::vector<PasswordForm*> form_list;
636 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 715 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
637 base::IgnoreReturn<bool>(base::Bind( 716 base::IgnoreReturn<bool>(base::Bind(
638 &NativeBackendGnome::GetAutofillableLogins, 717 &NativeBackendGnome::GetAutofillableLogins,
639 base::Unretained(&backend), &form_list))); 718 base::Unretained(&backend), &form_list)));
640 719
641 RunBothThreads(); 720 RunAllThreads();
642 721
643 // Quick check that we got something back. 722 // Quick check that we got something back.
644 EXPECT_EQ(1u, form_list.size()); 723 EXPECT_EQ(1u, form_list.size());
645 STLDeleteElements(&form_list); 724 STLDeleteElements(&form_list);
646 } 725 }
647 726
648 EXPECT_EQ(2u, mock_keyring_items.size()); 727 EXPECT_EQ(2u, mock_keyring_items.size());
649 if (mock_keyring_items.size() > 0) 728 if (mock_keyring_items.size() > 0)
650 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 729 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
651 if (mock_keyring_items.size() > 1) 730 if (mock_keyring_items.size() > 1)
652 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 731 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
653 732
654 // Check that we have set the persistent preference. 733 // Check that we have set the persistent preference.
655 EXPECT_TRUE( 734 EXPECT_TRUE(
656 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 735 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
657 } 736 }
658 737
659 TEST_F(NativeBackendGnomeTest, MigrateToMultipleProfiles) { 738 TEST_F(NativeBackendGnomeTest, MigrateToMultipleProfiles) {
660 // Reject attempts to migrate so we can populate the store. 739 // Reject attempts to migrate so we can populate the store.
661 mock_keyring_reject_local_ids = true; 740 mock_keyring_reject_local_ids = true;
662 741
663 { 742 {
664 NativeBackendGnome backend(42, profile_.GetPrefs()); 743 NativeBackendGnome backend(42, profile_.GetPrefs());
665 backend.Init(); 744 InitNativeBackend(&backend);
666 745
667 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 746 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
668 base::IgnoreReturn<bool>(base::Bind( 747 base::IgnoreReturn<bool>(base::Bind(
669 &NativeBackendGnome::AddLogin, 748 &NativeBackendGnome::AddLogin,
670 base::Unretained(&backend), form_google_))); 749 base::Unretained(&backend), form_google_)));
671 750
672 RunBothThreads(); 751 RunAllThreads();
673 } 752 }
674 753
675 EXPECT_EQ(1u, mock_keyring_items.size()); 754 EXPECT_EQ(1u, mock_keyring_items.size());
676 if (mock_keyring_items.size() > 0) 755 if (mock_keyring_items.size() > 0)
677 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 756 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
678 757
679 // Now allow the migration. 758 // Now allow the migration.
680 mock_keyring_reject_local_ids = false; 759 mock_keyring_reject_local_ids = false;
681 760
682 { 761 {
683 NativeBackendGnome backend(42, profile_.GetPrefs()); 762 NativeBackendGnome backend(42, profile_.GetPrefs());
684 backend.Init(); 763 InitNativeBackend(&backend);
685 764
686 // Trigger the migration by looking something up. 765 // Trigger the migration by looking something up.
687 std::vector<PasswordForm*> form_list; 766 std::vector<PasswordForm*> form_list;
688 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 767 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
689 base::IgnoreReturn<bool>(base::Bind( 768 base::IgnoreReturn<bool>(base::Bind(
690 &NativeBackendGnome::GetAutofillableLogins, 769 &NativeBackendGnome::GetAutofillableLogins,
691 base::Unretained(&backend), &form_list))); 770 base::Unretained(&backend), &form_list)));
692 771
693 RunBothThreads(); 772 RunAllThreads();
694 773
695 // Quick check that we got something back. 774 // Quick check that we got something back.
696 EXPECT_EQ(1u, form_list.size()); 775 EXPECT_EQ(1u, form_list.size());
697 STLDeleteElements(&form_list); 776 STLDeleteElements(&form_list);
698 } 777 }
699 778
700 EXPECT_EQ(2u, mock_keyring_items.size()); 779 EXPECT_EQ(2u, mock_keyring_items.size());
701 if (mock_keyring_items.size() > 0) 780 if (mock_keyring_items.size() > 0)
702 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 781 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
703 if (mock_keyring_items.size() > 1) 782 if (mock_keyring_items.size() > 1)
704 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 783 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
705 784
706 // Check that we have set the persistent preference. 785 // Check that we have set the persistent preference.
707 EXPECT_TRUE( 786 EXPECT_TRUE(
708 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 787 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
709 788
710 // Normally we'd actually have a different profile. But in the test just reset 789 // Normally we'd actually have a different profile. But in the test just reset
711 // the profile's persistent pref; we pass in the local profile id anyway. 790 // the profile's persistent pref; we pass in the local profile id anyway.
712 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); 791 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
713 792
714 { 793 {
715 NativeBackendGnome backend(24, profile_.GetPrefs()); 794 NativeBackendGnome backend(24, profile_.GetPrefs());
716 backend.Init(); 795 InitNativeBackend(&backend);
717 796
718 // Trigger the migration by looking something up. 797 // Trigger the migration by looking something up.
719 std::vector<PasswordForm*> form_list; 798 std::vector<PasswordForm*> form_list;
720 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 799 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
721 base::IgnoreReturn<bool>(base::Bind( 800 base::IgnoreReturn<bool>(base::Bind(
722 &NativeBackendGnome::GetAutofillableLogins, 801 &NativeBackendGnome::GetAutofillableLogins,
723 base::Unretained(&backend), &form_list))); 802 base::Unretained(&backend), &form_list)));
724 803
725 RunBothThreads(); 804 RunAllThreads();
726 805
727 // Quick check that we got something back. 806 // Quick check that we got something back.
728 EXPECT_EQ(1u, form_list.size()); 807 EXPECT_EQ(1u, form_list.size());
729 STLDeleteElements(&form_list); 808 STLDeleteElements(&form_list);
730 } 809 }
731 810
732 EXPECT_EQ(3u, mock_keyring_items.size()); 811 EXPECT_EQ(3u, mock_keyring_items.size());
733 if (mock_keyring_items.size() > 0) 812 if (mock_keyring_items.size() > 0)
734 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 813 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
735 if (mock_keyring_items.size() > 1) 814 if (mock_keyring_items.size() > 1)
736 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 815 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
737 if (mock_keyring_items.size() > 2) 816 if (mock_keyring_items.size() > 2)
738 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); 817 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24");
739 } 818 }
740 819
741 TEST_F(NativeBackendGnomeTest, NoMigrationWithPrefSet) { 820 TEST_F(NativeBackendGnomeTest, NoMigrationWithPrefSet) {
742 // Reject attempts to migrate so we can populate the store. 821 // Reject attempts to migrate so we can populate the store.
743 mock_keyring_reject_local_ids = true; 822 mock_keyring_reject_local_ids = true;
744 823
745 { 824 {
746 NativeBackendGnome backend(42, profile_.GetPrefs()); 825 NativeBackendGnome backend(42, profile_.GetPrefs());
747 backend.Init(); 826 InitNativeBackend(&backend);
748 827
749 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 828 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
750 base::IgnoreReturn<bool>(base::Bind( 829 base::IgnoreReturn<bool>(base::Bind(
751 &NativeBackendGnome::AddLogin, 830 &NativeBackendGnome::AddLogin,
752 base::Unretained(&backend), form_google_))); 831 base::Unretained(&backend), form_google_)));
753 832
754 RunBothThreads(); 833 RunAllThreads();
755 } 834 }
756 835
757 EXPECT_EQ(1u, mock_keyring_items.size()); 836 EXPECT_EQ(1u, mock_keyring_items.size());
758 if (mock_keyring_items.size() > 0) 837 if (mock_keyring_items.size() > 0)
759 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 838 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
760 839
761 // Now allow migration, but also pretend that the it has already taken place. 840 // Now allow migration, but also pretend that the it has already taken place.
762 mock_keyring_reject_local_ids = false; 841 mock_keyring_reject_local_ids = false;
763 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); 842 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true);
764 843
765 { 844 {
766 NativeBackendGnome backend(42, profile_.GetPrefs()); 845 NativeBackendGnome backend(42, profile_.GetPrefs());
767 backend.Init(); 846 InitNativeBackend(&backend);
768 847
769 // Trigger the migration by adding a new login. 848 // Trigger the migration by adding a new login.
770 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 849 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
771 base::IgnoreReturn<bool>(base::Bind( 850 base::IgnoreReturn<bool>(base::Bind(
772 &NativeBackendGnome::AddLogin, 851 &NativeBackendGnome::AddLogin,
773 base::Unretained(&backend), form_isc_))); 852 base::Unretained(&backend), form_isc_)));
774 853
775 // Look up all logins; we expect only the one we added. 854 // Look up all logins; we expect only the one we added.
776 std::vector<PasswordForm*> form_list; 855 std::vector<PasswordForm*> form_list;
777 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 856 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
778 base::IgnoreReturn<bool>(base::Bind( 857 base::IgnoreReturn<bool>(base::Bind(
779 &NativeBackendGnome::GetAutofillableLogins, 858 &NativeBackendGnome::GetAutofillableLogins,
780 base::Unretained(&backend), &form_list))); 859 base::Unretained(&backend), &form_list)));
781 860
782 RunBothThreads(); 861 RunAllThreads();
783 862
784 // Quick check that we got the right thing back. 863 // Quick check that we got the right thing back.
785 EXPECT_EQ(1u, form_list.size()); 864 EXPECT_EQ(1u, form_list.size());
786 if (form_list.size() > 0) 865 if (form_list.size() > 0)
787 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); 866 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm);
788 STLDeleteElements(&form_list); 867 STLDeleteElements(&form_list);
789 } 868 }
790 869
791 EXPECT_EQ(2u, mock_keyring_items.size()); 870 EXPECT_EQ(2u, mock_keyring_items.size());
792 if (mock_keyring_items.size() > 0) 871 if (mock_keyring_items.size() > 0)
793 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 872 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
794 if (mock_keyring_items.size() > 1) 873 if (mock_keyring_items.size() > 1)
795 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); 874 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42");
796 } 875 }
797 876
798 TEST_F(NativeBackendGnomeTest, DeleteMigratedPasswordIsIsolated) { 877 TEST_F(NativeBackendGnomeTest, DeleteMigratedPasswordIsIsolated) {
799 // Reject attempts to migrate so we can populate the store. 878 // Reject attempts to migrate so we can populate the store.
800 mock_keyring_reject_local_ids = true; 879 mock_keyring_reject_local_ids = true;
801 880
802 { 881 {
803 NativeBackendGnome backend(42, profile_.GetPrefs()); 882 NativeBackendGnome backend(42, profile_.GetPrefs());
804 backend.Init(); 883 InitNativeBackend(&backend);
805 884
806 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 885 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
807 base::IgnoreReturn<bool>(base::Bind( 886 base::IgnoreReturn<bool>(base::Bind(
808 &NativeBackendGnome::AddLogin, 887 &NativeBackendGnome::AddLogin,
809 base::Unretained(&backend), form_google_))); 888 base::Unretained(&backend), form_google_)));
810 889
811 RunBothThreads(); 890 RunAllThreads();
812 } 891 }
813 892
814 EXPECT_EQ(1u, mock_keyring_items.size()); 893 EXPECT_EQ(1u, mock_keyring_items.size());
815 if (mock_keyring_items.size() > 0) 894 if (mock_keyring_items.size() > 0)
816 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 895 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
817 896
818 // Now allow the migration. 897 // Now allow the migration.
819 mock_keyring_reject_local_ids = false; 898 mock_keyring_reject_local_ids = false;
820 899
821 { 900 {
822 NativeBackendGnome backend(42, profile_.GetPrefs()); 901 NativeBackendGnome backend(42, profile_.GetPrefs());
823 backend.Init(); 902 InitNativeBackend(&backend);
824 903
825 // Trigger the migration by looking something up. 904 // Trigger the migration by looking something up.
826 std::vector<PasswordForm*> form_list; 905 std::vector<PasswordForm*> form_list;
827 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 906 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
828 base::IgnoreReturn<bool>(base::Bind( 907 base::IgnoreReturn<bool>(base::Bind(
829 &NativeBackendGnome::GetAutofillableLogins, 908 &NativeBackendGnome::GetAutofillableLogins,
830 base::Unretained(&backend), &form_list))); 909 base::Unretained(&backend), &form_list)));
831 910
832 RunBothThreads(); 911 RunAllThreads();
833 912
834 // Quick check that we got something back. 913 // Quick check that we got something back.
835 EXPECT_EQ(1u, form_list.size()); 914 EXPECT_EQ(1u, form_list.size());
836 STLDeleteElements(&form_list); 915 STLDeleteElements(&form_list);
837 } 916 }
838 917
839 EXPECT_EQ(2u, mock_keyring_items.size()); 918 EXPECT_EQ(2u, mock_keyring_items.size());
840 if (mock_keyring_items.size() > 0) 919 if (mock_keyring_items.size() > 0)
841 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 920 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
842 if (mock_keyring_items.size() > 1) 921 if (mock_keyring_items.size() > 1)
843 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 922 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
844 923
845 // Check that we have set the persistent preference. 924 // Check that we have set the persistent preference.
846 EXPECT_TRUE( 925 EXPECT_TRUE(
847 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); 926 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId));
848 927
849 // Normally we'd actually have a different profile. But in the test just reset 928 // Normally we'd actually have a different profile. But in the test just reset
850 // the profile's persistent pref; we pass in the local profile id anyway. 929 // the profile's persistent pref; we pass in the local profile id anyway.
851 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); 930 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false);
852 931
853 { 932 {
854 NativeBackendGnome backend(24, profile_.GetPrefs()); 933 NativeBackendGnome backend(24, profile_.GetPrefs());
855 backend.Init(); 934 InitNativeBackend(&backend);
856 935
857 // Trigger the migration by looking something up. 936 // Trigger the migration by looking something up.
858 std::vector<PasswordForm*> form_list; 937 std::vector<PasswordForm*> form_list;
859 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 938 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
860 base::IgnoreReturn<bool>(base::Bind( 939 base::IgnoreReturn<bool>(base::Bind(
861 &NativeBackendGnome::GetAutofillableLogins, 940 &NativeBackendGnome::GetAutofillableLogins,
862 base::Unretained(&backend), &form_list))); 941 base::Unretained(&backend), &form_list)));
863 942
864 RunBothThreads(); 943 RunAllThreads();
865 944
866 // Quick check that we got something back. 945 // Quick check that we got something back.
867 EXPECT_EQ(1u, form_list.size()); 946 EXPECT_EQ(1u, form_list.size());
868 STLDeleteElements(&form_list); 947 STLDeleteElements(&form_list);
869 948
870 // There should be three passwords now. 949 // There should be three passwords now.
871 EXPECT_EQ(3u, mock_keyring_items.size()); 950 EXPECT_EQ(3u, mock_keyring_items.size());
872 if (mock_keyring_items.size() > 0) 951 if (mock_keyring_items.size() > 0)
873 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 952 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
874 if (mock_keyring_items.size() > 1) 953 if (mock_keyring_items.size() > 1)
875 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 954 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
876 if (mock_keyring_items.size() > 2) 955 if (mock_keyring_items.size() > 2)
877 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); 956 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24");
878 957
879 // Now delete the password from this second profile. 958 // Now delete the password from this second profile.
880 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 959 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
881 base::IgnoreReturn<bool>(base::Bind( 960 base::IgnoreReturn<bool>(base::Bind(
882 &NativeBackendGnome::RemoveLogin, 961 &NativeBackendGnome::RemoveLogin,
883 base::Unretained(&backend), form_google_))); 962 base::Unretained(&backend), form_google_)));
884 963
885 RunBothThreads(); 964 RunAllThreads();
886 965
887 // The other two copies of the password in different profiles should remain. 966 // The other two copies of the password in different profiles should remain.
888 EXPECT_EQ(2u, mock_keyring_items.size()); 967 EXPECT_EQ(2u, mock_keyring_items.size());
889 if (mock_keyring_items.size() > 0) 968 if (mock_keyring_items.size() > 0)
890 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); 969 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome");
891 if (mock_keyring_items.size() > 1) 970 if (mock_keyring_items.size() > 1)
892 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); 971 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42");
893 } 972 }
894 } 973 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698