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