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

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

Issue 1782443006: Create LoadProfile method in profile_manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months 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
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 Delegate* delegate) override { 86 Delegate* delegate) override {
87 // This is safe while all file operations are done on the FILE thread. 87 // This is safe while all file operations are done on the FILE thread.
88 BrowserThread::PostTask( 88 BrowserThread::PostTask(
89 BrowserThread::FILE, FROM_HERE, 89 BrowserThread::FILE, FROM_HERE,
90 base::Bind(base::IgnoreResult(&base::CreateDirectory), path)); 90 base::Bind(base::IgnoreResult(&base::CreateDirectory), path));
91 91
92 return new TestingProfile(path, this); 92 return new TestingProfile(path, this);
93 } 93 }
94 }; 94 };
95 95
96 void ExpectNullProfile(Profile* profile) {
Bernhard Bauer 2016/03/14 19:05:34 Can you make this take an additional Closure to ru
Miguel Garcia 2016/03/17 20:04:07 I will look into this and fix it before submitting
97 EXPECT_EQ(nullptr, profile);
98 }
99
100 void ExpectProfileWithName(const std::string& profile_name,
101 bool incognito,
102 Profile* profile) {
103 EXPECT_NE(nullptr, profile);
104 EXPECT_EQ(incognito, profile->IsOffTheRecord());
105 if (!incognito) {
Bernhard Bauer 2016/03/14 19:05:34 For incognito profiles, you could verify the name
Miguel Garcia 2016/03/17 20:04:07 Good idea!
106 #if defined(OS_WIN)
107 EXPECT_EQ(base::ASCIIToUTF16(profile_name),
Bernhard Bauer 2016/03/14 19:05:34 Alternatively, use FilePath().AppendASCII(profile_
Miguel Garcia 2016/03/17 20:04:07 Agreed. Done
108 profile->GetPath().BaseName().value());
109 #else
110 EXPECT_EQ(profile_name, profile->GetPath().BaseName().value());
111 #endif
112 }
113 }
114
96 } // namespace 115 } // namespace
97 116
98 class ProfileManagerTest : public testing::Test { 117 class ProfileManagerTest : public testing::Test {
99 protected: 118 protected:
100 class MockObserver { 119 class MockObserver {
101 public: 120 public:
102 MOCK_METHOD2(OnProfileCreated, 121 MOCK_METHOD2(OnProfileCreated,
103 void(Profile* profile, Profile::CreateStatus status)); 122 void(Profile* profile, Profile::CreateStatus status));
104 }; 123 };
105 124
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 305
287 // Make sure any pending tasks run before we destroy the profiles. 306 // Make sure any pending tasks run before we destroy the profiles.
288 base::RunLoop().RunUntilIdle(); 307 base::RunLoop().RunUntilIdle();
289 308
290 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); 309 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
291 310
292 // Make sure history cleans up correctly. 311 // Make sure history cleans up correctly.
293 base::RunLoop().RunUntilIdle(); 312 base::RunLoop().RunUntilIdle();
294 } 313 }
295 314
315 TEST_F(ProfileManagerTest, LoadProfileDoesNotExist) {
Bernhard Bauer 2016/03/14 19:05:34 Nit: "LoadNonExistingProfile" (and "LoadExistingPr
Miguel Garcia 2016/03/17 20:04:07 Done.
316 const std::string profile_name = "NonExistingProfile";
317
318 ProfileManager* profile_manager = g_browser_process->profile_manager();
319 profile_manager->LoadProfile(profile_name, false /* incognito */,
320 base::Bind(&ExpectNullProfile));
321 base::RunLoop().RunUntilIdle();
322 profile_manager->LoadProfile(profile_name, true /* incognito */,
323 base::Bind(&ExpectNullProfile));
324 base::RunLoop().RunUntilIdle();
325 }
326
327 TEST_F(ProfileManagerTest, LoadProfileExisting) {
328 const std::string profile_name = "MyProfile";
329 const std::string other_name = "SomeOtherProfile";
330 MockObserver mock_observer1;
331 EXPECT_CALL(mock_observer1, OnProfileCreated(SameNotNull(), NotFail()))
332 .Times(testing::AtLeast(1));
333
334 ProfileManager* profile_manager = g_browser_process->profile_manager();
335 CreateProfileAsync(profile_manager, profile_name, false, &mock_observer1);
336
337 // Make sure a real profile is created before continuing.
338 base::RunLoop().RunUntilIdle();
339
340 bool incognito = false;
341 profile_manager->LoadProfile(
342 profile_name, incognito,
343 base::Bind(&ExpectProfileWithName, profile_name, incognito));
344
345 incognito = true;
346 profile_manager->LoadProfile(
347 profile_name, incognito,
348 base::Bind(&ExpectProfileWithName, profile_name, incognito));
349
350 // Loading some other non existing profile should still return null.
351 profile_manager->LoadProfile(other_name, false,
352 base::Bind(&ExpectNullProfile));
353 base::RunLoop().RunUntilIdle();
354 }
355
296 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { 356 TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) {
297 g_created_profile = NULL; 357 g_created_profile = NULL;
298 358
299 MockObserver mock_observer1; 359 MockObserver mock_observer1;
300 EXPECT_CALL(mock_observer1, OnProfileCreated( 360 EXPECT_CALL(mock_observer1, OnProfileCreated(
301 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); 361 SameNotNull(), NotFail())).Times(testing::AtLeast(1));
302 MockObserver mock_observer2; 362 MockObserver mock_observer2;
303 EXPECT_CALL(mock_observer2, OnProfileCreated( 363 EXPECT_CALL(mock_observer2, OnProfileCreated(
304 SameNotNull(), NotFail())).Times(testing::AtLeast(1)); 364 SameNotNull(), NotFail())).Times(testing::AtLeast(1));
305 MockObserver mock_observer3; 365 MockObserver mock_observer3;
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after
1339 dest_path2.BaseName().MaybeAsASCII()); 1399 dest_path2.BaseName().MaybeAsASCII());
1340 profile_manager->ScheduleProfileForDeletion(dest_path2, 1400 profile_manager->ScheduleProfileForDeletion(dest_path2,
1341 ProfileManager::CreateCallback()); 1401 ProfileManager::CreateCallback());
1342 // Spin the message loop so that all the callbacks can finish running. 1402 // Spin the message loop so that all the callbacks can finish running.
1343 base::RunLoop().RunUntilIdle(); 1403 base::RunLoop().RunUntilIdle();
1344 1404
1345 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 1405 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
1346 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 1406 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
1347 } 1407 }
1348 #endif // !defined(OS_MACOSX) 1408 #endif // !defined(OS_MACOSX)
OLDNEW
« chrome/browser/profiles/profile_manager.cc ('K') | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698