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 customize the Builder, or access TestingProfile member functions, | |
sky
2014/09/12 15:33:29
to customize?
tapted
2014/09/15 05:05:17
Done.
| |
115 // you can probably just call original_profile->GetOffTheRecordProfile(). | |
sky
2014/09/12 15:33:29
'probably just call' -> use
tapted
2014/09/15 05:05:17
Done.
| |
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* incognito_parent, |
sky
2014/09/12 15:33:29
incognito_parent is mildly confusing, in so far as
tapted
2014/09/15 05:05:17
Done.
| |
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 // Used by some tests to provide an OffTheRecordProfileImpl instead of an | |
214 // instance of TestingProfile. | |
215 void SetOffTheRecordProfile(scoped_ptr<Profile> profile); | |
216 | |
212 // content::BrowserContext | 217 // content::BrowserContext |
213 virtual base::FilePath GetPath() const OVERRIDE; | 218 virtual base::FilePath GetPath() const OVERRIDE; |
214 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; | 219 virtual scoped_refptr<base::SequencedTaskRunner> GetIOTaskRunner() OVERRIDE; |
215 virtual bool IsOffTheRecord() const OVERRIDE; | 220 virtual bool IsOffTheRecord() const OVERRIDE; |
216 virtual content::DownloadManagerDelegate* | 221 virtual content::DownloadManagerDelegate* |
217 GetDownloadManagerDelegate() OVERRIDE; | 222 GetDownloadManagerDelegate() OVERRIDE; |
218 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; | 223 virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; |
219 virtual net::URLRequestContextGetter* CreateRequestContext( | 224 virtual net::URLRequestContextGetter* CreateRequestContext( |
220 content::ProtocolHandlerMap* protocol_handlers, | 225 content::ProtocolHandlerMap* protocol_handlers, |
221 content::URLRequestInterceptorScopedVector request_interceptors) OVERRIDE; | 226 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 | 248 // Changes a profile's to/from incognito mode temporarily - profile will be |
244 // returned to non-incognito before destruction to allow services to | 249 // returned to non-incognito before destruction to allow services to |
245 // properly shutdown. This is only supported for legacy tests - new tests | 250 // properly shutdown. This is only supported for legacy tests - new tests |
246 // should create a true incognito profile using Builder::SetIncognito() or | 251 // should create a true incognito profile using Builder::SetIncognito() or |
247 // by using the TestingProfile constructor that allows setting the incognito | 252 // by using the TestingProfile constructor that allows setting the incognito |
248 // flag. | 253 // flag. |
249 void ForceIncognito(bool force_incognito) { | 254 void ForceIncognito(bool force_incognito) { |
250 force_incognito_ = force_incognito; | 255 force_incognito_ = force_incognito; |
251 } | 256 } |
252 | 257 |
253 virtual void SetOffTheRecordProfile(scoped_ptr<Profile> profile); | |
254 virtual void SetOriginalProfile(Profile* profile); | |
255 virtual Profile* GetOffTheRecordProfile() OVERRIDE; | 258 virtual Profile* GetOffTheRecordProfile() OVERRIDE; |
256 virtual void DestroyOffTheRecordProfile() OVERRIDE {} | 259 virtual void DestroyOffTheRecordProfile() OVERRIDE {} |
257 virtual bool HasOffTheRecordProfile() OVERRIDE; | 260 virtual bool HasOffTheRecordProfile() OVERRIDE; |
258 virtual Profile* GetOriginalProfile() OVERRIDE; | 261 virtual Profile* GetOriginalProfile() OVERRIDE; |
259 virtual bool IsSupervised() OVERRIDE; | 262 virtual bool IsSupervised() OVERRIDE; |
260 #if defined(ENABLE_EXTENSIONS) | 263 #if defined(ENABLE_EXTENSIONS) |
261 void SetExtensionSpecialStoragePolicy( | 264 void SetExtensionSpecialStoragePolicy( |
262 ExtensionSpecialStoragePolicy* extension_special_storage_policy); | 265 ExtensionSpecialStoragePolicy* extension_special_storage_policy); |
263 #endif | 266 #endif |
264 virtual ExtensionSpecialStoragePolicy* | 267 virtual ExtensionSpecialStoragePolicy* |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
342 | 345 |
343 // Common initialization between the two constructors. | 346 // Common initialization between the two constructors. |
344 void Init(); | 347 void Init(); |
345 | 348 |
346 // Finishes initialization when a profile is created asynchronously. | 349 // Finishes initialization when a profile is created asynchronously. |
347 void FinishInit(); | 350 void FinishInit(); |
348 | 351 |
349 // Creates a TestingPrefService and associates it with the TestingProfile. | 352 // Creates a TestingPrefService and associates it with the TestingProfile. |
350 void CreateTestingPrefService(); | 353 void CreateTestingPrefService(); |
351 | 354 |
355 // Initializes |prefs_| for an incognito profile, derived from | |
356 // |original_profile_|. | |
357 void CreateIncognitoPrefService(); | |
358 | |
352 // Creates a ProfilePolicyConnector that the ProfilePolicyConnectorFactory | 359 // Creates a ProfilePolicyConnector that the ProfilePolicyConnectorFactory |
353 // maps to this profile. | 360 // maps to this profile. |
354 void CreateProfilePolicyConnector(); | 361 void CreateProfilePolicyConnector(); |
355 | 362 |
363 // Called from the constructor of an OTR TestingProfile. Takes ownership of | |
364 // |incognito_profile|. | |
365 void SetTestingOffTheRecordProfile(Profile* incognito_profile); | |
366 | |
356 // Internally, this is a TestURLRequestContextGetter that creates a dummy | 367 // Internally, this is a TestURLRequestContextGetter that creates a dummy |
357 // request context. Currently, only the CookieMonster is hooked up. | 368 // request context. Currently, only the CookieMonster is hooked up. |
358 scoped_refptr<net::URLRequestContextGetter> extensions_request_context_; | 369 scoped_refptr<net::URLRequestContextGetter> extensions_request_context_; |
359 | 370 |
360 bool incognito_; | |
361 bool force_incognito_; | 371 bool force_incognito_; |
362 scoped_ptr<Profile> incognito_profile_; | 372 scoped_ptr<Profile> incognito_profile_; |
363 Profile* original_profile_; | 373 TestingProfile* original_profile_; |
364 | 374 |
365 bool guest_session_; | 375 bool guest_session_; |
366 | 376 |
367 std::string supervised_user_id_; | 377 std::string supervised_user_id_; |
368 | 378 |
369 // Did the last session exit cleanly? Default is true. | 379 // Did the last session exit cleanly? Default is true. |
370 bool last_session_exited_cleanly_; | 380 bool last_session_exited_cleanly_; |
371 | 381 |
372 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; | 382 scoped_refptr<HostContentSettingsMap> host_content_settings_map_; |
373 | 383 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
406 | 416 |
407 // Weak pointer to a delegate for indicating that a profile was created. | 417 // Weak pointer to a delegate for indicating that a profile was created. |
408 Delegate* delegate_; | 418 Delegate* delegate_; |
409 | 419 |
410 std::string profile_name_; | 420 std::string profile_name_; |
411 | 421 |
412 scoped_ptr<policy::PolicyService> policy_service_; | 422 scoped_ptr<policy::PolicyService> policy_service_; |
413 }; | 423 }; |
414 | 424 |
415 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ | 425 #endif // CHROME_TEST_BASE_TESTING_PROFILE_H_ |
OLD | NEW |