Commit ad2fac25 authored by dschuyler's avatar dschuyler Committed by Commit bot

[MD settings] content exceptions with embeddingOrigin as read-only

This CL makes content settings exceptions that have an embeddingOrigin
read-only. That means they may be removed (deleted), but they cannot be
edited (not even changing the category).

BUG=716687
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:closure_compilation

Review-Url: https://codereview.chromium.org/2868223002
Cr-Commit-Position: refs/heads/master@{#472297}
parent 5228a283
......@@ -92,14 +92,12 @@
</template>
<paper-icon-button id="resetSite" icon="cr:delete"
hidden="[[isResetButtonHidden_(
item.enforcement, readOnlyList)]]"
hidden="[[shouldHideResetButton_(item, readOnlyList)]]"
on-tap="onResetButtonTap_"
alt="$i18n{siteSettingsActionReset}">
</paper-icon-button>
<paper-icon-button id="actionMenuButton" icon="cr:more-vert"
hidden=
"[[isActionMenuHidden_(item.enforcement, readOnlyList)]]"
hidden="[[shouldHideActionMenu_(item, readOnlyList)]]"
on-tap="onShowActionMenuTap_" title="$i18n{moreActions}">
</paper-icon-button>
</div>
......
......@@ -184,26 +184,27 @@ Polymer({
},
/**
* @param {chrome.settingsPrivate.Enforcement} enforcement The level of
* enforcement.
* @param {!SiteException} exception The content setting exception.
* @param {boolean} readOnlyList Whether the site exception list is read-only.
* @return {boolean}
* @private
*/
isResetButtonHidden_: function(enforcement, readOnlyList) {
return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
this.allSites || !readOnlyList;
shouldHideResetButton_: function(exception, readOnlyList) {
return exception.enforcement ==
chrome.settingsPrivate.Enforcement.ENFORCED ||
this.allSites || !(readOnlyList || !!exception.embeddingOrigin);
},
/**
* @param {string} enforcement Whether the exception is controlled.
* @param {!SiteException} exception The content setting exception.
* @param {boolean} readOnlyList Whether the site exception list is read-only.
* @return {boolean}
* @private
*/
isActionMenuHidden_: function(enforcement, readOnlyList) {
return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED ||
this.allSites || readOnlyList;
shouldHideActionMenu_: function(exception, readOnlyList) {
return exception.enforcement ==
chrome.settingsPrivate.Enforcement.ENFORCED ||
this.allSites || readOnlyList || !!exception.embeddingOrigin;
},
/**
......
......@@ -126,6 +126,29 @@ var prefsMixedProvider = {
}
};
/**
* An example pref with with and without embeddingOrigin.
* @type {SiteSettingsPref}
*/
var prefsMixedEmbeddingOrigin = {
exceptions: {
images: [
{
origin: 'https://foo.com',
embeddingOrigin: 'https://example.com',
setting: 'allow',
source: 'preference',
},
{
origin: 'https://bar.com',
embeddingOrigin: '',
setting: 'allow',
source: 'preference',
},
],
}
};
/**
* An example pref with mixed origin and pattern.
* @type {SiteSettingsPref}
......@@ -139,7 +162,7 @@ var prefsMixedOriginAndPattern = {
geolocation: [
{
origin: 'https://foo.com',
embeddingOrigin: '*',
embeddingOrigin: 'https://example.com',
setting: 'allow',
source: 'preference',
},
......@@ -148,7 +171,7 @@ var prefsMixedOriginAndPattern = {
javascript: [
{
origin: 'https://[*.]foo.com',
embeddingOrigin: '*',
embeddingOrigin: '',
setting: 'allow',
source: 'preference',
},
......@@ -177,14 +200,14 @@ var prefsVarious = {
cookies: [],
geolocation: [
{
embeddingOrigin: 'https://foo.com',
embeddingOrigin: '',
incognito: false,
origin: 'https://foo.com',
setting: 'allow',
source: 'preference',
},
{
embeddingOrigin: 'https://bar.com',
embeddingOrigin: '',
incognito: false,
origin: 'https://bar.com',
setting: 'block',
......@@ -197,21 +220,21 @@ var prefsVarious = {
midiDevices: [],
notifications: [
{
embeddingOrigin: 'https://google.com',
embeddingOrigin: '',
incognito: false,
origin: 'https://google.com',
setting: 'block',
source: 'preference',
},
{
embeddingOrigin: 'https://bar.com',
embeddingOrigin: '',
incognito: false,
origin: 'https://bar.com',
setting: 'block',
source: 'preference',
},
{
embeddingOrigin: 'https://foo.com',
embeddingOrigin: '',
incognito: false,
origin: 'https://foo.com',
setting: 'block',
......@@ -234,7 +257,7 @@ var prefsOneEnabled = {
exceptions: {
geolocation: [
{
embeddingOrigin: 'https://foo-allow.com:443',
embeddingOrigin: '',
incognito: false,
origin: 'https://foo-allow.com:443',
setting: 'allow',
......@@ -252,7 +275,7 @@ var prefsOneDisabled = {
exceptions: {
geolocation: [
{
embeddingOrigin: 'https://foo-block.com:443',
embeddingOrigin: '',
incognito: false,
origin: 'https://foo-block.com:443',
setting: 'block',
......@@ -270,21 +293,21 @@ var prefsSessionOnly = {
exceptions: {
cookies: [
{
embeddingOrigin: 'http://foo-block.com',
embeddingOrigin: '',
incognito: false,
origin: 'http://foo-block.com',
setting: 'block',
source: 'preference',
},
{
embeddingOrigin: 'http://foo-allow.com',
embeddingOrigin: '',
incognito: false,
origin: 'http://foo-allow.com',
setting: 'allow',
source: 'preference',
},
{
embeddingOrigin: 'http://foo-session.com',
embeddingOrigin: '',
incognito: false,
origin: 'http://foo-session.com',
setting: 'session_only',
......@@ -303,13 +326,13 @@ var prefsIncognito = {
cookies: [
// foo.com is blocked for regular sessions.
{
embeddingOrigin: 'http://foo.com',
embeddingOrigin: '',
incognito: false,
origin: 'http://foo.com',
setting: 'block',
source: 'preference',
},
// bar.com is an allowed incognito item without an embedder.
// bar.com is an allowed incognito item.
{
embeddingOrigin: '',
incognito: true,
......@@ -319,7 +342,7 @@ var prefsIncognito = {
},
// foo.com is allowed in incognito (overridden).
{
embeddingOrigin: 'http://foo.com',
embeddingOrigin: '',
incognito: true,
origin: 'http://foo.com',
setting: 'allow',
......@@ -683,7 +706,7 @@ suite('SiteList', function() {
})
.then(function(args) {
assertEquals('http://foo.com', args[0]);
assertEquals('http://foo.com', args[1]);
assertEquals('', args[1]);
assertEquals(contentType, args[2]);
assertFalse(args[3]); // Incognito.
});
......@@ -721,7 +744,7 @@ suite('SiteList', function() {
})
.then(function(args) {
assertEquals('http://foo.com', args[0]);
assertEquals('http://foo.com', args[1]);
assertEquals('', args[1]);
assertEquals(contentType, args[2]);
assertTrue(args[3]); // Incognito.
});
......@@ -763,7 +786,7 @@ suite('SiteList', function() {
})
.then(function(args) {
assertEquals('https://foo-allow.com:443', args[0]);
assertEquals('https://foo-allow.com:443', args[1]);
assertEquals('', args[1]);
assertEquals(contentType, args[2]);
});
});
......@@ -1012,6 +1035,25 @@ suite('SiteList', function() {
});
});
test('Mixed embeddingOrigin', function() {
setUpCategory(
settings.ContentSettingsTypes.IMAGES, settings.PermissionValues.ALLOW,
prefsMixedEmbeddingOrigin);
return browserProxy.whenCalled('getExceptionList')
.then(function(contentType) {
// Required for firstItem to be found below.
Polymer.dom.flush();
// Validate that embeddingOrigin sites cannot be edited.
var firstItem = testElement.$.listContainer.children[0];
assertTrue(firstItem.querySelector('#actionMenuButton').hidden);
assertFalse(firstItem.querySelector('#resetSite').hidden);
// Validate that non-embeddingOrigin sites can be edited.
var secondItem = testElement.$.listContainer.children[1];
assertFalse(secondItem.querySelector('#actionMenuButton').hidden);
assertTrue(secondItem.querySelector('#resetSite').hidden);
});
});
test('Mixed schemes (present and absent)', function() {
// Prefs: One item with scheme and one without.
setUpCategory(
......
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