Commit 799d1229 authored by pneubeck@chromium.org's avatar pneubeck@chromium.org

Revert 221410 "Add ManagedUserSettingsService and a SupervisedUs..."

Broke Linux ChromiumOS Tests (1):
http://build.chromium.org/p/chromium.chromiumos/buildstatus?builder=Linux%20ChromiumOS%20Tests%20%281%29&number=32217

> Add ManagedUserSettingsService and a SupervisedUserPrefStore using it.
> 
> BUG=280674
> 
> Review URL: https://chromiumcodereview.appspot.com/23466004

TBR=bauerb@chromium.org

Review URL: https://codereview.chromium.org/23477040

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221411 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f98008b
// Copyright 2013 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 "chrome/browser/managed_mode/managed_user_constants.h"
namespace managed_users {
const char kContentPackDefaultFilteringBehavior[] =
"ContentPackDefaultFilteringBehavior";
const char kContentPackManualBehaviorHosts[] = "ContentPackManualBehaviorHosts";
const char kContentPackManualBehaviorURLs[] = "ContentPackManualBehaviorURLs";
const char kForceSafeSearch[] = "ForceSafeSearch";
const char kSigninAllowed[] = "SigninAllowed";
const char kUserName[] = "UserName";
} // namespace managed_users
// Copyright 2013 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.
#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_CONSTANTS_H_
#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_CONSTANTS_H_
namespace managed_users {
// Keys for managed user settings. These are configured remotely and mapped to
// preferences by the SupervisedUserPrefStore.
extern const char kContentPackDefaultFilteringBehavior[];
extern const char kContentPackManualBehaviorHosts[];
extern const char kContentPackManualBehaviorURLs[];
extern const char kForceSafeSearch[];
extern const char kSigninAllowed[];
extern const char kUserName[];
} // namespace managed_users
#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_CONSTANTS_H_
// Copyright 2013 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 "chrome/browser/managed_mode/managed_user_settings_service.h"
#include "base/callback.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/prefs/json_pref_store.h"
#include "base/strings/string_util.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/common/chrome_constants.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/user_metrics.h"
using base::DictionaryValue;
using base::Value;
using content::BrowserThread;
using content::UserMetricsAction;
const char kAtomicSettings[] = "atomic_settings";
const char kManagedUserInternalItemPrefix[] = "X-";
const char kQueuedItems[] = "queued_items";
const char kSplitSettingKeySeparator = ':';
const char kSplitSettings[] = "split_settings";
namespace {
bool SettingShouldApplyToPrefs(const std::string& name) {
return !StartsWithASCII(name, kManagedUserInternalItemPrefix, false);
}
} // namespace
ManagedUserSettingsService::ManagedUserSettingsService()
: active_(false), local_settings_(new DictionaryValue) {}
ManagedUserSettingsService::~ManagedUserSettingsService() {}
void ManagedUserSettingsService::Init(
scoped_refptr<PersistentPrefStore> store) {
DCHECK(!store_);
store_ = store;
store_->AddObserver(this);
}
void ManagedUserSettingsService::Subscribe(const SettingsCallback& callback) {
if (IsReady()) {
scoped_ptr<base::DictionaryValue> settings = GetSettings();
callback.Run(settings.get());
}
subscribers_.push_back(callback);
}
void ManagedUserSettingsService::Activate() {
active_ = true;
InformSubscribers();
}
bool ManagedUserSettingsService::IsReady() {
return store_->IsInitializationComplete();
}
void ManagedUserSettingsService::Clear() {
store_->RemoveValue(kAtomicSettings);
store_->RemoveValue(kSplitSettings);
}
void ManagedUserSettingsService::SetLocalSettingForTesting(
const std::string& key,
scoped_ptr<Value> value) {
if (value)
local_settings_->SetWithoutPathExpansion(key, value.release());
else
local_settings_->RemoveWithoutPathExpansion(key, NULL);
InformSubscribers();
}
void ManagedUserSettingsService::Shutdown() {
store_->RemoveObserver(this);
}
void ManagedUserSettingsService::OnPrefValueChanged(const std::string& key) {}
void ManagedUserSettingsService::OnInitializationCompleted(bool success) {
DCHECK(success);
DCHECK(IsReady());
InformSubscribers();
}
DictionaryValue* ManagedUserSettingsService::GetOrCreateDictionary(
const std::string& key) const {
Value* value = NULL;
DictionaryValue* dict = NULL;
if (store_->GetMutableValue(key, &value)) {
bool success = value->GetAsDictionary(&dict);
DCHECK(success);
} else {
dict = new base::DictionaryValue;
store_->SetValue(key, dict);
}
return dict;
}
DictionaryValue* ManagedUserSettingsService::GetAtomicSettings() const {
return GetOrCreateDictionary(kAtomicSettings);
}
DictionaryValue* ManagedUserSettingsService::GetSplitSettings() const {
return GetOrCreateDictionary(kSplitSettings);
}
DictionaryValue* ManagedUserSettingsService::GetQueuedItems() const {
return GetOrCreateDictionary(kQueuedItems);
}
scoped_ptr<DictionaryValue> ManagedUserSettingsService::GetSettings() {
DCHECK(IsReady());
if (!active_)
return scoped_ptr<base::DictionaryValue>();
scoped_ptr<DictionaryValue> settings(local_settings_->DeepCopy());
DictionaryValue* atomic_settings = GetAtomicSettings();
for (DictionaryValue::Iterator it(*atomic_settings); !it.IsAtEnd();
it.Advance()) {
if (!SettingShouldApplyToPrefs(it.key()))
continue;
settings->Set(it.key(), it.value().DeepCopy());
}
DictionaryValue* split_settings = GetSplitSettings();
for (DictionaryValue::Iterator it(*split_settings); !it.IsAtEnd();
it.Advance()) {
if (!SettingShouldApplyToPrefs(it.key()))
continue;
settings->Set(it.key(), it.value().DeepCopy());
}
return settings.Pass();
}
void ManagedUserSettingsService::InformSubscribers() {
if (!IsReady())
return;
scoped_ptr<base::DictionaryValue> settings = GetSettings();
for (std::vector<SettingsCallback>::iterator it = subscribers_.begin();
it != subscribers_.end(); ++it) {
it->Run(settings.get());
}
}
// Copyright 2013 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.
#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
#include <string>
#include <vector>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/prefs/pref_store.h"
#include "base/values.h"
#include "chrome/browser/managed_mode/managed_users.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service.h"
class PersistentPrefStore;
class Profile;
namespace base {
class FilePath;
class SequencedTaskRunner;
}
// TODO(bauerb): This class is not yet fully functional.
// This class syncs managed user settings from a server, which are mapped to
// preferences. The downloaded settings are persisted in a PrefStore (which is
// not directly hooked up to the PrefService; it's just used internally).
// Settings are key-value pairs, where the key uniquely identifies the setting.
// The value is a string containing a JSON serialization of an arbitrary value,
// which is the value of the setting.
//
// There are two kinds of settings handled by this class: Atomic and split
// settings.
// Atomic settings consist of a single key (which will be mapped to a pref key)
// and a single (arbitrary) value.
// Split settings encode a dictionary value and are stored as multiple Sync
// items, one for each dictionary entry. The key for each of these Sync items
// is the key of the split setting, followed by a separator (':') and the key
// for the dictionary entry. The value of the Sync item is the value of the
// dictionary entry.
//
// As an example, a split setting with key "Moose" and value
// {
// "foo": "bar",
// "baz": "blurp"
// }
// would be encoded as two sync items, one with key "Moose:foo" and value "bar",
// and one with key "Moose:baz" and value "blurp".
class ManagedUserSettingsService : public BrowserContextKeyedService,
public PrefStore::Observer {
public:
// A callback whose first parameter is a dictionary containing all managed
// user settings. If the dictionary is NULL, it means that the service is
// inactive, i.e. the user is not managed.
typedef base::Callback<void(const base::DictionaryValue*)> SettingsCallback;
ManagedUserSettingsService();
virtual ~ManagedUserSettingsService();
// Initializes the service by loading its settings from the |pref_store|.
// Use this method in tests to inject a different PrefStore than the
// default one.
void Init(scoped_refptr<PersistentPrefStore> pref_store);
// Adds a callback to be called when managed user settings are initially
// available, or when they change.
void Subscribe(const SettingsCallback& callback);
// Activates the service. This happens when the user is managed.
void Activate();
// Whether managed user settings are available.
bool IsReady();
// Clears all managed user settings and items.
void Clear();
// Sets the setting with the given |key| to a copy of the given |value|.
void SetLocalSettingForTesting(const std::string& key,
scoped_ptr<base::Value> value);
// BrowserContextKeyedService implementation:
virtual void Shutdown() OVERRIDE;
// PrefStore::Observer implementation:
virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
virtual void OnInitializationCompleted(bool success) OVERRIDE;
private:
base::DictionaryValue* GetOrCreateDictionary(const std::string& key) const;
base::DictionaryValue* GetAtomicSettings() const;
base::DictionaryValue* GetSplitSettings() const;
base::DictionaryValue* GetQueuedItems() const;
// Returns a dictionary with all managed user settings if the service is
// active, or NULL otherwise.
scoped_ptr<base::DictionaryValue> GetSettings();
// Sends the settings to all subscribers. This method should be called by the
// subclass whenever the settings change.
void InformSubscribers();
// Used for persisting the settings. Unlike other PrefStores, this one is not
// directly hooked up to the PrefService.
scoped_refptr<PersistentPrefStore> store_;
bool active_;
// A set of local settings that are fixed and not configured remotely.
scoped_ptr<base::DictionaryValue> local_settings_;
std::vector<SettingsCallback> subscribers_;
DISALLOW_COPY_AND_ASSIGN(ManagedUserSettingsService);
};
#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_H_
// Copyright 2013 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 "chrome/browser/managed_mode/managed_user_settings_service_factory.h"
#include "chrome/browser/managed_mode/managed_user_settings_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
// static
ManagedUserSettingsService*
ManagedUserSettingsServiceFactory::GetForProfile(Profile* profile) {
return static_cast<ManagedUserSettingsService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
ManagedUserSettingsServiceFactory*
ManagedUserSettingsServiceFactory::GetInstance() {
return Singleton<ManagedUserSettingsServiceFactory>::get();
}
ManagedUserSettingsServiceFactory::ManagedUserSettingsServiceFactory()
: BrowserContextKeyedServiceFactory(
"ManagedUserSettingsService",
BrowserContextDependencyManager::GetInstance()) {
}
ManagedUserSettingsServiceFactory::
~ManagedUserSettingsServiceFactory() {}
BrowserContextKeyedService*
ManagedUserSettingsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const {
return new ManagedUserSettingsService();
}
content::BrowserContext*
ManagedUserSettingsServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
// Copyright 2013 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.
#ifndef CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_FACTORY_H_
#define CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_FACTORY_H_
#include "base/memory/singleton.h"
#include "chrome/browser/managed_mode/managed_users.h"
#include "components/browser_context_keyed_service/browser_context_keyed_service_factory.h"
class ManagedUserSettingsService;
class Profile;
class ManagedUserSettingsServiceFactory
: public BrowserContextKeyedServiceFactory {
public:
static ManagedUserSettingsService* GetForProfile(Profile* profile);
static ManagedUserSettingsServiceFactory* GetInstance();
private:
friend struct DefaultSingletonTraits<ManagedUserSettingsServiceFactory>;
ManagedUserSettingsServiceFactory();
virtual ~ManagedUserSettingsServiceFactory();
// BrowserContextKeyedServiceFactory:
virtual BrowserContextKeyedService* BuildServiceInstanceFor(
content::BrowserContext* profile) const OVERRIDE;
virtual content::BrowserContext* GetBrowserContextToUse(
content::BrowserContext* context) const OVERRIDE;
};
#endif // CHROME_BROWSER_MANAGED_MODE_MANAGED_USER_SETTINGS_SERVICE_FACTORY_H_
// Copyright 2013 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/bind.h"
#include "base/callback.h"
#include "base/prefs/testing_pref_store.h"
#include "chrome/browser/managed_mode/managed_user_settings_service.h"
#include "testing/gtest/include/gtest/gtest.h"
const char kAtomicItemName[] = "X-Wombat";
const char kSettingsName[] = "TestingSetting";
const char kSettingsValue[] = "SettingsValue";
const char kSplitItemName[] = "X-SuperMoosePowers";
class ManagedUserSettingsServiceTest : public ::testing::Test {
protected:
ManagedUserSettingsServiceTest() {}
virtual ~ManagedUserSettingsServiceTest() {}
void OnNewSettingsAvailable(const base::DictionaryValue* settings) {
if (!settings)
settings_.reset();
else
settings_.reset(settings->DeepCopy());
}
// testing::Test overrides:
virtual void SetUp() OVERRIDE {
TestingPrefStore* pref_store = new TestingPrefStore;
settings_service_.Init(pref_store);
settings_service_.Subscribe(
base::Bind(&ManagedUserSettingsServiceTest::OnNewSettingsAvailable,
base::Unretained(this)));
pref_store->SetInitializationCompleted();
ASSERT_FALSE(settings_);
settings_service_.Activate();
ASSERT_TRUE(settings_);
}
virtual void TearDown() OVERRIDE {
settings_service_.Shutdown();
}
base::DictionaryValue split_items_;
scoped_ptr<base::Value> atomic_setting_value_;
ManagedUserSettingsService settings_service_;
scoped_ptr<base::DictionaryValue> settings_;
};
TEST_F(ManagedUserSettingsServiceTest, SetLocalSetting) {
const base::Value* value = NULL;
EXPECT_FALSE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
settings_.reset();
settings_service_.SetLocalSettingForTesting(
kSettingsName,
scoped_ptr<base::Value>(new base::StringValue(kSettingsValue)));
ASSERT_TRUE(settings_);
ASSERT_TRUE(settings_->GetWithoutPathExpansion(kSettingsName, &value));
std::string string_value;
EXPECT_TRUE(value->GetAsString(&string_value));
EXPECT_EQ(kSettingsValue, string_value);
}
// Copyright 2013 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 "chrome/browser/managed_mode/supervised_user_pref_store.h"
#include "base/bind.h"
#include "base/prefs/pref_value_map.h"
#include "base/values.h"
#include "chrome/browser/managed_mode/managed_mode_url_filter.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_settings_service.h"
#include "chrome/browser/prefs/incognito_mode_prefs.h"
#include "chrome/common/pref_names.h"
using base::FundamentalValue;
namespace {
struct ManagedUserSettingsPrefMappingEntry {
const char* settings_name;
const char* pref_name;
};
ManagedUserSettingsPrefMappingEntry kManagedUserSettingsPrefMapping[] = {
{
managed_users::kContentPackDefaultFilteringBehavior,
prefs::kDefaultManagedModeFilteringBehavior,
},
{
managed_users::kContentPackManualBehaviorHosts,
prefs::kManagedModeManualHosts,
},
{
managed_users::kContentPackManualBehaviorURLs,
prefs::kManagedModeManualURLs,
},
{
managed_users::kForceSafeSearch,
prefs::kForceSafeSearch,
},
{
managed_users::kUserName,
prefs::kProfileName,
},
};
} // namespace
SupervisedUserPrefStore::SupervisedUserPrefStore(
ManagedUserSettingsService* managed_user_settings_service)
: weak_ptr_factory_(this) {
managed_user_settings_service->Subscribe(
base::Bind(&SupervisedUserPrefStore::OnNewSettingsAvailable,
weak_ptr_factory_.GetWeakPtr()));
}
bool SupervisedUserPrefStore::GetValue(const std::string& key,
const base::Value** value) const {
DCHECK(prefs_);
return prefs_->GetValue(key, value);
}
void SupervisedUserPrefStore::AddObserver(PrefStore::Observer* observer) {
observers_.AddObserver(observer);
}
void SupervisedUserPrefStore::RemoveObserver(PrefStore::Observer* observer) {
observers_.RemoveObserver(observer);
}
bool SupervisedUserPrefStore::HasObservers() const {
return observers_.might_have_observers();
}
bool SupervisedUserPrefStore::IsInitializationComplete() const {
return !!prefs_;
}
SupervisedUserPrefStore::~SupervisedUserPrefStore() {
}
void SupervisedUserPrefStore::OnNewSettingsAvailable(
const base::DictionaryValue* settings) {
scoped_ptr<PrefValueMap> old_prefs = prefs_.Pass();
prefs_.reset(new PrefValueMap);
if (settings) {
// Set hardcoded prefs.
prefs_->SetValue(prefs::kAllowDeletingBrowserHistory,
new FundamentalValue(false));
prefs_->SetValue(prefs::kDefaultManagedModeFilteringBehavior,
new FundamentalValue(ManagedModeURLFilter::ALLOW));
prefs_->SetValue(prefs::kForceSafeSearch, new FundamentalValue(true));
prefs_->SetValue(prefs::kHideWebStoreIcon, new FundamentalValue(true));
prefs_->SetValue(prefs::kIncognitoModeAvailability,
new FundamentalValue(IncognitoModePrefs::DISABLED));
prefs_->SetValue(prefs::kSigninAllowed, new FundamentalValue(false));
// Copy managed user settings to prefs.
for (size_t i = 0; i < arraysize(kManagedUserSettingsPrefMapping); ++i) {
const ManagedUserSettingsPrefMappingEntry& entry =
kManagedUserSettingsPrefMapping[i];
const base::Value* value = NULL;
if (settings->GetWithoutPathExpansion(entry.settings_name, &value))
prefs_->SetValue(entry.pref_name, value->DeepCopy());
}
}
if (!old_prefs) {
FOR_EACH_OBSERVER(Observer, observers_, OnInitializationCompleted(true));
return;
}
std::vector<std::string> changed_prefs;
prefs_->GetDifferingKeys(old_prefs.get(), &changed_prefs);
// Send out change notifications.
for (std::vector<std::string>::const_iterator pref(changed_prefs.begin());
pref != changed_prefs.end();
++pref) {
FOR_EACH_OBSERVER(
PrefStore::Observer, observers_, OnPrefValueChanged(*pref));
}
}
// Copyright 2013 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.
#ifndef CHROME_BROWSER_MANAGED_MODE_SUPERVISED_USER_PREF_STORE_H_
#define CHROME_BROWSER_MANAGED_MODE_SUPERVISED_USER_PREF_STORE_H_
#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
#include "base/prefs/pref_store.h"
#include "chrome/browser/managed_mode/managed_users.h"
namespace base {
class DictionaryValue;
class Value;
}
class ManagedUserSettingsService;
class PrefValueMap;
// A PrefStore that gets its values from managed user settings via the
// ManagedUserSettingsService passed in at construction.
class SupervisedUserPrefStore : public PrefStore {
public:
SupervisedUserPrefStore(
ManagedUserSettingsService* managed_user_settings_service);
// PrefStore overrides:
virtual bool GetValue(const std::string& key,
const base::Value** value) const OVERRIDE;
virtual void AddObserver(PrefStore::Observer* observer) OVERRIDE;
virtual void RemoveObserver(PrefStore::Observer* observer) OVERRIDE;
virtual bool HasObservers() const OVERRIDE;
virtual bool IsInitializationComplete() const OVERRIDE;
private:
virtual ~SupervisedUserPrefStore();
void OnNewSettingsAvailable(const base::DictionaryValue* settings);
base::WeakPtrFactory<SupervisedUserPrefStore> weak_ptr_factory_;
scoped_ptr<PrefValueMap> prefs_;
ObserverList<PrefStore::Observer, true> observers_;
};
#endif // CHROME_BROWSER_MANAGED_MODE_SUPERVISED_USER_PREF_STORE_H_
// Copyright 2013 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 <set>
#include <string>
#include "base/memory/ref_counted.h"
#include "base/prefs/testing_pref_store.h"
#include "base/values.h"
#include "chrome/browser/managed_mode/managed_user_constants.h"
#include "chrome/browser/managed_mode/managed_user_settings_service.h"
#include "chrome/browser/managed_mode/supervised_user_pref_store.h"
#include "chrome/common/pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::DictionaryValue;
using base::Value;
namespace {
class SupervisedUserPrefStoreFixture : public PrefStore::Observer {
public:
explicit SupervisedUserPrefStoreFixture(
ManagedUserSettingsService* settings_service);
virtual ~SupervisedUserPrefStoreFixture();
DictionaryValue* changed_prefs() {
return &changed_prefs_;
}
bool initialization_completed() const {
return initialization_completed_;
}
// PrefStore::Observer implementation:
virtual void OnPrefValueChanged(const std::string& key) OVERRIDE;
virtual void OnInitializationCompleted(bool succeeded) OVERRIDE;
private:
scoped_refptr<SupervisedUserPrefStore> pref_store_;
DictionaryValue changed_prefs_;
bool initialization_completed_;
};
SupervisedUserPrefStoreFixture::SupervisedUserPrefStoreFixture(
ManagedUserSettingsService* settings_service)
: pref_store_(new SupervisedUserPrefStore(settings_service)),
initialization_completed_(pref_store_->IsInitializationComplete()) {
pref_store_->AddObserver(this);
}
SupervisedUserPrefStoreFixture::~SupervisedUserPrefStoreFixture() {
pref_store_->RemoveObserver(this);
}
void SupervisedUserPrefStoreFixture::OnPrefValueChanged(
const std::string& key) {
const Value* value = NULL;
ASSERT_TRUE(pref_store_->GetValue(key, &value));
changed_prefs_.Set(key, value->DeepCopy());
}
void SupervisedUserPrefStoreFixture::OnInitializationCompleted(bool succeeded) {
EXPECT_FALSE(initialization_completed_);
EXPECT_TRUE(succeeded);
EXPECT_TRUE(pref_store_->IsInitializationComplete());
initialization_completed_ = true;
}
} // namespace
class SupervisedUserPrefStoreTest : public ::testing::Test {
public:
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
protected:
ManagedUserSettingsService service_;
scoped_refptr<TestingPrefStore> pref_store_;
};
void SupervisedUserPrefStoreTest::SetUp() {
pref_store_ = new TestingPrefStore();
service_.Init(pref_store_);
}
void SupervisedUserPrefStoreTest::TearDown() {
service_.Shutdown();
}
TEST_F(SupervisedUserPrefStoreTest, ConfigureSettings) {
SupervisedUserPrefStoreFixture fixture(&service_);
EXPECT_FALSE(fixture.initialization_completed());
// Prefs should not change yet when the service is ready, but not
// activated yet.
pref_store_->SetInitializationCompleted();
EXPECT_TRUE(fixture.initialization_completed());
EXPECT_EQ(0u, fixture.changed_prefs()->size());
service_.Activate();
// kAllowDeletingBrowserHistory is hardcoded to false for managed users.
bool allow_deleting_browser_history = true;
EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(
prefs::kAllowDeletingBrowserHistory, &allow_deleting_browser_history));
EXPECT_FALSE(allow_deleting_browser_history);
// kManagedModeManualHosts does not have a hardcoded value.
DictionaryValue* manual_hosts = NULL;
EXPECT_FALSE(fixture.changed_prefs()->GetDictionary(
prefs::kManagedModeManualHosts, &manual_hosts));
// kForceSafeSearch defaults to true for managed users.
bool force_safesearch = false;
EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch,
&force_safesearch));
EXPECT_TRUE(force_safesearch);
// Activating the service again should not change anything.
fixture.changed_prefs()->Clear();
service_.Activate();
EXPECT_EQ(0u, fixture.changed_prefs()->size());
// kManagedModeManualHosts can be configured by the custodian.
scoped_ptr<DictionaryValue> dict(new DictionaryValue);
dict->SetBoolean("example.com", true);
dict->SetBoolean("moose.org", false);
service_.SetLocalSettingForTesting(
managed_users::kContentPackManualBehaviorHosts,
scoped_ptr<Value>(dict->DeepCopy()));
EXPECT_EQ(1u, fixture.changed_prefs()->size());
ASSERT_TRUE(fixture.changed_prefs()->GetDictionary(
prefs::kManagedModeManualHosts, &manual_hosts));
EXPECT_TRUE(manual_hosts->Equals(dict.get()));
// kForceSafeSearch can be configured by the custodian, overriding the
// hardcoded default.
fixture.changed_prefs()->Clear();
service_.SetLocalSettingForTesting(
managed_users::kForceSafeSearch,
scoped_ptr<Value>(new base::FundamentalValue(false)));
EXPECT_EQ(1u, fixture.changed_prefs()->size());
EXPECT_TRUE(fixture.changed_prefs()->GetBoolean(prefs::kForceSafeSearch,
&force_safesearch));
EXPECT_FALSE(force_safesearch);
}
TEST_F(SupervisedUserPrefStoreTest, ActivateSettingsBeforeInitialization) {
SupervisedUserPrefStoreFixture fixture(&service_);
EXPECT_FALSE(fixture.initialization_completed());
service_.Activate();
EXPECT_FALSE(fixture.initialization_completed());
EXPECT_EQ(0u, fixture.changed_prefs()->size());
pref_store_->SetInitializationCompleted();
EXPECT_TRUE(fixture.initialization_completed());
EXPECT_EQ(0u, fixture.changed_prefs()->size());
}
TEST_F(SupervisedUserPrefStoreTest, CreatePrefStoreAfterInitialization) {
pref_store_->SetInitializationCompleted();
service_.Activate();
SupervisedUserPrefStoreFixture fixture(&service_);
EXPECT_TRUE(fixture.initialization_completed());
EXPECT_EQ(0u, fixture.changed_prefs()->size());
}
...@@ -966,18 +966,12 @@ ...@@ -966,18 +966,12 @@
'browser/managed_mode/managed_mode_site_list.h', 'browser/managed_mode/managed_mode_site_list.h',
'browser/managed_mode/managed_mode_url_filter.cc', 'browser/managed_mode/managed_mode_url_filter.cc',
'browser/managed_mode/managed_mode_url_filter.h', 'browser/managed_mode/managed_mode_url_filter.h',
'browser/managed_mode/managed_user_constants.cc',
'browser/managed_mode/managed_user_constants.h',
'browser/managed_mode/managed_user_refresh_token_fetcher.cc', 'browser/managed_mode/managed_user_refresh_token_fetcher.cc',
'browser/managed_mode/managed_user_refresh_token_fetcher.h', 'browser/managed_mode/managed_user_refresh_token_fetcher.h',
'browser/managed_mode/managed_user_registration_utility.cc', 'browser/managed_mode/managed_user_registration_utility.cc',
'browser/managed_mode/managed_user_registration_utility.h', 'browser/managed_mode/managed_user_registration_utility.h',
'browser/managed_mode/managed_user_registration_utility_stub.cc', 'browser/managed_mode/managed_user_registration_utility_stub.cc',
'browser/managed_mode/managed_user_registration_utility_stub.h', 'browser/managed_mode/managed_user_registration_utility_stub.h',
'browser/managed_mode/managed_user_settings_service.cc',
'browser/managed_mode/managed_user_settings_service.h',
'browser/managed_mode/managed_user_settings_service_factory.cc',
'browser/managed_mode/managed_user_settings_service_factory.h',
'browser/managed_mode/managed_user_service.cc', 'browser/managed_mode/managed_user_service.cc',
'browser/managed_mode/managed_user_service.h', 'browser/managed_mode/managed_user_service.h',
'browser/managed_mode/managed_user_service_factory.cc', 'browser/managed_mode/managed_user_service_factory.cc',
...@@ -990,8 +984,6 @@ ...@@ -990,8 +984,6 @@
'browser/managed_mode/managed_user_theme.cc', 'browser/managed_mode/managed_user_theme.cc',
'browser/managed_mode/managed_user_theme.h', 'browser/managed_mode/managed_user_theme.h',
'browser/managed_mode/managed_users.h', 'browser/managed_mode/managed_users.h',
'browser/managed_mode/supervised_user_pref_store.cc',
'browser/managed_mode/supervised_user_pref_store.h',
'browser/media/audio_stream_indicator.cc', 'browser/media/audio_stream_indicator.cc',
'browser/media/audio_stream_indicator.h', 'browser/media/audio_stream_indicator.h',
'browser/media/chrome_midi_permission_context.cc', 'browser/media/chrome_midi_permission_context.cc',
...@@ -3338,7 +3330,7 @@ ...@@ -3338,7 +3330,7 @@
['enable_managed_users!=1', { ['enable_managed_users!=1', {
'sources/': [ 'sources/': [
['exclude', '^browser/managed_mode/'], ['exclude', '^browser/managed_mode/'],
], ]
}], }],
['enable_webrtc==0', { ['enable_webrtc==0', {
'sources!': [ 'sources!': [
......
...@@ -969,8 +969,6 @@ ...@@ -969,8 +969,6 @@
'browser/managed_mode/managed_user_sync_service_unittest.cc', 'browser/managed_mode/managed_user_sync_service_unittest.cc',
'browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc', 'browser/managed_mode/managed_user_refresh_token_fetcher_unittest.cc',
'browser/managed_mode/managed_user_registration_utility_unittest.cc', 'browser/managed_mode/managed_user_registration_utility_unittest.cc',
'browser/managed_mode/managed_user_settings_service_unittest.cc',
'browser/managed_mode/supervised_user_pref_store_unittest.cc',
'browser/media/desktop_media_picker_model_unittest.cc', 'browser/media/desktop_media_picker_model_unittest.cc',
'browser/media/webrtc_log_uploader_unittest.cc', 'browser/media/webrtc_log_uploader_unittest.cc',
'browser/media_galleries/fileapi/native_media_file_util_unittest.cc', 'browser/media_galleries/fileapi/native_media_file_util_unittest.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment