chromium/components/device_signals/core/browser/user_permission_service_impl_unittest.cc

// Copyright 2022 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/device_signals/core/browser/user_permission_service_impl.h"

#include <optional>

#include "base/memory/raw_ptr.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h"
#include "components/device_signals/core/browser/mock_user_delegate.h"
#include "components/device_signals/core/browser/pref_names.h"
#include "components/device_signals/core/browser/user_context.h"
#include "components/device_signals/core/browser/user_delegate.h"
#include "components/device_signals/core/common/signals_features.h"
#include "components/policy/core/common/management/management_service.h"
#include "components/policy/core/common/management/scoped_management_service_override_for_testing.h"
#include "components/prefs/pref_registry.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/testing_pref_service.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

EnterpriseManagementAuthority;
ScopedManagementServiceOverrideForTesting;
_;
AnyNumber;
Return;

namespace device_signals {

namespace {

class TestManagementService : public policy::ManagementService {};

}  // namespace

class UserPermissionServiceImplTest : public testing::Test,
                                      public testing::WithParamInterface<bool> {};

// Tests that consent does not need to be collected if it was already given.
TEST_P(UserPermissionServiceImplTest, ShouldCollectConsent_ConsentGiven) {}
TEST_P(UserPermissionServiceImplTest,
       ShouldCollectConsent_PermanentConsentGiven) {}

struct DeviceManagedSpecificPolicyTestCase {};

// Tests that consent does not need to be collected if the device is cloud
// managed.
TEST_P(UserPermissionServiceImplTest, ShouldCollectConsent_DeviceCloudManaged) {}

// Tests that consent does not need to be collected if the device is not cloud
// managed but the "enable consent flow" policy is not enabled.
TEST_P(UserPermissionServiceImplTest,
       ShouldCollectConsent_NoEnableConsentFlowPolicy) {}

// Tests that consent needs to be collected if the device is not cloud managed
// and the "enable consent flow" policy is enabled.
TEST_P(UserPermissionServiceImplTest,
       ShouldCollectConsent_SpecificPolicy_ManagedUser) {}

struct DeviceManagedDependentPolicyTestCase {};

// Tests the behavior of ShouldCollectConsent against all permutations of
// dependent policy scope and affiliation.
TEST_P(UserPermissionServiceImplTest,
       ShouldCollectConsent_ManagedDevice_DependentPolicy) {}

// Tests that consent should be collected when a dependent policy is enabled on
// an unmanaged device.
TEST_P(UserPermissionServiceImplTest,
       ShouldCollectConsent_UnmanagedDevice_DependentPolicy) {}

#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
namespace {
constexpr char kUserGaiaId[] =;
}  // namespace

// Tests CanUserCollectSignals with a missing user ID.
TEST_P(UserPermissionServiceImplTest, CanUserCollectSignals_EmptyUserId) {}

// Tests CanUserCollectSignals with a user ID that does not represent the
// current browser user.
TEST_P(UserPermissionServiceImplTest,
       CanUserCollectSignals_UserId_NotSameUser) {}

// Tests CanUserCollectSignals with a user ID that represents the browser user,
// but that user is not managed.
TEST_P(UserPermissionServiceImplTest, CanUserCollectSignals_User_NotManaged) {}

// Tests CanUserCollectSignals with a managed user ID but the browser is not
// managed and the user has not given consent.
TEST_P(UserPermissionServiceImplTest,
       CanUserCollectSignals_BrowserNotManaged_NoConsent) {}

// Tests CanUserCollectSignals with a managed user ID but the browser is not
// managed and the user has given consent.
TEST_P(UserPermissionServiceImplTest,
       CanUserCollectSignals_BrowserNotManaged_WithConsent) {}

// Tests CanUserCollectSignals with a managed user ID and the browser is
// managed, where the user is the same as the profile user but it is not
// affiliated with the browser's org.
TEST_P(UserPermissionServiceImplTest,
       CanUserCollectSignals_BrowserManaged_ProfileUser_Unaffiliated) {}

// Tests CanUserCollectSignals with a managed user ID and the browser is
// managed, where the user is the same as the profile user and it is affiliated
// with the browser's org.
TEST_P(UserPermissionServiceImplTest,
       CanUserCollectSignals_BrowserManaged_ProfileUser_Affiliated) {}
#endif  // BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX

// Tests that signals can be collected if the user has already given their
// consent.
TEST_P(UserPermissionServiceImplTest, CanCollectSignals_AlreadyConsented) {}
TEST_P(UserPermissionServiceImplTest, CanCollectSignals_PermanentConsent) {}

// Tests that consent is required before allowing to collect signals from an
// unmanaged browser.
TEST_P(UserPermissionServiceImplTest, CanCollectSignals_BrowserNotManaged) {}

// Tests that signals can be collected when on a managed browser in an unmanaged
// profile.
TEST_P(UserPermissionServiceImplTest,
       CanCollectSignals_BrowserManaged_UnmanagedUser) {}

// Tests that signals can be collected when on a managed browser in an
// affiliated profile.
TEST_P(UserPermissionServiceImplTest,
       CanCollectSignals_BrowserManaged_AffiliatedUser) {}

struct UnaffiliatedUserTestCase {};

// Tests whether signals can be collected in various unaffiliated context
// use-cases.
TEST_P(UserPermissionServiceImplTest,
       CanCollectSignals_BrowserManaged_UnaffiliatedUser) {}

INSTANTIATE_TEST_SUITE_P();

}  // namespace device_signals