diff --git a/chromium_src/components/content_settings/core/browser/brave_content_settings_registry_browsertest.cc b/chromium_src/components/content_settings/core/browser/brave_content_settings_registry_browsertest.cc new file mode 100644 index 000000000000..9518e376083a --- /dev/null +++ b/chromium_src/components/content_settings/core/browser/brave_content_settings_registry_browsertest.cc @@ -0,0 +1,92 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "brave/components/brave_shields/common/brave_shield_constants.h" +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "components/content_settings/core/browser/host_content_settings_map.h" +#include "components/content_settings/core/common/content_settings_pattern.h" + +const GURL kBraveURL("https://www.brave.com"); + +class BraveContentSettingsRegistryBrowserTest : public InProcessBrowserTest { + public: + using InProcessBrowserTest::InProcessBrowserTest; + + HostContentSettingsMap* content_settings() { + return HostContentSettingsMapFactory::GetForProfile(browser()->profile()); + } + + HostContentSettingsMap* private_content_settings() { + return HostContentSettingsMapFactory::GetForProfile( + browser()->profile()->GetOffTheRecordProfile()); + } + + private: + DISALLOW_COPY_AND_ASSIGN(BraveContentSettingsRegistryBrowserTest); +}; + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsRegistryBrowserTest, + WithWildcardContentSetting) { + content_settings()->SetContentSettingCustomScope( + ContentSettingsPattern::Wildcard(), + ContentSettingsPattern::Wildcard(), + CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields, + CONTENT_SETTING_ALLOW); + + ContentSetting brave_url_shields_setting = + content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_ALLOW, brave_url_shields_setting); + + ContentSetting brave_url_shields_setting_private = + private_content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_ALLOW, brave_url_shields_setting_private); +} + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsRegistryBrowserTest, + WithoutWildcardContentSetting) { + ContentSetting brave_url_shields_setting = + content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_DEFAULT, brave_url_shields_setting); + + ContentSetting brave_url_shields_setting_private = + private_content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_DEFAULT, brave_url_shields_setting_private); +} + +IN_PROC_BROWSER_TEST_F(BraveContentSettingsRegistryBrowserTest, + WithBraveShieldsContentSetting) { + ContentSettingsPattern brave_url_pattern = + ContentSettingsPattern::FromURL(kBraveURL); + + content_settings()->SetContentSettingCustomScope( + brave_url_pattern, + brave_url_pattern, + CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields, + CONTENT_SETTING_ALLOW); + + ContentSetting brave_url_shields_setting = + content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_ALLOW, brave_url_shields_setting); + + ContentSetting brave_url_shields_setting_private = + private_content_settings()->GetContentSetting( + kBraveURL, kBraveURL, CONTENT_SETTINGS_TYPE_PLUGINS, + brave_shields::kBraveShields); + EXPECT_EQ(CONTENT_SETTING_ALLOW, brave_url_shields_setting_private); +} diff --git a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc index 51a599569fbe..1904ceb6a10f 100644 --- a/chromium_src/components/content_settings/core/browser/content_settings_registry.cc +++ b/chromium_src/components/content_settings/core/browser/content_settings_registry.cc @@ -29,7 +29,7 @@ void ContentSettingsRegistry::BraveInit() { CONTENT_SETTING_DETECT_IMPORTANT_CONTENT), WebsiteSettingsInfo::SINGLE_ORIGIN_WITH_EMBEDDED_EXCEPTIONS_SCOPE, WebsiteSettingsRegistry::DESKTOP, - ContentSettingsInfo::INHERIT_IF_LESS_PERMISSIVE, + ContentSettingsInfo::INHERIT_IN_INCOGNITO, ContentSettingsInfo::EPHEMERAL, ContentSettingsInfo::EXCEPTIONS_ON_SECURE_AND_INSECURE_ORIGINS); } diff --git a/test/BUILD.gn b/test/BUILD.gn index 60de009bfed9..9ff3a8d040d9 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -232,6 +232,7 @@ test("brave_browser_tests") { "//brave/app/sharedarraybuffer_disabledtest.cc", "//brave/browser/autocomplete/brave_autocomplete_provider_client_browsertest.cc", "//brave/chromium_src/chrome/browser/google/chrome_google_url_tracker_client_browsertest.cc", + "//brave/chromium_src/components/content_settings/core/browser/brave_content_settings_registry_browsertest.cc", "//brave/chromium_src/third_party/blink/renderer/modules/battery/navigator_batterytest.cc", "//brave/chromium_src/third_party/blink/renderer/modules/bluetooth/navigator_bluetoothtest.cc", "//brave/chromium_src/third_party/blink/renderer/modules/credentialmanager/credentials_containertest.cc",