chromium/components/policy/core/common/policy_service_impl_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/policy/core/common/policy_service_impl.h"

#include <memory>
#include <utility>

#include "base/containers/flat_set.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/strcat.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/policy/core/common/external_data_fetcher.h"
#include "components/policy/core/common/mock_configuration_policy_provider.h"
#include "components/policy/core/common/mock_policy_service.h"
#include "components/policy/core/common/policy_migrator.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/strings/grit/components_strings.h"
#include "extensions/buildflags/buildflags.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

_;
AnyNumber;
Invoke;
IsEmpty;
Mock;
Return;

namespace policy {

namespace {

const char kExtension[] =;
const char kSameLevelPolicy[] =;
const char kDiffLevelPolicy[] =;
const std::string kUrl1 =;
const std::string kUrl2 =;
const std::string kUrl3 =;

#if !BUILDFLAG(IS_IOS)
const std::string kUrl4 =;
#endif

const std::string kAffiliationId1 =;
const std::string kAffiliationId2 =;

// Helper to compare the arguments to an EXPECT_CALL of OnPolicyUpdated() with
// their expected values.
MATCHER_P(PolicyEquals, expected, "") {}

// Helper to compare the arguments to an EXPECT_CALL of OnPolicyValueUpdated()
// with their expected values.
MATCHER_P(ValueEquals, expected, "") {}

// Helper that fills |bundle| with test policies.
void AddTestPolicies(PolicyBundle* bundle,
                     const char* value,
                     PolicyLevel level,
                     PolicyScope scope) {}

// Observer class that changes the policy in the passed provider when the
// callback is invoked.
class ChangePolicyObserver : public PolicyService::Observer {};

class MockPolicyMigrator : public PolicyMigrator {};

}  // namespace

class PolicyServiceTest : public testing::Test {};

TEST_F(PolicyServiceTest, LoadsPoliciesBeforeProvidersRefresh) {}

TEST_F(PolicyServiceTest, NotifyObservers) {}

TEST_F(PolicyServiceTest, NotifyObserversInMultipleNamespaces) {}

TEST_F(PolicyServiceTest, ObserverChangesPolicy) {}

TEST_F(PolicyServiceTest, HasProvider) {}

TEST_F(PolicyServiceTest, NotifyProviderUpdateObserver) {}

TEST_F(PolicyServiceTest, Priorities) {}

TEST_F(PolicyServiceTest, PolicyChangeRegistrar) {}

TEST_F(PolicyServiceTest, RefreshPolicies) {}

TEST_F(PolicyServiceTest, NamespaceMerge) {}

TEST_F(PolicyServiceTest, IsInitializationComplete) {}

DomainParameters;
ObserverTestParameters;

class PolicyServiceTestForObservers
    : public testing::Test,
      public testing::WithParamInterface<ObserverTestParameters> {};

TEST_P(PolicyServiceTestForObservers, MaybeNotifyPolicyDomainStatusChange) {}

INSTANTIATE_TEST_SUITE_P();

TEST_F(PolicyServiceTest, IsInitializationCompleteMightDestroyThis) {}

// Tests initialization throttling of PolicyServiceImpl.
// This actually tests two cases:
// (1) A domain was initialized before UnthrottleInitialization is called.
//     Observers only get notified after calling UnthrottleInitialization.
//     This is tested on POLICY_DOMAIN_CHROME.
// (2) A domain becomes initialized after UnthrottleInitialization has already
//     been called. Because initialization is not throttled anymore, observers
//     get notified immediately when the domain becomes initialized.
//     This is tested on POLICY_DOMAIN_EXTENSIONS and
//     POLICY_DOMAIN_SIGNIN_EXTENSIONS.
TEST_F(PolicyServiceTest, InitializationThrottled) {}

TEST_F(PolicyServiceTest, InitializationThrottledProvidersAlreadyInitialized) {}

TEST_F(PolicyServiceTest, IsFirstPolicyLoadComplete) {}

#if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_ANDROID) && !BUILDFLAG(IS_IOS)
TEST_F(PolicyServiceTest, DictionaryPoliciesMerging) {}

TEST_F(PolicyServiceTest, DictionaryPoliciesMerging_InvalidType) {}

// Policy precedence changes are not supported on Chrome OS.
TEST_F(PolicyServiceTest, DictionaryPoliciesMerging_PrecedenceChange) {}
#endif  // !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_ANDROID) &&
        // !BUILDFLAG(IS_IOS)

TEST_F(PolicyServiceTest, ListsPoliciesMerging) {}

TEST_F(PolicyServiceTest, ListsPoliciesMerging_InvalidType) {}

#if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_IOS)
// The cloud user policy merging metapolicy is not applicable in Chrome OS.
TEST_F(PolicyServiceTest, ListsPoliciesMerging_CloudMetapolicy) {}
#endif  // !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_IOS)

#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(PolicyServiceTest, GroupPoliciesMergingDisabledForCloudUsers) {}

TEST_F(PolicyServiceTest, GroupPoliciesMergingEnabled) {}
#endif  // BUILDFLAG(ENABLE_EXTENSIONS)

#if !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_IOS)
TEST_F(PolicyServiceTest, CloudUserListPolicyMerge_Successful) {}

TEST_F(PolicyServiceTest, CloudUserListPolicyMerge_Unaffiliated) {}

TEST_F(PolicyServiceTest, CloudUserListPolicyMerge_FalsePolicy) {}

TEST_F(PolicyServiceTest, PlatformUserListPolicyMerge_Affiliated) {}

TEST_F(PolicyServiceTest, PlatformUserListPolicyMerge_Unaffiliated) {}

TEST_F(PolicyServiceTest, IgnoreUserCloudPrecedencePolicies) {}

TEST_F(PolicyServiceTest, PolicyMessages) {}
#endif  // !BUILDFLAG(IS_CHROMEOS) && !BUILDFLAG(IS_IOS)

struct PolicyServiceInitTimeTestParams {} kInitTimeTestParams[] =;

class PolicyServiceInitTimeTest
    : public testing::TestWithParam<PolicyServiceInitTimeTestParams> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(PolicyServiceInitTimeTest, HistogramsRecorded) {}

class PolicyServiceUserAffiliationMetricsTest
    : public PolicyServiceTest,
      public testing::WithParamInterface<
          testing::tuple<std::string, std::string>> {};

TEST_P(PolicyServiceUserAffiliationMetricsTest, Histograms) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace policy