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

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 8840003: Replace ProfileManagerObserver with callback (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix typo Created 9 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_manager_browsertest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 CommandLine *cl = CommandLine::ForCurrentProcess(); 108 CommandLine *cl = CommandLine::ForCurrentProcess();
109 cl->AppendSwitch(switches::kTestType); 109 cl->AppendSwitch(switches::kTestType);
110 #endif 110 #endif
111 } 111 }
112 112
113 virtual void TearDown() { 113 virtual void TearDown() {
114 profile_manager_.reset(); 114 profile_manager_.reset();
115 message_loop_.RunAllPending(); 115 message_loop_.RunAllPending();
116 } 116 }
117 117
118 class MockObserver : public ProfileManagerObserver { 118 class MockObserver {
119 public: 119 public:
120 MOCK_METHOD2(OnProfileCreated, void(Profile* profile, Status status)); 120 MOCK_METHOD2(OnProfileCreated,
121 void(Profile* profile, Profile::CreateStatus status));
121 }; 122 };
122 123
123 #if defined(OS_CHROMEOS) 124 #if defined(OS_CHROMEOS)
124 // Do not change order of stub_cros_enabler_, which needs to be constructed 125 // 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 126 // before io_thread_ which requires CrosLibrary to be initialized to construct
126 // its data member pref_proxy_config_tracker_ on ChromeOS. 127 // its data member pref_proxy_config_tracker_ on ChromeOS.
127 chromeos::ScopedStubCrosEnabler stub_cros_enabler_; 128 chromeos::ScopedStubCrosEnabler stub_cros_enabler_;
128 #endif 129 #endif
129 130
130 // The path to temporary directory used to contain the test operations. 131 // The path to temporary directory used to contain the test operations.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Make sure any pending tasks run before we destroy the profiles. 222 // Make sure any pending tasks run before we destroy the profiles.
222 message_loop_.RunAllPending(); 223 message_loop_.RunAllPending();
223 224
224 profile_manager_.reset(); 225 profile_manager_.reset();
225 226
226 // Make sure history cleans up correctly. 227 // Make sure history cleans up correctly.
227 message_loop_.RunAllPending(); 228 message_loop_.RunAllPending();
228 } 229 }
229 230
230 MATCHER(NotFail, "Profile creation failure status is not reported.") { 231 MATCHER(NotFail, "Profile creation failure status is not reported.") {
231 return arg == ProfileManagerObserver::STATUS_CREATED || 232 return arg == Profile::CREATE_STATUS_CREATED ||
232 arg == ProfileManagerObserver::STATUS_INITIALIZED; 233 arg == Profile::CREATE_STATUS_INITIALIZED;
233 } 234 }
234 235
235 // Tests asynchronous profile creation mechanism. 236 // Tests asynchronous profile creation mechanism.
236 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) { 237 TEST_F(ProfileManagerTest, DISABLED_CreateProfileAsync) {
237 FilePath dest_path = 238 FilePath dest_path =
238 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile")); 239 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile"));
239 240
240 MockObserver mock_observer; 241 MockObserver mock_observer;
241 EXPECT_CALL(mock_observer, OnProfileCreated( 242 EXPECT_CALL(mock_observer, OnProfileCreated(
242 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); 243 testing::NotNull(), NotFail())).Times(testing::AtLeast(1));
243 244
244 profile_manager_->CreateProfileAsync(dest_path, &mock_observer); 245 profile_manager_->CreateProfileAsync(dest_path,
246 base::Bind(&MockObserver::OnProfileCreated,
247 base::Unretained(&mock_observer)));
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 MockObserver mock_observer1;
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 MockObserver mock_observer2;
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 MockObserver mock_observer3;
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,
273 profile_manager_->CreateProfileAsync(dest_path, &mock_observer3); 276 base::Unretained(&mock_observer1)));
277 profile_manager_->CreateProfileAsync(dest_path,
278 base::Bind(&MockObserver::OnProfileCreated,
279 base::Unretained(&mock_observer2)));
280 profile_manager_->CreateProfileAsync(dest_path,
281 base::Bind(&MockObserver::OnProfileCreated,
282 base::Unretained(&mock_observer3)));
274 283
275 message_loop_.RunAllPending(); 284 message_loop_.RunAllPending();
276 } 285 }
277 286
278 TEST_F(ProfileManagerTest, CreateProfilesAsync) { 287 TEST_F(ProfileManagerTest, CreateProfilesAsync) {
279 FilePath dest_path1 = 288 FilePath dest_path1 =
280 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1")); 289 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 1"));
281 FilePath dest_path2 = 290 FilePath dest_path2 =
282 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2")); 291 temp_dir_.path().Append(FILE_PATH_LITERAL("New Profile 2"));
283 292
284 MockObserver mock_observer; 293 MockObserver mock_observer;
285 EXPECT_CALL(mock_observer, OnProfileCreated( 294 EXPECT_CALL(mock_observer, OnProfileCreated(
286 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); 295 testing::NotNull(), NotFail())).Times(testing::AtLeast(3));
287 296
288 profile_manager_->CreateProfileAsync(dest_path1, &mock_observer); 297 profile_manager_->CreateProfileAsync(dest_path1,
289 profile_manager_->CreateProfileAsync(dest_path2, &mock_observer); 298 base::Bind(&MockObserver::OnProfileCreated,
299 base::Unretained(&mock_observer)));
300 profile_manager_->CreateProfileAsync(dest_path2,
301 base::Bind(&MockObserver::OnProfileCreated,
302 base::Unretained(&mock_observer)));
290 303
291 message_loop_.RunAllPending(); 304 message_loop_.RunAllPending();
292 } 305 }
293 306
294 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { 307 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) {
295 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache(); 308 ProfileInfoCache& cache = profile_manager_->GetProfileInfoCache();
296 309
297 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); 310 EXPECT_EQ(0u, cache.GetNumberOfProfiles());
298 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), 311 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"),
299 ASCIIToUTF16("name_1"), string16(), 0); 312 ASCIIToUTF16("name_1"), string16(), 0);
300 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), 313 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"),
301 ASCIIToUTF16("name_2"), string16(), 0); 314 ASCIIToUTF16("name_2"), string16(), 0);
302 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), 315 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"),
303 ASCIIToUTF16("name_3"), string16(), 0); 316 ASCIIToUTF16("name_3"), string16(), 0);
304 cache.SetBackgroundStatusOfProfileAtIndex(0, true); 317 cache.SetBackgroundStatusOfProfileAtIndex(0, true);
305 cache.SetBackgroundStatusOfProfileAtIndex(2, true); 318 cache.SetBackgroundStatusOfProfileAtIndex(2, true);
306 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); 319 EXPECT_EQ(3u, cache.GetNumberOfProfiles());
307 320
308 profile_manager_->AutoloadProfiles(); 321 profile_manager_->AutoloadProfiles();
309 322
310 EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size()); 323 EXPECT_EQ(2u, profile_manager_->GetLoadedProfiles().size());
311 } 324 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698