#include "components/sync/service/sync_policy_handler.h"
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/values.h"
#include "build/chromeos_buildflags.h"
#include "components/policy/core/browser/policy_error_map.h"
#include "components/policy/core/common/policy_map.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/prefs/pref_value_map.h"
#include "components/sync/base/pref_names.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace syncer {
namespace {
TEST(SyncPolicyHandlerTest, Default) { … }
TEST(SyncPolicyHandlerTest, Enabled) { … }
TEST(SyncPolicyHandlerTest, Disabled) { … }
TEST(SyncPolicyHandlerTest, SyncTypesListDisabled) { … }
TEST(SyncPolicyHandlerTest, SyncTypesListDisabledAutofill) { … }
TEST(SyncPolicyHandlerTest, SyncTypesListDisabledInvalidEntry) { … }
TEST(SyncPolicyHandlerTest, SyncTypesListDisabledUnknownEntry) { … }
#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST(SyncPolicyHandlerOsTest, SyncTypesListDisabled_OsTypes) {
PrefValueMap prefs;
prefs.SetBoolean(prefs::internal::kSyncOsApps, true);
prefs.SetBoolean(prefs::internal::kSyncOsPreferences, true);
prefs.SetBoolean(prefs::internal::kSyncWifiConfigurations, true);
policy::PolicyMap policy;
auto disabled_types = base::Value::List()
.Append("osApps")
.Append("osPreferences")
.Append("osWifiConfigurations");
policy.Set(policy::key::kSyncTypesListDisabled,
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
policy::POLICY_SOURCE_CLOUD,
base::Value(std::move(disabled_types)), nullptr);
SyncPolicyHandler handler;
handler.ApplyPolicySettings(policy, &prefs);
bool enabled;
ASSERT_TRUE(prefs.GetBoolean(prefs::internal::kSyncOsApps, &enabled));
EXPECT_FALSE(enabled);
ASSERT_TRUE(prefs.GetBoolean(prefs::internal::kSyncOsPreferences, &enabled));
EXPECT_FALSE(enabled);
ASSERT_TRUE(
prefs.GetBoolean(prefs::internal::kSyncWifiConfigurations, &enabled));
EXPECT_FALSE(enabled);
}
TEST(SyncPolicyHandlerOsTest, SyncTypesListDisabled_MigratedTypes) {
PrefValueMap prefs;
prefs.SetBoolean(prefs::internal::kSyncOsApps, true);
prefs.SetBoolean(prefs::internal::kSyncOsPreferences, true);
policy::PolicyMap policy;
auto disabled_types = base::Value::List()
.Append("apps")
.Append("wifiConfigurations")
.Append("preferences");
policy.Set(policy::key::kSyncTypesListDisabled,
policy::POLICY_LEVEL_MANDATORY, policy::POLICY_SCOPE_USER,
policy::POLICY_SOURCE_CLOUD,
base::Value(std::move(disabled_types)), nullptr);
SyncPolicyHandler handler;
handler.ApplyPolicySettings(policy, &prefs);
bool enabled;
ASSERT_TRUE(prefs.GetBoolean(prefs::internal::kSyncOsApps, &enabled));
EXPECT_FALSE(enabled);
ASSERT_TRUE(
prefs.GetBoolean(prefs::internal::kSyncWifiConfigurations, &enabled));
EXPECT_FALSE(enabled);
ASSERT_TRUE(prefs.GetBoolean(prefs::internal::kSyncOsPreferences, &enabled));
EXPECT_FALSE(enabled);
}
#endif
}
}