Skip to content

Commit

Permalink
Add tests of plugins content settings type with INHERIT_IN_INCOGNITO
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhong committed Dec 15, 2018
1 parent 41ba6d4 commit 985a492
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
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);
}
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,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 985a492

Please sign in to comment.