Commit 3dd6dab7 authored by Patricia Lor's avatar Patricia Lor Committed by Commit Bot

MD Settings: Show default settings in the drop-down menu in Site Details.

The Site Details page currently only shows two options in the drop-down menu
for each permission, 'Allow' and 'Block'. This change adds a third option to the
list, which shows the default option, similar to the Page Info bubble.

The "Site Details" page that opens should show matching permissions to those
seen in the Page Info bubble, including the defaults - e.g. Javascript should be
"Allow (default)", Popups should be "Block (default)", and Camera should be
"Ask (default)". Navigating to chrome:settings/content/camera and toggling the
"Ask before accessing (recommended)" option should then make the Site Details
page for for https://permission.site show "Block (default)" next to the Camera
permission.

Bug: 656758
Change-Id: I74cd332c44d8fcb1ab5c700e4fa394ce74fe973b
Test: With the #enable-site-details flag turned on, navigate to
https: //permission.site, open the Page Info bubble, and click "Site settings".
Reviewed-on: https://chromium-review.googlesource.com/558541
Commit-Queue: Patti <patricialor@chromium.org>
Reviewed-by: default avatarDave Schuyler <dschuyler@chromium.org>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarRaymes Khoury <raymes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488086}
parent b1e047ad
......@@ -2176,6 +2176,15 @@
<message name="IDS_SETTINGS_SITE_SETTINGS_SITE_URL" desc="Label for site URL text entry in site settings.">
Site URL
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ASK_DEFAULT_MENU" desc="Label for the default menu item to ask for permission for a particular site.">
Ask (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ALLOW_DEFAULT_MENU" desc="Label for the default menu item to allow a permission for a particular site.">
Allow (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_BLOCK_DEFAULT_MENU" desc="Label for the default menu item to block a permission for a particular site.">
Block (default)
</message>
<message name="IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU" desc="Label for the menu item to allow permission for a particular site.">
Allow
</message>
......
......@@ -195,6 +195,7 @@
'dependencies': [
'<(DEPTH)/ui/webui/resources/js/compiled_resources2.gyp:cr',
'<(EXTERNS_GYP):chrome_send',
'<(EXTERNS_GYP):settings_private',
'constants',
'cookie_tree_node',
],
......
......@@ -83,10 +83,8 @@ Polymer({
exceptionList.forEach(function(exception, i) {
// |exceptionList| should be in the same order as |categoryList|,
// which is in the same order as |siteDetailsPermissions|.
var element = /** @type{!SiteDetailsPermissionElement} */ (
siteDetailsPermissions[i]);
element.site = /** @type{!SiteException} */ (
element.expandSiteException(exception));
siteDetailsPermissions[i].site =
/** @type {!RawSiteException} */ (exception);
});
});
},
......
......@@ -23,6 +23,13 @@
<select id="permission" class="md-select"
aria-labelledby="permissionHeader"
on-change="onPermissionSelectionChange_">
<option id="default" value$="[[ContentSetting.DEFAULT]]">
[[defaultSettingString_(
defaultSetting_,
'$i18nPolymer{siteSettingsActionAskDefault}',
'$i18nPolymer{siteSettingsActionAllowDefault}',
'$i18nPolymer{siteSettingsActionBlockDefault}')]]
</option>
<option id="allow" value$="[[ContentSetting.ALLOW]]">
$i18n{siteSettingsActionAllow}
</option>
......
......@@ -15,9 +15,16 @@ Polymer({
properties: {
/**
* The site that this widget is showing details for.
* @type {SiteException}
* @type {RawSiteException}
*/
site: Object,
/**
* The default setting for this permission category.
* @type {settings.ContentSetting}
* @private
*/
defaultSetting_: String,
},
observers: ['siteChanged_(site, category)'],
......@@ -44,10 +51,20 @@ Polymer({
/**
* Updates the drop-down value after |site| has changed.
* @param {!SiteException} site The site to display.
* @param {!RawSiteException} site The site to display.
* @private
*/
siteChanged_: function(site) {
if (site.source == 'default') {
this.defaultSetting_ = site.setting;
this.$.permission.value = settings.ContentSetting.DEFAULT;
return;
}
// The default setting is unknown, so consult the C++ backend for it.
this.browserProxy.getDefaultValueForContentType(this.category)
.then((defaultValue) => {
this.defaultSetting_ = defaultValue.setting;
});
this.$.permission.value = site.setting;
},
......@@ -86,8 +103,34 @@ Polymer({
* @private
*/
onPermissionSelectionChange_: function() {
if (this.$.permission.value == settings.ContentSetting.DEFAULT) {
this.resetPermission();
return;
}
this.browserProxy.setCategoryPermissionForOrigin(
this.site.origin, this.site.embeddingOrigin, this.category,
this.$.permission.value, this.site.incognito);
},
/**
* Updates the string used for this permission category's default setting.
* @param {!settings.ContentSetting} defaultSetting Value of the default
* setting for this permission category.
* @param {string} askString 'Ask' label, e.g. 'Ask (default)'.
* @param {string} allowString 'Allow' label, e.g. 'Allow (default)'.
* @param {string} blockString 'Block' label, e.g. 'Blocked (default)'.
* @private
*/
defaultSettingString_(defaultSetting, askString, allowString, blockString) {
if (defaultSetting == settings.ContentSetting.ASK ||
defaultSetting == settings.ContentSetting.IMPORTANT_CONTENT) {
return askString;
} else if (defaultSetting == settings.ContentSetting.ALLOW) {
return allowString;
} else if (defaultSetting == settings.ContentSetting.BLOCK) {
return blockString;
}
assertNotReached(
`No string for ${this.category}'s default of ${defaultSetting}`);
},
});
......@@ -145,13 +145,15 @@ var SiteSettingsBehaviorImpl = {
var origin = exception.origin;
var embeddingOrigin = exception.embeddingOrigin;
var enforcement = '';
var enforcement = /** @type {?chrome.settingsPrivate.Enforcement} */ (null);
if (exception.source == 'extension' || exception.source == 'HostedApp' ||
exception.source == 'platform_app' || exception.source == 'policy') {
enforcement = chrome.settingsPrivate.Enforcement.ENFORCED;
}
var controlledBy = kControlledByLookup[exception.source] || '';
var controlledBy = /** @type {!chrome.settingsPrivate.ControlledBy} */ (
kControlledByLookup[exception.source] ||
chrome.settingsPrivate.ControlledBy.PRIMARY_USER);
return {
category: this.category,
......
......@@ -21,11 +21,12 @@ var ContentSettingProvider = {
/**
* The site exception information passed from the C++ handler.
* See also: SiteException.
* TODO(patricialor): Investigate making the |source| field an enum type.
* @typedef {{embeddingOrigin: string,
* incognito: boolean,
* origin: string,
* displayName: string,
* setting: string,
* setting: !settings.ContentSetting,
* source: string}}
*/
var RawSiteException;
......@@ -38,21 +39,15 @@ var RawSiteException;
* incognito: boolean,
* origin: string,
* displayName: string,
* setting: string,
* enforcement: string,
* controlledBy: string}}
* setting: !settings.ContentSetting,
* enforcement: ?chrome.settingsPrivate.Enforcement,
* controlledBy: !chrome.settingsPrivate.ControlledBy}}
*/
var SiteException;
/**
* @typedef {{location: string,
* notifications: string}}
*/
var CategoryDefaultsPref;
/**
* @typedef {{setting: string,
* source: ContentSettingProvider}}
* @typedef {{setting: !settings.ContentSetting,
* source: !ContentSettingProvider}}
*/
var DefaultContentSetting;
......
......@@ -1893,6 +1893,12 @@ void AddSiteSettingsStrings(content::WebUIDataSource* html_source,
{"siteSettingsBlockedRecommended",
IDS_SETTINGS_SITE_SETTINGS_BLOCKED_RECOMMENDED},
{"siteSettingsSiteUrl", IDS_SETTINGS_SITE_SETTINGS_SITE_URL},
{"siteSettingsActionAskDefault",
IDS_SETTINGS_SITE_SETTINGS_ASK_DEFAULT_MENU},
{"siteSettingsActionAllowDefault",
IDS_SETTINGS_SITE_SETTINGS_ALLOW_DEFAULT_MENU},
{"siteSettingsActionBlockDefault",
IDS_SETTINGS_SITE_SETTINGS_BLOCK_DEFAULT_MENU},
{"siteSettingsActionAllow", IDS_SETTINGS_SITE_SETTINGS_ALLOW_MENU},
{"siteSettingsActionBlock", IDS_SETTINGS_SITE_SETTINGS_BLOCK_MENU},
{"siteSettingsActionReset", IDS_SETTINGS_SITE_SETTINGS_RESET_MENU},
......
......@@ -114,23 +114,23 @@ void AddExceptionsGrantedByHostedApps(content::BrowserContext* context,
// 7. User-set global default for a ContentSettingsType.
// 8. Chrome's built-in default.
std::string ConvertContentSettingSourceToString(
content_settings::SettingSource content_settings_source,
const content_settings::SettingInfo& info,
PermissionStatusSource permission_status_source) {
// TODO(patricialor): Do some plumbing for sources #1, #2, #3, and #5 through
// to the Web UI. Currently there aren't strings to represent these sources.
if (permission_status_source == PermissionStatusSource::KILL_SWITCH)
return site_settings::kPreferencesSource; // Source #1.
if (content_settings_source == content_settings::SETTING_SOURCE_POLICY ||
content_settings_source == content_settings::SETTING_SOURCE_SUPERVISED) {
if (info.source == content_settings::SETTING_SOURCE_POLICY ||
info.source == content_settings::SETTING_SOURCE_SUPERVISED) {
return site_settings::kPolicyProviderId; // Source #2.
}
if (content_settings_source == content_settings::SETTING_SOURCE_EXTENSION)
if (info.source == content_settings::SETTING_SOURCE_EXTENSION)
return site_settings::kExtensionProviderId; // Source #3.
DCHECK_NE(content_settings::SETTING_SOURCE_NONE, content_settings_source);
if (content_settings_source == content_settings::SETTING_SOURCE_USER) {
DCHECK_NE(content_settings::SETTING_SOURCE_NONE, info.source);
if (info.source == content_settings::SETTING_SOURCE_USER) {
if (permission_status_source ==
PermissionStatusSource::SAFE_BROWSING_BLACKLIST ||
permission_status_source ==
......@@ -138,7 +138,11 @@ std::string ConvertContentSettingSourceToString(
permission_status_source == PermissionStatusSource::MULTIPLE_IGNORES) {
return site_settings::kPreferencesSource; // Source #5.
}
// Source #4, #6, #7, #8. When #4 is the source, |permission_status_source|
if (info.primary_pattern == ContentSettingsPattern::Wildcard() &&
info.secondary_pattern == ContentSettingsPattern::Wildcard()) {
return "default"; // Source #7, #8.
}
// Source #4, #6. When #4 is the source, |permission_status_source|
// won't be set to any of the source #5 enum values, as PermissionManager is
// aware of the difference between these two sources internally. The
// subtlety here should go away when PermissionManager can handle all
......@@ -177,8 +181,8 @@ ContentSetting GetContentSettingForOrigin(const GURL& origin,
}
// Retrieve the source of the content setting.
*source_string =
ConvertContentSettingSourceToString(info.source, result.source);
*source_string = ConvertContentSettingSourceToString(info, result.source);
return result.content_setting;
}
......
......@@ -59,6 +59,7 @@ class SiteSettingsHandler : public SettingsPageUIHandler,
private:
friend class SiteSettingsHandlerTest;
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, DefaultSettingSource);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, GetAndSetDefault);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, Origins);
FRIEND_TEST_ALL_PREFIXES(SiteSettingsHandlerTest, ExceptionHelpers);
......
......@@ -8,10 +8,14 @@
#include "base/test/histogram_tester.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/host_content_settings_map_factory.h"
#include "chrome/browser/ui/webui/site_settings_helper.h"
#include "chrome/test/base/testing_profile.h"
#include "components/content_settings/core/browser/host_content_settings_map.h"
#include "components/content_settings/core/common/content_settings.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/sync_preferences/testing_pref_service_syncable.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/test/test_browser_thread_bundle.h"
......@@ -34,6 +38,40 @@ const char kSource[] = "source";
namespace settings {
// Helper class for setting ContentSettings via different sources.
class ContentSettingSourceSetter {
public:
ContentSettingSourceSetter(TestingProfile* profile,
ContentSettingsType content_type)
: prefs_(profile->GetTestingPrefService()),
host_content_settings_map_(
HostContentSettingsMapFactory::GetForProfile(profile)),
content_type_(content_type) {}
void SetPolicyDefault(ContentSetting setting) {
prefs_->SetManagedPref(GetPrefNameForDefaultPermissionSetting(),
base::MakeUnique<base::Value>(setting));
}
const char* GetPrefNameForDefaultPermissionSetting() {
switch (content_type_) {
case CONTENT_SETTINGS_TYPE_NOTIFICATIONS:
return prefs::kManagedDefaultNotificationsSetting;
default:
// Add support as needed.
NOTREACHED();
return "";
}
}
private:
sync_preferences::TestingPrefServiceSyncable* prefs_;
HostContentSettingsMap* host_content_settings_map_;
ContentSettingsType content_type_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSourceSetter);
};
class SiteSettingsHandlerTest : public testing::Test {
public:
SiteSettingsHandlerTest() : handler_(&profile_) {
......@@ -50,7 +88,7 @@ class SiteSettingsHandlerTest : public testing::Test {
web_ui()->ClearTrackedCalls();
}
Profile* profile() { return &profile_; }
TestingProfile* profile() { return &profile_; }
content::TestWebUI* web_ui() { return &web_ui_; }
SiteSettingsHandler* handler() { return &handler_; }
......@@ -315,7 +353,61 @@ TEST_F(SiteSettingsHandlerTest, Origins) {
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
// "Ask" is the default value for Notifications.
ValidateOrigin(google, google, google, "ask", "preference", 6U);
ValidateOrigin(google, google, google, "ask", "default", 6U);
}
TEST_F(SiteSettingsHandlerTest, DefaultSettingSource) {
const std::string google("http://www.google.com");
ContentSettingSourceSetter source_setter(profile(),
CONTENT_SETTINGS_TYPE_NOTIFICATIONS);
base::ListValue get_origin_permissions_args;
get_origin_permissions_args.AppendString(kCallbackId);
get_origin_permissions_args.AppendString(google);
auto category_list = base::MakeUnique<base::ListValue>();
category_list->AppendString("notifications");
get_origin_permissions_args.Append(std::move(category_list));
// Test Chrome built-in defaults are marked as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "ask", "default", 1U);
base::ListValue default_value_args;
default_value_args.AppendString("notifications");
default_value_args.AppendString("block");
handler()->HandleSetDefaultValueForContentType(&default_value_args);
// A user-set global default should also show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "block", "default", 3U);
base::ListValue set_notification_pattern_args;
set_notification_pattern_args.AppendString("[*.]google.com");
set_notification_pattern_args.AppendString("*");
set_notification_pattern_args.AppendString("notifications");
set_notification_pattern_args.AppendString("allow");
set_notification_pattern_args.AppendBoolean(false);
handler()->HandleSetCategoryPermissionForOrigin(
&set_notification_pattern_args);
// A user-set pattern should not show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "allow", "preference", 5U);
base::ListValue set_notification_origin_args;
set_notification_origin_args.AppendString(google);
set_notification_origin_args.AppendString(google);
set_notification_origin_args.AppendString("notifications");
set_notification_origin_args.AppendString("block");
set_notification_origin_args.AppendBoolean(false);
handler()->HandleSetCategoryPermissionForOrigin(
&set_notification_origin_args);
// A user-set per-origin permission should not show up as default.
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "block", "preference", 7U);
// Enterprise-policy set defaults should not show up as default.
source_setter.SetPolicyDefault(CONTENT_SETTING_ALLOW);
handler()->HandleGetOriginPermissions(&get_origin_permissions_args);
ValidateOrigin(google, google, google, "allow", "policy", 8U);
}
TEST_F(SiteSettingsHandlerTest, ExceptionHelpers) {
......
......@@ -12,22 +12,30 @@ suite('SiteDetailsPermission', function() {
/**
* An example pref with only camera allowed.
* @type {SiteSettingsPref}
*/
var prefs = {
exceptions: {
camera: [
{
embeddingOrigin: '',
origin: 'https://www.example.com',
setting: 'allow',
source: 'preference',
},
]
}
};
var prefs;
// Initialize a site-details-permission before each test.
setup(function() {
prefs = {
defaults: {
camera: {
setting: settings.ContentSetting.ALLOW,
}
},
exceptions: {
camera: [
{
embeddingOrigin: '',
origin: 'https://www.example.com',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
]
}
};
browserProxy = new TestSiteSettingsPrefsBrowserProxy();
settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody();
......@@ -45,25 +53,32 @@ suite('SiteDetailsPermission', function() {
function isAllowed(origin, exceptionList) {
for (var i = 0; i < exceptionList.length; ++i) {
if (exceptionList[i].origin == origin)
return exceptionList[i].setting == 'allow';
return exceptionList[i].setting == settings.ContentSetting.ALLOW;
}
return false;
};
function validatePermissionFlipWorks(origin, expectedContentSetting) {
browserProxy.resetResolver('setCategoryPermissionForOrigin');
// Flipping a permission typically calls setCategoryPermissionForOrigin, but
// clearing it should call resetCategoryPermissionForOrigin.
var isReset = expectedContentSetting == settings.ContentSetting.DEFAULT;
var expectedMethodCalled = isReset ? 'resetCategoryPermissionForOrigin' :
'setCategoryPermissionForOrigin';
browserProxy.resetResolver(expectedMethodCalled);
// Simulate permission change initiated by the user.
testElement.$.permission.value = expectedContentSetting;
testElement.$.permission.dispatchEvent(new CustomEvent('change'));
return browserProxy.whenCalled('setCategoryPermissionForOrigin')
.then(function(args) {
assertEquals(origin, args[0]);
assertEquals('', args[1]);
assertEquals(testElement.category, args[2]);
assertEquals(expectedContentSetting, args[3]);
});
return browserProxy.whenCalled(expectedMethodCalled).then(function(args) {
assertEquals(origin, args[0]);
assertEquals('', args[1]);
assertEquals(testElement.category, args[2]);
// Since resetting the permission doesn't return its new value, don't
// test it here - checking that the correct method was called is fine.
if (!isReset)
assertEquals(expectedContentSetting, args[3]);
});
};
test('camera category', function() {
......@@ -92,6 +107,60 @@ suite('SiteDetailsPermission', function() {
.then(function() {
return validatePermissionFlipWorks(
origin, settings.ContentSetting.ALLOW);
})
.then(function() {
return validatePermissionFlipWorks(
origin, settings.ContentSetting.DEFAULT);
});
});
test('default string is correct', function() {
var origin = 'https://www.example.com';
browserProxy.setPrefs(prefs)
testElement.category = settings.ContentSettingsTypes.CAMERA;
testElement.label = 'Camera';
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.ALLOW,
};
return browserProxy.whenCalled('getDefaultValueForContentType')
.then(function() {
// The default option will always be the first in the menu.
assertEquals(
'Allow (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
browserProxy.resetResolver('getDefaultValueForContentType');
prefs.defaults.camera.setting = settings.ContentSetting.BLOCK;
browserProxy.setPrefs(prefs);
// Trigger a call to siteChanged_() by touching |testElement.site|.
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.BLOCK
};
return browserProxy.whenCalled('getDefaultValueForContentType');
})
.then(function() {
assertEquals(
'Block (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
browserProxy.resetResolver('getDefaultValueForContentType');
prefs.defaults.camera.setting = settings.ContentSetting.ASK;
browserProxy.setPrefs(prefs);
// Trigger a call to siteChanged_() by touching |testElement.site|.
testElement.site = {
origin: origin,
embeddingOrigin: '',
setting: settings.ContentSetting.ASK
};
return browserProxy.whenCalled('getDefaultValueForContentType');
})
.then(function() {
assertEquals(
'Ask (default)', testElement.$.permission.options[0].text,
'Default setting string should match prefs');
});
});
});
......@@ -11,103 +11,141 @@ suite('SiteDetails', function() {
var testElement;
/**
* An example pref with 1 allowed in each category.
* An example pref with 1 pref in each category.
* @type {SiteSettingsPref}
*/
var prefs = {
exceptions: {
auto_downloads: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
var prefs;
// Initialize a site-details before each test.
setup(function() {
prefs = {
defaults: {
auto_downloads: {
setting: settings.ContentSetting.ASK,
},
],
background_sync: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
background_sync: {
setting: settings.ContentSetting.ALLOW,
},
],
camera: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'extension',
camera: {
setting: settings.ContentSetting.ASK,
},
],
geolocation: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'block',
source: 'policy',
geolocation: {
setting: settings.ContentSetting.ASK,
},
],
images: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
images: {
setting: settings.ContentSetting.ALLOW,
},
],
javascript: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
javascript: {
setting: settings.ContentSetting.ALLOW,
},
],
mic: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
mic: {
setting: settings.ContentSetting.ASK,
},
],
notifications: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
notifications: {
setting: settings.ContentSetting.ASK,
},
],
plugins: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
plugins: {
setting: settings.ContentSetting.ASK,
},
],
popups: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
popups: {
setting: settings.ContentSetting.BLOCK,
},
],
unsandboxed_plugins: [
{
embeddingOrigin: 'https://foo-allow.com:443',
origin: 'https://foo-allow.com:443',
setting: 'allow',
source: 'preference',
unsandboxed_plugins: {
setting: settings.ContentSetting.ASK,
},
],
}
};
},
exceptions: {
auto_downloads: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
background_sync: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
camera: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
geolocation: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
images: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'default',
},
],
javascript: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
mic: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
notifications: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.BLOCK,
source: 'policy',
},
],
plugins: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'extension',
},
],
popups: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.BLOCK,
source: 'default',
},
],
unsandboxed_plugins: [
{
embeddingOrigin: 'https://foo.com:443',
origin: 'https://foo.com:443',
setting: settings.ContentSetting.ALLOW,
source: 'preference',
},
],
}
};
// Initialize a site-details before each test.
setup(function() {
browserProxy = new TestSiteSettingsPrefsBrowserProxy();
settings.SiteSettingsPrefsBrowserProxyImpl.instance_ = browserProxy;
PolymerTest.clearBody();
......@@ -133,7 +171,7 @@ suite('SiteDetails', function() {
Polymer.dom(parent).appendChild(api);
browserProxy.setPrefs(prefs);
testElement.origin = 'https://foo-allow.com:443';
testElement.origin = 'https://foo.com:443';
Polymer.dom.flush();
......@@ -143,17 +181,40 @@ suite('SiteDetails', function() {
test('correct pref settings are shown', function() {
browserProxy.setPrefs(prefs);
testElement.origin = 'https://foo-allow.com:443';
testElement.origin = 'https://foo.com:443';
return browserProxy.whenCalled('getOriginPermissions').then(function() {
testElement.root.querySelectorAll('site-details-permission')
.forEach(function(siteDetailsPermission) {
// Verify settings match the values specified in |prefs|.
var setting = 'allow';
if (siteDetailsPermission.site.category == 'location')
setting = 'block';
assertEquals(setting, siteDetailsPermission.site.setting);
assertEquals(setting, siteDetailsPermission.$.permission.value);
var expectedSetting = settings.ContentSetting.ALLOW;
var expectedSource = 'preference';
var expectedMenuValue = settings.ContentSetting.ALLOW;
// For all the categories with non-user-set 'Allow' preferences,
// update expected values.
if (siteDetailsPermission.category ==
settings.ContentSettingsTypes.NOTIFICATIONS ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.PLUGINS ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.JAVASCRIPT ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.IMAGES ||
siteDetailsPermission.category ==
settings.ContentSettingsTypes.POPUPS) {
expectedSetting =
prefs.exceptions[siteDetailsPermission.category][0].setting;
expectedSource =
prefs.exceptions[siteDetailsPermission.category][0].source;
expectedMenuValue = (expectedSource == 'default') ?
settings.ContentSetting.DEFAULT :
expectedSetting;
}
assertEquals(expectedSetting, siteDetailsPermission.site.setting);
assertEquals(expectedSource, siteDetailsPermission.site.source);
assertEquals(
expectedMenuValue, siteDetailsPermission.$.permission.value);
});
});
});
......
......@@ -546,7 +546,7 @@ suite('SiteList', function() {
assertEquals(
kControlledByLookup[prefsMixedProvider.exceptions.geolocation[i]
.source] ||
'',
chrome.settingsPrivate.ControlledBy.PRIMARY_USER,
testElement.sites[i].controlledBy);
}
});
......
......@@ -3,53 +3,35 @@
// found in the LICENSE file.
/**
* In the real (non-test) code, this data comes from the C++ handler.
* Only used for tests.
* @typedef {{
* auto_downloads: !Array<!RawSiteException>},
* background_sync: !Array<!RawSiteException>},
* camera: !Array<!RawSiteException>},
* cookies: !Array<!RawSiteException>},
* geolocation: !Array<!RawSiteException>},
* javascript: !Array<!RawSiteException>},
* mic: !Array<!RawSiteException>},
* midiDevices: !Array<!RawSiteException>},
* notifications: !Array<!RawSiteException>},
* plugins: !Array<!RawSiteException>},
* images: !Array<!RawSiteException>},
* popups: !Array<!RawSiteException>},
* unsandboxed_plugins: !Array<!RawSiteException>},
* }}
*/
var ExceptionListPref;
/**
* In the real (non-test) code, these data come from the C++ handler.
* Only used for tests.
* @typedef {{defaults: CategoryDefaultsPref,
* exceptions: ExceptionListPref}}
* @typedef {{defaults: Map<string, !DefaultContentSetting>,
* exceptions: !Map<string, !Array<!RawSiteException>>}}
*/
var SiteSettingsPref;
/**
* An example empty pref.
* TODO(patricialor): Use the values from settings.ContentSettingsTypes (see
* site_settings/constants.js) as the keys for these instead.
* @type {SiteSettingsPref}
*/
var prefsEmpty = {
defaults: {
ads: '',
auto_downloads: '',
background_sync: '',
camera: '',
cookies: '',
geolocation: '',
javascript: '',
mic: '',
midiDevices: '',
notifications: '',
plugins: '',
images: '',
popups: '',
unsandboxed_plugins: '',
ads: {},
auto_downloads: {},
background_sync: {},
camera: {},
cookies: {},
geolocation: {},
javascript: {},
mic: {},
midiDevices: {},
notifications: {},
plugins: {},
images: {},
popups: {},
unsandboxed_plugins: {},
},
exceptions: {
ads: [],
......@@ -203,10 +185,11 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
var pref = undefined;
if (contentType == settings.ContentSettingsTypes.ADS) {
pref = this.prefs_.defaults.ads;
} else if (contentType == settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS) {
} else if (
contentType == settings.ContentSettingsTypes.AUTOMATIC_DOWNLOADS) {
pref = this.prefs_.defaults.auto_downloads;
} else if (contentType == settings.ContentSettingsTypes.BACKGROUND_SYNC) {
pref = this.prefs_.background_sync;
pref = this.prefs_.defaults.background_sync;
} else if (contentType == settings.ContentSettingsTypes.CAMERA) {
pref = this.prefs_.defaults.camera;
} else if (contentType == settings.ContentSettingsTypes.COOKIES) {
......@@ -336,10 +319,12 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
contentType = 'unsandboxed_plugins';
}
var setting = undefined;
var setting;
var source;
this.prefs_.exceptions[contentType].some(function(originPrefs) {
if (originPrefs.origin == origin) {
setting = originPrefs.setting;
source = originPrefs.source;
return true;
}
});
......@@ -354,7 +339,7 @@ TestSiteSettingsPrefsBrowserProxy.prototype = {
origin: origin,
displayName: '',
setting: setting,
source: undefined
source: source,
})
}, this);
return Promise.resolve(exceptionList);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment