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

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

Issue 23068005: Convert UserPolicySigninService to use OAuth2TokenService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT Created 7 years, 4 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 | Annotate | Revision Log
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 <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/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #endif 47 #endif
48 48
49 using content::BrowserThread; 49 using content::BrowserThread;
50 50
51 namespace { 51 namespace {
52 52
53 // This global variable is used to check that value returned to different 53 // This global variable is used to check that value returned to different
54 // observers is the same. 54 // observers is the same.
55 Profile* g_created_profile; 55 Profile* g_created_profile;
56 56
57 } // namespace 57 class UnittestProfileManager : public ::ProfileManagerWithoutInit {
58
59 namespace testing {
60
61 class ProfileManager : public ::ProfileManagerWithoutInit {
62 public: 58 public:
63 explicit ProfileManager(const base::FilePath& user_data_dir) 59 explicit UnittestProfileManager(const base::FilePath& user_data_dir)
64 : ::ProfileManagerWithoutInit(user_data_dir) {} 60 : ::ProfileManagerWithoutInit(user_data_dir) {}
65 61
66 protected: 62 protected:
67 virtual Profile* CreateProfileHelper( 63 virtual Profile* CreateProfileHelper(
68 const base::FilePath& file_path) OVERRIDE { 64 const base::FilePath& file_path) OVERRIDE {
69 if (!base::PathExists(file_path)) { 65 if (!base::PathExists(file_path)) {
70 if (!file_util::CreateDirectory(file_path)) 66 if (!file_util::CreateDirectory(file_path))
71 return NULL; 67 return NULL;
72 } 68 }
73 return new TestingProfile(file_path, NULL); 69 return new TestingProfile(file_path, NULL);
74 } 70 }
75 71
76 virtual Profile* CreateProfileAsyncHelper(const base::FilePath& path, 72 virtual Profile* CreateProfileAsyncHelper(const base::FilePath& path,
77 Delegate* delegate) OVERRIDE { 73 Delegate* delegate) OVERRIDE {
78 // This is safe while all file operations are done on the FILE thread. 74 // This is safe while all file operations are done on the FILE thread.
79 BrowserThread::PostTask( 75 BrowserThread::PostTask(
80 BrowserThread::FILE, FROM_HERE, 76 BrowserThread::FILE, FROM_HERE,
81 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path)); 77 base::Bind(base::IgnoreResult(&file_util::CreateDirectory), path));
82 78
83 return new TestingProfile(path, this); 79 return new TestingProfile(path, this);
84 } 80 }
85 }; 81 };
86 82
87 } // namespace testing 83 } // namespace
88 84
89 class ProfileManagerTest : public testing::Test { 85 class ProfileManagerTest : public testing::Test {
90 protected: 86 protected:
91 class MockObserver { 87 class MockObserver {
92 public: 88 public:
93 MOCK_METHOD2(OnProfileCreated, 89 MOCK_METHOD2(OnProfileCreated,
94 void(Profile* profile, Profile::CreateStatus status)); 90 void(Profile* profile, Profile::CreateStatus status));
95 }; 91 };
96 92
97 ProfileManagerTest() 93 ProfileManagerTest()
98 : local_state_(TestingBrowserProcess::GetGlobal()) { 94 : local_state_(TestingBrowserProcess::GetGlobal()) {
99 } 95 }
100 96
101 virtual void SetUp() { 97 virtual void SetUp() {
102 // Create a new temporary directory, and store the path 98 // Create a new temporary directory, and store the path
103 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 99 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
104 TestingBrowserProcess::GetGlobal()->SetProfileManager( 100 TestingBrowserProcess::GetGlobal()->SetProfileManager(
105 new testing::ProfileManager(temp_dir_.path())); 101 new UnittestProfileManager(temp_dir_.path()));
106 102
107 #if defined(OS_CHROMEOS) 103 #if defined(OS_CHROMEOS)
108 CommandLine* cl = CommandLine::ForCurrentProcess(); 104 CommandLine* cl = CommandLine::ForCurrentProcess();
109 cl->AppendSwitch(switches::kTestType); 105 cl->AppendSwitch(switches::kTestType);
110 #endif 106 #endif
111 } 107 }
112 108
113 virtual void TearDown() { 109 virtual void TearDown() {
114 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); 110 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
115 base::RunLoop().RunUntilIdle(); 111 base::RunLoop().RunUntilIdle();
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 406
411 Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy(); 407 Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy();
412 ASSERT_TRUE(profile); 408 ASSERT_TRUE(profile);
413 EXPECT_FALSE(profile->IsOffTheRecord()); 409 EXPECT_FALSE(profile->IsOffTheRecord());
414 PrefService* prefs = profile->GetPrefs(); 410 PrefService* prefs = profile->GetPrefs();
415 EXPECT_EQ(IncognitoModePrefs::ENABLED, 411 EXPECT_EQ(IncognitoModePrefs::ENABLED,
416 IncognitoModePrefs::GetAvailability(prefs)); 412 IncognitoModePrefs::GetAvailability(prefs));
417 413
418 // Attach an incognito Profile to the TestingProfile. 414 // Attach an incognito Profile to the TestingProfile.
419 ASSERT_FALSE(profile->GetOffTheRecordProfile()); 415 ASSERT_FALSE(profile->GetOffTheRecordProfile());
420 TestingProfile* incognito_profile = new TestingProfile(); 416 TestingProfile::Builder builder;
421 incognito_profile->set_incognito(true); 417 builder.SetIncognito();
418 scoped_ptr<TestingProfile> incognito_profile = builder.Build();
422 EXPECT_TRUE(incognito_profile->IsOffTheRecord()); 419 EXPECT_TRUE(incognito_profile->IsOffTheRecord());
423 TestingProfile* testing_profile = static_cast<TestingProfile*>(profile); 420 TestingProfile* testing_profile = static_cast<TestingProfile*>(profile);
424 testing_profile->SetOffTheRecordProfile(incognito_profile); 421 testing_profile->SetOffTheRecordProfile(incognito_profile.PassAs<Profile>());
425 ASSERT_TRUE(profile->GetOffTheRecordProfile()); 422 ASSERT_TRUE(profile->GetOffTheRecordProfile());
426 423
427 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED); 424 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::DISABLED);
428 EXPECT_FALSE( 425 EXPECT_FALSE(
429 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); 426 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord());
430 427
431 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when 428 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when
432 // incognito mode is forced. 429 // incognito mode is forced.
433 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); 430 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED);
434 EXPECT_TRUE( 431 EXPECT_TRUE(
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 559
563 ProfileManager* profile_manager = g_browser_process->profile_manager(); 560 ProfileManager* profile_manager = g_browser_process->profile_manager();
564 561
565 // Successfully create the profiles. 562 // Successfully create the profiles.
566 TestingProfile* profile1 = 563 TestingProfile* profile1 =
567 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); 564 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1));
568 ASSERT_TRUE(profile1); 565 ASSERT_TRUE(profile1);
569 566
570 // incognito profiles should not be managed by the profile manager but by the 567 // incognito profiles should not be managed by the profile manager but by the
571 // original profile. 568 // original profile.
572 TestingProfile* profile2 = new TestingProfile(); 569 TestingProfile::Builder builder;
573 ASSERT_TRUE(profile2); 570 builder.SetIncognito();
574 profile2->set_incognito(true); 571 scoped_ptr<TestingProfile> profile2 = builder.Build();
575 profile1->SetOffTheRecordProfile(profile2); 572 profile1->SetOffTheRecordProfile(profile2.PassAs<Profile>());
576 573
577 std::vector<Profile*> last_opened_profiles = 574 std::vector<Profile*> last_opened_profiles =
578 profile_manager->GetLastOpenedProfiles(); 575 profile_manager->GetLastOpenedProfiles();
579 ASSERT_EQ(0U, last_opened_profiles.size()); 576 ASSERT_EQ(0U, last_opened_profiles.size());
580 577
581 // Create a browser for profile1. 578 // Create a browser for profile1.
582 Browser::CreateParams profile1_params(profile1, chrome::GetActiveDesktop()); 579 Browser::CreateParams profile1_params(profile1, chrome::GetActiveDesktop());
583 scoped_ptr<Browser> browser1( 580 scoped_ptr<Browser> browser1(
584 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); 581 chrome::CreateBrowserWithTestWindowForParams(&profile1_params));
585 582
586 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); 583 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
587 ASSERT_EQ(1U, last_opened_profiles.size()); 584 ASSERT_EQ(1U, last_opened_profiles.size());
588 EXPECT_EQ(profile1, last_opened_profiles[0]); 585 EXPECT_EQ(profile1, last_opened_profiles[0]);
589 586
590 // And for profile2. 587 // And for profile2.
591 Browser::CreateParams profile2_params(profile2, chrome::GetActiveDesktop()); 588 Browser::CreateParams profile2_params(profile1->GetOffTheRecordProfile(),
589 chrome::GetActiveDesktop());
592 scoped_ptr<Browser> browser2a( 590 scoped_ptr<Browser> browser2a(
593 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); 591 chrome::CreateBrowserWithTestWindowForParams(&profile2_params));
594 592
595 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); 593 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
596 ASSERT_EQ(1U, last_opened_profiles.size()); 594 ASSERT_EQ(1U, last_opened_profiles.size());
597 EXPECT_EQ(profile1, last_opened_profiles[0]); 595 EXPECT_EQ(profile1, last_opened_profiles[0]);
598 596
599 // Adding more browsers doesn't change anything. 597 // Adding more browsers doesn't change anything.
600 scoped_ptr<Browser> browser2b( 598 scoped_ptr<Browser> browser2b(
601 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); 599 chrome::CreateBrowserWithTestWindowForParams(&profile2_params));
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 dest_path2.BaseName().MaybeAsASCII()); 762 dest_path2.BaseName().MaybeAsASCII());
765 profile_manager->ScheduleProfileForDeletion(dest_path2, 763 profile_manager->ScheduleProfileForDeletion(dest_path2,
766 ProfileManager::CreateCallback()); 764 ProfileManager::CreateCallback());
767 // Spin the message loop so that all the callbacks can finish running. 765 // Spin the message loop so that all the callbacks can finish running.
768 base::RunLoop().RunUntilIdle(); 766 base::RunLoop().RunUntilIdle();
769 767
770 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 768 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
771 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 769 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
772 } 770 }
773 #endif // !defined(OS_MACOSX) 771 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl.cc ('k') | chrome/browser/signin/android_profile_oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698