From 0ff6198e70ef84b03b43673650e8f9f0444d78b2 Mon Sep 17 00:00:00 2001 From: "dpolukhin@chromium.org" Date: Wed, 8 Jan 2014 22:45:00 +0000 Subject: [PATCH] Test that Guest profile is Incognito Follow up test for https://codereview.chromium.org/101413011 BUG=329498 TEST=unit_tests Review URL: https://codereview.chromium.org/115073003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243678 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chromeos/settings/device_settings_service.cc | 2 + .../browser/profiles/profile_manager_unittest.cc | 53 ++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/chrome/browser/chromeos/settings/device_settings_service.cc b/chrome/browser/chromeos/settings/device_settings_service.cc index 6c89d1ba3765..1173a87e18a6 100644 --- a/chrome/browser/chromeos/settings/device_settings_service.cc +++ b/chrome/browser/chromeos/settings/device_settings_service.cc @@ -367,6 +367,8 @@ ScopedTestDeviceSettingsService::ScopedTestDeviceSettingsService() { } ScopedTestDeviceSettingsService::~ScopedTestDeviceSettingsService() { + // Clean pending operations. + DeviceSettingsService::Get()->UnsetSessionManager(); DeviceSettingsService::Shutdown(); } diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc index 0ae5714ffb78..ef358c570df6 100644 --- a/chrome/browser/profiles/profile_manager_unittest.cc +++ b/chrome/browser/profiles/profile_manager_unittest.cc @@ -301,6 +301,59 @@ TEST_F(ProfileManagerTest, GetGuestProfilePath) { EXPECT_EQ(expected_path, guest_path); } +#if defined(OS_CHROMEOS) +class UnittestGuestProfileManager : public UnittestProfileManager { + public: + explicit UnittestGuestProfileManager(const base::FilePath& user_data_dir) + : UnittestProfileManager(user_data_dir) {} + + protected: + virtual Profile* CreateProfileHelper( + const base::FilePath& file_path) OVERRIDE { + TestingProfile* testing_profile = new TestingProfile(file_path, NULL); + + TestingProfile::Builder builder; + builder.SetIncognito(); + builder.SetGuestSession(); + builder.SetPath(ProfileManager::GetGuestProfilePath()); + testing_profile->SetOffTheRecordProfile(builder.Build().PassAs()); + + return testing_profile; + } +}; + +class ProfileManagerGuestTest : public ProfileManagerTest { + protected: + virtual void SetUp() { + // Create a new temporary directory, and store the path + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + TestingBrowserProcess::GetGlobal()->SetProfileManager( + new UnittestGuestProfileManager(temp_dir_.path())); + + CommandLine* cl = CommandLine::ForCurrentProcess(); + cl->AppendSwitch(switches::kTestType); + cl->AppendSwitchASCII(chromeos::switches::kLoginProfile, "user"); + cl->AppendSwitch(chromeos::switches::kGuestSession); + cl->AppendSwitch(::switches::kIncognito); + + chromeos::UserManager::Get()->UserLoggedIn( + chromeos::UserManager::kGuestUserName, + chromeos::UserManager::kGuestUserName, + false); + } +}; + +TEST_F(ProfileManagerGuestTest, GuestProfileIngonito) { + Profile* primary_profile = ProfileManager::GetPrimaryUserProfile(); + EXPECT_TRUE(primary_profile->IsOffTheRecord()); + + Profile* active_profile = ProfileManager::GetActiveUserProfile(); + EXPECT_TRUE(active_profile->IsOffTheRecord()); + + EXPECT_TRUE(active_profile->IsSameProfile(primary_profile)); +} +#endif + TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { ProfileManager* profile_manager = g_browser_process->profile_manager(); ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); -- 2.11.4.GIT