chromium/chrome/browser/content_settings/host_content_settings_map_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.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <memory>
#include <string>
#include <utility>

#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/json/json_writer.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.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/time.h"
#include "build/build_config.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/content_settings/mock_settings_observer.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/testing_profile.h"
#include "components/client_hints/common/client_hints.h"
#include "components/content_settings/core/browser/content_settings_mock_observer.h"
#include "components/content_settings/core/browser/content_settings_pref_provider.h"
#include "components/content_settings/core/browser/content_settings_registry.h"
#include "components/content_settings/core/browser/content_settings_rule.h"
#include "components/content_settings/core/browser/content_settings_uma_util.h"
#include "components/content_settings/core/browser/content_settings_utils.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/browser/user_modifiable_provider.h"
#include "components/content_settings/core/browser/website_settings_info.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/content_settings_utils.h"
#include "components/content_settings/core/common/features.h"
#include "components/content_settings/core/common/host_indexed_content_settings.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/content_settings/core/test/content_settings_test_utils.h"
#include "components/permissions/features.h"
#include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "net/base/schemeful_site.h"
#include "net/cookies/site_for_cookies.h"
#include "net/cookies/static_cookie_policy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/permissions/permission_utils.h"
#include "url/gurl.h"

_;
MockFunction;
Return;

namespace {

bool MatchPrimaryPattern(const ContentSettingsPattern& expected_primary,
                         const ContentSettingsPattern& primary_pattern,
                         const ContentSettingsPattern& secondary_pattern) {}

base::Time GetSettingLastModifiedDate(HostContentSettingsMap* map,
                                      GURL primary_url,
                                      GURL secondary_url,
                                      ContentSettingsType type) {}
}  // namespace

class MockUserModifiableProvider
    : public content_settings::UserModifiableProvider {};

class HostContentSettingsMapTest : public testing::Test {};

// Wrapper to TestingProfile to reduce test boilerplates, by keeping a fixed
// |content_type| so caller only need to specify it once.
class TesterForType {};

TEST_F(HostContentSettingsMapTest, DefaultValues) {}

TEST_F(HostContentSettingsMapTest, IndividualSettings) {}

TEST_F(HostContentSettingsMapTest, GetWebsiteSettingsForOneType) {}

TEST_F(HostContentSettingsMapTest, Clear) {}

TEST_F(HostContentSettingsMapTest, Patterns) {}

// Changing a setting for one origin doesn't affect subdomains.
TEST_F(HostContentSettingsMapTest, Origins) {}

TEST_F(HostContentSettingsMapTest, Observer) {}

TEST_F(HostContentSettingsMapTest, ObserveDefaultPref) {}

TEST_F(HostContentSettingsMapTest, ObserveExceptionPref) {}

TEST_F(HostContentSettingsMapTest, HostTrimEndingDotCheck) {}

TEST_F(HostContentSettingsMapTest, NestedSettings) {}

TEST_F(HostContentSettingsMapTest, TypeIsolatedSettings) {}

TEST_F(HostContentSettingsMapTest, IncognitoInheritInitialAllow) {}

TEST_F(HostContentSettingsMapTest, IncognitoInheritPopups) {}

TEST_F(HostContentSettingsMapTest, IncognitoPartialInheritPref) {}

TEST_F(HostContentSettingsMapTest, IncognitoPartialInheritDefault) {}

TEST_F(HostContentSettingsMapTest, IncognitoInheritCookies) {}

TEST_F(HostContentSettingsMapTest, IncognitoDontInheritWebsiteSetting) {}

TEST_F(HostContentSettingsMapTest, IncognitoDontInheritContentSetting) {}

TEST_F(HostContentSettingsMapTest, PrefExceptionsOperation) {}

TEST_F(HostContentSettingsMapTest, GetUserModifiableContentSetting) {}

// For a single Unicode encoded pattern, check if it gets converted to punycode
// and old pattern gets deleted.
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) {}

// If both Unicode and its punycode pattern exist, make sure we don't touch the
// settings for the punycode, and that Unicode pattern gets deleted.
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) {}

// If a default-content-setting is managed, the managed value should be used
// instead of the default value.
TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) {}

