diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-17 22:05:22 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-17 22:05:22 +0000 |
commit | 371662e37598fb4e9401167a85e5c9c1ff2c9fcf (patch) | |
tree | 5341004f2fdde8967b17b1bd28aa6a74e086cc86 | |
parent | 7fe5831055e00658ef85c81148b557eb628fa425 (diff) | |
download | chromium_src-371662e37598fb4e9401167a85e5c9c1ff2c9fcf.zip chromium_src-371662e37598fb4e9401167a85e5c9c1ff2c9fcf.tar.gz chromium_src-371662e37598fb4e9401167a85e5c9c1ff2c9fcf.tar.bz2 |
Mark supervised profiles as such immediately when they're created.
This happens in Profile::InitProfileUserPrefs(), so we add a new method Profile::Delegate::OnPrefsLoaded() which is called immediately after the PrefService has been creted, and which ProfileManager implements by calling InitProfileUserPrefs().
Also, remove ManagedUserService::InitForTesting in favor of marking the profile as managed at creation.
BUG=279307
Review URL: https://codereview.chromium.org/23868042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@229237 0039d316-1c4b-4281-b951-d872f2087c98
27 files changed, 250 insertions, 182 deletions
diff --git a/chrome/browser/extensions/extension_service_unittest.cc b/chrome/browser/extensions/extension_service_unittest.cc index 6465fd3..fa09f0d 100644 --- a/chrome/browser/extensions/extension_service_unittest.cc +++ b/chrome/browser/extensions/extension_service_unittest.cc @@ -450,7 +450,7 @@ class MockProviderVisitor ExtensionServiceTestBase::ExtensionServiceInitParams:: ExtensionServiceInitParams() - : autoupdate_enabled(false), is_first_run(true) { + : autoupdate_enabled(false), is_first_run(true), profile_is_managed(false) { } // Our message loop may be used in tests which require it to be an IO loop. @@ -488,6 +488,10 @@ void ExtensionServiceTestBase::InitializeExtensionService( chrome::RegisterUserProfilePrefs(registry.get()); profile_builder.SetPrefService(prefs.Pass()); } + + if (params.profile_is_managed) + profile_builder.SetManagedUserId("asdf"); + profile_builder.SetPath(params.profile_path); profile_ = profile_builder.Build(); @@ -513,6 +517,8 @@ void ExtensionServiceTestBase::InitializeExtensionService( management_policy_ = ExtensionSystem::Get(profile_.get())->management_policy(); + extensions_install_dir_ = params.extensions_install_dir; + // When we start up, we want to make sure there is no external provider, // since the ExtensionService on Windows will use the Registry as a default // provider and if there is something already registered there then it will @@ -530,22 +536,25 @@ void ExtensionServiceTestBase::InitializeExtensionService( void ExtensionServiceTestBase::InitializeInstalledExtensionService( const base::FilePath& prefs_file, const base::FilePath& source_install_dir) { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); base::FilePath path = temp_dir_.path(); path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); - base::DeleteFile(path, true); - file_util::CreateDirectory(path); + EXPECT_TRUE(base::DeleteFile(path, true)); + base::PlatformFileError error = base::PLATFORM_FILE_OK; + EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; base::FilePath temp_prefs = path.Append(FILE_PATH_LITERAL("Preferences")); - base::CopyFile(prefs_file, temp_prefs); + EXPECT_TRUE(base::CopyFile(prefs_file, temp_prefs)); - extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); - base::DeleteFile(extensions_install_dir_, true); - base::CopyDirectory(source_install_dir, extensions_install_dir_, true); + base::FilePath extensions_install_dir = + path.Append(FILE_PATH_LITERAL("Extensions")); + EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); + EXPECT_TRUE( + base::CopyDirectory(source_install_dir, extensions_install_dir, true)); ExtensionServiceInitParams params; params.profile_path = path; params.pref_file = temp_prefs; - params.extensions_install_dir = extensions_install_dir_; + params.extensions_install_dir = extensions_install_dir; InitializeExtensionService(params); } @@ -560,7 +569,7 @@ void ExtensionServiceTestBase::InitializeGoodInstalledExtensionService() { } void ExtensionServiceTestBase::InitializeEmptyExtensionService() { - InitializeExtensionServiceHelper(false, true); + InitializeExtensionService(CreateDefaultInitParams()); } void ExtensionServiceTestBase::InitializeExtensionProcessManager() { @@ -570,30 +579,33 @@ void ExtensionServiceTestBase::InitializeExtensionProcessManager() { } void ExtensionServiceTestBase::InitializeExtensionServiceWithUpdater() { - InitializeExtensionServiceHelper(true, true); + ExtensionServiceInitParams params = CreateDefaultInitParams(); + params.autoupdate_enabled = true; + InitializeExtensionService(params); service_->updater()->Start(); } -void ExtensionServiceTestBase::InitializeExtensionServiceHelper( - bool autoupdate_enabled, bool is_first_run) { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); +ExtensionServiceTestBase::ExtensionServiceInitParams +ExtensionServiceTestBase::CreateDefaultInitParams() { + ExtensionServiceInitParams params; + EXPECT_TRUE(temp_dir_.CreateUniqueTempDir()); base::FilePath path = temp_dir_.path(); path = path.Append(FILE_PATH_LITERAL("TestingExtensionsPath")); - base::DeleteFile(path, true); - file_util::CreateDirectory(path); + EXPECT_TRUE(base::DeleteFile(path, true)); + base::PlatformFileError error = base::PLATFORM_FILE_OK; + EXPECT_TRUE(file_util::CreateDirectoryAndGetError(path, &error)) << error; base::FilePath prefs_filename = path.Append(FILE_PATH_LITERAL("TestPreferences")); - extensions_install_dir_ = path.Append(FILE_PATH_LITERAL("Extensions")); - base::DeleteFile(extensions_install_dir_, true); - file_util::CreateDirectory(extensions_install_dir_); + base::FilePath extensions_install_dir = + path.Append(FILE_PATH_LITERAL("Extensions")); + EXPECT_TRUE(base::DeleteFile(extensions_install_dir, true)); + EXPECT_TRUE(file_util::CreateDirectoryAndGetError(extensions_install_dir, + &error)) << error; - ExtensionServiceInitParams params; params.profile_path = path; params.pref_file = prefs_filename; - params.extensions_install_dir = extensions_install_dir_; - params.autoupdate_enabled = autoupdate_enabled; - params.is_first_run = is_first_run; - InitializeExtensionService(params); + params.extensions_install_dir = extensions_install_dir; + return params; } // static @@ -6478,7 +6490,9 @@ TEST_F(ExtensionServiceTest, ExternalInstallUpdatesFromWebstoreOldProfile) { // This sets up the ExtensionPrefs used by our ExtensionService to be // post-first run. - InitializeExtensionServiceHelper(false, false); + ExtensionServiceInitParams params = CreateDefaultInitParams(); + params.is_first_run = false; + InitializeExtensionService(params); base::FilePath crx_path = temp_dir_.path().AppendASCII("webstore.crx"); PackCRX(data_dir_.AppendASCII("update_from_webstore"), diff --git a/chrome/browser/extensions/extension_service_unittest.h b/chrome/browser/extensions/extension_service_unittest.h index 05b71a08..2972c6d 100644 --- a/chrome/browser/extensions/extension_service_unittest.h +++ b/chrome/browser/extensions/extension_service_unittest.h @@ -36,6 +36,7 @@ class ExtensionServiceTestBase : public testing::Test { base::FilePath extensions_install_dir; bool autoupdate_enabled; bool is_first_run; + bool profile_is_managed; ExtensionServiceInitParams(); }; @@ -67,8 +68,7 @@ class ExtensionServiceTestBase : public testing::Test { } protected: - void InitializeExtensionServiceHelper(bool autoupdate_enabled, - bool is_first_run); + ExtensionServiceInitParams CreateDefaultInitParams(); // Destroying at_exit_manager_ will delete all LazyInstances, so it must come // after thread_bundle_ in the destruction order. diff --git a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc index 24de760..0451bbc 100644 --- a/chrome/browser/extensions/webstore_startup_installer_browsertest.cc +++ b/chrome/browser/extensions/webstore_startup_installer_browsertest.cc @@ -171,8 +171,18 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, InstallFromHostedApp) { EXPECT_TRUE(extension_service->extensions()->Contains(kTestExtensionId)); } -IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, - InstallProhibitedForManagedUsers) { +class WebstoreStartupInstallerManagedUsersTest + : public WebstoreStartupInstallerTest { + public: + // InProcessBrowserTest overrides: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + WebstoreStartupInstallerTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kNewProfileIsSupervised); + } +}; + +IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerManagedUsersTest, + InstallProhibited) { #if defined(OS_WIN) && defined(USE_ASH) // Disable this test in Metro+Ash for now (http://crbug.com/262796). if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) @@ -182,11 +192,6 @@ IN_PROC_BROWSER_TEST_F(WebstoreStartupInstallerTest, CommandLine::ForCurrentProcess()->AppendSwitchASCII( switches::kAppsGalleryInstallAutoConfirmForTests, "accept"); - // Make the profile managed such that no extension installs are allowed. - ManagedUserService* service = - ManagedUserServiceFactory::GetForProfile(browser()->profile()); - service->InitForTesting(); - ui_test_utils::NavigateToURL( browser(), GenerateTestServerUrl(kAppDomain, "install_prohibited.html")); diff --git a/chrome/browser/managed_mode/managed_mode_browsertest.cc b/chrome/browser/managed_mode/managed_mode_browsertest.cc index 67e54ed..86e3817 100644 --- a/chrome/browser/managed_mode/managed_mode_browsertest.cc +++ b/chrome/browser/managed_mode/managed_mode_browsertest.cc @@ -107,7 +107,6 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { Profile* profile = browser()->profile(); managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); - managed_user_service_->InitForTesting(); ManagedUserSettingsService* managed_user_settings_service = ManagedUserSettingsServiceFactory::GetForProfile(profile); managed_user_settings_service->SetLocalSettingForTesting( @@ -124,6 +123,8 @@ class ManagedModeBlockModeTest : public InProcessBrowserTest { "MAP *.example.com " + host_port + "," + "MAP *.new-example.com " + host_port + "," + "MAP *.a.com " + host_port); + + command_line->AppendSwitch(switches::kNewProfileIsSupervised); } // Acts like a synchronous call to history's QueryHistory. Modified from diff --git a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc index 9fdf8a6..9bfb460 100644 --- a/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc +++ b/chrome/browser/managed_mode/managed_mode_resource_throttle_browsertest.cc @@ -4,6 +4,7 @@ #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" +#include "base/command_line.h" #include "base/prefs/pref_service.h" #include "base/values.h" #include "chrome/browser/managed_mode/managed_user_constants.h" @@ -13,6 +14,7 @@ #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/navigation_entry.h" @@ -33,6 +35,7 @@ class ManagedModeResourceThrottleTest : public InProcessBrowserTest { private: virtual void SetUpOnMainThread() OVERRIDE; + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; ManagedUserService* managed_user_service_; }; @@ -40,7 +43,11 @@ class ManagedModeResourceThrottleTest : public InProcessBrowserTest { void ManagedModeResourceThrottleTest::SetUpOnMainThread() { managed_user_service_ = ManagedUserServiceFactory::GetForProfile(browser()->profile()); - managed_user_service_->InitForTesting(); +} + +void ManagedModeResourceThrottleTest::SetUpCommandLine( + CommandLine* command_line) { + command_line->AppendSwitch(switches::kNewProfileIsSupervised); } // Tests that showing the blocking interstitial for a WebContents without a diff --git a/chrome/browser/managed_mode/managed_user_service.cc b/chrome/browser/managed_mode/managed_user_service.cc index 96bb3a1..7015c3f 100644 --- a/chrome/browser/managed_mode/managed_user_service.cc +++ b/chrome/browser/managed_mode/managed_user_service.cc @@ -293,11 +293,6 @@ void ManagedUserService::DidBlockNavigation( } } -void ManagedUserService::AddInitCallback( - const base::Closure& callback) { - init_callbacks_.push_back(callback); -} - std::string ManagedUserService::GetDebugPolicyProviderName() const { // Save the string space in official builds. #ifdef NDEBUG @@ -528,12 +523,6 @@ void ManagedUserService::GetManualExceptionsForHost(const std::string& host, } } -void ManagedUserService::InitForTesting() { - DCHECK(!profile_->IsManaged()); - profile_->GetPrefs()->SetString(prefs::kManagedUserId, "Test ID"); - Init(); -} - void ManagedUserService::InitSync(const std::string& refresh_token) { ProfileSyncService* service = ProfileSyncServiceFactory::GetForProfile(profile_); @@ -611,14 +600,6 @@ void ManagedUserService::Init() { UpdateSiteLists(); UpdateManualHosts(); UpdateManualURLs(); - - // Call the callbacks to notify that the ManagedUserService has been - // initialized. - for (std::vector<base::Closure>::iterator it = init_callbacks_.begin(); - it != init_callbacks_.end(); - ++it) { - it->Run(); - } } void ManagedUserService::RegisterAndInitSync( diff --git a/chrome/browser/managed_mode/managed_user_service.h b/chrome/browser/managed_mode/managed_user_service.h index b2d05f6..baf790c 100644 --- a/chrome/browser/managed_mode/managed_user_service.h +++ b/chrome/browser/managed_mode/managed_user_service.h @@ -116,9 +116,6 @@ class ManagedUserService : public BrowserContextKeyedService, // managed. void Init(); - // Marks the profile as managed and initializes it. - void InitForTesting(); - // Initializes this profile for syncing, using the provided |refresh_token| to // mint access tokens for Sync. void InitSync(const std::string& refresh_token); @@ -144,8 +141,6 @@ class ManagedUserService : public BrowserContextKeyedService, void AddNavigationBlockedCallback(const NavigationBlockedCallback& callback); void DidBlockNavigation(content::WebContents* web_contents); - void AddInitCallback(const base::Closure& callback); - // extensions::ManagementPolicy::Provider implementation: virtual std::string GetDebugPolicyProviderName() const OVERRIDE; virtual bool UserMayLoad(const extensions::Extension* extension, @@ -165,7 +160,7 @@ class ManagedUserService : public BrowserContextKeyedService, virtual void OnBrowserSetLastActive(Browser* browser) OVERRIDE; private: - friend class ManagedUserServiceExtensionTest; + friend class ManagedUserServiceExtensionTestBase; friend class ManagedUserServiceFactory; FRIEND_TEST_ALL_PREFIXES(ManagedUserServiceTest, ExtensionManagementPolicyProviderUnmanaged); @@ -259,8 +254,6 @@ class ManagedUserService : public BrowserContextKeyedService, bool waiting_for_sync_initialization_; bool is_profile_active_; - std::vector<base::Closure> init_callbacks_; - std::vector<NavigationBlockedCallback> navigation_blocked_callbacks_; // Sets a profile in elevated state for testing if set to true. diff --git a/chrome/browser/managed_mode/managed_user_service_browsertest.cc b/chrome/browser/managed_mode/managed_user_service_browsertest.cc index 9af82f6..571f413 100644 --- a/chrome/browser/managed_mode/managed_user_service_browsertest.cc +++ b/chrome/browser/managed_mode/managed_user_service_browsertest.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "base/prefs/pref_service.h" #include "base/strings/utf_string_conversions.h" #include "chrome/browser/browser_process.h" @@ -14,24 +15,26 @@ #include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/in_process_browser_test.h" #include "content/public/test/test_utils.h" typedef InProcessBrowserTest ManagedUserServiceTest; +class ManagedUserServiceTestManaged : public InProcessBrowserTest { + public: + // content::BrowserTestBase: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + command_line->AppendSwitch(switches::kNewProfileIsSupervised); + } +}; + IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) { Profile* profile = browser()->profile(); PrefService* prefs = profile->GetPrefs(); EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); - - ManagedUserService* managed_user_service = - ManagedUserServiceFactory::GetForProfile(profile); - managed_user_service->InitForTesting(); - - EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); - EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); } IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { @@ -45,11 +48,22 @@ IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); EXPECT_EQ(original_name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); +} + +IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, LocalPolicies) { + Profile* profile = browser()->profile(); + PrefService* prefs = profile->GetPrefs(); + EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); + EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); +} + +IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, ProfileName) { + Profile* profile = browser()->profile(); + PrefService* prefs = profile->GetPrefs(); + std::string original_name = prefs->GetString(prefs::kProfileName); + ProfileManager* profile_manager = g_browser_process->profile_manager(); + const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); - // Change the profile to a managed user. - ManagedUserService* managed_user_service = - ManagedUserServiceFactory::GetForProfile(profile); - managed_user_service->InitForTesting(); ManagedUserSettingsService* settings = ManagedUserSettingsServiceFactory::GetForProfile(profile); @@ -59,7 +73,7 @@ IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { scoped_ptr<base::Value>(new base::StringValue(name))); EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName)); EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); - profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); + size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); // Change the name once more. diff --git a/chrome/browser/managed_mode/managed_user_service_unittest.cc b/chrome/browser/managed_mode/managed_user_service_unittest.cc index 42a2a32..97183eb 100644 --- a/chrome/browser/managed_mode/managed_user_service_unittest.cc +++ b/chrome/browser/managed_mode/managed_user_service_unittest.cc @@ -20,7 +20,7 @@ #include "chrome/common/extensions/extension_builder.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" #include "extensions/common/manifest_constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -66,16 +66,14 @@ class ManagedModeURLFilterObserver : public ManagedModeURLFilter::Observer { class ManagedUserServiceTest : public ::testing::Test { public: - ManagedUserServiceTest() : ui_thread_(content::BrowserThread::UI, - &message_loop_) { + ManagedUserServiceTest() { managed_user_service_ = ManagedUserServiceFactory::GetForProfile(&profile_); } virtual ~ManagedUserServiceTest() {} protected: - base::MessageLoop message_loop_; - content::TestBrowserThread ui_thread_; + content::TestBrowserThreadBundle thread_bundle_; TestingProfile profile_; ManagedUserService* managed_user_service_; }; @@ -152,18 +150,19 @@ TEST_F(ManagedUserServiceTest, ShutDownCustodianProfileDownloader) { downloader_service->DownloadProfile(base::Bind(&OnProfileDownloadedFail)); } -class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase { +class ManagedUserServiceExtensionTestBase : public ExtensionServiceTestBase { public: - ManagedUserServiceExtensionTest() {} - virtual ~ManagedUserServiceExtensionTest() {} + explicit ManagedUserServiceExtensionTestBase(bool is_managed) + : is_managed_(is_managed) {} + virtual ~ManagedUserServiceExtensionTestBase() {} virtual void SetUp() OVERRIDE { ExtensionServiceTestBase::SetUp(); - InitializeEmptyExtensionService(); - } - - virtual void TearDown() OVERRIDE { - ExtensionServiceTestBase::TearDown(); + ExtensionServiceTestBase::ExtensionServiceInitParams params = + CreateDefaultInitParams(); + params.profile_is_managed = is_managed_; + InitializeExtensionService(params); + ManagedUserServiceFactory::GetForProfile(profile_.get())->Init(); } protected: @@ -193,10 +192,26 @@ class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase { builder.SetManifest(manifest.Pass()).Build(); return extension; } + + bool is_managed_; +}; + +class ManagedUserServiceExtensionTestUnmanaged + : public ManagedUserServiceExtensionTestBase { + public: + ManagedUserServiceExtensionTestUnmanaged() + : ManagedUserServiceExtensionTestBase(false) {} }; -TEST_F(ManagedUserServiceExtensionTest, - ExtensionManagementPolicyProviderUnmanaged) { +class ManagedUserServiceExtensionTest + : public ManagedUserServiceExtensionTestBase { + public: + ManagedUserServiceExtensionTest() + : ManagedUserServiceExtensionTestBase(true) {} +}; + +TEST_F(ManagedUserServiceExtensionTestUnmanaged, + ExtensionManagementPolicyProvider) { ManagedUserService* managed_user_service = ManagedUserServiceFactory::GetForProfile(profile_.get()); EXPECT_FALSE(profile_->IsManaged()); @@ -212,14 +227,12 @@ TEST_F(ManagedUserServiceExtensionTest, EXPECT_EQ(string16(), error_2); } -TEST_F(ManagedUserServiceExtensionTest, - ExtensionManagementPolicyProviderManaged) { +TEST_F(ManagedUserServiceExtensionTest, ExtensionManagementPolicyProvider) { ManagedUserService* managed_user_service = ManagedUserServiceFactory::GetForProfile(profile_.get()); - managed_user_service->InitForTesting(); ManagedModeURLFilterObserver observer( managed_user_service->GetURLFilterForUIThread()); - EXPECT_TRUE(profile_->IsManaged()); + ASSERT_TRUE(profile_->IsManaged()); // Wait for the initial update to finish (otherwise we'll get leaks). observer.Wait(); @@ -247,11 +260,9 @@ TEST_F(ManagedUserServiceExtensionTest, #endif } - TEST_F(ManagedUserServiceExtensionTest, NoContentPacks) { ManagedUserService* managed_user_service = ManagedUserServiceFactory::GetForProfile(profile_.get()); - managed_user_service->Init(); ManagedModeURLFilter* url_filter = managed_user_service->GetURLFilterForUIThread(); @@ -266,7 +277,6 @@ TEST_F(ManagedUserServiceExtensionTest, NoContentPacks) { TEST_F(ManagedUserServiceExtensionTest, InstallContentPacks) { ManagedUserService* managed_user_service = ManagedUserServiceFactory::GetForProfile(profile_.get()); - managed_user_service->InitForTesting(); ManagedModeURLFilter* url_filter = managed_user_service->GetURLFilterForUIThread(); ManagedModeURLFilterObserver observer(url_filter); diff --git a/chrome/browser/profiles/profile_browsertest.cc b/chrome/browser/profiles/profile_browsertest.cc index 0386d22..063c13e 100644 --- a/chrome/browser/profiles/profile_browsertest.cc +++ b/chrome/browser/profiles/profile_browsertest.cc @@ -24,6 +24,7 @@ namespace { class MockProfileDelegate : public Profile::Delegate { public: + MOCK_METHOD1(OnPrefsLoaded, void(Profile*)); MOCK_METHOD3(OnProfileCreated, void(Profile*, bool, bool)); }; diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index d761103..baf2557 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -783,6 +783,8 @@ void ProfileImpl::OnPrefsLoaded(bool success) { // TODO(sky): remove this in a couple of releases (m28ish). prefs_->SetBoolean(prefs::kSessionExitedCleanly, true); + g_browser_process->profile_manager()->InitProfileUserPrefs(this); + BrowserContextDependencyManager::GetInstance()->CreateBrowserContextServices( this); diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc index 1d5e6df..1a6e089 100644 --- a/chrome/browser/profiles/profile_info_cache_unittest.cc +++ b/chrome/browser/profiles/profile_info_cache_unittest.cc @@ -18,6 +18,7 @@ #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/notification_service.h" +#include "content/public/test/test_browser_thread_bundle.h" #include "content/public/test/test_utils.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" @@ -459,6 +460,11 @@ TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) { std::string managed_user_id = is_managed ? "TEST_ID" : ""; EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); } + + // Managed profiles have a custom theme, which needs to be deleted on the FILE + // thread. Reset the profile manager now so everything is deleted while we + // still have a FILE thread. + TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); } TEST_F(ProfileInfoCacheTest, AddStubProfile) { diff --git a/chrome/browser/profiles/profile_manager.cc b/chrome/browser/profiles/profile_manager.cc index 5256afc..aa1b7b9 100644 --- a/chrome/browser/profiles/profile_manager.cc +++ b/chrome/browser/profiles/profile_manager.cc @@ -552,6 +552,7 @@ bool ProfileManager::AddProfile(Profile* profile) { } RegisterProfile(profile, true); + InitProfileUserPrefs(profile); DoFinalInit(profile, ShouldGoOffTheRecord(profile)); return true; } @@ -731,7 +732,6 @@ void ProfileManager::BrowserListObserver::OnBrowserSetLastActive( #endif // !defined(OS_ANDROID) && !defined(OS_IOS) void ProfileManager::DoFinalInit(Profile* profile, bool go_off_the_record) { - InitProfileUserPrefs(profile); DoFinalInitForServices(profile, go_off_the_record); AddProfileToCache(profile); DoFinalInitLogging(profile); @@ -1013,8 +1013,14 @@ void ProfileManager::InitProfileUserPrefs(Profile* profile) { if (!profile->GetPrefs()->HasPrefPath(prefs::kProfileName)) profile->GetPrefs()->SetString(prefs::kProfileName, profile_name); - if (!profile->GetPrefs()->HasPrefPath(prefs::kManagedUserId)) + if (!profile->GetPrefs()->HasPrefPath(prefs::kManagedUserId)) { + if (managed_user_id.empty() && + CommandLine::ForCurrentProcess()->HasSwitch( + switches::kNewProfileIsSupervised)) { + managed_user_id = "Test ID"; + } profile->GetPrefs()->SetString(prefs::kManagedUserId, managed_user_id); + } } void ProfileManager::SetGuestProfilePrefs(Profile* profile) { diff --git a/chrome/browser/profiles/profile_manager.h b/chrome/browser/profiles/profile_manager.h index f84ac95..a8674de 100644 --- a/chrome/browser/profiles/profile_manager.h +++ b/chrome/browser/profiles/profile_manager.h @@ -193,6 +193,10 @@ class ProfileManager : public base::NonThreadSafe, // Sign-Out a profile against use until re-authentication. void SignOutProfile(Profile* profile); + // Initializes user prefs of |profile|. This includes profile name and + // avatar values. + void InitProfileUserPrefs(Profile* profile); + // Register and add testing profile to the ProfileManager. Use ONLY in tests. // This allows the creation of Profiles outside of the standard creation path // for testing. If |addToCache|, adds to ProfileInfoCache as well. @@ -277,10 +281,6 @@ class ProfileManager : public base::NonThreadSafe, // Adds |profile| to the profile info cache if it hasn't been added yet. void AddProfileToCache(Profile* profile); - // Initializes user prefs of |profile|. This includes profile name and - // avatar values - void InitProfileUserPrefs(Profile* profile); - // Apply settings for (desktop) Guest User profile. void SetGuestProfilePrefs(Profile* profile); diff --git a/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc b/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc index 51b25fd..55b2e08 100644 --- a/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc +++ b/chrome/browser/sync/test/integration/single_client_managed_user_settings_sync_test.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/command_line.h" #include "base/prefs/pref_service.h" #include "base/values.h" #include "chrome/browser/managed_mode/managed_user_constants.h" @@ -12,12 +13,19 @@ #include "chrome/browser/profiles/profile.h" #include "chrome/browser/sync/profile_sync_service_harness.h" #include "chrome/browser/sync/test/integration/sync_test.h" +#include "chrome/common/chrome_switches.h" class SingleClientManagedUserSettingsSyncTest : public SyncTest { public: SingleClientManagedUserSettingsSyncTest() : SyncTest(SINGLE_CLIENT) {} virtual ~SingleClientManagedUserSettingsSyncTest() {} + + // SyncTest overrides: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + SyncTest::SetUpCommandLine(command_line); + command_line->AppendSwitch(switches::kNewProfileIsSupervised); + } }; // TODO(pavely): Fix this test. See also: http://crbug.com/279307 @@ -26,7 +34,6 @@ IN_PROC_BROWSER_TEST_F(SingleClientManagedUserSettingsSyncTest, ASSERT_TRUE(SetupClients()); for (int i = 0; i < num_clients(); ++i) { Profile* profile = GetProfile(i); - ManagedUserServiceFactory::GetForProfile(profile)->InitForTesting(); // Managed users are prohibited from signing into the browser. Currently // that means they're also unable to sync anything, so override that for // this test. diff --git a/chrome/browser/themes/theme_service.cc b/chrome/browser/themes/theme_service.cc index bf6b9cc..238824b 100644 --- a/chrome/browser/themes/theme_service.cc +++ b/chrome/browser/themes/theme_service.cc @@ -14,8 +14,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_system.h" -#include "chrome/browser/managed_mode/managed_user_service.h" -#include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/managed_mode/managed_user_theme.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/themes/browser_theme_pack.h" @@ -98,9 +96,6 @@ void ThemeService::Init(Profile* profile) { DCHECK(CalledOnValidThread()); profile_ = profile; - ManagedUserServiceFactory::GetForProfile(profile)->AddInitCallback(base::Bind( - &ThemeService::OnManagedUserInitialized, weak_ptr_factory_.GetWeakPtr())); - LoadThemePrefs(); registrar_.Add(this, @@ -578,25 +573,6 @@ void ThemeService::SetManagedUserTheme() { SetCustomDefaultTheme(new ManagedUserTheme); } -void ThemeService::OnManagedUserInitialized() { - // Currently when creating a supervised user, the ThemeService is initialized - // before the boolean flag indicating the profile belongs to a supervised - // user gets set. In order to get the custom managed user theme, we get a - // callback when ManagedUserService is initialized, which happens some time - // after the boolean flag has been set in - // ProfileManager::InitProfileUserPrefs() and after the - // NOTIFICATION_EXTENSIONS_READY notification is sent. - if ((theme_supplier_.get() && - (theme_supplier_->get_theme_type() == CustomThemeSupplier::EXTENSION || - theme_supplier_->get_theme_type() == - CustomThemeSupplier::MANAGED_USER_THEME)) || - !IsManagedUser()) { - return; - } - - SetManagedUserTheme(); -} - void ThemeService::OnInfobarDisplayed() { number_of_infobars_++; } diff --git a/chrome/browser/themes/theme_service_unittest.cc b/chrome/browser/themes/theme_service_unittest.cc index 4b03205..19b78f9 100644 --- a/chrome/browser/themes/theme_service_unittest.cc +++ b/chrome/browser/themes/theme_service_unittest.cc @@ -26,10 +26,8 @@ namespace theme_service_internal { class ThemeServiceTest : public ExtensionServiceTestBase { public: - ThemeServiceTest() { - manager_.reset( - new TestingProfileManager(TestingBrowserProcess::GetGlobal())); - } + ThemeServiceTest() : is_managed_(false), + manager_(TestingBrowserProcess::GetGlobal()) {} virtual ~ThemeServiceTest() {} // Moves a minimal theme to |temp_dir_path| and unpacks it from that @@ -81,10 +79,12 @@ class ThemeServiceTest : public ExtensionServiceTestBase { virtual void SetUp() { ExtensionServiceTestBase::SetUp(); - InitializeEmptyExtensionService(); + ExtensionServiceTestBase::ExtensionServiceInitParams params = + CreateDefaultInitParams(); + params.profile_is_managed = is_managed_; + InitializeExtensionService(params); service_->Init(); - bool success = manager_->SetUp(); - ASSERT_TRUE(success); + ASSERT_TRUE(manager_.SetUp()); } const CustomThemeSupplier* get_theme_supplier(ThemeService* theme_service) { @@ -92,11 +92,14 @@ class ThemeServiceTest : public ExtensionServiceTestBase { } TestingProfileManager* manager() { - return manager_.get(); + return &manager_; } + protected: + bool is_managed_; + private: - scoped_ptr<TestingProfileManager> manager_; + TestingProfileManager manager_; }; // Installs then uninstalls a theme and makes sure that the ThemeService @@ -226,9 +229,19 @@ TEST_F(ThemeServiceTest, ThemeUpgrade) { ExtensionService::INCLUDE_DISABLED)); } +class ThemeServiceManagedUserTest : public ThemeServiceTest { + public: + ThemeServiceManagedUserTest() {} + virtual ~ThemeServiceManagedUserTest() {} + + virtual void SetUp() OVERRIDE { + is_managed_ = true; + ThemeServiceTest::SetUp(); + } +}; + // Checks that managed users have their own default theme. -TEST_F(ThemeServiceTest, ManagedUserThemeReplacesDefaultTheme) { - ManagedUserServiceFactory::GetForProfile(profile_.get())->InitForTesting(); +TEST_F(ThemeServiceManagedUserTest, ManagedUserThemeReplacesDefaultTheme) { ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_.get()); theme_service->UseDefaultTheme(); @@ -238,23 +251,10 @@ TEST_F(ThemeServiceTest, ManagedUserThemeReplacesDefaultTheme) { CustomThemeSupplier::MANAGED_USER_THEME); } -TEST_F(ThemeServiceTest, ManagedUserThemeNewUser) { - TestingProfile* profile = manager()->CreateTestingProfile("mu"); - // Simulate the current initialization behavior: first the ThemeService is - // created, then the supervised user profile is initialized. - ThemeService* theme_service = - ThemeServiceFactory::GetForProfile(profile); - ManagedUserServiceFactory::GetForProfile(profile)->InitForTesting(); - EXPECT_EQ(get_theme_supplier(theme_service)->get_theme_type(), - CustomThemeSupplier::MANAGED_USER_THEME); - manager()->DeleteTestingProfile("mu"); -} - #if defined(OS_LINUX) && !defined(OS_CHROMEOS) // Checks that managed users don't use the system theme even if it is the // default. The system theme is only available on Linux. -TEST_F(ThemeServiceTest, ManagedUserThemeReplacesNativeTheme) { - ManagedUserServiceFactory::GetForProfile(profile_.get())->InitForTesting(); +TEST_F(ThemeServiceManagedUserTest, ManagedUserThemeReplacesNativeTheme) { profile_->GetPrefs()->SetBoolean(prefs::kUsesSystemTheme, true); ThemeService* theme_service = ThemeServiceFactory::GetForProfile(profile_.get()); diff --git a/chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm b/chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm index bae7802..a014160 100644 --- a/chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/browser/avatar_button_controller_unittest.mm @@ -5,19 +5,26 @@ #import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" #include "base/mac/scoped_nsobject.h" +#include "base/strings/utf_string_conversions.h" +#include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" +#include "chrome/browser/bookmarks/bookmark_test_helpers.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" +#include "chrome/browser/prefs/pref_service_syncable.h" +#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_window.h" #import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" #include "chrome/browser/ui/cocoa/cocoa_profile_test.h" #include "chrome/browser/ui/cocoa/info_bubble_window.h" +#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/common/pref_names.h" #include "chrome/test/base/testing_profile.h" class AvatarButtonControllerTest : public CocoaProfileTest { public: - virtual void SetUp() { + virtual void SetUp() OVERRIDE { CocoaProfileTest::SetUp(); ASSERT_TRUE(browser()); @@ -26,7 +33,7 @@ class AvatarButtonControllerTest : public CocoaProfileTest { [[controller_ view] setHidden:YES]; } - virtual void TearDown() { + virtual void TearDown() OVERRIDE { browser()->window()->Close(); CocoaProfileTest::TearDown(); } @@ -82,18 +89,31 @@ TEST_F(AvatarButtonControllerTest, DoubleOpen) { } TEST_F(AvatarButtonControllerTest, ManagedUserLabel) { - // Create a second profile to enable the avatar menu. - testing_profile_manager()->CreateTestingProfile("p2"); - + DCHECK(!profile()->IsManaged()); EXPECT_FALSE([controller() labelButtonView]); - // Transform the first profile to a managed user profile. - ManagedUserServiceFactory::GetForProfile(profile())->InitForTesting(); - + // Create a second, managed profile to enable the avatar menu. + std::string name = "p2"; + TestingProfile* profile = testing_profile_manager()->CreateTestingProfile( + name, scoped_ptr<PrefServiceSyncable>(), ASCIIToUTF16(name), 0, "asdf"); + EXPECT_TRUE(profile->IsManaged()); + + // http://crbug.com/39725 + TemplateURLServiceFactory::GetInstance()->SetTestingFactoryAndUse( + profile, &TemplateURLServiceFactory::BuildInstanceFor); + AutocompleteClassifierFactory::GetInstance()->SetTestingFactoryAndUse( + profile, &AutocompleteClassifierFactory::BuildInstanceFor); + profile->CreateBookmarkModel(true); + test::WaitForBookmarkModelToLoad(profile); + + Browser* browser = + new Browser(Browser::CreateParams(profile, chrome::GetActiveDesktop())); // Build a new controller to check if it is initialized correctly for a // managed user profile. base::scoped_nsobject<AvatarButtonController> controller( - [[AvatarButtonController alloc] initWithBrowser:browser()]); + [[AvatarButtonController alloc] initWithBrowser:browser]); EXPECT_TRUE([controller labelButtonView]); + + browser->window()->Close(); } diff --git a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc index d76ca8d..b341161 100644 --- a/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc +++ b/chrome/browser/ui/startup/startup_browser_creator_browsertest.cc @@ -960,16 +960,12 @@ class ManagedModeBrowserCreatorTest : public InProcessBrowserTest { virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { InProcessBrowserTest::SetUpCommandLine(command_line); command_line->AppendSwitch(switches::kEnableManagedUsers); + command_line->AppendSwitch(switches::kNewProfileIsSupervised); } }; IN_PROC_BROWSER_TEST_F(ManagedModeBrowserCreatorTest, StartupManagedModeProfile) { - // Make this a managed profile. - ManagedUserService* managed_user_service = - ManagedUserServiceFactory::GetForProfile(browser()->profile()); - managed_user_service->InitForTesting(); - StartupBrowserCreator browser_creator; // Do a simple non-process-startup browser launch. diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.cc b/chrome/browser/ui/webui/downloads_ui_browsertest.cc index 1abeb5e..4195864 100644 --- a/chrome/browser/ui/webui/downloads_ui_browsertest.cc +++ b/chrome/browser/ui/webui/downloads_ui_browsertest.cc @@ -4,27 +4,26 @@ #include "chrome/browser/ui/webui/downloads_ui_browsertest.h" +#include "base/command_line.h" #include "base/prefs/pref_service.h" #include "chrome/browser/managed_mode/managed_user_service.h" #include "chrome/browser/managed_mode/managed_user_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/public/test/test_utils.h" -DownloadsUIBrowserTest::DownloadsUIBrowserTest() { -} +DownloadsUIBrowserTest::DownloadsUIBrowserTest() {} -DownloadsUIBrowserTest::~DownloadsUIBrowserTest() { -} +DownloadsUIBrowserTest::~DownloadsUIBrowserTest() {} void DownloadsUIBrowserTest::SetDeleteAllowed(bool allowed) { browser()->profile()->GetPrefs()-> SetBoolean(prefs::kAllowDeletingBrowserHistory, allowed); } -void DownloadsUIBrowserTest::ChangeProfileToSupervised() { - ManagedUserServiceFactory::GetForProfile( - browser()->profile())->InitForTesting(); - content::RunAllPendingInMessageLoop(); +void DownloadsWebUIForSupervisedUsersTest::SetUpCommandLine( + CommandLine* command_line) { + command_line->AppendSwitch(switches::kNewProfileIsSupervised); } diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.h b/chrome/browser/ui/webui/downloads_ui_browsertest.h index f5370c8..d38ee1e 100644 --- a/chrome/browser/ui/webui/downloads_ui_browsertest.h +++ b/chrome/browser/ui/webui/downloads_ui_browsertest.h @@ -17,10 +17,14 @@ class DownloadsUIBrowserTest : public WebUIBrowserTest { // Sets the pref to allow or prohibit deleting history entries. void SetDeleteAllowed(bool allowed); - void ChangeProfileToSupervised(); - private: DISALLOW_COPY_AND_ASSIGN(DownloadsUIBrowserTest); }; +class DownloadsWebUIForSupervisedUsersTest : public DownloadsUIBrowserTest { + public: + // InProcessBrowserTest overrides: + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; +}; + #endif // CHROME_BROWSER_UI_WEBUI_DOWNLOADS_UI_BROWSERTEST_H_ diff --git a/chrome/browser/ui/webui/downloads_ui_browsertest.js b/chrome/browser/ui/webui/downloads_ui_browsertest.js index c55ca6f..f4e43c8 100644 --- a/chrome/browser/ui/webui/downloads_ui_browsertest.js +++ b/chrome/browser/ui/webui/downloads_ui_browsertest.js @@ -171,9 +171,7 @@ DownloadsWebUIForSupervisedUsersTest.prototype = { __proto__: BaseDownloadsWebUITest.prototype, /** @override */ - testGenPreamble: function() { - GEN(' ChangeProfileToSupervised();'); - }, + typedefCppFixture: 'DownloadsWebUIForSupervisedUsersTest', }; // Test UI for supervised users, removing entries should be disabled diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index a291c0a..cd8d761 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -1007,9 +1007,12 @@ const char kNativeMessagingHosts[] = "native-messaging-hosts"; // Intended primarily for use with --log-net-log. const char kNetLogLevel[] = "net-log-level"; +// Marks a newly created profile as a supervised profile. Used for tests. +const char kNewProfileIsSupervised[] = "new-profile-is-supervised"; + // Use new profile management system, including profile sign-out and new // choosers. -const char kNewProfileManagement[] = "new-profile-management"; +const char kNewProfileManagement[] = "new-profile-management"; // Disables the default browser check. Useful for UI/browser tests where we // want to avoid having the default browser info-bar displayed. diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index 86328bd..525345c 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -278,6 +278,7 @@ extern const char kMetricsRecordingOnly[]; extern const char kMultiProfiles[]; extern const char kNativeMessagingHosts[]; extern const char kNetLogLevel[]; +extern const char kNewProfileIsSupervised[]; extern const char kNewProfileManagement[]; extern const char kNoDefaultBrowserCheck[]; extern const char kNoDisplayingInsecureContent[]; diff --git a/chrome/test/base/testing_profile.cc b/chrome/test/base/testing_profile.cc index 138bb16..bc655aa 100644 --- a/chrome/test/base/testing_profile.cc +++ b/chrome/test/base/testing_profile.cc @@ -47,6 +47,7 @@ #include "chrome/browser/prefs/pref_service_syncable.h" #include "chrome/browser/prerender/prerender_manager.h" #include "chrome/browser/profiles/chrome_browser_main_extra_parts_profiles.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/profiles/storage_partition_descriptor.h" #include "chrome/browser/search_engines/template_url_fetcher_factory.h" #include "chrome/browser/webdata/web_data_service.h" @@ -230,6 +231,7 @@ TestingProfile::TestingProfile( scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, scoped_ptr<PrefServiceSyncable> prefs, bool incognito, + const std::string& managed_user_id, const TestingFactories& factories) : start_time_(Time::Now()), prefs_(prefs.release()), @@ -237,6 +239,7 @@ TestingProfile::TestingProfile( incognito_(incognito), force_incognito_(false), original_profile_(NULL), + managed_user_id_(managed_user_id), last_session_exited_cleanly_(true), extension_special_storage_policy_(extension_policy), profile_path_(path), @@ -355,6 +358,10 @@ void TestingProfile::FinishInit() { content::Source<Profile>(static_cast<Profile*>(this)), content::NotificationService::NoDetails()); + ProfileManager* profile_manager = g_browser_process->profile_manager(); + if (profile_manager) + profile_manager->InitProfileUserPrefs(this); + if (delegate_) delegate_->OnProfileCreated(this, true, false); } @@ -586,7 +593,7 @@ Profile* TestingProfile::GetOriginalProfile() { } bool TestingProfile::IsManaged() { - return !GetPrefs()->GetString(prefs::kManagedUserId).empty(); + return !managed_user_id_.empty(); } ExtensionService* TestingProfile::GetExtensionService() { @@ -866,6 +873,11 @@ void TestingProfile::Builder::SetIncognito() { incognito_ = true; } +void TestingProfile::Builder::SetManagedUserId( + const std::string& managed_user_id) { + managed_user_id_ = managed_user_id; +} + void TestingProfile::Builder::AddTestingFactory( BrowserContextKeyedServiceFactory* service_factory, BrowserContextKeyedServiceFactory::FactoryFunction callback) { @@ -875,11 +887,13 @@ void TestingProfile::Builder::AddTestingFactory( scoped_ptr<TestingProfile> TestingProfile::Builder::Build() { DCHECK(!build_called_); build_called_ = true; + return scoped_ptr<TestingProfile>(new TestingProfile( path_, delegate_, extension_policy_, pref_service_.Pass(), incognito_, + managed_user_id_, testing_factories_)); } diff --git a/chrome/test/base/testing_profile.h b/chrome/test/base/testing_profile.h index 4bcd052d..297cb95 100644 --- a/chrome/test/base/testing_profile.h +++ b/chrome/test/base/testing_profile.h @@ -100,6 +100,10 @@ class TestingProfile : public Profile { // Makes the Profile being built an incognito profile. void SetIncognito(); + // Sets the managed user ID (which is empty by default). If it is set to a + // non-empty string, the profile is managed. + void SetManagedUserId(const std::string& managed_user_id); + // Creates the TestingProfile using previously-set settings. scoped_ptr<TestingProfile> Build(); @@ -113,6 +117,7 @@ class TestingProfile : public Profile { base::FilePath path_; Delegate* delegate_; bool incognito_; + std::string managed_user_id_; TestingFactories testing_factories_; DISALLOW_COPY_AND_ASSIGN(Builder); @@ -138,6 +143,7 @@ class TestingProfile : public Profile { scoped_refptr<ExtensionSpecialStoragePolicy> extension_policy, scoped_ptr<PrefServiceSyncable> prefs, bool incognito, + const std::string& managed_user_id, const TestingFactories& factories); virtual ~TestingProfile(); @@ -348,6 +354,8 @@ class TestingProfile : public Profile { scoped_ptr<Profile> incognito_profile_; Profile* original_profile_; + std::string managed_user_id_; + // Did the last session exit cleanly? Default is true. bool last_session_exited_cleanly_; diff --git a/chrome/test/base/testing_profile_manager.cc b/chrome/test/base/testing_profile_manager.cc index 644760c..a5ef121 100644 --- a/chrome/test/base/testing_profile_manager.cc +++ b/chrome/test/base/testing_profile_manager.cc @@ -60,6 +60,8 @@ TestingProfile* TestingProfileManager::CreateTestingProfile( TestingProfile::Builder builder; builder.SetPath(profile_path); builder.SetPrefService(prefs.Pass()); + builder.SetManagedUserId(managed_user_id); + TestingProfile* profile = builder.Build().release(); profile_manager_->AddProfile(profile); // Takes ownership. |