Merge pull request #9215 from brave/bugfix/fingerprinting/dark-mode-settings

Bugfix: dark mode broken for settings when strict fingerprinting
This commit is contained in:
Shivan Kaul Sahib
2021-06-23 11:30:53 -07:00
committed by GitHub
2 changed files with 19 additions and 3 deletions
+5 -3
View File
@@ -691,12 +691,14 @@ bool BraveContentBrowserClient::OverrideWebPreferencesAfterNavigation(
web_contents, prefs);
Profile* profile =
Profile::FromBrowserContext(web_contents->GetBrowserContext());
const GURL url = web_contents->GetLastCommittedURL();
const bool shields_up = brave_shields::GetBraveShieldsEnabled(
HostContentSettingsMapFactory::GetForProfile(profile), url);
auto fingerprinting_type = brave_shields::GetFingerprintingControlType(
HostContentSettingsMapFactory::GetForProfile(profile),
web_contents->GetLastCommittedURL());
HostContentSettingsMapFactory::GetForProfile(profile), url);
// https://github.com/brave/brave-browser/issues/15265
// Always use color scheme Light if fingerprinting mode strict
if (fingerprinting_type == ControlType::BLOCK) {
if (shields_up && fingerprinting_type == ControlType::BLOCK) {
prefs->preferred_color_scheme = blink::mojom::PreferredColorScheme::kLight;
changed = true;
}
@@ -27,6 +27,9 @@
using brave_shields::ControlType;
const char kEmbeddedTestServerDirectory[] = "dark_mode_block";
const char kMatchDarkMode[] =
"window.domAutomationController.send(window.matchMedia('(prefers-color-"
"scheme: dark)').matches)";
class BraveDarkModeFingerprintProtection : public InProcessBrowserTest {
public:
@@ -143,3 +146,14 @@ IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, RegressionCheck) {
ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
EXPECT_EQ(base::ASCIIToUTF16("light"), tab_title);
}
IN_PROC_BROWSER_TEST_F(BraveDarkModeFingerprintProtection, SettingsPagesCheck) {
// On settings page should get dark mode with fingerprinting strict
test_theme_.SetDarkMode(true);
BlockFingerprinting();
NavigateToURLUntilLoadStop(GURL("brave://settings"));
bool result;
ASSERT_TRUE(content::ExecuteScriptAndExtractBool(contents(), kMatchDarkMode,
&result));
EXPECT_TRUE(result);
}