| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/managed_mode/managed_user_constants.h" |
| 8 #include "chrome/browser/managed_mode/managed_user_service.h" | 9 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 9 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 10 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 10 #include "chrome/browser/policy/managed_mode_policy_provider.h" | 11 #include "chrome/browser/managed_mode/managed_user_settings_service.h" |
| 11 #include "chrome/browser/policy/profile_policy_connector.h" | 12 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" |
| 12 #include "chrome/browser/policy/profile_policy_connector_factory.h" | |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 18 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 20 #include "policy/policy_constants.h" | |
| 21 | 20 |
| 22 typedef InProcessBrowserTest ManagedUserServiceTest; | 21 typedef InProcessBrowserTest ManagedUserServiceTest; |
| 23 | 22 |
| 24 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) { | 23 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) { |
| 25 Profile* profile = browser()->profile(); | 24 Profile* profile = browser()->profile(); |
| 26 PrefService* prefs = profile->GetPrefs(); | 25 PrefService* prefs = profile->GetPrefs(); |
| 27 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 26 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 28 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 27 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); |
| 29 | 28 |
| 30 ManagedUserService* managed_user_service = | 29 ManagedUserService* managed_user_service = |
| 31 ManagedUserServiceFactory::GetForProfile(profile); | 30 ManagedUserServiceFactory::GetForProfile(profile); |
| 32 managed_user_service->InitForTesting(); | 31 managed_user_service->InitForTesting(); |
| 33 content::RunAllPendingInMessageLoop(); | |
| 34 | 32 |
| 35 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 33 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 36 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kForceSafeSearch)); | 34 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); |
| 37 } | 35 } |
| 38 | 36 |
| 39 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { | 37 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { |
| 40 Profile* profile = browser()->profile(); | 38 Profile* profile = browser()->profile(); |
| 41 PrefService* prefs = profile->GetPrefs(); | 39 PrefService* prefs = profile->GetPrefs(); |
| 42 EXPECT_FALSE(prefs->IsManagedPreference(prefs::kProfileName)); | 40 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName)); |
| 43 | 41 |
| 44 std::string original_name = prefs->GetString(prefs::kProfileName); | 42 std::string original_name = prefs->GetString(prefs::kProfileName); |
| 45 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 43 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 46 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 44 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 47 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 45 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 48 EXPECT_EQ(original_name, | 46 EXPECT_EQ(original_name, |
| 49 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 47 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 50 | 48 |
| 51 // Change the profile to a managed user. | 49 // Change the profile to a managed user. |
| 52 ManagedUserService* managed_user_service = | 50 ManagedUserService* managed_user_service = |
| 53 ManagedUserServiceFactory::GetForProfile(profile); | 51 ManagedUserServiceFactory::GetForProfile(profile); |
| 54 managed_user_service->InitForTesting(); | 52 managed_user_service->InitForTesting(); |
| 55 policy::ProfilePolicyConnector* connector = | 53 ManagedUserSettingsService* settings = |
| 56 policy::ProfilePolicyConnectorFactory::GetForProfile(profile); | 54 ManagedUserSettingsServiceFactory::GetForProfile(profile); |
| 57 policy::ManagedModePolicyProvider* provider = | |
| 58 connector->managed_mode_policy_provider(); | |
| 59 | 55 |
| 60 std::string name = "Managed User Test Name"; | 56 std::string name = "Managed User Test Name"; |
| 61 provider->SetLocalPolicyForTesting( | 57 settings->SetLocalSettingForTesting( |
| 62 policy::key::kUserDisplayName, | 58 managed_users::kUserName, |
| 63 scoped_ptr<base::Value>(new base::StringValue(name))); | 59 scoped_ptr<base::Value>(new base::StringValue(name))); |
| 64 content::RunAllPendingInMessageLoop(); | 60 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName)); |
| 65 EXPECT_TRUE(prefs->IsManagedPreference(prefs::kProfileName)); | |
| 66 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); | 61 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); |
| 67 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 62 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 68 EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 63 EXPECT_EQ(name, UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 69 | 64 |
| 70 // Change the name once more. | 65 // Change the name once more. |
| 71 std::string new_name = "New Managed User Test Name"; | 66 std::string new_name = "New Managed User Test Name"; |
| 72 provider->SetLocalPolicyForTesting( | 67 settings->SetLocalSettingForTesting( |
| 73 policy::key::kUserDisplayName, | 68 managed_users::kUserName, |
| 74 scoped_ptr<base::Value>(new base::StringValue(new_name))); | 69 scoped_ptr<base::Value>(new base::StringValue(new_name))); |
| 75 content::RunAllPendingInMessageLoop();; | |
| 76 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName)); | 70 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName)); |
| 77 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 71 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 78 EXPECT_EQ(new_name, | 72 EXPECT_EQ(new_name, |
| 79 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 73 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 80 | 74 |
| 81 // Remove the policy. | 75 // Remove the setting. |
| 82 provider->SetLocalPolicyForTesting(policy::key::kUserDisplayName, | 76 settings->SetLocalSettingForTesting(managed_users::kUserName, |
| 83 scoped_ptr<base::Value>()); | 77 scoped_ptr<base::Value>()); |
| 84 content::RunAllPendingInMessageLoop(); | |
| 85 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName)); | 78 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName)); |
| 86 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 79 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 87 EXPECT_EQ(original_name, | 80 EXPECT_EQ(original_name, |
| 88 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 81 UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 89 } | 82 } |
| OLD | NEW |