| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/password_manager/password_store_factory.h" | |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
| 11 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 12 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/profiles/profile_window.h" | 12 #include "chrome/browser/profiles/profile_window.h" |
| 14 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 18 #include "chrome/browser/ui/host_desktop.h" | 17 #include "chrome/browser/ui/host_desktop.h" |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 24 #include "components/autofill/core/common/password_form.h" | |
| 25 #include "components/password_manager/core/browser/password_store.h" | |
| 26 #include "components/password_manager/core/browser/password_store_consumer.h" | |
| 27 | 23 |
| 28 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 29 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 30 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 32 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #endif | 30 #endif |
| 35 | 31 |
| 36 namespace { | 32 namespace { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 last_used_profile_name_ = g_browser_process->local_state()->GetString( | 78 last_used_profile_name_ = g_browser_process->local_state()->GetString( |
| 83 prefs::kProfileLastUsed); | 79 prefs::kProfileLastUsed); |
| 84 } | 80 } |
| 85 | 81 |
| 86 private: | 82 private: |
| 87 std::string last_used_profile_name_; | 83 std::string last_used_profile_name_; |
| 88 | 84 |
| 89 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); | 85 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); |
| 90 }; | 86 }; |
| 91 | 87 |
| 92 class PasswordStoreConsumerVerifier : | |
| 93 public password_manager::PasswordStoreConsumer { | |
| 94 public: | |
| 95 PasswordStoreConsumerVerifier() : called_(false) {} | |
| 96 | |
| 97 virtual void OnGetPasswordStoreResults( | |
| 98 const std::vector<autofill::PasswordForm*>& results) OVERRIDE { | |
| 99 EXPECT_FALSE(called_); | |
| 100 called_ = true; | |
| 101 password_entries_.clear(); | |
| 102 password_entries_.assign(results.begin(), results.end()); | |
| 103 } | |
| 104 | |
| 105 bool IsCalled() const { return called_; } | |
| 106 | |
| 107 const std::vector<autofill::PasswordForm*>& GetPasswords() const { | |
| 108 return password_entries_.get(); | |
| 109 } | |
| 110 private: | |
| 111 ScopedVector<autofill::PasswordForm> password_entries_; | |
| 112 bool called_; | |
| 113 }; | |
| 114 | |
| 115 } // namespace | 88 } // namespace |
| 116 | 89 |
| 117 // This file contains tests for the ProfileManager that require a heavyweight | 90 // This file contains tests for the ProfileManager that require a heavyweight |
| 118 // InProcessBrowserTest. These include tests involving profile deletion. | 91 // InProcessBrowserTest. These include tests involving profile deletion. |
| 119 | 92 |
| 120 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 93 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
| 121 // platforms. | 94 // platforms. |
| 122 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 95 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
| 123 protected: | 96 protected: |
| 124 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 97 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 EXPECT_EQ(2U, browser_list->size()); | 362 EXPECT_EQ(2U, browser_list->size()); |
| 390 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); | 363 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); |
| 391 | 364 |
| 392 // The second should though. | 365 // The second should though. |
| 393 browser_list->get(1)->window()->Close(); | 366 browser_list->get(1)->window()->Close(); |
| 394 content::RunAllPendingInMessageLoop(); | 367 content::RunAllPendingInMessageLoop(); |
| 395 EXPECT_EQ(1U, browser_list->size()); | 368 EXPECT_EQ(1U, browser_list->size()); |
| 396 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); | 369 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); |
| 397 } | 370 } |
| 398 | 371 |
| 399 // The test is ending with timeout on Win. It's not important because there is | |
| 400 // no keychain on Windows. | |
| 401 #if !defined(OS_WIN) | |
| 402 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeletePasswords) { | |
| 403 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 404 ASSERT_TRUE(profile); | |
| 405 | |
| 406 autofill::PasswordForm form; | |
| 407 form.scheme = autofill::PasswordForm::SCHEME_HTML; | |
| 408 form.origin = GURL("http://accounts.google.com/LoginAuth"); | |
| 409 form.signon_realm = "http://accounts.google.com/"; | |
| 410 form.username_value = base::ASCIIToUTF16("my_username"); | |
| 411 form.password_value = base::ASCIIToUTF16("my_password"); | |
| 412 form.ssl_valid = false; | |
| 413 form.preferred = true; | |
| 414 form.blacklisted_by_user = false; | |
| 415 | |
| 416 scoped_refptr<password_manager::PasswordStore> password_store = | |
| 417 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | |
| 418 .get(); | |
| 419 ASSERT_TRUE(password_store); | |
| 420 | |
| 421 password_store->AddLogin(form); | |
| 422 PasswordStoreConsumerVerifier verify_add; | |
| 423 password_store->GetAutofillableLogins(&verify_add); | |
| 424 | |
| 425 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 426 profile_manager->ScheduleProfileForDeletion(profile->GetPath(), | |
| 427 ProfileManager::CreateCallback()); | |
| 428 content::RunAllPendingInMessageLoop(); | |
| 429 PasswordStoreConsumerVerifier verify_delete; | |
| 430 password_store->GetAutofillableLogins(&verify_delete); | |
| 431 | |
| 432 // Run the password background thread. | |
| 433 base::RunLoop run_loop; | |
| 434 base::Closure task = base::Bind( | |
| 435 base::IgnoreResult(&content::BrowserThread::PostTask), | |
| 436 content::BrowserThread::UI, | |
| 437 FROM_HERE, | |
| 438 run_loop.QuitClosure()); | |
| 439 EXPECT_TRUE(password_store->ScheduleTask(task)); | |
| 440 run_loop.Run(); | |
| 441 | |
| 442 EXPECT_TRUE(verify_add.IsCalled()); | |
| 443 EXPECT_EQ(1u, verify_add.GetPasswords().size()); | |
| 444 EXPECT_TRUE(verify_delete.IsCalled()); | |
| 445 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); | |
| 446 } | |
| 447 #endif | |
| OLD | NEW |