OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/memory/ref_counted.h" | |
9 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
11 #include "base/scoped_temp_dir.h" | 12 #include "base/scoped_temp_dir.h" |
12 #include "base/system_monitor/system_monitor.h" | 13 #include "base/system_monitor/system_monitor.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "base/values.h" | 15 #include "base/values.h" |
15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
16 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/extensions/extension_event_router_forwarder.h" | 18 #include "chrome/browser/extensions/extension_event_router_forwarder.h" |
18 #include "chrome/browser/io_thread.h" | 19 #include "chrome/browser/io_thread.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
108 CommandLine *cl = CommandLine::ForCurrentProcess(); | 109 CommandLine *cl = CommandLine::ForCurrentProcess(); |
109 cl->AppendSwitch(switches::kTestType); | 110 cl->AppendSwitch(switches::kTestType); |
110 #endif | 111 #endif |
111 } | 112 } |
112 | 113 |
113 virtual void TearDown() { | 114 virtual void TearDown() { |
114 profile_manager_.reset(); | 115 profile_manager_.reset(); |
115 message_loop_.RunAllPending(); | 116 message_loop_.RunAllPending(); |
116 } | 117 } |
117 | 118 |
118 class MockObserver : public ProfileManagerObserver { | 119 class MockObserver : public base::RefCountedThreadSafe<MockObserver> { |
Robert Sesek
2011/12/07 16:36:13
Why does this need to be refcounted?
sail
2011/12/07 17:18:13
So I can use it in base::Bind().
Robert Sesek
2011/12/07 18:07:40
Can't you just use Unretained() because the MockOb
sail
2011/12/07 18:34:04
Done.
| |
119 public: | 120 public: |
120 MOCK_METHOD2(OnProfileCreated, void(Profile* profile, Status status)); | 121 MOCK_METHOD2(OnProfileCreated, void(Profile* profile, |
Robert Sesek
2011/12/07 16:36:13
I'd break after the first ,
sail
2011/12/07 17:18:13
Done.
| |
122 Profile::CreateStatus status)); | |
121 }; | 123 }; |
122 | 124 |
123 #if defined(OS_CHROMEOS) | 125 #if defined(OS_CHROMEOS) |
124 // Do not change order of stub_cros_enabler_, which needs to be constructed | 126 // Do not change order of stub_cros_enabler_, which needs to be constructed |
125 // before io_thread_ which requires CrosLibrary to be initialized to construct | 127 // before io_thread_ which requires CrosLibrary to be initialized to construct |
126 // its data member pref_proxy_config_tracker_ on ChromeOS. | 128 // its data member pref_proxy_config_tracker_ on ChromeOS. |
127 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; | 129 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; |
128 #endif | 130 #endif |
129 | 131 |
130 // The path to temporary directory used to contain the test operations. | 132 // The path to temporary directory used to contain the test operations. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 // Make sure any pending tasks run before we destroy the profiles. | 223 // Make sure any pending tasks run before we destroy the profiles. |
222 message_loop_.RunAllPending(); | 224 message_loop_.RunAllPending(); |
223 | 225 |
224 profile_manager_.reset(); | 226 profile_manager_.reset(); |
225 | 227 |
226 // Make sure history cleans up correctly. | 228 // Make sure history cleans up correctly. |
227 message_loop_.RunAllPending(); | 229 message_loop_.RunAllPending(); |
228 } | 230 } |
229 | 231 |
230 MATCHER(NotFail, "Profile creation failure status is not reported.") { | 232 MATCHER(NotFail, "Profile creation failure status is not reported.") { |
231 return arg == ProfileManagerObserver::STATUS_CREATED || | 233 return arg == Profile::CREATE_STATUS_CREATED || |
232 arg == ProfileManagerObserver::STATUS_INITIALIZED; | 234 arg == Profile::CREATE_STATUS_INITIALIZED; |
233 } | 235 } |
234 | 236 |
235 // Tests asynchronous profile creation mechanism. | 237 // Tests asynchronous profile creation mechanism. |
236 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { | 238 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { |
237 FilePath dest_path = | 239 FilePath dest_path = |
238 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 240 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
239 | 241 |
240 MockObserver mock_observer; | 242 scoped_refptr<MockObserver> mock_observer = new MockObserver; |
241 EXPECT_CALL(mock_observer, OnProfileCreated( | 243 EXPECT_CALL(*mock_observer, OnProfileCreated( |
242 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 244 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
243 | 245 |
244 profile_manager_->CreateProfileAsync(dest_path, &mock_observer); | 246 profile_manager_->CreateProfileAsync(dest_path, |
247 base::Bind(&MockObserver::OnProfileCreated, mock_observer.get())); | |
245 | 248 |
246 message_loop_.RunAllPending(); | 249 message_loop_.RunAllPending(); |
247 } | 250 } |
248 | 251 |
249 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { | 252 MATCHER(SameNotNull, "The same non-NULL value for all calls.") { |
250 if (!g_created_profile) | 253 if (!g_created_profile) |
251 g_created_profile = arg; | 254 g_created_profile = arg; |
252 return arg != NULL && arg == g_created_profile; | 255 return arg != NULL && arg == g_created_profile; |
253 } | 256 } |
254 | 257 |
255 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { | 258 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
256 FilePath dest_path = | 259 FilePath dest_path = |
257 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); | 260 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); |
258 | 261 |
259 g_created_profile = NULL; | 262 g_created_profile = NULL; |
260 | 263 |
261 MockObserver mock_observer1; | 264 scoped_refptr<MockObserver> mock_observer1 = new MockObserver; |
262 EXPECT_CALL(mock_observer1, OnProfileCreated( | 265 EXPECT_CALL(*mock_observer1, OnProfileCreated( |
263 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 266 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
264 MockObserver mock_observer2; | 267 scoped_refptr<MockObserver> mock_observer2 = new MockObserver; |
265 EXPECT_CALL(mock_observer2, OnProfileCreated( | 268 EXPECT_CALL(*mock_observer2, OnProfileCreated( |
266 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 269 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
267 MockObserver mock_observer3; | 270 scoped_refptr<MockObserver> mock_observer3 = new MockObserver; |
268 EXPECT_CALL(mock_observer3, OnProfileCreated( | 271 EXPECT_CALL(*mock_observer3, OnProfileCreated( |
269 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); | 272 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); |
270 | 273 |
271 profile_manager_->CreateProfileAsync(dest_path, &mock_observer1); | 274 profile_manager_->CreateProfileAsync(dest_path, |
272 profile_manager_->CreateProfileAsync(dest_path, &mock_observer2); | 275 base::Bind(&MockObserver::OnProfileCreated, mock_observer1.get())); |
273 profile_manager_->CreateProfileAsync(dest_path, &mock_observer3); | 276 profile_manager_->CreateProfileAsync(dest_path, |
277 base::Bind(&MockObserver::OnProfileCreated, mock_observer2.get())); | |
278 profile_manager_->CreateProfileAsync(dest_path, | |
279 base::Bind(&MockObserver::OnProfileCreated, mock_observer3.get())); | |
274 | 280 |
275 message_loop_.RunAllPending(); | 281 message_loop_.RunAllPending(); |
276 } | 282 } |
277 | 283 |
278 TEST_F(ProfileManagerTest, CreateProfilesAsync) { | 284 TEST_F(ProfileManagerTest, CreateProfilesAsync) { |
279 FilePath dest_path1 = | 285 FilePath dest_path1 = |
280 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); | 286 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); |
281 FilePath dest_path2 = | 287 FilePath dest_path2 = |
282 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); | 288 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); |
283 | 289 |
284 MockObserver mock_observer; | 290 scoped_refptr<MockObserver> mock_observer = new MockObserver; |
285 EXPECT_CALL(mock_observer, OnProfileCreated( | 291 EXPECT_CALL(*mock_observer, OnProfileCreated( |
286 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 292 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
287 | 293 |
288 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); | 294 profile_manager_->CreateProfileAsync(dest_path1, |
289 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); | 295 base::Bind(&MockObserver::OnProfileCreated, mock_observer.get())); |
296 profile_manager_->CreateProfileAsync(dest_path2, | |
297 base::Bind(&MockObserver::OnProfileCreated, mock_observer.get())); | |
290 | 298 |
291 message_loop_.RunAllPending(); | 299 message_loop_.RunAllPending(); |
292 } | 300 } |
293 | 301 |
294 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 302 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
295 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); | 303 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); |
296 | 304 |
297 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 305 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
298 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 306 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), |
299 ASCIIToUTF16("name_1"), string16(), 0); | 307 ASCIIToUTF16("name_1"), string16(), 0); |
300 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 308 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), |
301 ASCIIToUTF16("name_2"), string16(), 0); | 309 ASCIIToUTF16("name_2"), string16(), 0); |
302 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), | 310 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), |
303 ASCIIToUTF16("name_3"), string16(), 0); | 311 ASCIIToUTF16("name_3"), string16(), 0); |
304 cache.SetBackgroundStatusOfProfileAtIndex(0, true); | 312 cache.SetBackgroundStatusOfProfileAtIndex(0, true); |
305 cache.SetBackgroundStatusOfProfileAtIndex(2, true); | 313 cache.SetBackgroundStatusOfProfileAtIndex(2, true); |
306 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 314 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); |
307 | 315 |
308 profile_manager_->AutoloadProfiles(); | 316 profile_manager_->AutoloadProfiles(); |
309 | 317 |
310 EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size()); | 318 EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size()); |
311 } | 319 } |
OLD | NEW |