12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004 |
- // Copyright 2020 The Chromium Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style license that can be
- // found in the LICENSE file.
- #include "components/privacy_sandbox/privacy_sandbox_settings.h"
- #include "base/json/values_util.h"
- #include "base/test/gtest_util.h"
- #include "base/test/scoped_feature_list.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/common/pref_names.h"
- #include "components/content_settings/core/test/content_settings_mock_provider.h"
- #include "components/content_settings/core/test/content_settings_test_utils.h"
- #include "components/privacy_sandbox/privacy_sandbox_features.h"
- #include "components/privacy_sandbox/privacy_sandbox_prefs.h"
- #include "components/privacy_sandbox/privacy_sandbox_test_util.h"
- #include "components/sync_preferences/testing_pref_service_syncable.h"
- #include "content/public/test/browser_task_environment.h"
- #include "testing/gtest/include/gtest/gtest.h"
- #include "url/origin.h"
- namespace privacy_sandbox {
- using Topic = browsing_topics::Topic;
- class PrivacySandboxSettingsTest : public testing::TestWithParam<bool> {
- public:
- PrivacySandboxSettingsTest()
- : browser_task_environment_(
- base::test::TaskEnvironment::TimeSource::MOCK_TIME) {
- content_settings::CookieSettings::RegisterProfilePrefs(prefs()->registry());
- HostContentSettingsMap::RegisterProfilePrefs(prefs()->registry());
- privacy_sandbox::RegisterProfilePrefs(prefs()->registry());
- host_content_settings_map_ = new HostContentSettingsMap(
- &prefs_, false /* is_off_the_record */, false /* store_last_modified */,
- false /* restore_session */);
- cookie_settings_ = new content_settings::CookieSettings(
- host_content_settings_map_.get(), &prefs_, false, "chrome-extension");
- }
- ~PrivacySandboxSettingsTest() override {
- host_content_settings_map()->ShutdownOnUIThread();
- }
- void SetUp() override {
- auto mock_delegate = std::make_unique<testing::NiceMock<
- privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>>();
- mock_delegate_ = mock_delegate.get();
- InitializePrefsBeforeStart();
- InitializeFeaturesBeforeStart();
- InitializeDelegateBeforeStart();
- privacy_sandbox_settings_ = std::make_unique<PrivacySandboxSettings>(
- std::move(mock_delegate), host_content_settings_map(), cookie_settings_,
- prefs(), IsIncognitoProfile());
- }
- virtual void InitializePrefsBeforeStart() {}
- virtual void InitializeFeaturesBeforeStart() {
- if (GetParam()) {
- feature_list_.InitAndEnableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- } else {
- feature_list_.InitAndDisableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- }
- }
- virtual void InitializeDelegateBeforeStart() {
- mock_delegate()->SetUpDefaultResponse(/*restricted=*/false);
- }
- virtual bool IsIncognitoProfile() { return false; }
- privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate*
- mock_delegate() {
- return mock_delegate_;
- }
- sync_preferences::TestingPrefServiceSyncable* prefs() { return &prefs_; }
- HostContentSettingsMap* host_content_settings_map() {
- return host_content_settings_map_.get();
- }
- content_settings::CookieSettings* cookie_settings() {
- return cookie_settings_.get();
- }
- PrivacySandboxSettings* privacy_sandbox_settings() {
- return privacy_sandbox_settings_.get();
- }
- content::BrowserTaskEnvironment* task_environment() {
- return &browser_task_environment_;
- }
- protected:
- base::test::ScopedFeatureList feature_list_;
- private:
- content::BrowserTaskEnvironment browser_task_environment_;
- raw_ptr<privacy_sandbox_test_util::MockPrivacySandboxSettingsDelegate>
- mock_delegate_;
- sync_preferences::TestingPrefServiceSyncable prefs_;
- scoped_refptr<HostContentSettingsMap> host_content_settings_map_;
- scoped_refptr<content_settings::CookieSettings> cookie_settings_;
- std::unique_ptr<PrivacySandboxSettings> privacy_sandbox_settings_;
- };
- TEST_P(PrivacySandboxSettingsTest, DefaultContentSettingBlockOverridePref) {
- // A block default content setting should override the Privacy Sandbox pref.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // An allow default or exception, whether via user or policy, should not
- // override the preference value.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://another-embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://embedded.com", "https://another-test.com",
- ContentSetting::CONTENT_SETTING_ALLOW}},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*managed_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://another-embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://embedded.com", "https://another-test.com",
- ContentSetting::CONTENT_SETTING_ALLOW}});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- }
- TEST_P(PrivacySandboxSettingsTest, CookieExceptionsApply) {
- // All cookie exceptions which disable access should apply to the Privacy
- // Sandbox. General topics calculations should however remain allowed.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_BLOCK},
- {"https://another-embedded.com", "*",
- ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // The default managed content setting should apply, overriding any user ones,
- // and disabling Topics calculations.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://another-embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://embedded.com", "https://another-test.com",
- ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // Managed content setting exceptions should override both the privacy
- // sandbox pref and any user settings.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://another-embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://embedded.com", "https://another-test.com",
- ContentSetting::CONTENT_SETTING_ALLOW}},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_BLOCK}});
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://unrelated.com"),
- url::Origin::Create(GURL("https://unrelated.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://unrelated-a.com")),
- url::Origin::Create(GURL("https://unrelated-b.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://unrelated-c.com")),
- url::Origin::Create(GURL("https://unrelated-d.com")),
- url::Origin::Create(GURL("https://unrelated-e.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://unrelated-a.com")),
- url::Origin::Create(GURL("https://unrelated-b.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{GURL("https://another-embedded.com")},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // A less specific block exception should not override a more specific allow
- // exception. The effective content setting in this scenario is still allow,
- // even though a block exception exists.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://embedded.com", "https://another-test.com",
- ContentSetting::CONTENT_SETTING_ALLOW},
- {"https://[*.]embedded.com", "https://[*.]test.com",
- ContentSetting::CONTENT_SETTING_BLOCK},
- {"https://[*.]embedded.com", "https://[*.]another-test.com",
- ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // Exceptions which specify a top frame origin should not match against other
- // top frame origins, or an empty origin.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_BLOCK}});
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"), absl::nullopt));
- EXPECT_TRUE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://yet-another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{GURL("https://another-embedded.com/")},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_TRUE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // Exceptions which specify a wildcard top frame origin should match both
- // empty top frames and non empty top frames.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "*", ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"), absl::nullopt));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{GURL("https://another-embedded.com")},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- }
- TEST_P(PrivacySandboxSettingsTest, ThirdPartyCookies) {
- // Privacy Sandbox APIs should be disabled if Third Party Cookies are blocked.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // Privacy Sandbox APIs should be disabled if all cookies are blocked.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- // Privacy Sandbox APIs should be disabled if the privacy sandbox is disabled,
- // regardless of other cookie settings.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW}},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*managed_cookie_exceptions=*/
- {{"https://embedded.com", "https://test.com",
- ContentSetting::CONTENT_SETTING_ALLOW}});
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowed());
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicsAllowedForContext(
- GURL("https://embedded.com"),
- url::Origin::Create(GURL("https://test.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsConversionMeasurementAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->ShouldSendConversionReport(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://another-test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivateAggregationAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- EXPECT_EQ(std::vector<GURL>{},
- privacy_sandbox_settings()->FilterFledgeAllowedParties(
- url::Origin::Create(GURL("https://test.com")),
- {GURL("https://embedded.com"),
- GURL("https://another-embedded.com")}));
- EXPECT_FALSE(privacy_sandbox_settings()->IsSharedStorageAllowed(
- url::Origin::Create(GURL("https://test.com")),
- url::Origin::Create(GURL("https://embedded.com"))));
- }
- TEST_P(PrivacySandboxSettingsTest, IsPrivacySandboxEnabled) {
- // IsPrivacySandboxEnabled should directly reflect the state of the Privacy
- // Sandbox control.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/false,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_ALLOW,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/privacy_sandbox_test_util::kNoSetting,
- /*managed_cookie_exceptions=*/{});
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/true,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/{},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*managed_cookie_exceptions=*/{});
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- }
- TEST_P(PrivacySandboxSettingsTest, TopicsDataAccessibleSince) {
- ASSERT_NE(base::Time(), base::Time::Now());
- EXPECT_EQ(base::Time(),
- privacy_sandbox_settings()->TopicsDataAccessibleSince());
- privacy_sandbox_settings()->OnCookiesCleared();
- EXPECT_EQ(base::Time::Now(),
- privacy_sandbox_settings()->TopicsDataAccessibleSince());
- }
- TEST_P(PrivacySandboxSettingsTest, FledgeJoiningAllowed) {
- // Whether or not a site can join a user to an interest group is independent
- // of any other profile state.
- privacy_sandbox_test_util::SetupTestState(
- prefs(), host_content_settings_map(),
- /*privacy_sandbox_enabled=*/false,
- /*block_third_party_cookies=*/true,
- /*default_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*user_cookie_exceptions=*/
- {{"https://example.com", "*", ContentSetting::CONTENT_SETTING_BLOCK}},
- /*managed_cookie_setting=*/ContentSetting::CONTENT_SETTING_BLOCK,
- /*managed_cookie_exceptions=*/
- {{"https://example.com", "*", ContentSetting::CONTENT_SETTING_BLOCK}});
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- // Settings should match at the eTLD + 1 level.
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("example.com", false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://subsite.example.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://example.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com:888"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com.au"))));
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("example.com", true);
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://subsite.example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com:888"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com.au"))));
- }
- TEST_P(PrivacySandboxSettingsTest, NonEtldPlusOneBlocked) {
- // Confirm that, as a fallback, hosts are accepted by SetFledgeJoiningAllowed.
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("subsite.example.com",
- false);
- // Applied setting should affect subdomaings.
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://subsite.example.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://another.subsite.example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- // When removing the setting, only an exact match, and not the associated
- // eTLD+1, should remove a setting.
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("example.com", true);
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://subsite.example.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://another.subsite.example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("subsite.example.com",
- true);
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://subsite.example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://another.subsite.example.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://example.com"))));
- // IP addresses should also be accepted as a fallback.
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("10.1.1.100", false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://10.1.1.100"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("http://10.1.1.100:8080"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://10.2.2.200"))));
- }
- TEST_P(PrivacySandboxSettingsTest, FledgeJoinSettingTimeRangeDeletion) {
- // Confirm that time range deletions work appropriately for FLEDGE join
- // settings.
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("first.com", false);
- task_environment()->AdvanceClock(base::Hours(1));
- const base::Time kSecondSettingTime = base::Time::Now();
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("second.com", false);
- task_environment()->AdvanceClock(base::Hours(1));
- privacy_sandbox_settings()->SetFledgeJoiningAllowed("third.com", false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://first.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://second.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://third.com"))));
- // Construct a deletion which only targets the second setting.
- privacy_sandbox_settings()->ClearFledgeJoiningAllowedSettings(
- kSecondSettingTime - base::Seconds(1),
- kSecondSettingTime + base::Seconds(1));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://first.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://second.com"))));
- EXPECT_FALSE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://third.com"))));
- // Perform a maximmal time range deletion, which should remove the two
- // remaining settings.
- privacy_sandbox_settings()->ClearFledgeJoiningAllowedSettings(
- base::Time(), base::Time::Max());
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://first.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://second.com"))));
- EXPECT_TRUE(privacy_sandbox_settings()->IsFledgeJoiningAllowed(
- url::Origin::Create(GURL("https://third.com"))));
- }
- TEST_P(PrivacySandboxSettingsTest, TrustTokensAllowed) {
- // IsTrustTokensAllowed() should follow the top level privacy sandbox setting
- // as long as the release 3 feature is enabled, always returning true
- // otherwise
- base::test::ScopedFeatureList feature_list_;
- feature_list_.InitAndEnableFeature(privacy_sandbox::kPrivacySandboxSettings3);
- privacy_sandbox_test_util::MockPrivacySandboxObserver observer;
- privacy_sandbox_settings()->AddObserver(&observer);
- EXPECT_CALL(observer, OnTrustTokenBlockingChanged(/*blocked=*/true));
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsTrustTokensAllowed());
- testing::Mock::VerifyAndClearExpectations(&observer);
- EXPECT_CALL(observer, OnTrustTokenBlockingChanged(/*blocked=*/false));
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(true);
- EXPECT_TRUE(privacy_sandbox_settings()->IsTrustTokensAllowed());
- testing::Mock::VerifyAndClearExpectations(&observer);
- feature_list_.Reset();
- feature_list_.InitAndDisableFeature(
- privacy_sandbox::kPrivacySandboxSettings3);
- EXPECT_CALL(observer, OnTrustTokenBlockingChanged(testing::_)).Times(0);
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(false);
- EXPECT_TRUE(privacy_sandbox_settings()->IsTrustTokensAllowed());
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(true);
- EXPECT_TRUE(privacy_sandbox_settings()->IsTrustTokensAllowed());
- }
- TEST_P(PrivacySandboxSettingsTest, IsTopicAllowed) {
- // Confirm that allowing / blocking topics is correctly reflected by
- // IsTopicsAllowed().
- CanonicalTopic topic_one(Topic(1), CanonicalTopic::AVAILABLE_TAXONOMY);
- CanonicalTopic topic_two(Topic(2), CanonicalTopic::AVAILABLE_TAXONOMY);
- privacy_sandbox_settings()->SetTopicAllowed(topic_one, false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- privacy_sandbox_settings()->SetTopicAllowed(topic_two, false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- privacy_sandbox_settings()->SetTopicAllowed(topic_two, true);
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- privacy_sandbox_settings()->SetTopicAllowed(topic_one, true);
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- }
- TEST_P(PrivacySandboxSettingsTest, ClearingTopicSettings) {
- // Confirm that time range deletions affect the correct settings.
- CanonicalTopic topic_one(Topic(1), CanonicalTopic::AVAILABLE_TAXONOMY);
- CanonicalTopic topic_two(Topic(2), CanonicalTopic::AVAILABLE_TAXONOMY);
- CanonicalTopic topic_three(Topic(3), CanonicalTopic::AVAILABLE_TAXONOMY);
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_three));
- privacy_sandbox_settings()->SetTopicAllowed(topic_one, false);
- task_environment()->AdvanceClock(base::Hours(1));
- const auto kSecondSettingTime = base::Time::Now();
- privacy_sandbox_settings()->SetTopicAllowed(topic_two, false);
- task_environment()->AdvanceClock(base::Hours(1));
- privacy_sandbox_settings()->SetTopicAllowed(topic_three, false);
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_three));
- // Construct a deletion which only targets the second setting.
- privacy_sandbox_settings()->ClearTopicSettings(
- kSecondSettingTime - base::Seconds(1),
- kSecondSettingTime + base::Seconds(1));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- EXPECT_FALSE(privacy_sandbox_settings()->IsTopicAllowed(topic_three));
- // Perform a maximmal time range deletion, which should remove the two
- // remaining settings.
- privacy_sandbox_settings()->ClearTopicSettings(base::Time(),
- base::Time::Max());
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_one));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_two));
- EXPECT_TRUE(privacy_sandbox_settings()->IsTopicAllowed(topic_three));
- }
- INSTANTIATE_TEST_SUITE_P(PrivacySandboxSettingsTestInstance,
- PrivacySandboxSettingsTest,
- testing::Bool());
- class PrivacySandboxSettingsTestCookiesClearOnExitTurnedOff
- : public PrivacySandboxSettingsTest {
- public:
- void InitializePrefsBeforeStart() override {
- prefs()->SetUserPref(prefs::kPrivacySandboxTopicsDataAccessibleSince,
- std::make_unique<base::Value>(::base::TimeToValue(
- base::Time::FromTimeT(12345))));
- }
- void InitializeFeaturesBeforeStart() override {}
- };
- TEST_P(PrivacySandboxSettingsTestCookiesClearOnExitTurnedOff,
- UseLastTopicsDataAccessibleSince) {
- EXPECT_EQ(base::Time::FromTimeT(12345),
- privacy_sandbox_settings()->TopicsDataAccessibleSince());
- }
- INSTANTIATE_TEST_SUITE_P(
- PrivacySandboxSettingsTestCookiesClearOnExitTurnedOffInstance,
- PrivacySandboxSettingsTestCookiesClearOnExitTurnedOff,
- testing::Bool());
- class PrivacySandboxSettingsTestCookiesClearOnExitTurnedOn
- : public PrivacySandboxSettingsTest {
- public:
- void InitializePrefsBeforeStart() override {
- host_content_settings_map()->SetDefaultContentSetting(
- ContentSettingsType::COOKIES,
- ContentSetting::CONTENT_SETTING_SESSION_ONLY);
- prefs()->SetUserPref(prefs::kPrivacySandboxTopicsDataAccessibleSince,
- std::make_unique<base::Value>(::base::TimeToValue(
- base::Time::FromTimeT(12345))));
- }
- };
- TEST_P(PrivacySandboxSettingsTestCookiesClearOnExitTurnedOn,
- UpdateTopicsDataAccessibleSince) {
- EXPECT_EQ(base::Time::Now(),
- privacy_sandbox_settings()->TopicsDataAccessibleSince());
- }
- INSTANTIATE_TEST_SUITE_P(
- PrivacySandboxSettingsTestCookiesClearOnExitTurnedOnInstance,
- PrivacySandboxSettingsTestCookiesClearOnExitTurnedOn,
- testing::Bool());
- class PrivacySandboxSettingsIncognitoTest : public PrivacySandboxSettingsTest {
- bool IsIncognitoProfile() override { return true; }
- };
- TEST_P(PrivacySandboxSettingsIncognitoTest, DisabledInIncognito) {
- // When the Release 3 flag is enabled, APIs should always be disabled in
- // incognito. The Release 3 flag is set based on the test param.
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(true);
- if (GetParam())
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- else
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- }
- INSTANTIATE_TEST_SUITE_P(PrivacySandboxSettingsIncognitoTestInstance,
- PrivacySandboxSettingsIncognitoTest,
- testing::Bool());
- class PrivacySandboxSettingsMockDelegateTest
- : public PrivacySandboxSettingsTest {
- public:
- void InitializeDelegateBeforeStart() override {
- // Do not set default handlers so each call must be mocked.
- }
- };
- TEST_P(PrivacySandboxSettingsMockDelegateTest, IsPrivacySandboxRestricted) {
- // When the sandbox is otherwise enabled, the delegate returning true for
- // IsPrivacySandboxRestricted() should disable the sandbox.
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(true);
- EXPECT_CALL(*mock_delegate(), IsPrivacySandboxRestricted())
- .Times(1)
- .WillOnce(testing::Return(true));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- EXPECT_CALL(*mock_delegate(), IsPrivacySandboxRestricted())
- .Times(1)
- .WillOnce(testing::Return(false));
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- // The delegate should not override a disabled sandbox.
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(false);
- EXPECT_CALL(*mock_delegate(), IsPrivacySandboxRestricted())
- .Times(1)
- .WillOnce(testing::Return(false));
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- }
- INSTANTIATE_TEST_SUITE_P(PrivacySandboxSettingsMockDelegateTestInstance,
- PrivacySandboxSettingsMockDelegateTest,
- testing::Bool());
- class PrivacySandboxSettingLocalOverrideTest
- : public PrivacySandboxSettingsTest {
- void InitializeFeaturesBeforeStart() override {
- if (GetParam()) {
- feature_list_.InitWithFeatures(
- {privacy_sandbox::kPrivacySandboxSettings3,
- privacy_sandbox::kOverridePrivacySandboxSettingsLocalTesting},
- /*disabled_features=*/{});
- } else {
- feature_list_.InitWithFeatures(
- {privacy_sandbox::kPrivacySandboxSettings3},
- {privacy_sandbox::kOverridePrivacySandboxSettingsLocalTesting});
- }
- }
- };
- TEST_P(PrivacySandboxSettingLocalOverrideTest, FollowsOverrideBehavior) {
- // When the Release 3 flag is enabled, APIs should always be disabled in
- // incognito. The Release 3 flag is set based on the test param.
- privacy_sandbox_settings()->SetPrivacySandboxEnabled(false);
- if (GetParam())
- EXPECT_TRUE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- else
- EXPECT_FALSE(privacy_sandbox_settings()->IsPrivacySandboxEnabled());
- }
- INSTANTIATE_TEST_SUITE_P(PrivacySandboxSettingLocalOverrideTestInstance,
- PrivacySandboxSettingLocalOverrideTest,
- testing::Bool());
- } // namespace privacy_sandbox
|