chromium/chrome/browser/ui/safety_hub/unused_site_permissions_service_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 "chrome/browser/ui/safety_hub/unused_site_permissions_service.h"

#include <cstdint>
#include <ctime>
#include <list>
#include <memory>

#include "base/functional/bind.h"
#include "base/functional/callback_forward.h"
#include "base/json/values_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/time/clock.h"
#include "base/time/default_clock.h"
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/safe_browsing/test_safe_browsing_service.h"
#include "chrome/browser/ui/safety_hub/abusive_notification_permissions_manager.h"
#include "chrome/browser/ui/safety_hub/mock_safe_browsing_database_manager.h"
#include "chrome/browser/ui/safety_hub/safety_hub_prefs.h"
#include "chrome/browser/ui/safety_hub/safety_hub_service.h"
#include "chrome/browser/ui/safety_hub/safety_hub_test_util.h"
#include "chrome/browser/ui/safety_hub/safety_hub_util.h"
#include "chrome/browser/ui/safety_hub/unused_site_permissions_service_factory.h"
#include "chrome/common/chrome_features.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "chrome/test/base/testing_browser_process.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/browser/website_settings_registry.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_constraints.h"
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/features.h"
#include "components/history/core/browser/history_database_params.h"
#include "components/history/core/browser/history_service.h"
#include "components/history/core/test/test_history_database.h"
#include "components/keyed_service/core/refcounted_keyed_service.h"
#include "components/permissions/constants.h"
#include "components/permissions/permission_uma_util.h"
#include "components/permissions/permission_util.h"
#include "components/permissions/pref_names.h"
#include "components/permissions/test/test_permissions_client.h"
#include "components/safe_browsing/core/common/features.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "components/ukm/content/source_url_recorder.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

const char url1[] =;
const char url2[] =;
const char url3[] =;
const char url4[] =;
const ContentSettingsType automatic_downloads_type =;
const ContentSettingsType geolocation_type =;
const ContentSettingsType mediastream_type =;
const ContentSettingsType notifications_type =;
const ContentSettingsType chooser_type =;
const ContentSettingsType revoked_abusive_notification =;
const ContentSettingsType revoked_unused_site_type =;
// An arbitrary large number that doesn't match any ContentSettingsType;
const int32_t unknown_type =;

std::set<ContentSettingsType> abusive_permission_types({});
std::set<ContentSettingsType> unused_permission_types({});
std::set<ContentSettingsType> abusive_and_unused_permission_types(
    {});

std::unique_ptr<KeyedService> BuildUnusedSitePermissionsService(
    content::BrowserContext* context) {}

scoped_refptr<RefcountedKeyedService> BuildTestHostContentSettingsMap(
    content::BrowserContext* context) {}

std::unique_ptr<KeyedService> BuildTestHistoryService(
    content::BrowserContext* context) {}

PermissionsData CreatePermissionsData(
    ContentSettingsPattern& primary_pattern,
    std::set<ContentSettingsType>& permission_types) {}

void PopulateWebsiteSettingsLists(base::Value::List& integer_keyed,
                                  base::Value::List& string_keyed) {}

void PopulateChooserWebsiteSettingsDicts(base::Value::Dict& integer_keyed,
                                         base::Value::Dict& string_keyed) {}

}  // namespace

class UnusedSitePermissionsServiceTest
    : public ChromeRenderViewHostTestHarness,
      public testing::WithParamInterface<
          std::tuple</*should_setup_abusive_notification_sites*/ bool,
                     /*should_setup_unused_sites*/ bool>> {};

TEST_P(UnusedSitePermissionsServiceTest, UnusedSitePermissionsServiceTest) {}

TEST_P(UnusedSitePermissionsServiceTest, TrackOnlySingleOriginTest) {}

TEST_P(UnusedSitePermissionsServiceTest, TrackUnusedButDontRevoke) {}

TEST_P(UnusedSitePermissionsServiceTest, SecondaryPatternAlwaysWildcard) {}

TEST_P(UnusedSitePermissionsServiceTest, MultipleRevocationsForSameOrigin) {}

// TODO(crbug.com/40928115): Flaky on all platforms.
TEST_P(UnusedSitePermissionsServiceTest,
       DISABLED_ClearRevokedPermissionsListAfter30d) {}

TEST_P(UnusedSitePermissionsServiceTest, RegrantPermissionsForOrigin) {}

TEST_P(UnusedSitePermissionsServiceTest, RegrantPreventsAutorevoke) {}

TEST_P(UnusedSitePermissionsServiceTest, UndoRegrantPermissionsForOrigin) {}

TEST_P(UnusedSitePermissionsServiceTest, NotRevokeNotificationPermission) {}

TEST_P(UnusedSitePermissionsServiceTest, ClearRevokedPermissionsList) {}

TEST_P(UnusedSitePermissionsServiceTest, RecordRegrantMetricForAllowAgain) {}

TEST_P(UnusedSitePermissionsServiceTest,
       RemoveSiteFromRevokedPermissionsListOnPermissionChange) {}

TEST_P(UnusedSitePermissionsServiceTest, InitializeLatestResult) {}

TEST_P(UnusedSitePermissionsServiceTest, ResultToFromDict) {}

TEST_P(UnusedSitePermissionsServiceTest, ResultGetRevokedOrigins) {}

TEST_P(UnusedSitePermissionsServiceTest, ResultIsTriggerForMenuNotification) {}

TEST_P(UnusedSitePermissionsServiceTest, ResultWarrantsNewMenuNotification) {}

TEST_P(UnusedSitePermissionsServiceTest, AutoRevocationSetting) {}

TEST_P(UnusedSitePermissionsServiceTest, AutoCleanupRevokedPermissions) {}

TEST_P(UnusedSitePermissionsServiceTest,
       ChangingSettingOnRevokedSettingClearsIt) {}

TEST_P(UnusedSitePermissionsServiceTest,
       UpdateIntegerValuesToGroupName_AllContentSettings) {}

TEST_P(UnusedSitePermissionsServiceTest,
       UpdateIntegerValuesToGroupName_SubsetOfContentSettings) {}

TEST_P(UnusedSitePermissionsServiceTest,
       UpdateIntegerValuesToGroupName_UnknownContentSettings) {}

INSTANTIATE_TEST_SUITE_P();

class UnusedSitePermissionsServiceStartUpTest
    : public ChromeRenderViewHostTestHarness {};

TEST_F(UnusedSitePermissionsServiceStartUpTest,
       UpdateIntegerValuesToGroupName_OnlyIntegerKeys) {}

TEST_F(UnusedSitePermissionsServiceStartUpTest,
       UpdateIntegerValuesToGroupName_MixedKeys) {}

TEST_F(UnusedSitePermissionsServiceStartUpTest,
       UpdateIntegerValuesToGroupName_MixedKeysWithUnknownTypes) {}

class UnusedSitePermissionsServiceSafetyHubDisabledTest
    : public ChromeRenderViewHostTestHarness {};

TEST_F(UnusedSitePermissionsServiceSafetyHubDisabledTest,
       UnusedSitePermissionsRevocationEnabled) {}

TEST_F(UnusedSitePermissionsServiceSafetyHubDisabledTest,
       UnusedSitePermissionsRevocationDisabled) {}