TEST_F(HostContentSettingsMapTest, GetNonDefaultContentSettingsIfTypeManaged) {}

// Managed default content setting should have higher priority
// than user defined patterns.
TEST_F(HostContentSettingsMapTest,
       ManagedDefaultContentSettingIgnoreUserPattern) {}

// If a default-content-setting is set to managed setting, the user defined
// setting should be preserved.
TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) {}

// If a setting for a default-content-setting-type is set while the type is
// managed, then the new setting should be preserved and used after the
// default-content-setting-type is not managed anymore.
TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) {}

TEST_F(HostContentSettingsMapTest, GetContentSetting) {}

TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) {}

// Guest profiles do not exist on Android, so don't run these tests there.
#if !BUILDFLAG(IS_ANDROID)
TEST_F(HostContentSettingsMapTest, GuestProfile) {}

// Default settings should not be modifiable for Guest profile (there is no UI
// to do this).
TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) {}

#endif  // !BUILDFLAG(IS_ANDROID)

TEST_F(HostContentSettingsMapTest, InvalidPattern) {}

TEST_F(HostContentSettingsMapTest, ClearSettingsForOneTypeWithPredicate) {}

TEST_F(HostContentSettingsMapTest, ClearSettingsWithTimePredicate) {}

TEST_F(HostContentSettingsMapTest, GetSettingLastModified) {}

TEST_F(HostContentSettingsMapTest, IsRestrictedToSecureOrigins) {}

TEST_F(HostContentSettingsMapTest, CanSetNarrowestSetting) {}

TEST_F(HostContentSettingsMapTest, MigrateRequestingAndTopLevelOriginSettings) {}

TEST_F(HostContentSettingsMapTest,
       MigrateRequestingAndTopLevelOriginSettingsResetsEmbeddedSetting) {}

// Creates new instance of PrefProvider and overrides it in
// |host_content_settings_map|.
void ReloadProviders(PrefService* pref_service,
                     HostContentSettingsMap* host_content_settings_map) {}

TEST_F(HostContentSettingsMapTest, GetPatternsFromScopingType) {}

TEST_F(HostContentSettingsMapTest, GetPatternsForContentSettingsType) {}

// Tests if changing a settings in incognito mode does not affects the regular
// mode.
TEST_F(HostContentSettingsMapTest, IncognitoChangesDoNotPersist) {}

// Validate that a content setting that uses a different scope/constraint can
// co-exist with another setting
TEST_F(HostContentSettingsMapTest, MixedScopeSettings) {}

// Validate that GetSettingsForOneType works with a SessionModel specified.
// We should act like no preference is specified if the value is
// SessionModel::None; otherwise, only the preferences from the specified
// scope should be returned (if any).
TEST_F(HostContentSettingsMapTest, GetSettingsForOneTypeWithSessionModel) {}

class HostContentSettingsMapActiveExpirationTest
    : public HostContentSettingsMapTest,
      public ::testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();

// Validate that the settings array retrieved correctly carries the expiry data
// for settings and they can detect if and when they expire.
// GetSettingsForOneType should also omit any settings that are already expired.
TEST_P(HostContentSettingsMapActiveExpirationTest,
       GetSettingsForOneTypeWithExpiryAndVerifyUmaHistograms) {}

TEST_F(HostContentSettingsMapTest, StorageAccessMetrics) {}

TEST_F(HostContentSettingsMapTest, RenewContentSetting) {}

TEST_F(HostContentSettingsMapTest, Increments3pcSettingsMetrics) {}

// Regression test for https://crbug.com/1497777.
TEST_F(HostContentSettingsMapTest, IncognitoInheritSaaAndRenew) {}

TEST_F(HostContentSettingsMapTest, ShutdownDuringExpirationAsanTest) {}

TEST_F(HostContentSettingsMapTest, TrackingProtectionMetrics) {}

// File access is not implemented on Android. Luckily we don't need it for DevTools.
#if !BUILDFLAG(IS_ANDROID)
TEST_F(HostContentSettingsMapTest, DevToolsFileAccess) {}
#endif  // !BUILDFLAG(IS_ANDROID)