#include <stdint.h>
#include <memory>
#include <optional>
#include <string>
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/histogram_samples.h"
#include "base/metrics/sample_map.h"
#include "base/metrics/statistics_recorder.h"
#include "base/run_loop.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/simple_test_clock.h"
#include "base/test/task_environment.h"
#include "base/test/test_simple_task_runner.h"
#include "base/time/time.h"
#include "base/values.h"
#include "build/build_config.h"
#include "chrome/browser/policy/cloud/cloud_policy_invalidator.h"
#include "chrome/browser/policy/cloud/user_cloud_policy_invalidator.h"
#include "components/gcm_driver/fake_gcm_driver.h"
#include "components/gcm_driver/instance_id/instance_id.h"
#include "components/gcm_driver/instance_id/instance_id_driver.h"
#include "components/invalidation/impl/fake_invalidation_service.h"
#include "components/invalidation/impl/invalidator_registrar_with_memory.h"
#include "components/invalidation/invalidation_listener_impl.h"
#include "components/invalidation/public/invalidation_util.h"
#include "components/policy/core/common/cloud/cloud_policy_constants.h"
#include "components/policy/core/common/cloud/cloud_policy_core.h"
#include "components/policy/core/common/cloud/cloud_policy_refresh_scheduler.h"
#include "components/policy/core/common/cloud/cloud_policy_validator.h"
#include "components/policy/core/common/cloud/enterprise_metrics.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_client.h"
#include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
#include "components/policy/core/common/cloud/policy_invalidation_scope.h"
#include "components/policy/core/common/cloud/policy_invalidation_util.h"
#include "components/policy/core/common/policy_types.h"
#include "components/policy/policy_constants.h"
#include "components/policy/proto/device_management_backend.pb.h"
#include "services/network/test/test_network_connection_tracker.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
_;
WithArg;
em;
namespace policy {
namespace {
const invalidation::Topic kTopicA = …;
const invalidation::Topic kTopicB = …;
constexpr char kFakeSenderId[] = …;
constexpr char kTestLogPrefix[] = …;
constexpr char kFakeRegistrationToken[] = …;
}
class FakeRegistrationTokenHandler
: public invalidation::RegistrationTokenHandler { … };
class MockInstanceIDDriver : public instance_id::InstanceIDDriver { … };
class MockInstanceID : public instance_id::InstanceID { … };
class CloudPolicyInvalidatorWithListenerTestBase : public testing::Test { … };
CloudPolicyInvalidatorWithListenerTestBase::
CloudPolicyInvalidatorWithListenerTestBase()
: … { … }
void CloudPolicyInvalidatorWithListenerTestBase::TearDown() { … }
void CloudPolicyInvalidatorWithListenerTestBase::StartInvalidator(
bool initialize,
bool start_refresh_scheduler,
int64_t highest_handled_invalidation_version) { … }
void CloudPolicyInvalidatorWithListenerTestBase::InitializeInvalidator() { … }
void CloudPolicyInvalidatorWithListenerTestBase::ShutdownInvalidator() { … }
void CloudPolicyInvalidatorWithListenerTestBase::DestroyInvalidator() { … }
void CloudPolicyInvalidatorWithListenerTestBase::ConnectCore() { … }
void CloudPolicyInvalidatorWithListenerTestBase::StartRefreshScheduler() { … }
void CloudPolicyInvalidatorWithListenerTestBase::DisconnectCore() { … }
void CloudPolicyInvalidatorWithListenerTestBase::StorePolicy(
int64_t invalidation_version,
bool policy_changed,
const base::Time& time) { … }
void CloudPolicyInvalidatorWithListenerTestBase::DisableInvalidationService() { … }
void CloudPolicyInvalidatorWithListenerTestBase::EnableInvalidationService() { … }
void CloudPolicyInvalidatorWithListenerTestBase::StartInvalidationListener() { … }
invalidation::Invalidation
CloudPolicyInvalidatorWithListenerTestBase::FireInvalidation(
const invalidation::Topic& topic,
int64_t version,
const std::string& payload) { … }
bool CloudPolicyInvalidatorWithListenerTestBase::
ClientInvalidationInfoIsUnset() { … }
bool CloudPolicyInvalidatorWithListenerTestBase::ClientInvalidationInfoMatches(
const invalidation::Invalidation& invalidation) { … }
bool CloudPolicyInvalidatorWithListenerTestBase::CheckPolicyNotRefreshed() { … }
bool CloudPolicyInvalidatorWithListenerTestBase::InvalidationsEnabled() { … }
bool CloudPolicyInvalidatorWithListenerTestBase::IsInvalidatorRegistered() { … }
int64_t CloudPolicyInvalidatorWithListenerTestBase::
GetHighestHandledInvalidationVersion() const { … }
void CloudPolicyInvalidatorWithListenerTestBase::AdvanceClock(
base::TimeDelta delta) { … }
base::Time CloudPolicyInvalidatorWithListenerTestBase::Now() { … }
int64_t CloudPolicyInvalidatorWithListenerTestBase::V(int version) { … }
int64_t CloudPolicyInvalidatorWithListenerTestBase::GetVersion(
base::Time time) { … }
PolicyInvalidationScope
CloudPolicyInvalidatorWithListenerTestBase::GetPolicyInvalidationScope() const { … }
bool CloudPolicyInvalidatorWithListenerTestBase::CheckPolicyRefreshed(
base::TimeDelta delay) { … }
bool CloudPolicyInvalidatorWithListenerTestBase::CheckPolicyRefreshCount(
int count) { … }
class CloudPolicyInvalidatorWithListenerTest
: public CloudPolicyInvalidatorWithListenerTestBase { … };
TEST_F(CloudPolicyInvalidatorWithListenerTest, Uninitialized) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, RefreshSchedulerNotStarted) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, DisconnectCoreThenInitialize) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest,
InitializeThenStartRefreshScheduler) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, RegisterOnStoreLoaded) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, UnregisterOnStoreLoaded) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, HandleInvalidation) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, HandleMultipleInvalidations) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest,
InitialHighestHandledInvalidationVersionNonZero) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, StoreLoadedBeforeRefresh) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, NoCallbackAfterShutdown) { … }
TEST_F(CloudPolicyInvalidatorWithListenerTest, StateChanged) { … }
class CloudPolicyInvalidatorWithListenerOwnerNameTest
: public CloudPolicyInvalidatorWithListenerTestBase { … };
TEST_F(CloudPolicyInvalidatorWithListenerOwnerNameTest,
GetOwnerNameForUserScope) { … }
TEST_F(CloudPolicyInvalidatorWithListenerOwnerNameTest,
GetOwnerNameForDeviceScope) { … }
TEST_F(CloudPolicyInvalidatorWithListenerOwnerNameTest,
GetOwnerNameForDeviceLocalAccountScope) { … }
class CloudPolicyInvalidatorWithListenerUserTypedTest
: public CloudPolicyInvalidatorWithListenerTestBase,
public testing::WithParamInterface<PolicyInvalidationScope> { … };
base::HistogramBase::Count
CloudPolicyInvalidatorWithListenerUserTypedTest::GetCount(
MetricPolicyRefresh metric) { … }
base::HistogramBase::Count
CloudPolicyInvalidatorWithListenerUserTypedTest::GetInvalidationCount(
PolicyInvalidationType type) { … }
PolicyInvalidationScope
CloudPolicyInvalidatorWithListenerUserTypedTest::GetPolicyInvalidationScope()
const { … }
TEST_P(CloudPolicyInvalidatorWithListenerUserTypedTest,
RefreshMetricsUnregistered) { … }
TEST_P(CloudPolicyInvalidatorWithListenerUserTypedTest,
RefreshMetricsNoInvalidations) { … }
TEST_P(CloudPolicyInvalidatorWithListenerUserTypedTest,
RefreshMetricsInvalidation) { … }
TEST_P(CloudPolicyInvalidatorWithListenerUserTypedTest, ExpiredInvalidations) { … }
INSTANTIATE_TEST_SUITE_P(…);
}