| 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" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 ProfileCreationComplete(profile, status); | 62 ProfileCreationComplete(profile, status); |
| 63 } | 63 } |
| 64 | 64 |
| 65 class ProfileRemovalObserver : public ProfileInfoCacheObserver { | 65 class ProfileRemovalObserver : public ProfileInfoCacheObserver { |
| 66 public: | 66 public: |
| 67 ProfileRemovalObserver() { | 67 ProfileRemovalObserver() { |
| 68 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver( | 68 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver( |
| 69 this); | 69 this); |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual ~ProfileRemovalObserver() { | 72 ~ProfileRemovalObserver() override { |
| 73 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( | 73 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( |
| 74 this); | 74 this); |
| 75 } | 75 } |
| 76 | 76 |
| 77 std::string last_used_profile_name() { return last_used_profile_name_; } | 77 std::string last_used_profile_name() { return last_used_profile_name_; } |
| 78 | 78 |
| 79 // ProfileInfoCacheObserver overrides: | 79 // ProfileInfoCacheObserver overrides: |
| 80 virtual void OnProfileWillBeRemoved( | 80 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override { |
| 81 const base::FilePath& profile_path) override { | |
| 82 last_used_profile_name_ = g_browser_process->local_state()->GetString( | 81 last_used_profile_name_ = g_browser_process->local_state()->GetString( |
| 83 prefs::kProfileLastUsed); | 82 prefs::kProfileLastUsed); |
| 84 } | 83 } |
| 85 | 84 |
| 86 private: | 85 private: |
| 87 std::string last_used_profile_name_; | 86 std::string last_used_profile_name_; |
| 88 | 87 |
| 89 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); | 88 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 // The class serves to retrieve passwords from PasswordStore asynchronously. It | 91 // The class serves to retrieve passwords from PasswordStore asynchronously. It |
| 93 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms. | 92 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms. |
| 94 class PasswordStoreConsumerVerifier : | 93 class PasswordStoreConsumerVerifier : |
| 95 public password_manager::PasswordStoreConsumer { | 94 public password_manager::PasswordStoreConsumer { |
| 96 public: | 95 public: |
| 97 PasswordStoreConsumerVerifier() : called_(false) {} | 96 PasswordStoreConsumerVerifier() : called_(false) {} |
| 98 | 97 |
| 99 virtual void OnGetPasswordStoreResults( | 98 void OnGetPasswordStoreResults( |
| 100 const std::vector<autofill::PasswordForm*>& results) override { | 99 const std::vector<autofill::PasswordForm*>& results) override { |
| 101 EXPECT_FALSE(called_); | 100 EXPECT_FALSE(called_); |
| 102 called_ = true; | 101 called_ = true; |
| 103 password_entries_.clear(); | 102 password_entries_.clear(); |
| 104 password_entries_.assign(results.begin(), results.end()); | 103 password_entries_.assign(results.begin(), results.end()); |
| 105 } | 104 } |
| 106 | 105 |
| 107 bool IsCalled() const { return called_; } | 106 bool IsCalled() const { return called_; } |
| 108 | 107 |
| 109 const std::vector<autofill::PasswordForm*>& GetPasswords() const { | 108 const std::vector<autofill::PasswordForm*>& GetPasswords() const { |
| 110 return password_entries_.get(); | 109 return password_entries_.get(); |
| 111 } | 110 } |
| 112 private: | 111 private: |
| 113 ScopedVector<autofill::PasswordForm> password_entries_; | 112 ScopedVector<autofill::PasswordForm> password_entries_; |
| 114 bool called_; | 113 bool called_; |
| 115 }; | 114 }; |
| 116 | 115 |
| 117 } // namespace | 116 } // namespace |
| 118 | 117 |
| 119 // This file contains tests for the ProfileManager that require a heavyweight | 118 // This file contains tests for the ProfileManager that require a heavyweight |
| 120 // InProcessBrowserTest. These include tests involving profile deletion. | 119 // InProcessBrowserTest. These include tests involving profile deletion. |
| 121 | 120 |
| 122 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 121 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
| 123 // platforms. | 122 // platforms. |
| 124 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 123 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
| 125 protected: | 124 protected: |
| 126 virtual void SetUpCommandLine(CommandLine* command_line) override { | 125 void SetUpCommandLine(CommandLine* command_line) override { |
| 127 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
| 128 command_line->AppendSwitch( | 127 command_line->AppendSwitch( |
| 129 chromeos::switches::kIgnoreUserProfileMappingForTests); | 128 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 130 #endif | 129 #endif |
| 131 } | 130 } |
| 132 }; | 131 }; |
| 133 | 132 |
| 134 #if defined(OS_MACOSX) | 133 #if defined(OS_MACOSX) |
| 135 | 134 |
| 136 // Delete single profile and make sure a new one is created. | 135 // Delete single profile and make sure a new one is created. |
| (...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 run_loop.QuitClosure()); | 442 run_loop.QuitClosure()); |
| 444 EXPECT_TRUE(password_store->ScheduleTask(task)); | 443 EXPECT_TRUE(password_store->ScheduleTask(task)); |
| 445 run_loop.Run(); | 444 run_loop.Run(); |
| 446 | 445 |
| 447 EXPECT_TRUE(verify_add.IsCalled()); | 446 EXPECT_TRUE(verify_add.IsCalled()); |
| 448 EXPECT_EQ(1u, verify_add.GetPasswords().size()); | 447 EXPECT_EQ(1u, verify_add.GetPasswords().size()); |
| 449 EXPECT_TRUE(verify_delete.IsCalled()); | 448 EXPECT_TRUE(verify_delete.IsCalled()); |
| 450 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); | 449 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); |
| 451 } | 450 } |
| 452 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 451 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| OLD | NEW |