| 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 #ifndef CHROME_TEST_BASE_TESTING_PROFILE_H_ | 5 #ifndef CHROME_TEST_BASE_TESTING_PROFILE_H_ |
| 6 #define CHROME_TEST_BASE_TESTING_PROFILE_H_ | 6 #define CHROME_TEST_BASE_TESTING_PROFILE_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 void SetExtensionSpecialStoragePolicy( | 90 void SetExtensionSpecialStoragePolicy( |
| 91 scoped_refptr<ExtensionSpecialStoragePolicy> policy); | 91 scoped_refptr<ExtensionSpecialStoragePolicy> policy); |
| 92 #endif | 92 #endif |
| 93 | 93 |
| 94 // Sets the path to the directory to be used to hold profile data. | 94 // Sets the path to the directory to be used to hold profile data. |
| 95 void SetPath(const base::FilePath& path); | 95 void SetPath(const base::FilePath& path); |
| 96 | 96 |
| 97 // Sets the PrefService to be used by this profile. | 97 // Sets the PrefService to be used by this profile. |
| 98 void SetPrefService(scoped_ptr<PrefServiceSyncable> prefs); | 98 void SetPrefService(scoped_ptr<PrefServiceSyncable> prefs); |
| 99 | 99 |
| 100 // Makes the Profile being built an incognito profile. | |
| 101 void SetIncognito(); | |
| 102 | |
| 103 // Makes the Profile being built a guest profile. | 100 // Makes the Profile being built a guest profile. |
| 104 void SetGuestSession(); | 101 void SetGuestSession(); |
| 105 | 102 |
| 106 // Sets the supervised user ID (which is empty by default). If it is set to | 103 // Sets the supervised user ID (which is empty by default). If it is set to |
| 107 // a non-empty string, the profile is supervised. | 104 // a non-empty string, the profile is supervised. |
| 108 void SetSupervisedUserId(const std::string& supervised_user_id); | 105 void SetSupervisedUserId(const std::string& supervised_user_id); |
| 109 | 106 |
| 110 // Sets the PolicyService to be used by this profile. | 107 // Sets the PolicyService to be used by this profile. |
| 111 void SetPolicyService(scoped_ptr<policy::PolicyService> policy_service); | 108 void SetPolicyService(scoped_ptr<policy::PolicyService> policy_service); |
| 112 | 109 |
| 113 // Creates the TestingProfile using previously-set settings. | 110 // Creates the TestingProfile using previously-set settings. |
| 114 scoped_ptr<TestingProfile> Build(); | 111 scoped_ptr<TestingProfile> Build(); |
| 115 | 112 |
| 113 // Build an incognito profile, owned by |original_profile|. Note: unless you |
| 114 // need to customize the Builder, or access TestingProfile member functions, |
| 115 // you can use original_profile->GetOffTheRecordProfile(). |
| 116 TestingProfile* BuildIncognito(TestingProfile* original_profile); |
| 117 |
| 116 private: | 118 private: |
| 117 // If true, Build() has already been called. | 119 // If true, Build() has already been called. |
| 118 bool build_called_; | 120 bool build_called_; |
| 119 | 121 |
| 120 // Various staging variables where values are held until Build() is invoked. | 122 // Various staging variables where values are held until Build() is invoked. |
| 121 scoped_ptr<PrefServiceSyncable> pref_service_; | 123 scoped_ptr<PrefServiceSyncable> pref_service_; |
| 122 #if defined(ENABLE_EXTENSIONS) | 124 #if defined(ENABLE_EXTENSIONS) |
| 123 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; | 125 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; |
| 124 #endif | 126 #endif |
| 125 base::FilePath path_; | 127 base::FilePath path_; |
| 126 Delegate* delegate_; | 128 Delegate* delegate_; |
| 127 bool incognito_; | |
| 128 bool guest_session_; | 129 bool guest_session_; |
| 129 std::string supervised_user_id_; | 130 std::string supervised_user_id_; |
| 130 scoped_ptr<policy::PolicyService> policy_service_; | 131 scoped_ptr<policy::PolicyService> policy_service_; |
| 131 TestingFactories testing_factories_; | 132 TestingFactories testing_factories_; |
| 132 | 133 |
| 133 DISALLOW_COPY_AND_ASSIGN(Builder); | 134 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 134 }; | 135 }; |
| 135 | 136 |
| 136 // Multi-profile aware constructor that takes the path to a directory managed | 137 // Multi-profile aware constructor that takes the path to a directory managed |
| 137 // for this profile. This constructor is meant to be used by | 138 // for this profile. This constructor is meant to be used by |
| 138 // TestingProfileManager::CreateTestingProfile. If you need to create multi- | 139 // TestingProfileManager::CreateTestingProfile. If you need to create multi- |
| 139 // profile profiles, use that factory method instead of this directly. | 140 // profile profiles, use that factory method instead of this directly. |
| 140 // Exception: if you need to create multi-profile profiles for testing the | 141 // Exception: if you need to create multi-profile profiles for testing the |
| 141 // ProfileManager, then use the constructor below instead. | 142 // ProfileManager, then use the constructor below instead. |
| 142 explicit TestingProfile(const base::FilePath& path); | 143 explicit TestingProfile(const base::FilePath& path); |
| 143 | 144 |
| 144 // Multi-profile aware constructor that takes the path to a directory managed | 145 // Multi-profile aware constructor that takes the path to a directory managed |
| 145 // for this profile and a delegate. This constructor is meant to be used | 146 // for this profile and a delegate. This constructor is meant to be used |
| 146 // for unittesting the ProfileManager. | 147 // for unittesting the ProfileManager. |
| 147 TestingProfile(const base::FilePath& path, Delegate* delegate); | 148 TestingProfile(const base::FilePath& path, Delegate* delegate); |
| 148 | 149 |
| 149 // Full constructor allowing the setting of all possible instance data. | 150 // Full constructor allowing the setting of all possible instance data. |
| 150 // Callers should use Builder::Build() instead of invoking this constructor. | 151 // Callers should use Builder::Build() instead of invoking this constructor. |
| 151 TestingProfile(const base::FilePath& path, | 152 TestingProfile(const base::FilePath& path, |
| 152 Delegate* delegate, | 153 Delegate* delegate, |
| 153 #if defined(ENABLE_EXTENSIONS) | 154 #if defined(ENABLE_EXTENSIONS) |
| 154 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 155 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 155 #endif | 156 #endif |
| 156 scoped_ptr<PrefServiceSyncable> prefs, | 157 scoped_ptr<PrefServiceSyncable> prefs, |
| 157 bool incognito, | 158 TestingProfile* parent, |
| 158 bool guest_session, | 159 bool guest_session, |
| 159 const std::string& supervised_user_id, | 160 const std::string& supervised_user_id, |
| 160 scoped_ptr<policy::PolicyService> policy_service, | 161 scoped_ptr<policy::PolicyService> policy_service, |
| 161 const TestingFactories& factories); | 162 const TestingFactories& factories); |
| 162 | 163 |
| 163 virtual ~TestingProfile(); | 164 virtual ~TestingProfile(); |
| 164 | 165 |
| 165 // Creates the favicon service. Consequent calls would recreate the service. | 166 // Creates the favicon service. Consequent calls would recreate the service. |
| 166 void CreateFaviconService(); | 167 void CreateFaviconService(); |
| 167 | 168 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 void BlockUntilHistoryIndexIsRefreshed(); | 203 void BlockUntilHistoryIndexIsRefreshed(); |
| 203 | 204 |
| 204 // Blocks until TopSites finishes loading. | 205 // Blocks until TopSites finishes loading. |
| 205 void BlockUntilTopSitesLoaded(); | 206 void BlockUntilTopSitesLoaded(); |
| 206 | 207 |
| 207 // Allow setting a profile as Guest after-the-fact to simplify some tests. | 208 // Allow setting a profile as Guest after-the-fact to simplify some tests. |
| 208 void SetGuestSession(bool guest); | 209 void SetGuestSession(bool guest); |
| 209 | 210 |
| 210 TestingPrefServiceSyncable* GetTestingPrefService(); | 211 TestingPrefServiceSyncable* GetTestingPrefService(); |
| 211 | 212 |
| 213 // Called on the parent of an incognito |profile|. Usually called from the |
| 214 // constructor of an incognito TestingProfile, but can also be used by tests |
| 215 // to provide an OffTheRecordProfileImpl instance. |
| 216 void SetOffTheRecordProfile(scoped_ptr<Profile> profile); |
| 217 |
| 212 // content::BrowserContext | 218 // content::BrowserContext |
| 213 virtual base::FilePath GetPath() const OVERRIDE; | 219 virtual base::FilePath GetPath() const OVERRIDE; |
| 214 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; | 220 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; |
| 215 virtual bool IsOffTheRecord() const OVERRIDE; | 221 virtual bool IsOffTheRecord() const OVERRIDE; |
| 216 virtual content::DownloadManagerDelegate* | 222 virtual content::DownloadManagerDelegate* |
| 217 GetDownloadManagerDelegate() OVERRIDE; | 223 GetDownloadManagerDelegate() OVERRIDE; |
| 218 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 224 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
| 219 virtual net::URLRequestContextGetter* CreateRequestContext( | 225 virtual net::URLRequestContextGetter* CreateRequestContext( |
| 220 content::ProtocolHandlerMap* protocol_handlers, | 226 content::ProtocolHandlerMap* protocol_handlers, |
| 221 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; | 227 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 243 // Changes a profile's to/from incognito mode temporarily - profile will be | 249 // Changes a profile's to/from incognito mode temporarily - profile will be |
| 244 // returned to non-incognito before destruction to allow services to | 250 // returned to non-incognito before destruction to allow services to |
| 245 // properly shutdown. This is only supported for legacy tests - new tests | 251 // properly shutdown. This is only supported for legacy tests - new tests |
| 246 // should create a true incognito profile using Builder::SetIncognito() or | 252 // should create a true incognito profile using Builder::SetIncognito() or |
| 247 // by using the TestingProfile constructor that allows setting the incognito | 253 // by using the TestingProfile constructor that allows setting the incognito |
| 248 // flag. | 254 // flag. |
| 249 void ForceIncognito(bool force_incognito) { | 255 void ForceIncognito(bool force_incognito) { |
| 250 force_incognito_ = force_incognito; | 256 force_incognito_ = force_incognito; |
| 251 } | 257 } |
| 252 | 258 |
| 253 virtual void SetOffTheRecordProfile(scoped_ptr<Profile> profile); | |
| 254 virtual void SetOriginalProfile(Profile* profile); | |
| 255 virtual Profile* GetOffTheRecordProfile() OVERRIDE; | 259 virtual Profile* GetOffTheRecordProfile() OVERRIDE; |
| 256 virtual void DestroyOffTheRecordProfile() OVERRIDE {} | 260 virtual void DestroyOffTheRecordProfile() OVERRIDE {} |
| 257 virtual bool HasOffTheRecordProfile() OVERRIDE; | 261 virtual bool HasOffTheRecordProfile() OVERRIDE; |
| 258 virtual Profile* GetOriginalProfile() OVERRIDE; | 262 virtual Profile* GetOriginalProfile() OVERRIDE; |
| 259 virtual bool IsSupervised() OVERRIDE; | 263 virtual bool IsSupervised() OVERRIDE; |
| 260 #if defined(ENABLE_EXTENSIONS) | 264 #if defined(ENABLE_EXTENSIONS) |
| 261 void SetExtensionSpecialStoragePolicy( | 265 void SetExtensionSpecialStoragePolicy( |
| 262 ExtensionSpecialStoragePolicy* extension_special_storage_policy); | 266 ExtensionSpecialStoragePolicy* extension_special_storage_policy); |
| 263 #endif | 267 #endif |
| 264 virtual ExtensionSpecialStoragePolicy* | 268 virtual ExtensionSpecialStoragePolicy* |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 346 |
| 343 // Common initialization between the two constructors. | 347 // Common initialization between the two constructors. |
| 344 void Init(); | 348 void Init(); |
| 345 | 349 |
| 346 // Finishes initialization when a profile is created asynchronously. | 350 // Finishes initialization when a profile is created asynchronously. |
| 347 void FinishInit(); | 351 void FinishInit(); |
| 348 | 352 |
| 349 // Creates a TestingPrefService and associates it with the TestingProfile. | 353 // Creates a TestingPrefService and associates it with the TestingProfile. |
| 350 void CreateTestingPrefService(); | 354 void CreateTestingPrefService(); |
| 351 | 355 |
| 356 // Initializes |prefs_| for an incognito profile, derived from |
| 357 // |original_profile_|. |
| 358 void CreateIncognitoPrefService(); |
| 359 |
| 352 // Creates a ProfilePolicyConnector that the ProfilePolicyConnectorFactory | 360 // Creates a ProfilePolicyConnector that the ProfilePolicyConnectorFactory |
| 353 // maps to this profile. | 361 // maps to this profile. |
| 354 void CreateProfilePolicyConnector(); | 362 void CreateProfilePolicyConnector(); |
| 355 | 363 |
| 356 // Internally, this is a TestURLRequestContextGetter that creates a dummy | 364 // Internally, this is a TestURLRequestContextGetter that creates a dummy |
| 357 // request context. Currently, only the CookieMonster is hooked up. | 365 // request context. Currently, only the CookieMonster is hooked up. |
| 358 scoped_refptr<net::URLRequestContextGetter> extensions_request_context_; | 366 scoped_refptr<net::URLRequestContextGetter> extensions_request_context_; |
| 359 | 367 |
| 360 bool incognito_; | |
| 361 bool force_incognito_; | 368 bool force_incognito_; |
| 362 scoped_ptr<Profile> incognito_profile_; | 369 scoped_ptr<Profile> incognito_profile_; |
| 363 Profile* original_profile_; | 370 TestingProfile* original_profile_; |
| 364 | 371 |
| 365 bool guest_session_; | 372 bool guest_session_; |
| 366 | 373 |
| 367 std::string supervised_user_id_; | 374 std::string supervised_user_id_; |
| 368 | 375 |
| 369 // Did the last session exit cleanly? Default is true. | 376 // Did the last session exit cleanly? Default is true. |
| 370 bool last_session_exited_cleanly_; | 377 bool last_session_exited_cleanly_; |
| 371 | 378 |
| 372 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 379 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
| 373 | 380 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 | 413 |
| 407 // Weak pointer to a delegate for indicating that a profile was created. | 414 // Weak pointer to a delegate for indicating that a profile was created. |
| 408 Delegate* delegate_; | 415 Delegate* delegate_; |
| 409 | 416 |
| 410 std::string profile_name_; | 417 std::string profile_name_; |
| 411 | 418 |
| 412 scoped_ptr<policy::PolicyService> policy_service_; | 419 scoped_ptr<policy::PolicyService> policy_service_; |
| 413 }; | 420 }; |
| 414 | 421 |
| 415 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ | 422 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ |
| OLD | NEW |