Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1398)

Unified Diff: chrome/test/base/testing_profile.h

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android fixes. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/base/testing_profile.h
diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h
index 8e63e5a71b59aeb7cf6ee6d6ba8e24ca5b488e6a..c5aedde568690ed78729e61e140bca04d121a04b 100644
--- a/chrome/test/base/testing_profile.h
+++ b/chrome/test/base/testing_profile.h
@@ -11,6 +11,7 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/profiles/profile.h"
+#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
namespace content {
class MockResourceContext;
@@ -59,6 +60,10 @@ class TestingProfile : public Profile {
// Default constructor that cannot be used with multi-profiles.
TestingProfile();
+ typedef std::vector<std::pair<
+ BrowserContextKeyedServiceFactory*,
+ BrowserContextKeyedServiceFactory::FactoryFunction> > TestingFactories;
+
// Helper class for building an instance of TestingProfile (allows injecting
// mocks for various services prior to profile initialization).
// TODO(atwilson): Remove non-default constructors and various setters in
@@ -68,13 +73,19 @@ class TestingProfile : public Profile {
Builder();
~Builder();
- // Sets a Delegate to be called back when the Profile is fully initialized.
- // This causes the final initialization to be performed via a task so the
- // caller must run a MessageLoop. Caller maintains ownership of the Delegate
+ // Sets a Delegate to be called back during profile init. This causes the
+ // final initialization to be performed via a task so the caller must run
+ // a MessageLoop. Caller maintains ownership of the Delegate
// and must manage its lifetime so it continues to exist until profile
// initialization is complete.
void SetDelegate(Delegate* delegate);
+ // Adds a testing factory to the TestingProfile. These testing factories
+ // are applied before the ProfileKeyedServices are created.
+ void AddTestingFactory(
+ BrowserContextKeyedServiceFactory* service_factory,
+ BrowserContextKeyedServiceFactory::FactoryFunction callback);
Elliot Glaysher 2013/08/16 18:07:59 I'm fine with you adding this part of the change,
Andrew T Wilson (Slow) 2013/08/19 12:15:56 So I don't actually like SetGlobalTestingFactory()
Elliot Glaysher 2013/08/19 18:04:30 Yeah, I'm fine with AddTestingFactory() as long as
+
// Sets the ExtensionSpecialStoragePolicy to be returned by
// GetExtensionSpecialStoragePolicy().
void SetExtensionSpecialStoragePolicy(
@@ -86,6 +97,9 @@ class TestingProfile : public Profile {
// Sets the PrefService to be used by this profile.
void SetPrefService(scoped_ptr<PrefServiceSyncable> prefs);
+ // Makes the Profile being built an incognito profile.
+ void SetIncognito();
+
// Creates the TestingProfile using previously-set settings.
scoped_ptr<TestingProfile> Build();
@@ -98,6 +112,8 @@ class TestingProfile : public Profile {
scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_;
base::FilePath path_;
Delegate* delegate_;
+ bool incognito_;
+ TestingFactories testing_factories_;
DISALLOW_COPY_AND_ASSIGN(Builder);
};
@@ -120,7 +136,9 @@ class TestingProfile : public Profile {
TestingProfile(const base::FilePath& path,
Delegate* delegate,
scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy,
- scoped_ptr<PrefServiceSyncable> prefs);
+ scoped_ptr<PrefServiceSyncable> prefs,
+ bool incognito,
+ const TestingFactories& factories);
virtual ~TestingProfile();
@@ -186,9 +204,20 @@ class TestingProfile : public Profile {
virtual TestingProfile* AsTestingProfile() OVERRIDE;
virtual std::string GetProfileName() OVERRIDE;
- void set_incognito(bool incognito) { incognito_ = incognito; }
+
+ // DEPRECATED.
+ // Changes a profile's to/from incognito mode temporarily - profile will be
+ // returned to non-incognito before destruction to allow services to
+ // properly shutdown. This is only supported for legacy tests - new tests
+ // should create a true incognito profile using Builder::SetIncognito() or
+ // by using the TestingProfile constructor that allows setting the incognito
+ // flag.
+ void ForceIncognito(bool force_incognito) {
+ force_incognito_ = force_incognito;
+ }
+
// Assumes ownership.
- virtual void SetOffTheRecordProfile(Profile* profile);
+ virtual void SetOffTheRecordProfile(scoped_ptr<Profile> profile);
virtual void SetOriginalProfile(Profile* profile);
virtual Profile* GetOffTheRecordProfile() OVERRIDE;
virtual void DestroyOffTheRecordProfile() OVERRIDE {}
@@ -306,6 +335,7 @@ class TestingProfile : public Profile {
std::wstring id_;
bool incognito_;
+ bool force_incognito_;
scoped_ptr<Profile> incognito_profile_;
Profile* original_profile_;

Powered by Google App Engine
This is Rietveld 408576698