| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdarg.h> | 5 #include <stdarg.h> |
| 6 #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::forms::PasswordForm; | 25 using webkit::forms::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 Loading... |
| 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, MessageLoop::QuitClosure()); | 366 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 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 Loading... |
| 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( | 481 BrowserThread::PostTask( |
| 400 BrowserThread::DB, FROM_HERE, | 482 BrowserThread::DB, FROM_HERE, |
| 401 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 483 base::Bind(base::IgnoreResult(&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( | 500 BrowserThread::PostTask( |
| 419 BrowserThread::DB, FROM_HERE, | 501 BrowserThread::DB, FROM_HERE, |
| 420 base::Bind(base::IgnoreResult( &NativeBackendGnome::AddLogin), | 502 base::Bind(base::IgnoreResult( &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( | 506 BrowserThread::PostTask( |
| 425 BrowserThread::DB, FROM_HERE, | 507 BrowserThread::DB, FROM_HERE, |
| 426 base::Bind( | 508 base::Bind( |
| 427 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 509 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 428 base::Unretained(&backend), &form_list)); | 510 base::Unretained(&backend), &form_list)); |
| 429 | 511 |
| 430 RunBothThreads(); | 512 RunAllThreads(); |
| 431 | 513 |
| 432 // Quick check that we got something back. | 514 // Quick check that we got something back. |
| 433 EXPECT_EQ(1u, form_list.size()); | 515 EXPECT_EQ(1u, form_list.size()); |
| 434 STLDeleteElements(&form_list); | 516 STLDeleteElements(&form_list); |
| 435 | 517 |
| 436 EXPECT_EQ(1u, mock_keyring_items.size()); | 518 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 437 if (mock_keyring_items.size() > 0) | 519 if (mock_keyring_items.size() > 0) |
| 438 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 520 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 439 } | 521 } |
| 440 | 522 |
| 441 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { | 523 TEST_F(NativeBackendGnomeTest, BasicRemoveLogin) { |
| 442 // Pretend that the migration has already taken place. | 524 // Pretend that the migration has already taken place. |
| 443 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 525 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
| 444 | 526 |
| 445 NativeBackendGnome backend(42, profile_.GetPrefs()); | 527 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 446 backend.Init(); | 528 InitNativeBackend(&backend); |
| 447 | 529 |
| 448 BrowserThread::PostTask( | 530 BrowserThread::PostTask( |
| 449 BrowserThread::DB, FROM_HERE, | 531 BrowserThread::DB, FROM_HERE, |
| 450 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 532 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 451 base::Unretained(&backend), form_google_)); | 533 base::Unretained(&backend), form_google_)); |
| 452 | 534 |
| 453 RunBothThreads(); | 535 RunAllThreads(); |
| 454 | 536 |
| 455 EXPECT_EQ(1u, mock_keyring_items.size()); | 537 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 456 if (mock_keyring_items.size() > 0) | 538 if (mock_keyring_items.size() > 0) |
| 457 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 539 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 458 | 540 |
| 459 BrowserThread::PostTask( | 541 BrowserThread::PostTask( |
| 460 BrowserThread::DB, FROM_HERE, | 542 BrowserThread::DB, FROM_HERE, |
| 461 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | 543 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), |
| 462 base::Unretained(&backend), form_google_)); | 544 base::Unretained(&backend), form_google_)); |
| 463 | 545 |
| 464 RunBothThreads(); | 546 RunAllThreads(); |
| 465 | 547 |
| 466 EXPECT_EQ(0u, mock_keyring_items.size()); | 548 EXPECT_EQ(0u, mock_keyring_items.size()); |
| 467 } | 549 } |
| 468 | 550 |
| 469 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { | 551 TEST_F(NativeBackendGnomeTest, RemoveNonexistentLogin) { |
| 470 // Pretend that the migration has already taken place. | 552 // Pretend that the migration has already taken place. |
| 471 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 553 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
| 472 | 554 |
| 473 NativeBackendGnome backend(42, profile_.GetPrefs()); | 555 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 474 backend.Init(); | 556 InitNativeBackend(&backend); |
| 475 | 557 |
| 476 // First add an unrelated login. | 558 // First add an unrelated login. |
| 477 BrowserThread::PostTask( | 559 BrowserThread::PostTask( |
| 478 BrowserThread::DB, FROM_HERE, | 560 BrowserThread::DB, FROM_HERE, |
| 479 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 561 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 480 base::Unretained(&backend), form_google_)); | 562 base::Unretained(&backend), form_google_)); |
| 481 | 563 |
| 482 RunBothThreads(); | 564 RunAllThreads(); |
| 483 | 565 |
| 484 EXPECT_EQ(1u, mock_keyring_items.size()); | 566 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 485 if (mock_keyring_items.size() > 0) | 567 if (mock_keyring_items.size() > 0) |
| 486 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 568 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 487 | 569 |
| 488 // Attempt to remove a login that doesn't exist. | 570 // Attempt to remove a login that doesn't exist. |
| 489 BrowserThread::PostTask( | 571 BrowserThread::PostTask( |
| 490 BrowserThread::DB, FROM_HERE, | 572 BrowserThread::DB, FROM_HERE, |
| 491 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | 573 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), |
| 492 base::Unretained(&backend), form_isc_)); | 574 base::Unretained(&backend), form_isc_)); |
| 493 | 575 |
| 494 // Make sure we can still get the first form back. | 576 // Make sure we can still get the first form back. |
| 495 std::vector<PasswordForm*> form_list; | 577 std::vector<PasswordForm*> form_list; |
| 496 BrowserThread::PostTask( | 578 BrowserThread::PostTask( |
| 497 BrowserThread::DB, FROM_HERE, | 579 BrowserThread::DB, FROM_HERE, |
| 498 base::Bind( | 580 base::Bind( |
| 499 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 581 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 500 base::Unretained(&backend), &form_list)); | 582 base::Unretained(&backend), &form_list)); |
| 501 | 583 |
| 502 RunBothThreads(); | 584 RunAllThreads(); |
| 503 | 585 |
| 504 // Quick check that we got something back. | 586 // Quick check that we got something back. |
| 505 EXPECT_EQ(1u, form_list.size()); | 587 EXPECT_EQ(1u, form_list.size()); |
| 506 STLDeleteElements(&form_list); | 588 STLDeleteElements(&form_list); |
| 507 | 589 |
| 508 EXPECT_EQ(1u, mock_keyring_items.size()); | 590 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 509 if (mock_keyring_items.size() > 0) | 591 if (mock_keyring_items.size() > 0) |
| 510 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 592 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 511 } | 593 } |
| 512 | 594 |
| 513 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { | 595 TEST_F(NativeBackendGnomeTest, AddDuplicateLogin) { |
| 514 // Pretend that the migration has already taken place. | 596 // Pretend that the migration has already taken place. |
| 515 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 597 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
| 516 | 598 |
| 517 NativeBackendGnome backend(42, profile_.GetPrefs()); | 599 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 518 backend.Init(); | 600 InitNativeBackend(&backend); |
| 519 | 601 |
| 520 BrowserThread::PostTask( | 602 BrowserThread::PostTask( |
| 521 BrowserThread::DB, FROM_HERE, | 603 BrowserThread::DB, FROM_HERE, |
| 522 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 604 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 523 base::Unretained(&backend), form_google_)); | 605 base::Unretained(&backend), form_google_)); |
| 524 BrowserThread::PostTask( | 606 BrowserThread::PostTask( |
| 525 BrowserThread::DB, FROM_HERE, | 607 BrowserThread::DB, FROM_HERE, |
| 526 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 608 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 527 base::Unretained(&backend), form_google_)); | 609 base::Unretained(&backend), form_google_)); |
| 528 | 610 |
| 529 RunBothThreads(); | 611 RunAllThreads(); |
| 530 | 612 |
| 531 EXPECT_EQ(1u, mock_keyring_items.size()); | 613 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 532 if (mock_keyring_items.size() > 0) | 614 if (mock_keyring_items.size() > 0) |
| 533 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 615 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 534 } | 616 } |
| 535 | 617 |
| 536 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { | 618 TEST_F(NativeBackendGnomeTest, ListLoginsAppends) { |
| 537 // Pretend that the migration has already taken place. | 619 // Pretend that the migration has already taken place. |
| 538 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 620 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
| 539 | 621 |
| 540 NativeBackendGnome backend(42, profile_.GetPrefs()); | 622 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 541 backend.Init(); | 623 InitNativeBackend(&backend); |
| 542 | 624 |
| 543 BrowserThread::PostTask( | 625 BrowserThread::PostTask( |
| 544 BrowserThread::DB, FROM_HERE, | 626 BrowserThread::DB, FROM_HERE, |
| 545 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 627 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 546 base::Unretained(&backend), form_google_)); | 628 base::Unretained(&backend), form_google_)); |
| 547 | 629 |
| 548 // Send the same request twice with the same list both times. | 630 // Send the same request twice with the same list both times. |
| 549 std::vector<PasswordForm*> form_list; | 631 std::vector<PasswordForm*> form_list; |
| 550 BrowserThread::PostTask( | 632 BrowserThread::PostTask( |
| 551 BrowserThread::DB, FROM_HERE, | 633 BrowserThread::DB, FROM_HERE, |
| 552 base::Bind( | 634 base::Bind( |
| 553 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 635 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 554 base::Unretained(&backend), &form_list)); | 636 base::Unretained(&backend), &form_list)); |
| 555 BrowserThread::PostTask( | 637 BrowserThread::PostTask( |
| 556 BrowserThread::DB, FROM_HERE, | 638 BrowserThread::DB, FROM_HERE, |
| 557 base::Bind( | 639 base::Bind( |
| 558 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 640 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 559 base::Unretained(&backend), &form_list)); | 641 base::Unretained(&backend), &form_list)); |
| 560 | 642 |
| 561 RunBothThreads(); | 643 RunAllThreads(); |
| 562 | 644 |
| 563 // Quick check that we got two results back. | 645 // Quick check that we got two results back. |
| 564 EXPECT_EQ(2u, form_list.size()); | 646 EXPECT_EQ(2u, form_list.size()); |
| 565 STLDeleteElements(&form_list); | 647 STLDeleteElements(&form_list); |
| 566 | 648 |
| 567 EXPECT_EQ(1u, mock_keyring_items.size()); | 649 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 568 if (mock_keyring_items.size() > 0) | 650 if (mock_keyring_items.size() > 0) |
| 569 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); | 651 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome-42"); |
| 570 } | 652 } |
| 571 | 653 |
| 572 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. | 654 // TODO(mdm): add more basic (i.e. non-migration) tests here at some point. |
| 573 | 655 |
| 574 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { | 656 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateOneLogin) { |
| 575 // Reject attempts to migrate so we can populate the store. | 657 // Reject attempts to migrate so we can populate the store. |
| 576 mock_keyring_reject_local_ids = true; | 658 mock_keyring_reject_local_ids = true; |
| 577 | 659 |
| 578 { | 660 { |
| 579 NativeBackendGnome backend(42, profile_.GetPrefs()); | 661 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 580 backend.Init(); | 662 InitNativeBackend(&backend); |
| 581 | 663 |
| 582 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 664 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
| 583 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 665 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 584 base::Unretained(&backend), form_google_)); | 666 base::Unretained(&backend), form_google_)); |
| 585 | 667 |
| 586 // Make sure we can get the form back even when migration is failing. | 668 // Make sure we can get the form back even when migration is failing. |
| 587 std::vector<PasswordForm*> form_list; | 669 std::vector<PasswordForm*> form_list; |
| 588 BrowserThread::PostTask( | 670 BrowserThread::PostTask( |
| 589 BrowserThread::DB, FROM_HERE, | 671 BrowserThread::DB, FROM_HERE, |
| 590 base::Bind( | 672 base::Bind( |
| 591 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 673 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 592 base::Unretained(&backend), &form_list)); | 674 base::Unretained(&backend), &form_list)); |
| 593 | 675 |
| 594 RunBothThreads(); | 676 RunAllThreads(); |
| 595 | 677 |
| 596 // Quick check that we got something back. | 678 // Quick check that we got something back. |
| 597 EXPECT_EQ(1u, form_list.size()); | 679 EXPECT_EQ(1u, form_list.size()); |
| 598 STLDeleteElements(&form_list); | 680 STLDeleteElements(&form_list); |
| 599 } | 681 } |
| 600 | 682 |
| 601 EXPECT_EQ(1u, mock_keyring_items.size()); | 683 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 602 if (mock_keyring_items.size() > 0) | 684 if (mock_keyring_items.size() > 0) |
| 603 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 685 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 604 | 686 |
| 605 // Now allow the migration. | 687 // Now allow the migration. |
| 606 mock_keyring_reject_local_ids = false; | 688 mock_keyring_reject_local_ids = false; |
| 607 | 689 |
| 608 { | 690 { |
| 609 NativeBackendGnome backend(42, profile_.GetPrefs()); | 691 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 610 backend.Init(); | 692 InitNativeBackend(&backend); |
| 611 | 693 |
| 612 // This should not trigger migration because there will be no results. | 694 // This should not trigger migration because there will be no results. |
| 613 std::vector<PasswordForm*> form_list; | 695 std::vector<PasswordForm*> form_list; |
| 614 BrowserThread::PostTask( | 696 BrowserThread::PostTask( |
| 615 BrowserThread::DB, FROM_HERE, | 697 BrowserThread::DB, FROM_HERE, |
| 616 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins), | 698 base::Bind(base::IgnoreResult(&NativeBackendGnome::GetBlacklistLogins), |
| 617 base::Unretained(&backend), &form_list)); | 699 base::Unretained(&backend), &form_list)); |
| 618 | 700 |
| 619 RunBothThreads(); | 701 RunAllThreads(); |
| 620 | 702 |
| 621 // Check that we got nothing back. | 703 // Check that we got nothing back. |
| 622 EXPECT_EQ(0u, form_list.size()); | 704 EXPECT_EQ(0u, form_list.size()); |
| 623 STLDeleteElements(&form_list); | 705 STLDeleteElements(&form_list); |
| 624 } | 706 } |
| 625 | 707 |
| 626 // Check that the keyring is unmodified. | 708 // Check that the keyring is unmodified. |
| 627 EXPECT_EQ(1u, mock_keyring_items.size()); | 709 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 628 if (mock_keyring_items.size() > 0) | 710 if (mock_keyring_items.size() > 0) |
| 629 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 711 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 630 | 712 |
| 631 // Check that we haven't set the persistent preference. | 713 // Check that we haven't set the persistent preference. |
| 632 EXPECT_FALSE( | 714 EXPECT_FALSE( |
| 633 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 715 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
| 634 | 716 |
| 635 { | 717 { |
| 636 NativeBackendGnome backend(42, profile_.GetPrefs()); | 718 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 637 backend.Init(); | 719 InitNativeBackend(&backend); |
| 638 | 720 |
| 639 // Trigger the migration by looking something up. | 721 // Trigger the migration by looking something up. |
| 640 std::vector<PasswordForm*> form_list; | 722 std::vector<PasswordForm*> form_list; |
| 641 BrowserThread::PostTask( | 723 BrowserThread::PostTask( |
| 642 BrowserThread::DB, FROM_HERE, | 724 BrowserThread::DB, FROM_HERE, |
| 643 base::Bind( | 725 base::Bind( |
| 644 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 726 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 645 base::Unretained(&backend), &form_list)); | 727 base::Unretained(&backend), &form_list)); |
| 646 | 728 |
| 647 RunBothThreads(); | 729 RunAllThreads(); |
| 648 | 730 |
| 649 // Quick check that we got something back. | 731 // Quick check that we got something back. |
| 650 EXPECT_EQ(1u, form_list.size()); | 732 EXPECT_EQ(1u, form_list.size()); |
| 651 STLDeleteElements(&form_list); | 733 STLDeleteElements(&form_list); |
| 652 } | 734 } |
| 653 | 735 |
| 654 EXPECT_EQ(2u, mock_keyring_items.size()); | 736 EXPECT_EQ(2u, mock_keyring_items.size()); |
| 655 if (mock_keyring_items.size() > 0) | 737 if (mock_keyring_items.size() > 0) |
| 656 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 738 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 657 if (mock_keyring_items.size() > 1) | 739 if (mock_keyring_items.size() > 1) |
| 658 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 740 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 659 | 741 |
| 660 // Check that we have set the persistent preference. | 742 // Check that we have set the persistent preference. |
| 661 EXPECT_TRUE( | 743 EXPECT_TRUE( |
| 662 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 744 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
| 663 } | 745 } |
| 664 | 746 |
| 665 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { | 747 TEST_F(NativeBackendGnomeTest, DISABLED_MigrateToMultipleProfiles) { |
| 666 // Reject attempts to migrate so we can populate the store. | 748 // Reject attempts to migrate so we can populate the store. |
| 667 mock_keyring_reject_local_ids = true; | 749 mock_keyring_reject_local_ids = true; |
| 668 | 750 |
| 669 { | 751 { |
| 670 NativeBackendGnome backend(42, profile_.GetPrefs()); | 752 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 671 backend.Init(); | 753 InitNativeBackend(&backend); |
| 672 | 754 |
| 673 BrowserThread::PostTask( | 755 BrowserThread::PostTask( |
| 674 BrowserThread::DB, FROM_HERE, | 756 BrowserThread::DB, FROM_HERE, |
| 675 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 757 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 676 base::Unretained(&backend), form_google_)); | 758 base::Unretained(&backend), form_google_)); |
| 677 | 759 |
| 678 RunBothThreads(); | 760 RunAllThreads(); |
| 679 } | 761 } |
| 680 | 762 |
| 681 EXPECT_EQ(1u, mock_keyring_items.size()); | 763 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 682 if (mock_keyring_items.size() > 0) | 764 if (mock_keyring_items.size() > 0) |
| 683 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 765 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 684 | 766 |
| 685 // Now allow the migration. | 767 // Now allow the migration. |
| 686 mock_keyring_reject_local_ids = false; | 768 mock_keyring_reject_local_ids = false; |
| 687 | 769 |
| 688 { | 770 { |
| 689 NativeBackendGnome backend(42, profile_.GetPrefs()); | 771 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 690 backend.Init(); | 772 InitNativeBackend(&backend); |
| 691 | 773 |
| 692 // Trigger the migration by looking something up. | 774 // Trigger the migration by looking something up. |
| 693 std::vector<PasswordForm*> form_list; | 775 std::vector<PasswordForm*> form_list; |
| 694 BrowserThread::PostTask( | 776 BrowserThread::PostTask( |
| 695 BrowserThread::DB, FROM_HERE, | 777 BrowserThread::DB, FROM_HERE, |
| 696 base::Bind( | 778 base::Bind( |
| 697 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 779 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 698 base::Unretained(&backend), &form_list)); | 780 base::Unretained(&backend), &form_list)); |
| 699 | 781 |
| 700 RunBothThreads(); | 782 RunAllThreads(); |
| 701 | 783 |
| 702 // Quick check that we got something back. | 784 // Quick check that we got something back. |
| 703 EXPECT_EQ(1u, form_list.size()); | 785 EXPECT_EQ(1u, form_list.size()); |
| 704 STLDeleteElements(&form_list); | 786 STLDeleteElements(&form_list); |
| 705 } | 787 } |
| 706 | 788 |
| 707 EXPECT_EQ(2u, mock_keyring_items.size()); | 789 EXPECT_EQ(2u, mock_keyring_items.size()); |
| 708 if (mock_keyring_items.size() > 0) | 790 if (mock_keyring_items.size() > 0) |
| 709 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 791 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 710 if (mock_keyring_items.size() > 1) | 792 if (mock_keyring_items.size() > 1) |
| 711 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 793 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 712 | 794 |
| 713 // Check that we have set the persistent preference. | 795 // Check that we have set the persistent preference. |
| 714 EXPECT_TRUE( | 796 EXPECT_TRUE( |
| 715 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 797 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
| 716 | 798 |
| 717 // Normally we'd actually have a different profile. But in the test just reset | 799 // Normally we'd actually have a different profile. But in the test just reset |
| 718 // the profile's persistent pref; we pass in the local profile id anyway. | 800 // the profile's persistent pref; we pass in the local profile id anyway. |
| 719 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | 801 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); |
| 720 | 802 |
| 721 { | 803 { |
| 722 NativeBackendGnome backend(24, profile_.GetPrefs()); | 804 NativeBackendGnome backend(24, profile_.GetPrefs()); |
| 723 backend.Init(); | 805 InitNativeBackend(&backend); |
| 724 | 806 |
| 725 // Trigger the migration by looking something up. | 807 // Trigger the migration by looking something up. |
| 726 std::vector<PasswordForm*> form_list; | 808 std::vector<PasswordForm*> form_list; |
| 727 BrowserThread::PostTask( | 809 BrowserThread::PostTask( |
| 728 BrowserThread::DB, FROM_HERE, | 810 BrowserThread::DB, FROM_HERE, |
| 729 base::Bind( | 811 base::Bind( |
| 730 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 812 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 731 base::Unretained(&backend), &form_list)); | 813 base::Unretained(&backend), &form_list)); |
| 732 | 814 |
| 733 RunBothThreads(); | 815 RunAllThreads(); |
| 734 | 816 |
| 735 // Quick check that we got something back. | 817 // Quick check that we got something back. |
| 736 EXPECT_EQ(1u, form_list.size()); | 818 EXPECT_EQ(1u, form_list.size()); |
| 737 STLDeleteElements(&form_list); | 819 STLDeleteElements(&form_list); |
| 738 } | 820 } |
| 739 | 821 |
| 740 EXPECT_EQ(3u, mock_keyring_items.size()); | 822 EXPECT_EQ(3u, mock_keyring_items.size()); |
| 741 if (mock_keyring_items.size() > 0) | 823 if (mock_keyring_items.size() > 0) |
| 742 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 824 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 743 if (mock_keyring_items.size() > 1) | 825 if (mock_keyring_items.size() > 1) |
| 744 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 826 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 745 if (mock_keyring_items.size() > 2) | 827 if (mock_keyring_items.size() > 2) |
| 746 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); | 828 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); |
| 747 } | 829 } |
| 748 | 830 |
| 749 TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { | 831 TEST_F(NativeBackendGnomeTest, DISABLED_NoMigrationWithPrefSet) { |
| 750 // Reject attempts to migrate so we can populate the store. | 832 // Reject attempts to migrate so we can populate the store. |
| 751 mock_keyring_reject_local_ids = true; | 833 mock_keyring_reject_local_ids = true; |
| 752 | 834 |
| 753 { | 835 { |
| 754 NativeBackendGnome backend(42, profile_.GetPrefs()); | 836 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 755 backend.Init(); | 837 InitNativeBackend(&backend); |
| 756 | 838 |
| 757 BrowserThread::PostTask( | 839 BrowserThread::PostTask( |
| 758 BrowserThread::DB, FROM_HERE, | 840 BrowserThread::DB, FROM_HERE, |
| 759 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 841 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 760 base::Unretained(&backend), form_google_)); | 842 base::Unretained(&backend), form_google_)); |
| 761 | 843 |
| 762 RunBothThreads(); | 844 RunAllThreads(); |
| 763 } | 845 } |
| 764 | 846 |
| 765 EXPECT_EQ(1u, mock_keyring_items.size()); | 847 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 766 if (mock_keyring_items.size() > 0) | 848 if (mock_keyring_items.size() > 0) |
| 767 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 849 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 768 | 850 |
| 769 // Now allow migration, but also pretend that the it has already taken place. | 851 // Now allow migration, but also pretend that the it has already taken place. |
| 770 mock_keyring_reject_local_ids = false; | 852 mock_keyring_reject_local_ids = false; |
| 771 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); | 853 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, true); |
| 772 | 854 |
| 773 { | 855 { |
| 774 NativeBackendGnome backend(42, profile_.GetPrefs()); | 856 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 775 backend.Init(); | 857 InitNativeBackend(&backend); |
| 776 | 858 |
| 777 // Trigger the migration by adding a new login. | 859 // Trigger the migration by adding a new login. |
| 778 BrowserThread::PostTask( | 860 BrowserThread::PostTask( |
| 779 BrowserThread::DB, FROM_HERE, | 861 BrowserThread::DB, FROM_HERE, |
| 780 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 862 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 781 base::Unretained(&backend), form_isc_)); | 863 base::Unretained(&backend), form_isc_)); |
| 782 | 864 |
| 783 // Look up all logins; we expect only the one we added. | 865 // Look up all logins; we expect only the one we added. |
| 784 std::vector<PasswordForm*> form_list; | 866 std::vector<PasswordForm*> form_list; |
| 785 BrowserThread::PostTask( | 867 BrowserThread::PostTask( |
| 786 BrowserThread::DB, FROM_HERE, | 868 BrowserThread::DB, FROM_HERE, |
| 787 base::Bind( | 869 base::Bind( |
| 788 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 870 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 789 base::Unretained(&backend), &form_list)); | 871 base::Unretained(&backend), &form_list)); |
| 790 | 872 |
| 791 RunBothThreads(); | 873 RunAllThreads(); |
| 792 | 874 |
| 793 // Quick check that we got the right thing back. | 875 // Quick check that we got the right thing back. |
| 794 EXPECT_EQ(1u, form_list.size()); | 876 EXPECT_EQ(1u, form_list.size()); |
| 795 if (form_list.size() > 0) | 877 if (form_list.size() > 0) |
| 796 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); | 878 EXPECT_EQ(form_isc_.signon_realm, form_list[0]->signon_realm); |
| 797 STLDeleteElements(&form_list); | 879 STLDeleteElements(&form_list); |
| 798 } | 880 } |
| 799 | 881 |
| 800 EXPECT_EQ(2u, mock_keyring_items.size()); | 882 EXPECT_EQ(2u, mock_keyring_items.size()); |
| 801 if (mock_keyring_items.size() > 0) | 883 if (mock_keyring_items.size() > 0) |
| 802 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 884 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 803 if (mock_keyring_items.size() > 1) | 885 if (mock_keyring_items.size() > 1) |
| 804 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); | 886 CheckMockKeyringItem(&mock_keyring_items[1], form_isc_, "chrome-42"); |
| 805 } | 887 } |
| 806 | 888 |
| 807 TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { | 889 TEST_F(NativeBackendGnomeTest, DISABLED_DeleteMigratedPasswordIsIsolated) { |
| 808 // Reject attempts to migrate so we can populate the store. | 890 // Reject attempts to migrate so we can populate the store. |
| 809 mock_keyring_reject_local_ids = true; | 891 mock_keyring_reject_local_ids = true; |
| 810 | 892 |
| 811 { | 893 { |
| 812 NativeBackendGnome backend(42, profile_.GetPrefs()); | 894 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 813 backend.Init(); | 895 InitNativeBackend(&backend); |
| 814 | 896 |
| 815 BrowserThread::PostTask( | 897 BrowserThread::PostTask( |
| 816 BrowserThread::DB, FROM_HERE, | 898 BrowserThread::DB, FROM_HERE, |
| 817 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), | 899 base::Bind(base::IgnoreResult(&NativeBackendGnome::AddLogin), |
| 818 base::Unretained(&backend), form_google_)); | 900 base::Unretained(&backend), form_google_)); |
| 819 | 901 |
| 820 RunBothThreads(); | 902 RunAllThreads(); |
| 821 } | 903 } |
| 822 | 904 |
| 823 EXPECT_EQ(1u, mock_keyring_items.size()); | 905 EXPECT_EQ(1u, mock_keyring_items.size()); |
| 824 if (mock_keyring_items.size() > 0) | 906 if (mock_keyring_items.size() > 0) |
| 825 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 907 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 826 | 908 |
| 827 // Now allow the migration. | 909 // Now allow the migration. |
| 828 mock_keyring_reject_local_ids = false; | 910 mock_keyring_reject_local_ids = false; |
| 829 | 911 |
| 830 { | 912 { |
| 831 NativeBackendGnome backend(42, profile_.GetPrefs()); | 913 NativeBackendGnome backend(42, profile_.GetPrefs()); |
| 832 backend.Init(); | 914 InitNativeBackend(&backend); |
| 833 | 915 |
| 834 // Trigger the migration by looking something up. | 916 // Trigger the migration by looking something up. |
| 835 std::vector<PasswordForm*> form_list; | 917 std::vector<PasswordForm*> form_list; |
| 836 BrowserThread::PostTask( | 918 BrowserThread::PostTask( |
| 837 BrowserThread::DB, FROM_HERE, | 919 BrowserThread::DB, FROM_HERE, |
| 838 base::Bind( | 920 base::Bind( |
| 839 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 921 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 840 base::Unretained(&backend), &form_list)); | 922 base::Unretained(&backend), &form_list)); |
| 841 | 923 |
| 842 RunBothThreads(); | 924 RunAllThreads(); |
| 843 | 925 |
| 844 // Quick check that we got something back. | 926 // Quick check that we got something back. |
| 845 EXPECT_EQ(1u, form_list.size()); | 927 EXPECT_EQ(1u, form_list.size()); |
| 846 STLDeleteElements(&form_list); | 928 STLDeleteElements(&form_list); |
| 847 } | 929 } |
| 848 | 930 |
| 849 EXPECT_EQ(2u, mock_keyring_items.size()); | 931 EXPECT_EQ(2u, mock_keyring_items.size()); |
| 850 if (mock_keyring_items.size() > 0) | 932 if (mock_keyring_items.size() > 0) |
| 851 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 933 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 852 if (mock_keyring_items.size() > 1) | 934 if (mock_keyring_items.size() > 1) |
| 853 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 935 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 854 | 936 |
| 855 // Check that we have set the persistent preference. | 937 // Check that we have set the persistent preference. |
| 856 EXPECT_TRUE( | 938 EXPECT_TRUE( |
| 857 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); | 939 profile_.GetPrefs()->GetBoolean(prefs::kPasswordsUseLocalProfileId)); |
| 858 | 940 |
| 859 // Normally we'd actually have a different profile. But in the test just reset | 941 // Normally we'd actually have a different profile. But in the test just reset |
| 860 // the profile's persistent pref; we pass in the local profile id anyway. | 942 // the profile's persistent pref; we pass in the local profile id anyway. |
| 861 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); | 943 profile_.GetPrefs()->SetBoolean(prefs::kPasswordsUseLocalProfileId, false); |
| 862 | 944 |
| 863 { | 945 { |
| 864 NativeBackendGnome backend(24, profile_.GetPrefs()); | 946 NativeBackendGnome backend(24, profile_.GetPrefs()); |
| 865 backend.Init(); | 947 InitNativeBackend(&backend); |
| 866 | 948 |
| 867 // Trigger the migration by looking something up. | 949 // Trigger the migration by looking something up. |
| 868 std::vector<PasswordForm*> form_list; | 950 std::vector<PasswordForm*> form_list; |
| 869 BrowserThread::PostTask( | 951 BrowserThread::PostTask( |
| 870 BrowserThread::DB, FROM_HERE, | 952 BrowserThread::DB, FROM_HERE, |
| 871 base::Bind( | 953 base::Bind( |
| 872 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), | 954 base::IgnoreResult(&NativeBackendGnome::GetAutofillableLogins), |
| 873 base::Unretained(&backend), &form_list)); | 955 base::Unretained(&backend), &form_list)); |
| 874 | 956 |
| 875 RunBothThreads(); | 957 RunAllThreads(); |
| 876 | 958 |
| 877 // Quick check that we got something back. | 959 // Quick check that we got something back. |
| 878 EXPECT_EQ(1u, form_list.size()); | 960 EXPECT_EQ(1u, form_list.size()); |
| 879 STLDeleteElements(&form_list); | 961 STLDeleteElements(&form_list); |
| 880 | 962 |
| 881 // There should be three passwords now. | 963 // There should be three passwords now. |
| 882 EXPECT_EQ(3u, mock_keyring_items.size()); | 964 EXPECT_EQ(3u, mock_keyring_items.size()); |
| 883 if (mock_keyring_items.size() > 0) | 965 if (mock_keyring_items.size() > 0) |
| 884 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 966 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 885 if (mock_keyring_items.size() > 1) | 967 if (mock_keyring_items.size() > 1) |
| 886 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 968 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 887 if (mock_keyring_items.size() > 2) | 969 if (mock_keyring_items.size() > 2) |
| 888 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); | 970 CheckMockKeyringItem(&mock_keyring_items[2], form_google_, "chrome-24"); |
| 889 | 971 |
| 890 // Now delete the password from this second profile. | 972 // Now delete the password from this second profile. |
| 891 BrowserThread::PostTask( | 973 BrowserThread::PostTask( |
| 892 BrowserThread::DB, FROM_HERE, | 974 BrowserThread::DB, FROM_HERE, |
| 893 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), | 975 base::Bind(base::IgnoreResult(&NativeBackendGnome::RemoveLogin), |
| 894 base::Unretained(&backend), form_google_)); | 976 base::Unretained(&backend), form_google_)); |
| 895 | 977 |
| 896 RunBothThreads(); | 978 RunAllThreads(); |
| 897 | 979 |
| 898 // The other two copies of the password in different profiles should remain. | 980 // The other two copies of the password in different profiles should remain. |
| 899 EXPECT_EQ(2u, mock_keyring_items.size()); | 981 EXPECT_EQ(2u, mock_keyring_items.size()); |
| 900 if (mock_keyring_items.size() > 0) | 982 if (mock_keyring_items.size() > 0) |
| 901 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); | 983 CheckMockKeyringItem(&mock_keyring_items[0], form_google_, "chrome"); |
| 902 if (mock_keyring_items.size() > 1) | 984 if (mock_keyring_items.size() > 1) |
| 903 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); | 985 CheckMockKeyringItem(&mock_keyring_items[1], form_google_, "chrome-42"); |
| 904 } | 986 } |
| 905 } | 987 } |
| OLD | NEW |