#ifdef UNSAFE_BUFFERS_BUILD
#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) { … }
}
class MockUserModifiableProvider
: public content_settings::UserModifiableProvider { … };
class HostContentSettingsMapTest : public testing::Test { … };
class TesterForType { … };
TEST_F(HostContentSettingsMapTest, DefaultValues) { … }
TEST_F(HostContentSettingsMapTest, IndividualSettings) { … }
TEST_F(HostContentSettingsMapTest, GetWebsiteSettingsForOneType) { … }
TEST_F(HostContentSettingsMapTest, Clear) { … }
TEST_F(HostContentSettingsMapTest, Patterns) { … }
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) { … }
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeOnly) { … }
TEST_F(HostContentSettingsMapTest, CanonicalizeExceptionsUnicodeAndPunycode) { … }
TEST_F(HostContentSettingsMapTest, ManagedDefaultContentSetting) { … }
TEST_F(HostContentSettingsMapTest, GetNonDefaultContentSettingsIfTypeManaged) { … }
TEST_F(HostContentSettingsMapTest,
ManagedDefaultContentSettingIgnoreUserPattern) { … }
TEST_F(HostContentSettingsMapTest, OverwrittenDefaultContentSetting) { … }
TEST_F(HostContentSettingsMapTest, SettingDefaultContentSettingsWhenManaged) { … }
TEST_F(HostContentSettingsMapTest, GetContentSetting) { … }
TEST_F(HostContentSettingsMapTest, AddContentSettingsObserver) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(HostContentSettingsMapTest, GuestProfile) { … }
TEST_F(HostContentSettingsMapTest, GuestProfileDefaultSetting) { … }
#endif
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) { … }
void ReloadProviders(PrefService* pref_service,
HostContentSettingsMap* host_content_settings_map) { … }
TEST_F(HostContentSettingsMapTest, GetPatternsFromScopingType) { … }
TEST_F(HostContentSettingsMapTest, GetPatternsForContentSettingsType) { … }
TEST_F(HostContentSettingsMapTest, IncognitoChangesDoNotPersist) { … }
TEST_F(HostContentSettingsMapTest, MixedScopeSettings) { … }
TEST_F(HostContentSettingsMapTest, GetSettingsForOneTypeWithSessionModel) { … }
class HostContentSettingsMapActiveExpirationTest
: public HostContentSettingsMapTest,
public ::testing::WithParamInterface<bool> { … };
INSTANTIATE_TEST_SUITE_P(…);
TEST_P(HostContentSettingsMapActiveExpirationTest,
GetSettingsForOneTypeWithExpiryAndVerifyUmaHistograms) { … }
TEST_F(HostContentSettingsMapTest, StorageAccessMetrics) { … }
TEST_F(HostContentSettingsMapTest, RenewContentSetting) { … }
TEST_F(HostContentSettingsMapTest, Increments3pcSettingsMetrics) { … }
TEST_F(HostContentSettingsMapTest, IncognitoInheritSaaAndRenew) { … }
TEST_F(HostContentSettingsMapTest, ShutdownDuringExpirationAsanTest) { … }
TEST_F(HostContentSettingsMapTest, TrackingProtectionMetrics) { … }
#if !BUILDFLAG(IS_ANDROID)
TEST_F(HostContentSettingsMapTest, DevToolsFileAccess) { … }
#endif