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 #include "chrome/browser/profiles/profile.h" | 5 #include "chrome/browser/profiles/profile.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" |
8 #include "base/platform_file.h" | 9 #include "base/platform_file.h" |
9 #include "base/scoped_temp_dir.h" | |
10 #include "base/version.h" | 10 #include "base/version.h" |
11 #include "chrome/browser/prefs/pref_service.h" | 11 #include "chrome/browser/prefs/pref_service.h" |
12 #include "chrome/browser/profiles/chrome_version_service.h" | 12 #include "chrome/browser/profiles/chrome_version_service.h" |
13 #include "chrome/browser/profiles/profile_impl.h" | 13 #include "chrome/browser/profiles/profile_impl.h" |
14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
15 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/chrome_version_info.h" | 16 #include "chrome/common/chrome_version_info.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
19 #include "chrome/test/base/ui_test_utils.h" | 19 #include "chrome/test/base/ui_test_utils.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 } // namespace | 55 } // namespace |
56 | 56 |
57 typedef InProcessBrowserTest ProfileBrowserTest; | 57 typedef InProcessBrowserTest ProfileBrowserTest; |
58 | 58 |
59 // Test OnProfileCreate is called with is_new_profile set to true when | 59 // Test OnProfileCreate is called with is_new_profile set to true when |
60 // creating a new profile synchronously. | 60 // creating a new profile synchronously. |
61 // | 61 // |
62 // Flaky (sometimes timeout): http://crbug.com/141141 | 62 // Flaky (sometimes timeout): http://crbug.com/141141 |
63 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 63 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
64 DISABLED_CreateNewProfileSynchronous) { | 64 DISABLED_CreateNewProfileSynchronous) { |
65 ScopedTempDir temp_dir; | 65 base::ScopedTempDir temp_dir; |
66 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 66 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
67 | 67 |
68 MockProfileDelegate delegate; | 68 MockProfileDelegate delegate; |
69 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 69 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
70 | 70 |
71 scoped_ptr<Profile> profile(Profile::CreateProfile( | 71 scoped_ptr<Profile> profile(Profile::CreateProfile( |
72 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 72 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
73 ASSERT_TRUE(profile.get()); | 73 ASSERT_TRUE(profile.get()); |
74 CheckChromeVersion(profile.get(), true); | 74 CheckChromeVersion(profile.get(), true); |
75 } | 75 } |
76 | 76 |
77 // Test OnProfileCreate is called with is_new_profile set to false when | 77 // Test OnProfileCreate is called with is_new_profile set to false when |
78 // creating a profile synchronously with an existing prefs file. | 78 // creating a profile synchronously with an existing prefs file. |
79 // Flaky: http://crbug.com/141517 | 79 // Flaky: http://crbug.com/141517 |
80 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 80 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
81 DISABLED_CreateOldProfileSynchronous) { | 81 DISABLED_CreateOldProfileSynchronous) { |
82 ScopedTempDir temp_dir; | 82 base::ScopedTempDir temp_dir; |
83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
84 CreatePrefsFileInDirectory(temp_dir.path()); | 84 CreatePrefsFileInDirectory(temp_dir.path()); |
85 | 85 |
86 MockProfileDelegate delegate; | 86 MockProfileDelegate delegate; |
87 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 87 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
88 | 88 |
89 scoped_ptr<Profile> profile(Profile::CreateProfile( | 89 scoped_ptr<Profile> profile(Profile::CreateProfile( |
90 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 90 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
91 ASSERT_TRUE(profile.get()); | 91 ASSERT_TRUE(profile.get()); |
92 CheckChromeVersion(profile.get(), false); | 92 CheckChromeVersion(profile.get(), false); |
93 } | 93 } |
94 | 94 |
95 // Test OnProfileCreate is called with is_new_profile set to true when | 95 // Test OnProfileCreate is called with is_new_profile set to true when |
96 // creating a new profile asynchronously. | 96 // creating a new profile asynchronously. |
97 // This test is flaky on Linux, Win and Mac. See crbug.com/142787 | 97 // This test is flaky on Linux, Win and Mac. See crbug.com/142787 |
98 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 98 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
99 DISABLED_CreateNewProfileAsynchronous) { | 99 DISABLED_CreateNewProfileAsynchronous) { |
100 ScopedTempDir temp_dir; | 100 base::ScopedTempDir temp_dir; |
101 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 101 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
102 | 102 |
103 MockProfileDelegate delegate; | 103 MockProfileDelegate delegate; |
104 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 104 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
105 | 105 |
106 scoped_ptr<Profile> profile(Profile::CreateProfile( | 106 scoped_ptr<Profile> profile(Profile::CreateProfile( |
107 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 107 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
108 ASSERT_TRUE(profile.get()); | 108 ASSERT_TRUE(profile.get()); |
109 | 109 |
110 // Wait for the profile to be created. | 110 // Wait for the profile to be created. |
111 content::WindowedNotificationObserver observer( | 111 content::WindowedNotificationObserver observer( |
112 chrome::NOTIFICATION_PROFILE_CREATED, | 112 chrome::NOTIFICATION_PROFILE_CREATED, |
113 content::Source<Profile>(profile.get())); | 113 content::Source<Profile>(profile.get())); |
114 observer.Wait(); | 114 observer.Wait(); |
115 CheckChromeVersion(profile.get(), true); | 115 CheckChromeVersion(profile.get(), true); |
116 } | 116 } |
117 | 117 |
118 // Test OnProfileCreate is called with is_new_profile set to false when | 118 // Test OnProfileCreate is called with is_new_profile set to false when |
119 // creating a profile asynchronously with an existing prefs file. | 119 // creating a profile asynchronously with an existing prefs file. |
120 // Flaky: http://crbug.com/141517 | 120 // Flaky: http://crbug.com/141517 |
121 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, | 121 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, |
122 DISABLED_CreateOldProfileAsynchronous) { | 122 DISABLED_CreateOldProfileAsynchronous) { |
123 ScopedTempDir temp_dir; | 123 base::ScopedTempDir temp_dir; |
124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 124 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
125 CreatePrefsFileInDirectory(temp_dir.path()); | 125 CreatePrefsFileInDirectory(temp_dir.path()); |
126 | 126 |
127 MockProfileDelegate delegate; | 127 MockProfileDelegate delegate; |
128 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); | 128 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, false)); |
129 scoped_ptr<Profile> profile(Profile::CreateProfile( | 129 scoped_ptr<Profile> profile(Profile::CreateProfile( |
130 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 130 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
131 ASSERT_TRUE(profile.get()); | 131 ASSERT_TRUE(profile.get()); |
132 | 132 |
133 // Wait for the profile to be created. | 133 // Wait for the profile to be created. |
134 content::WindowedNotificationObserver observer( | 134 content::WindowedNotificationObserver observer( |
135 chrome::NOTIFICATION_PROFILE_CREATED, | 135 chrome::NOTIFICATION_PROFILE_CREATED, |
136 content::Source<Profile>(profile.get())); | 136 content::Source<Profile>(profile.get())); |
137 observer.Wait(); | 137 observer.Wait(); |
138 CheckChromeVersion(profile.get(), false); | 138 CheckChromeVersion(profile.get(), false); |
139 } | 139 } |
140 | 140 |
141 // Test that a README file is created for profiles that didn't have it. | 141 // Test that a README file is created for profiles that didn't have it. |
142 // Flaky: http://crbug.com/140882 | 142 // Flaky: http://crbug.com/140882 |
143 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) { | 143 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, DISABLED_ProfileReadmeCreated) { |
144 ScopedTempDir temp_dir; | 144 base::ScopedTempDir temp_dir; |
145 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 145 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
146 | 146 |
147 MockProfileDelegate delegate; | 147 MockProfileDelegate delegate; |
148 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 148 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
149 | 149 |
150 // No delay before README creation. | 150 // No delay before README creation. |
151 ProfileImpl::create_readme_delay_ms = 0; | 151 ProfileImpl::create_readme_delay_ms = 0; |
152 | 152 |
153 scoped_ptr<Profile> profile(Profile::CreateProfile( | 153 scoped_ptr<Profile> profile(Profile::CreateProfile( |
154 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); | 154 temp_dir.path(), &delegate, Profile::CREATE_MODE_ASYNCHRONOUS)); |
155 ASSERT_TRUE(profile.get()); | 155 ASSERT_TRUE(profile.get()); |
156 | 156 |
157 // Wait for the profile to be created. | 157 // Wait for the profile to be created. |
158 content::WindowedNotificationObserver observer( | 158 content::WindowedNotificationObserver observer( |
159 chrome::NOTIFICATION_PROFILE_CREATED, | 159 chrome::NOTIFICATION_PROFILE_CREATED, |
160 content::Source<Profile>(profile.get())); | 160 content::Source<Profile>(profile.get())); |
161 observer.Wait(); | 161 observer.Wait(); |
162 | 162 |
163 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 163 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
164 | 164 |
165 // Verify that README exists. | 165 // Verify that README exists. |
166 EXPECT_TRUE(file_util::PathExists( | 166 EXPECT_TRUE(file_util::PathExists( |
167 temp_dir.path().Append(chrome::kReadmeFilename))); | 167 temp_dir.path().Append(chrome::kReadmeFilename))); |
168 } | 168 } |
169 | 169 |
170 // Test that Profile can be deleted before README file is created. | 170 // Test that Profile can be deleted before README file is created. |
171 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) { | 171 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ProfileDeletedBeforeReadmeCreated) { |
172 ScopedTempDir temp_dir; | 172 base::ScopedTempDir temp_dir; |
173 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 173 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
174 | 174 |
175 MockProfileDelegate delegate; | 175 MockProfileDelegate delegate; |
176 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 176 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
177 | 177 |
178 // No delay before README creation. | 178 // No delay before README creation. |
179 ProfileImpl::create_readme_delay_ms = 0; | 179 ProfileImpl::create_readme_delay_ms = 0; |
180 | 180 |
181 scoped_ptr<Profile> profile(Profile::CreateProfile( | 181 scoped_ptr<Profile> profile(Profile::CreateProfile( |
182 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 182 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
183 ASSERT_TRUE(profile.get()); | 183 ASSERT_TRUE(profile.get()); |
184 | 184 |
185 // Delete the Profile instance and run pending tasks (this includes the task | 185 // Delete the Profile instance and run pending tasks (this includes the task |
186 // for README creation). | 186 // for README creation). |
187 profile.reset(); | 187 profile.reset(); |
188 content::RunAllPendingInMessageLoop(); | 188 content::RunAllPendingInMessageLoop(); |
189 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); | 189 content::RunAllPendingInMessageLoop(content::BrowserThread::FILE); |
190 } | 190 } |
191 | 191 |
192 // Test that repeated setting of exit type is handled correctly. | 192 // Test that repeated setting of exit type is handled correctly. |
193 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) { | 193 IN_PROC_BROWSER_TEST_F(ProfileBrowserTest, ExitType) { |
194 ScopedTempDir temp_dir; | 194 base::ScopedTempDir temp_dir; |
195 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 195 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
196 | 196 |
197 MockProfileDelegate delegate; | 197 MockProfileDelegate delegate; |
198 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); | 198 EXPECT_CALL(delegate, OnProfileCreated(testing::NotNull(), true, true)); |
199 | 199 |
200 scoped_ptr<Profile> profile(Profile::CreateProfile( | 200 scoped_ptr<Profile> profile(Profile::CreateProfile( |
201 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); | 201 temp_dir.path(), &delegate, Profile::CREATE_MODE_SYNCHRONOUS)); |
202 ASSERT_TRUE(profile.get()); | 202 ASSERT_TRUE(profile.get()); |
203 | 203 |
204 PrefService* prefs = profile->GetPrefs(); | 204 PrefService* prefs = profile->GetPrefs(); |
205 // The initial state is crashed; store for later reference. | 205 // The initial state is crashed; store for later reference. |
206 std::string crash_value(prefs->GetString(prefs::kSessionExitType)); | 206 std::string crash_value(prefs->GetString(prefs::kSessionExitType)); |
207 | 207 |
208 // The first call to a type other than crashed should change the value. | 208 // The first call to a type other than crashed should change the value. |
209 profile->SetExitType(Profile::EXIT_SESSION_ENDED); | 209 profile->SetExitType(Profile::EXIT_SESSION_ENDED); |
210 std::string first_call_value(prefs->GetString(prefs::kSessionExitType)); | 210 std::string first_call_value(prefs->GetString(prefs::kSessionExitType)); |
211 EXPECT_NE(crash_value, first_call_value); | 211 EXPECT_NE(crash_value, first_call_value); |
212 | 212 |
213 // Subsequent calls to a non-crash value should be ignored. | 213 // Subsequent calls to a non-crash value should be ignored. |
214 profile->SetExitType(Profile::EXIT_NORMAL); | 214 profile->SetExitType(Profile::EXIT_NORMAL); |
215 std::string second_call_value(prefs->GetString(prefs::kSessionExitType)); | 215 std::string second_call_value(prefs->GetString(prefs::kSessionExitType)); |
216 EXPECT_EQ(first_call_value, second_call_value); | 216 EXPECT_EQ(first_call_value, second_call_value); |
217 | 217 |
218 // Setting back to a crashed value should work. | 218 // Setting back to a crashed value should work. |
219 profile->SetExitType(Profile::EXIT_CRASHED); | 219 profile->SetExitType(Profile::EXIT_CRASHED); |
220 std::string final_value(prefs->GetString(prefs::kSessionExitType)); | 220 std::string final_value(prefs->GetString(prefs::kSessionExitType)); |
221 EXPECT_EQ(crash_value, final_value); | 221 EXPECT_EQ(crash_value, final_value); |
222 } | 222 } |
OLD | NEW |