| 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/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_constants.h" | |
| 11 #include "chrome/browser/managed_mode/managed_user_service.h" | |
| 12 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | |
| 13 #include "chrome/browser/managed_mode/managed_user_settings_service.h" | |
| 14 #include "chrome/browser/managed_mode/managed_user_settings_service_factory.h" | |
| 15 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/profiles/profile_info_cache.h" | 11 #include "chrome/browser/profiles/profile_info_cache.h" |
| 17 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
| 13 #include "chrome/browser/supervised_user/supervised_user_constants.h" |
| 14 #include "chrome/browser/supervised_user/supervised_user_service.h" |
| 15 #include "chrome/browser/supervised_user/supervised_user_service_factory.h" |
| 16 #include "chrome/browser/supervised_user/supervised_user_settings_service.h" |
| 17 #include "chrome/browser/supervised_user/supervised_user_settings_service_factor
y.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/test/base/in_process_browser_test.h" | 21 #include "chrome/test/base/in_process_browser_test.h" |
| 22 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 23 #include "google_apis/gaia/google_service_auth_error.h" | 23 #include "google_apis/gaia/google_service_auth_error.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 void TestAuthErrorCallback(const GoogleServiceAuthError& error) {} | 27 void TestAuthErrorCallback(const GoogleServiceAuthError& error) {} |
| 28 | 28 |
| 29 class ManagedUserServiceTestManaged : public InProcessBrowserTest { | 29 class SupervisedUserServiceTestSupervised : public InProcessBrowserTest { |
| 30 public: | 30 public: |
| 31 // content::BrowserTestBase: | 31 // content::BrowserTestBase: |
| 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 33 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); | 33 command_line->AppendSwitchASCII(switches::kSupervisedUserId, "asdf"); |
| 34 } | 34 } |
| 35 }; | 35 }; |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 typedef InProcessBrowserTest ManagedUserServiceTest; | 39 typedef InProcessBrowserTest SupervisedUserServiceTest; |
| 40 | 40 |
| 41 // Crashes on Mac. | 41 // Crashes on Mac. |
| 42 // http://crbug.com/339501 | 42 // http://crbug.com/339501 |
| 43 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
| 44 #define MAYBE_ClearOmitOnRegistration DISABLED_ClearOmitOnRegistration | 44 #define MAYBE_ClearOmitOnRegistration DISABLED_ClearOmitOnRegistration |
| 45 #else | 45 #else |
| 46 #define MAYBE_ClearOmitOnRegistration ClearOmitOnRegistration | 46 #define MAYBE_ClearOmitOnRegistration ClearOmitOnRegistration |
| 47 #endif | 47 #endif |
| 48 // Ensure that a profile that has completed registration is included in the | 48 // Ensure that a profile that has completed registration is included in the |
| 49 // list shown in the avatar menu. | 49 // list shown in the avatar menu. |
| 50 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, MAYBE_ClearOmitOnRegistration) { | 50 IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, |
| 51 MAYBE_ClearOmitOnRegistration) { |
| 51 // Artificially mark the profile as omitted. | 52 // Artificially mark the profile as omitted. |
| 52 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 53 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 53 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 54 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 54 Profile* profile = browser()->profile(); | 55 Profile* profile = browser()->profile(); |
| 55 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 56 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 56 cache.SetIsOmittedProfileAtIndex(index, true); | 57 cache.SetIsOmittedProfileAtIndex(index, true); |
| 57 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index)); | 58 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index)); |
| 58 | 59 |
| 59 ManagedUserService* managed_user_service = | 60 SupervisedUserService* supervised_user_service = |
| 60 ManagedUserServiceFactory::GetForProfile(profile); | 61 SupervisedUserServiceFactory::GetForProfile(profile); |
| 61 | 62 |
| 62 // A registration error does not clear the flag (the profile should be deleted | 63 // A registration error does not clear the flag (the profile should be deleted |
| 63 // anyway). | 64 // anyway). |
| 64 managed_user_service->OnManagedUserRegistered( | 65 supervised_user_service->OnSupervisedUserRegistered( |
| 65 base::Bind(&TestAuthErrorCallback), | 66 base::Bind(&TestAuthErrorCallback), |
| 66 profile, | 67 profile, |
| 67 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), | 68 GoogleServiceAuthError(GoogleServiceAuthError::CONNECTION_FAILED), |
| 68 std::string()); | 69 std::string()); |
| 69 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index)); | 70 ASSERT_TRUE(cache.IsOmittedProfileAtIndex(index)); |
| 70 | 71 |
| 71 // Successfully completing registration clears the flag. | 72 // Successfully completing registration clears the flag. |
| 72 managed_user_service->OnManagedUserRegistered( | 73 supervised_user_service->OnSupervisedUserRegistered( |
| 73 base::Bind(&TestAuthErrorCallback), | 74 base::Bind(&TestAuthErrorCallback), |
| 74 profile, | 75 profile, |
| 75 GoogleServiceAuthError(GoogleServiceAuthError::NONE), | 76 GoogleServiceAuthError(GoogleServiceAuthError::NONE), |
| 76 std::string("abcdef")); | 77 std::string("abcdef")); |
| 77 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(index)); | 78 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(index)); |
| 78 } | 79 } |
| 79 | 80 |
| 80 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, LocalPolicies) { | 81 IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, LocalPolicies) { |
| 81 Profile* profile = browser()->profile(); | 82 Profile* profile = browser()->profile(); |
| 82 PrefService* prefs = profile->GetPrefs(); | 83 PrefService* prefs = profile->GetPrefs(); |
| 83 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 84 EXPECT_FALSE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 84 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); | 85 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); |
| 85 } | 86 } |
| 86 | 87 |
| 87 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTest, ProfileName) { | 88 IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTest, ProfileName) { |
| 88 Profile* profile = browser()->profile(); | 89 Profile* profile = browser()->profile(); |
| 89 PrefService* prefs = profile->GetPrefs(); | 90 PrefService* prefs = profile->GetPrefs(); |
| 90 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName)); | 91 EXPECT_TRUE(prefs->IsUserModifiablePreference(prefs::kProfileName)); |
| 91 | 92 |
| 92 std::string original_name = prefs->GetString(prefs::kProfileName); | 93 std::string original_name = prefs->GetString(prefs::kProfileName); |
| 93 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 94 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 94 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 95 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 95 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 96 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 96 EXPECT_EQ(original_name, | 97 EXPECT_EQ(original_name, |
| 97 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 98 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 98 } | 99 } |
| 99 | 100 |
| 100 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, LocalPolicies) { | 101 IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTestSupervised, LocalPolicies) { |
| 101 Profile* profile = browser()->profile(); | 102 Profile* profile = browser()->profile(); |
| 102 PrefService* prefs = profile->GetPrefs(); | 103 PrefService* prefs = profile->GetPrefs(); |
| 103 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); | 104 EXPECT_TRUE(prefs->GetBoolean(prefs::kForceSafeSearch)); |
| 104 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); | 105 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kForceSafeSearch)); |
| 105 } | 106 } |
| 106 | 107 |
| 107 IN_PROC_BROWSER_TEST_F(ManagedUserServiceTestManaged, ProfileName) { | 108 IN_PROC_BROWSER_TEST_F(SupervisedUserServiceTestSupervised, ProfileName) { |
| 108 Profile* profile = browser()->profile(); | 109 Profile* profile = browser()->profile(); |
| 109 PrefService* prefs = profile->GetPrefs(); | 110 PrefService* prefs = profile->GetPrefs(); |
| 110 std::string original_name = prefs->GetString(prefs::kProfileName); | 111 std::string original_name = prefs->GetString(prefs::kProfileName); |
| 111 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 112 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 112 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 113 const ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 113 | 114 |
| 114 ManagedUserSettingsService* settings = | 115 SupervisedUserSettingsService* settings = |
| 115 ManagedUserSettingsServiceFactory::GetForProfile(profile); | 116 SupervisedUserSettingsServiceFactory::GetForProfile(profile); |
| 116 | 117 |
| 117 std::string name = "Managed User Test Name"; | 118 std::string name = "Supervised User Test Name"; |
| 118 settings->SetLocalSettingForTesting( | 119 settings->SetLocalSettingForTesting( |
| 119 managed_users::kUserName, | 120 supervised_users::kUserName, |
| 120 scoped_ptr<base::Value>(new base::StringValue(name))); | 121 scoped_ptr<base::Value>(new base::StringValue(name))); |
| 121 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName)); | 122 EXPECT_FALSE(prefs->IsUserModifiablePreference(prefs::kProfileName)); |
| 122 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); | 123 EXPECT_EQ(name, prefs->GetString(prefs::kProfileName)); |
| 123 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 124 size_t profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 124 EXPECT_EQ(name, | 125 EXPECT_EQ(name, |
| 125 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 126 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 126 | 127 |
| 127 // Change the name once more. | 128 // Change the name once more. |
| 128 std::string new_name = "New Managed User Test Name"; | 129 std::string new_name = "New Supervised User Test Name"; |
| 129 settings->SetLocalSettingForTesting( | 130 settings->SetLocalSettingForTesting( |
| 130 managed_users::kUserName, | 131 supervised_users::kUserName, |
| 131 scoped_ptr<base::Value>(new base::StringValue(new_name))); | 132 scoped_ptr<base::Value>(new base::StringValue(new_name))); |
| 132 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName)); | 133 EXPECT_EQ(new_name, prefs->GetString(prefs::kProfileName)); |
| 133 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 134 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 134 EXPECT_EQ(new_name, | 135 EXPECT_EQ(new_name, |
| 135 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 136 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 136 | 137 |
| 137 // Remove the setting. | 138 // Remove the setting. |
| 138 settings->SetLocalSettingForTesting(managed_users::kUserName, | 139 settings->SetLocalSettingForTesting(supervised_users::kUserName, |
| 139 scoped_ptr<base::Value>()); | 140 scoped_ptr<base::Value>()); |
| 140 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName)); | 141 EXPECT_EQ(original_name, prefs->GetString(prefs::kProfileName)); |
| 141 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 142 profile_index = cache.GetIndexOfProfileWithPath(profile->GetPath()); |
| 142 EXPECT_EQ(original_name, | 143 EXPECT_EQ(original_name, |
| 143 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 144 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); |
| 144 } | 145 } |
| OLD | NEW |