Skip to content

Commit

Permalink
Merge pull request #1097 from brave/fix_shields_settings_in_private
Browse files Browse the repository at this point in the history
Fix shields setting in private is weird
  • Loading branch information
simonhong committed Jan 1, 2019
1 parent f469f10 commit e034955
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit e034955

Please sign in to comment.