-
Notifications
You must be signed in to change notification settings - Fork 893
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes brave/brave-browser#6119 Account for CONTENT_SETTING_SESSION_ONLY as a possibility for the default cookie setting in preferences - do not override it with CONTENT_SETTING_ALLOW if it's already set. Added browser test CookiePrefServiceTest.CookieControlType_Preference to test Shields cookie setting change when preference setting changes and in reverse.
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,12 @@ void SetCookiePrefDefaults(HostContentSettingsMap* map, PrefService* prefs) { | |
prefs->SetInteger("profile.default_content_setting_values.cookies", | ||
CONTENT_SETTING_BLOCK); | ||
} else { | ||
prefs->SetInteger("profile.default_content_setting_values.cookies", | ||
CONTENT_SETTING_ALLOW); | ||
int value = | ||
prefs->GetInteger("profile.default_content_setting_values.cookies"); | ||
if (IntToContentSetting(value) != CONTENT_SETTING_SESSION_ONLY) { | ||
value = CONTENT_SETTING_ALLOW; | ||
} | ||
prefs->SetInteger("profile.default_content_setting_values.cookies", value); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mkarolin
Author
Collaborator
|
||
} | ||
} | ||
|
||
|
78 changes: 78 additions & 0 deletions
78
components/brave_shields/browser/cookie_pref_service_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. | ||
* 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/browser/brave_shields_util.h" | ||
#include "chrome/browser/profiles/profile.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "components/content_settings/core/common/content_settings.h" | ||
#include "components/prefs/pref_service.h" | ||
#include "url/gurl.h" | ||
|
||
using brave_shields::ControlType; | ||
|
||
class CookiePrefServiceTest : public InProcessBrowserTest { | ||
public: | ||
CookiePrefServiceTest() = default; | ||
~CookiePrefServiceTest() override = default; | ||
|
||
Profile* profile() { return browser()->profile(); } | ||
|
||
ContentSetting GetCookiePref() { | ||
return IntToContentSetting(profile()->GetPrefs()->GetInteger( | ||
"profile.default_content_setting_values.cookies")); | ||
} | ||
|
||
void SetCookiePref(ContentSetting setting) { | ||
profile()->GetPrefs()->SetInteger( | ||
"profile.default_content_setting_values.cookies", setting); | ||
} | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(CookiePrefServiceTest, CookieControlType_Preference) { | ||
// Initial state | ||
auto setting = brave_shields::GetCookieControlType(profile(), GURL()); | ||
EXPECT_EQ(ControlType::BLOCK_THIRD_PARTY, setting); | ||
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetCookiePref()); | ||
|
||
// Control -> preference | ||
/* BLOCK */ | ||
brave_shields::SetCookieControlType(profile(), ControlType::BLOCK, GURL()); | ||
EXPECT_EQ(CONTENT_SETTING_BLOCK, GetCookiePref()); | ||
|
||
/* ALLOW */ | ||
brave_shields::SetCookieControlType(profile(), ControlType::ALLOW, GURL()); | ||
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetCookiePref()); | ||
|
||
/* BLOCK_THIRD_PARTY */ | ||
brave_shields::SetCookieControlType(profile(), ControlType::BLOCK, GURL()); | ||
EXPECT_EQ(CONTENT_SETTING_BLOCK, GetCookiePref()); | ||
brave_shields::SetCookieControlType(profile(), ControlType::BLOCK_THIRD_PARTY, | ||
GURL()); | ||
EXPECT_EQ(CONTENT_SETTING_ALLOW, GetCookiePref()); | ||
|
||
// Preference -> control | ||
/* BLOCK */ | ||
SetCookiePref(CONTENT_SETTING_BLOCK); | ||
EXPECT_EQ(ControlType::BLOCK, | ||
brave_shields::GetCookieControlType(profile(), GURL())); | ||
|
||
/* ALLOW */ | ||
SetCookiePref(CONTENT_SETTING_ALLOW); | ||
EXPECT_EQ(ControlType::ALLOW, | ||
brave_shields::GetCookieControlType(profile(), GURL())); | ||
|
||
// Preserve CONTENT_SETTING_SESSION_ONLY | ||
SetCookiePref(CONTENT_SETTING_BLOCK); | ||
EXPECT_EQ(ControlType::BLOCK, | ||
brave_shields::GetCookieControlType(profile(), GURL())); | ||
SetCookiePref(CONTENT_SETTING_SESSION_ONLY); | ||
EXPECT_EQ(ControlType::ALLOW, | ||
brave_shields::GetCookieControlType(profile(), GURL())); | ||
SetCookiePref(CONTENT_SETTING_ALLOW); | ||
EXPECT_EQ(ControlType::ALLOW, | ||
brave_shields::GetCookieControlType(profile(), GURL())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
why would you set the value again if it hasn't changed?