| 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 <memory> |    8 #include <memory> | 
|    9 #include <string> |    9 #include <string> | 
|   10 #include <utility> |   10 #include <utility> | 
| (...skipping 25 matching lines...) Expand all  Loading... | 
|   36 namespace policy { |   36 namespace policy { | 
|   37 class PolicyService; |   37 class PolicyService; | 
|   38 class ProfilePolicyConnector; |   38 class ProfilePolicyConnector; | 
|   39 class SchemaRegistryService; |   39 class SchemaRegistryService; | 
|   40 } |   40 } | 
|   41  |   41  | 
|   42 namespace storage { |   42 namespace storage { | 
|   43 class SpecialStoragePolicy; |   43 class SpecialStoragePolicy; | 
|   44 } |   44 } | 
|   45  |   45  | 
|   46 namespace syncable_prefs { |   46 namespace sync_preferences { | 
|   47 class PrefServiceSyncable; |   47 class PrefServiceSyncable; | 
|   48 class TestingPrefServiceSyncable; |   48 class TestingPrefServiceSyncable; | 
|   49 } |   49 } | 
|   50  |   50  | 
|   51 class TestingProfile : public Profile { |   51 class TestingProfile : public Profile { | 
|   52  public: |   52  public: | 
|   53   // Profile directory name for the test user. This is "Default" on most |   53   // Profile directory name for the test user. This is "Default" on most | 
|   54   // platforms but must be different on ChromeOS because a logged-in user cannot |   54   // platforms but must be different on ChromeOS because a logged-in user cannot | 
|   55   // use "Default" as profile directory. |   55   // use "Default" as profile directory. | 
|   56   // Browser- and UI tests should always use this to get to the user's profile |   56   // Browser- and UI tests should always use this to get to the user's profile | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   93     // GetExtensionSpecialStoragePolicy(). |   93     // GetExtensionSpecialStoragePolicy(). | 
|   94     void SetExtensionSpecialStoragePolicy( |   94     void SetExtensionSpecialStoragePolicy( | 
|   95         scoped_refptr<ExtensionSpecialStoragePolicy> policy); |   95         scoped_refptr<ExtensionSpecialStoragePolicy> policy); | 
|   96 #endif |   96 #endif | 
|   97  |   97  | 
|   98     // Sets the path to the directory to be used to hold profile data. |   98     // Sets the path to the directory to be used to hold profile data. | 
|   99     void SetPath(const base::FilePath& path); |   99     void SetPath(const base::FilePath& path); | 
|  100  |  100  | 
|  101     // Sets the PrefService to be used by this profile. |  101     // Sets the PrefService to be used by this profile. | 
|  102     void SetPrefService( |  102     void SetPrefService( | 
|  103         std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs); |  103         std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs); | 
|  104  |  104  | 
|  105     // Makes the Profile being built a guest profile. |  105     // Makes the Profile being built a guest profile. | 
|  106     void SetGuestSession(); |  106     void SetGuestSession(); | 
|  107  |  107  | 
|  108     // Sets the supervised user ID (which is empty by default). If it is set to |  108     // Sets the supervised user ID (which is empty by default). If it is set to | 
|  109     // a non-empty string, the profile is supervised. |  109     // a non-empty string, the profile is supervised. | 
|  110     void SetSupervisedUserId(const std::string& supervised_user_id); |  110     void SetSupervisedUserId(const std::string& supervised_user_id); | 
|  111  |  111  | 
|  112     // Sets the PolicyService to be used by this profile. |  112     // Sets the PolicyService to be used by this profile. | 
|  113     void SetPolicyService( |  113     void SetPolicyService( | 
|  114         std::unique_ptr<policy::PolicyService> policy_service); |  114         std::unique_ptr<policy::PolicyService> policy_service); | 
|  115  |  115  | 
|  116     // Sets the UserProfileName to be used by this profile. |  116     // Sets the UserProfileName to be used by this profile. | 
|  117     void SetProfileName(const std::string& profile_name); |  117     void SetProfileName(const std::string& profile_name); | 
|  118  |  118  | 
|  119     // Creates the TestingProfile using previously-set settings. |  119     // Creates the TestingProfile using previously-set settings. | 
|  120     std::unique_ptr<TestingProfile> Build(); |  120     std::unique_ptr<TestingProfile> Build(); | 
|  121  |  121  | 
|  122     // Build an incognito profile, owned by |original_profile|. Note: unless you |  122     // Build an incognito profile, owned by |original_profile|. Note: unless you | 
|  123     // need to customize the Builder, or access TestingProfile member functions, |  123     // need to customize the Builder, or access TestingProfile member functions, | 
|  124     // you can use original_profile->GetOffTheRecordProfile(). |  124     // you can use original_profile->GetOffTheRecordProfile(). | 
|  125     TestingProfile* BuildIncognito(TestingProfile* original_profile); |  125     TestingProfile* BuildIncognito(TestingProfile* original_profile); | 
|  126  |  126  | 
|  127    private: |  127    private: | 
|  128     // If true, Build() has already been called. |  128     // If true, Build() has already been called. | 
|  129     bool build_called_; |  129     bool build_called_; | 
|  130  |  130  | 
|  131     // Various staging variables where values are held until Build() is invoked. |  131     // Various staging variables where values are held until Build() is invoked. | 
|  132     std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service_; |  132     std::unique_ptr<sync_preferences::PrefServiceSyncable> pref_service_; | 
|  133 #if defined(ENABLE_EXTENSIONS) |  133 #if defined(ENABLE_EXTENSIONS) | 
|  134     scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; |  134     scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy_; | 
|  135 #endif |  135 #endif | 
|  136     base::FilePath path_; |  136     base::FilePath path_; | 
|  137     Delegate* delegate_; |  137     Delegate* delegate_; | 
|  138     bool guest_session_; |  138     bool guest_session_; | 
|  139     std::string supervised_user_id_; |  139     std::string supervised_user_id_; | 
|  140     std::unique_ptr<policy::PolicyService> policy_service_; |  140     std::unique_ptr<policy::PolicyService> policy_service_; | 
|  141     TestingFactories testing_factories_; |  141     TestingFactories testing_factories_; | 
|  142     std::string profile_name_; |  142     std::string profile_name_; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  157   // for unittesting the ProfileManager. |  157   // for unittesting the ProfileManager. | 
|  158   TestingProfile(const base::FilePath& path, Delegate* delegate); |  158   TestingProfile(const base::FilePath& path, Delegate* delegate); | 
|  159  |  159  | 
|  160   // Full constructor allowing the setting of all possible instance data. |  160   // Full constructor allowing the setting of all possible instance data. | 
|  161   // Callers should use Builder::Build() instead of invoking this constructor. |  161   // Callers should use Builder::Build() instead of invoking this constructor. | 
|  162   TestingProfile(const base::FilePath& path, |  162   TestingProfile(const base::FilePath& path, | 
|  163                  Delegate* delegate, |  163                  Delegate* delegate, | 
|  164 #if defined(ENABLE_EXTENSIONS) |  164 #if defined(ENABLE_EXTENSIONS) | 
|  165                  scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, |  165                  scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, | 
|  166 #endif |  166 #endif | 
|  167                  std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs, |  167                  std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs, | 
|  168                  TestingProfile* parent, |  168                  TestingProfile* parent, | 
|  169                  bool guest_session, |  169                  bool guest_session, | 
|  170                  const std::string& supervised_user_id, |  170                  const std::string& supervised_user_id, | 
|  171                  std::unique_ptr<policy::PolicyService> policy_service, |  171                  std::unique_ptr<policy::PolicyService> policy_service, | 
|  172                  const TestingFactories& factories, |  172                  const TestingFactories& factories, | 
|  173                  const std::string& profile_name); |  173                  const std::string& profile_name); | 
|  174  |  174  | 
|  175   ~TestingProfile() override; |  175   ~TestingProfile() override; | 
|  176  |  176  | 
|  177   // Creates the favicon service. Consequent calls would recreate the service. |  177   // Creates the favicon service. Consequent calls would recreate the service. | 
| (...skipping 23 matching lines...) Expand all  Loading... | 
|  201   // Creates a WebDataService. If not invoked, the web data service is NULL. |  201   // Creates a WebDataService. If not invoked, the web data service is NULL. | 
|  202   void CreateWebDataService(); |  202   void CreateWebDataService(); | 
|  203  |  203  | 
|  204   // Blocks until the HistoryService finishes restoring its in-memory cache. |  204   // Blocks until the HistoryService finishes restoring its in-memory cache. | 
|  205   // This is NOT invoked from CreateHistoryService. |  205   // This is NOT invoked from CreateHistoryService. | 
|  206   void BlockUntilHistoryIndexIsRefreshed(); |  206   void BlockUntilHistoryIndexIsRefreshed(); | 
|  207  |  207  | 
|  208   // 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. | 
|  209   void SetGuestSession(bool guest); |  209   void SetGuestSession(bool guest); | 
|  210  |  210  | 
|  211   syncable_prefs::TestingPrefServiceSyncable* GetTestingPrefService(); |  211   sync_preferences::TestingPrefServiceSyncable* GetTestingPrefService(); | 
|  212  |  212  | 
|  213   // Called on the parent of an incognito |profile|. Usually called from the |  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 |  214   // constructor of an incognito TestingProfile, but can also be used by tests | 
|  215   // to provide an OffTheRecordProfileImpl instance. |  215   // to provide an OffTheRecordProfileImpl instance. | 
|  216   void SetOffTheRecordProfile(std::unique_ptr<Profile> profile); |  216   void SetOffTheRecordProfile(std::unique_ptr<Profile> profile); | 
|  217  |  217  | 
|  218   void SetSupervisedUserId(const std::string& id); |  218   void SetSupervisedUserId(const std::string& id); | 
|  219  |  219  | 
|  220   // content::BrowserContext |  220   // content::BrowserContext | 
|  221   base::FilePath GetPath() const override; |  221   base::FilePath GetPath() const override; | 
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  330  private: |  330  private: | 
|  331   // We use a temporary directory to store testing profile data. This |  331   // We use a temporary directory to store testing profile data. This | 
|  332   // must be declared before anything that may make use of the |  332   // must be declared before anything that may make use of the | 
|  333   // directory so as to ensure files are closed before cleanup.  In a |  333   // directory so as to ensure files are closed before cleanup.  In a | 
|  334   // multi-profile environment, this is invalid and the directory is |  334   // multi-profile environment, this is invalid and the directory is | 
|  335   // managed by the TestingProfileManager. |  335   // managed by the TestingProfileManager. | 
|  336   base::ScopedTempDir temp_dir_; |  336   base::ScopedTempDir temp_dir_; | 
|  337  |  337  | 
|  338  protected: |  338  protected: | 
|  339   base::Time start_time_; |  339   base::Time start_time_; | 
|  340   std::unique_ptr<syncable_prefs::PrefServiceSyncable> prefs_; |  340   std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs_; | 
|  341   // ref only for right type, lifecycle is managed by prefs_ |  341   // ref only for right type, lifecycle is managed by prefs_ | 
|  342   syncable_prefs::TestingPrefServiceSyncable* testing_prefs_; |  342   sync_preferences::TestingPrefServiceSyncable* testing_prefs_; | 
|  343  |  343  | 
|  344  private: |  344  private: | 
|  345   // Creates a temporary directory for use by this profile. |  345   // Creates a temporary directory for use by this profile. | 
|  346   void CreateTempProfileDir(); |  346   void CreateTempProfileDir(); | 
|  347  |  347  | 
|  348   // Common initialization between the two constructors. |  348   // Common initialization between the two constructors. | 
|  349   void Init(); |  349   void Init(); | 
|  350  |  350  | 
|  351   // Finishes initialization when a profile is created asynchronously. |  351   // Finishes initialization when a profile is created asynchronously. | 
|  352   void FinishInit(); |  352   void FinishInit(); | 
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  413  |  413  | 
|  414   // 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. | 
|  415   Delegate* delegate_; |  415   Delegate* delegate_; | 
|  416  |  416  | 
|  417   std::string profile_name_; |  417   std::string profile_name_; | 
|  418  |  418  | 
|  419   std::unique_ptr<policy::PolicyService> policy_service_; |  419   std::unique_ptr<policy::PolicyService> policy_service_; | 
|  420 }; |  420 }; | 
|  421  |  421  | 
|  422 #endif  // CHROME_TEST_BASE_TESTING_PROFILE_H_ |  422 #endif  // CHROME_TEST_BASE_TESTING_PROFILE_H_ | 
| OLD | NEW |