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

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

Powered by Google App Engine
This is Rietveld 408576698