| 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 20 matching lines...) Expand all Loading... |
| 31 class URLRequestContextGetter; | 31 class URLRequestContextGetter; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace quota { | 34 namespace quota { |
| 35 class SpecialStoragePolicy; | 35 class SpecialStoragePolicy; |
| 36 } | 36 } |
| 37 | 37 |
| 38 class CommandLine; | 38 class CommandLine; |
| 39 class ExtensionSpecialStoragePolicy; | 39 class ExtensionSpecialStoragePolicy; |
| 40 class HostContentSettingsMap; | 40 class HostContentSettingsMap; |
| 41 class PrefService; | 41 class PrefServiceSyncable; |
| 42 class ProfileDependencyManager; | 42 class ProfileDependencyManager; |
| 43 class ProfileSyncService; | 43 class ProfileSyncService; |
| 44 class TemplateURLService; | 44 class TemplateURLService; |
| 45 class TestingPrefService; | 45 class TestingPrefServiceSyncable; |
| 46 | 46 |
| 47 class TestingProfile : public Profile { | 47 class TestingProfile : public Profile { |
| 48 public: | 48 public: |
| 49 // Profile directory name for the test user. This is "Default" on most | 49 // Profile directory name for the test user. This is "Default" on most |
| 50 // platforms but must be different on ChromeOS because a logged-in user cannot | 50 // platforms but must be different on ChromeOS because a logged-in user cannot |
| 51 // use "Default" as profile directory. | 51 // use "Default" as profile directory. |
| 52 // Browser- and UI tests should always use this to get to the user's profile | 52 // Browser- and UI tests should always use this to get to the user's profile |
| 53 // directory. Unit-tests, though, should use |kInitialProfile|, which is | 53 // directory. Unit-tests, though, should use |kInitialProfile|, which is |
| 54 // always "Default", because they are runnining without logged-in user. | 54 // always "Default", because they are runnining without logged-in user. |
| 55 static const char kTestUserProfileDir[]; | 55 static const char kTestUserProfileDir[]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 75 | 75 |
| 76 // Sets the ExtensionSpecialStoragePolicy to be returned by | 76 // Sets the ExtensionSpecialStoragePolicy to be returned by |
| 77 // GetExtensionSpecialStoragePolicy(). | 77 // GetExtensionSpecialStoragePolicy(). |
| 78 void SetExtensionSpecialStoragePolicy( | 78 void SetExtensionSpecialStoragePolicy( |
| 79 scoped_refptr<ExtensionSpecialStoragePolicy> policy); | 79 scoped_refptr<ExtensionSpecialStoragePolicy> policy); |
| 80 | 80 |
| 81 // Sets the path to the directory to be used to hold profile data. | 81 // Sets the path to the directory to be used to hold profile data. |
| 82 void SetPath(const FilePath& path); | 82 void SetPath(const FilePath& path); |
| 83 | 83 |
| 84 // Sets the PrefService to be used by this profile. | 84 // Sets the PrefService to be used by this profile. |
| 85 void SetPrefService(scoped_ptr<PrefService> prefs); | 85 void SetPrefService(scoped_ptr<PrefServiceSyncable> prefs); |
| 86 | 86 |
| 87 // Creates the TestingProfile using previously-set settings. | 87 // Creates the TestingProfile using previously-set settings. |
| 88 scoped_ptr<TestingProfile> Build(); | 88 scoped_ptr<TestingProfile> Build(); |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 // If true, Build() has already been called. | 91 // If true, Build() has already been called. |
| 92 bool build_called_; | 92 bool build_called_; |
| 93 | 93 |
| 94 // Various staging variables where values are held until Build() is invoked. | 94 // Various staging variables where values are held until Build() is invoked. |
| 95 scoped_ptr<PrefService> pref_service_; | 95 scoped_ptr<PrefServiceSyncable> pref_service_; |
| 96 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; | 96 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; |
| 97 FilePath path_; | 97 FilePath path_; |
| 98 Delegate* delegate_; | 98 Delegate* delegate_; |
| 99 | 99 |
| 100 DISALLOW_COPY_AND_ASSIGN(Builder); | 100 DISALLOW_COPY_AND_ASSIGN(Builder); |
| 101 }; | 101 }; |
| 102 | 102 |
| 103 // Multi-profile aware constructor that takes the path to a directory managed | 103 // Multi-profile aware constructor that takes the path to a directory managed |
| 104 // for this profile. This constructor is meant to be used by | 104 // for this profile. This constructor is meant to be used by |
| 105 // TestingProfileManager::CreateTestingProfile. If you need to create multi- | 105 // TestingProfileManager::CreateTestingProfile. If you need to create multi- |
| 106 // profile profiles, use that factory method instead of this directly. | 106 // profile profiles, use that factory method instead of this directly. |
| 107 // Exception: if you need to create multi-profile profiles for testing the | 107 // Exception: if you need to create multi-profile profiles for testing the |
| 108 // ProfileManager, then use the constructor below instead. | 108 // ProfileManager, then use the constructor below instead. |
| 109 explicit TestingProfile(const FilePath& path); | 109 explicit TestingProfile(const FilePath& path); |
| 110 | 110 |
| 111 // Multi-profile aware constructor that takes the path to a directory managed | 111 // Multi-profile aware constructor that takes the path to a directory managed |
| 112 // for this profile and a delegate. This constructor is meant to be used | 112 // for this profile and a delegate. This constructor is meant to be used |
| 113 // for unittesting the ProfileManager. | 113 // for unittesting the ProfileManager. |
| 114 TestingProfile(const FilePath& path, Delegate* delegate); | 114 TestingProfile(const FilePath& path, Delegate* delegate); |
| 115 | 115 |
| 116 // Full constructor allowing the setting of all possible instance data. | 116 // Full constructor allowing the setting of all possible instance data. |
| 117 // Callers should use Builder::Build() instead of invoking this constructor. | 117 // Callers should use Builder::Build() instead of invoking this constructor. |
| 118 TestingProfile(const FilePath& path, | 118 TestingProfile(const FilePath& path, |
| 119 Delegate* delegate, | 119 Delegate* delegate, |
| 120 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 120 scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |
| 121 scoped_ptr<PrefService> prefs); | 121 scoped_ptr<PrefServiceSyncable> prefs); |
| 122 | 122 |
| 123 virtual ~TestingProfile(); | 123 virtual ~TestingProfile(); |
| 124 | 124 |
| 125 // Creates the favicon service. Consequent calls would recreate the service. | 125 // Creates the favicon service. Consequent calls would recreate the service. |
| 126 void CreateFaviconService(); | 126 void CreateFaviconService(); |
| 127 | 127 |
| 128 // Creates the history service. If |delete_file| is true, the history file is | 128 // Creates the history service. If |delete_file| is true, the history file is |
| 129 // deleted first, then the HistoryService is created. As TestingProfile | 129 // deleted first, then the HistoryService is created. As TestingProfile |
| 130 // deletes the directory containing the files used by HistoryService, this | 130 // deletes the directory containing the files used by HistoryService, this |
| 131 // only matters if you're recreating the HistoryService. If |no_db| is true, | 131 // only matters if you're recreating the HistoryService. If |no_db| is true, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 161 // CreateBookmarkModel. | 161 // CreateBookmarkModel. |
| 162 void BlockUntilBookmarkModelLoaded(); | 162 void BlockUntilBookmarkModelLoaded(); |
| 163 | 163 |
| 164 // Blocks until the HistoryService finishes restoring its in-memory cache. | 164 // Blocks until the HistoryService finishes restoring its in-memory cache. |
| 165 // This is NOT invoked from CreateHistoryService. | 165 // This is NOT invoked from CreateHistoryService. |
| 166 void BlockUntilHistoryIndexIsRefreshed(); | 166 void BlockUntilHistoryIndexIsRefreshed(); |
| 167 | 167 |
| 168 // Blocks until TopSites finishes loading. | 168 // Blocks until TopSites finishes loading. |
| 169 void BlockUntilTopSitesLoaded(); | 169 void BlockUntilTopSitesLoaded(); |
| 170 | 170 |
| 171 TestingPrefService* GetTestingPrefService(); | 171 TestingPrefServiceSyncable* GetTestingPrefService(); |
| 172 | 172 |
| 173 // content::BrowserContext | 173 // content::BrowserContext |
| 174 virtual FilePath GetPath() OVERRIDE; | 174 virtual FilePath GetPath() OVERRIDE; |
| 175 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; | 175 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; |
| 176 virtual bool IsOffTheRecord() const OVERRIDE; | 176 virtual bool IsOffTheRecord() const OVERRIDE; |
| 177 virtual content::DownloadManagerDelegate* | 177 virtual content::DownloadManagerDelegate* |
| 178 GetDownloadManagerDelegate() OVERRIDE; | 178 GetDownloadManagerDelegate() OVERRIDE; |
| 179 // Returns a testing ContextGetter (if one has been created via | 179 // Returns a testing ContextGetter (if one has been created via |
| 180 // CreateRequestContext) or NULL. This is not done on-demand for two reasons: | 180 // CreateRequestContext) or NULL. This is not done on-demand for two reasons: |
| 181 // (1) Some tests depend on GetRequestContext() returning NULL. (2) Because | 181 // (1) Some tests depend on GetRequestContext() returning NULL. (2) Because |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 // for more information. | 214 // for more information. |
| 215 net::CookieMonster* GetCookieMonster(); | 215 net::CookieMonster* GetCookieMonster(); |
| 216 | 216 |
| 217 virtual policy::ManagedModePolicyProvider* | 217 virtual policy::ManagedModePolicyProvider* |
| 218 GetManagedModePolicyProvider() OVERRIDE; | 218 GetManagedModePolicyProvider() OVERRIDE; |
| 219 virtual policy::PolicyService* GetPolicyService() OVERRIDE; | 219 virtual policy::PolicyService* GetPolicyService() OVERRIDE; |
| 220 // Sets the profile's PrefService. If a pref service hasn't been explicitly | 220 // Sets the profile's PrefService. If a pref service hasn't been explicitly |
| 221 // set GetPrefs creates one, so normally you need not invoke this. If you need | 221 // set GetPrefs creates one, so normally you need not invoke this. If you need |
| 222 // to set a pref service you must invoke this before GetPrefs. | 222 // to set a pref service you must invoke this before GetPrefs. |
| 223 // TestingPrefService takes ownership of |prefs|. | 223 // TestingPrefService takes ownership of |prefs|. |
| 224 void SetPrefService(PrefService* prefs); | 224 void SetPrefService(PrefServiceSyncable* prefs); |
| 225 virtual PrefService* GetPrefs() OVERRIDE; | 225 virtual PrefServiceSyncable* GetPrefs() OVERRIDE; |
| 226 virtual history::TopSites* GetTopSites() OVERRIDE; | 226 virtual history::TopSites* GetTopSites() OVERRIDE; |
| 227 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; | 227 virtual history::TopSites* GetTopSitesWithoutCreating() OVERRIDE; |
| 228 | 228 |
| 229 void CreateRequestContext(); | 229 void CreateRequestContext(); |
| 230 // Clears out the created request context (which must be done before shutting | 230 // Clears out the created request context (which must be done before shutting |
| 231 // down the IO thread to avoid leaks). | 231 // down the IO thread to avoid leaks). |
| 232 void ResetRequestContext(); | 232 void ResetRequestContext(); |
| 233 | 233 |
| 234 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; | 234 virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; |
| 235 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( | 235 virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 // task is processed. This has the effect of blocking the caller until the | 284 // task is processed. This has the effect of blocking the caller until the |
| 285 // history service processes all pending requests. | 285 // history service processes all pending requests. |
| 286 void BlockUntilHistoryProcessesPendingRequests(); | 286 void BlockUntilHistoryProcessesPendingRequests(); |
| 287 | 287 |
| 288 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; | 288 virtual chrome_browser_net::Predictor* GetNetworkPredictor() OVERRIDE; |
| 289 virtual void ClearNetworkingHistorySince( | 289 virtual void ClearNetworkingHistorySince( |
| 290 base::Time time, | 290 base::Time time, |
| 291 const base::Closure& completion) OVERRIDE; | 291 const base::Closure& completion) OVERRIDE; |
| 292 virtual GURL GetHomePage() OVERRIDE; | 292 virtual GURL GetHomePage() OVERRIDE; |
| 293 | 293 |
| 294 virtual PrefService* GetOffTheRecordPrefs() OVERRIDE; | 294 virtual PrefServiceSyncable* GetOffTheRecordPrefs() OVERRIDE; |
| 295 | 295 |
| 296 protected: | 296 protected: |
| 297 base::Time start_time_; | 297 base::Time start_time_; |
| 298 scoped_ptr<PrefService> prefs_; | 298 scoped_ptr<PrefServiceSyncable> prefs_; |
| 299 // ref only for right type, lifecycle is managed by prefs_ | 299 // ref only for right type, lifecycle is managed by prefs_ |
| 300 TestingPrefService* testing_prefs_; | 300 TestingPrefServiceSyncable* testing_prefs_; |
| 301 | 301 |
| 302 private: | 302 private: |
| 303 // Creates a temporary directory for use by this profile. | 303 // Creates a temporary directory for use by this profile. |
| 304 void CreateTempProfileDir(); | 304 void CreateTempProfileDir(); |
| 305 | 305 |
| 306 // Common initialization between the two constructors. | 306 // Common initialization between the two constructors. |
| 307 void Init(); | 307 void Init(); |
| 308 | 308 |
| 309 // Finishes initialization when a profile is created asynchronously. | 309 // Finishes initialization when a profile is created asynchronously. |
| 310 void FinishInit(); | 310 void FinishInit(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 // testing. | 357 // testing. |
| 358 ProfileDependencyManager* profile_dependency_manager_; | 358 ProfileDependencyManager* profile_dependency_manager_; |
| 359 | 359 |
| 360 scoped_ptr<content::MockResourceContext> resource_context_; | 360 scoped_ptr<content::MockResourceContext> resource_context_; |
| 361 | 361 |
| 362 // Weak pointer to a delegate for indicating that a profile was created. | 362 // Weak pointer to a delegate for indicating that a profile was created. |
| 363 Delegate* delegate_; | 363 Delegate* delegate_; |
| 364 }; | 364 }; |
| 365 | 365 |
| 366 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ | 366 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ |
| OLD | NEW |