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_MANAGER_H_ | 5 #ifndef CHROME_TEST_BASE_TESTING_PROFILE_MANAGER_H_ |
6 #define CHROME_TEST_BASE_TESTING_PROFILE_MANAGER_H_ | 6 #define CHROME_TEST_BASE_TESTING_PROFILE_MANAGER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/scoped_temp_dir.h" | 12 #include "base/files/scoped_temp_dir.h" |
13 #include "base/memory/scoped_ptr.h" | |
14 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
15 #include "chrome/test/base/scoped_testing_local_state.h" | 14 #include "chrome/test/base/scoped_testing_local_state.h" |
16 | 15 |
17 class PrefServiceSyncable; | |
18 class ProfileInfoCache; | 16 class ProfileInfoCache; |
19 class ProfileManager; | 17 class ProfileManager; |
20 class TestingBrowserProcess; | 18 class TestingBrowserProcess; |
21 class TestingProfile; | 19 class TestingProfile; |
22 | 20 |
23 // The TestingProfileManager is a TestingProfile factory for a multi-profile | 21 // The TestingProfileManager is a TestingProfile factory for a multi-profile |
24 // environment. It will bring up a full ProfileManager and attach it to the | 22 // environment. It will bring up a full ProfileManager and attach it to the |
25 // TestingBrowserProcess set up in your test. | 23 // TestingBrowserProcess set up in your test. |
26 // | 24 // |
27 // When a Profile is needed for testing, create it through the factory method | 25 // When a Profile is needed for testing, create it through the factory method |
28 // below instead of creating it via |new TestingProfile|. It is not possible | 26 // below instead of creating it via |new TestingProfile|. It is not possible |
29 // to register profiles created in that fashion with the ProfileManager. | 27 // to register profiles created in that fashion with the ProfileManager. |
30 class TestingProfileManager { | 28 class TestingProfileManager { |
31 public: | 29 public: |
32 explicit TestingProfileManager(TestingBrowserProcess* browser_process); | 30 explicit TestingProfileManager(TestingBrowserProcess* browser_process); |
33 ~TestingProfileManager(); | 31 ~TestingProfileManager(); |
34 | 32 |
35 // This needs to be called in testing::Test::SetUp() to put the object in a | 33 // This needs to be called in testing::Test::SetUp() to put the object in a |
36 // valid state. Some work cannot be done in a constructor because it may | 34 // valid state. Some work cannot be done in a constructor because it may |
37 // call gtest asserts to verify setup. The result of this call can be used | 35 // call gtest asserts to verify setup. The result of this call can be used |
38 // to ASSERT before doing more SetUp work in the test. | 36 // to ASSERT before doing more SetUp work in the test. |
39 bool SetUp() WARN_UNUSED_RESULT; | 37 bool SetUp() WARN_UNUSED_RESULT; |
40 | 38 |
41 // Creates a new TestingProfile whose data lives in a directory related to | 39 // Creates a new TestingProfile whose data lives in a directory related to |
42 // profile_name, which is a non-user-visible key for the test environment. | 40 // profile_name, which is a non-user-visible key for the test environment. |
43 // |prefs| is the PrefService used by the profile. If it is NULL, the profile | |
44 // creates a PrefService on demand. | |
45 // |user_name| and |avatar_id| are passed along to the ProfileInfoCache and | 41 // |user_name| and |avatar_id| are passed along to the ProfileInfoCache and |
46 // provide the user-visible profile metadata. This will register the | 42 // provide the user-visible profile metadata. This will register the |
47 // TestingProfile with the profile subsystem as well. The subsystem owns the | 43 // TestingProfile with the profile subsystem as well. The subsystem owns the |
48 // Profile and returns a weak pointer. | 44 // Profile and returns a weak pointer. |
49 TestingProfile* CreateTestingProfile(const std::string& profile_name, | 45 TestingProfile* CreateTestingProfile(const std::string& profile_name, |
50 scoped_ptr<PrefServiceSyncable> prefs, | |
51 const string16& user_name, | 46 const string16& user_name, |
52 int avatar_id); | 47 int avatar_id); |
53 | 48 |
54 // Small helper for creating testing profiles. Just forwards to above. | 49 // Small helper for creating testing profiles. Just forwards to above. |
55 TestingProfile* CreateTestingProfile(const std::string& name); | 50 TestingProfile* CreateTestingProfile(const std::string& name); |
56 | 51 |
57 // Deletes a TestingProfile from the profile subsystem. | 52 // Deletes a TestingProfile from the profile subsystem. |
58 void DeleteTestingProfile(const std::string& profile_name); | 53 void DeleteTestingProfile(const std::string& profile_name); |
59 | 54 |
60 // Deletes the cache instance. This is useful for testing that the cache is | 55 // Deletes the cache instance. This is useful for testing that the cache is |
(...skipping 30 matching lines...) Expand all Loading... |
91 // Weak reference to the profile manager. | 86 // Weak reference to the profile manager. |
92 ProfileManager* profile_manager_; | 87 ProfileManager* profile_manager_; |
93 | 88 |
94 // Map of profile_name to TestingProfile* from CreateTestingProfile(). | 89 // Map of profile_name to TestingProfile* from CreateTestingProfile(). |
95 TestingProfilesMap testing_profiles_; | 90 TestingProfilesMap testing_profiles_; |
96 | 91 |
97 DISALLOW_COPY_AND_ASSIGN(TestingProfileManager); | 92 DISALLOW_COPY_AND_ASSIGN(TestingProfileManager); |
98 }; | 93 }; |
99 | 94 |
100 #endif // CHROME_TEST_BASE_TESTING_PROFILE_MANAGER_H_ | 95 #endif // CHROME_TEST_BASE_TESTING_PROFILE_MANAGER_H_ |
OLD | NEW |