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 @@ ...@@ -92,14 +92,12 @@
</template> </template>
<paper-icon-button id="resetSite" icon="cr:delete" <paper-icon-button id="resetSite" icon="cr:delete"
hidden="[[isResetButtonHidden_( hidden="[[shouldHideResetButton_(item, readOnlyList)]]"
item.enforcement, readOnlyList)]]"
on-tap="onResetButtonTap_" on-tap="onResetButtonTap_"
alt="$i18n{siteSettingsActionReset}"> alt="$i18n{siteSettingsActionReset}">
</paper-icon-button> </paper-icon-button>
<paper-icon-button id="actionMenuButton" icon="cr:more-vert" <paper-icon-button id="actionMenuButton" icon="cr:more-vert"
hidden= hidden="[[shouldHideActionMenu_(item, readOnlyList)]]"
"[[isActionMenuHidden_(item.enforcement, readOnlyList)]]"
on-tap="onShowActionMenuTap_" title="$i18n{moreActions}"> on-tap="onShowActionMenuTap_" title="$i18n{moreActions}">
</paper-icon-button> </paper-icon-button>
</div> </div>
......
...@@ -184,26 +184,27 @@ Polymer({ ...@@ -184,26 +184,27 @@ Polymer({
}, },
/** /**
* @param {chrome.settingsPrivate.Enforcement} enforcement The level of * @param {!SiteException} exception The content setting exception.
* enforcement.
* @param {boolean} readOnlyList Whether the site exception list is read-only. * @param {boolean} readOnlyList Whether the site exception list is read-only.
* @return {boolean} * @return {boolean}
* @private * @private
*/ */
isResetButtonHidden_: function(enforcement, readOnlyList) { shouldHideResetButton_: function(exception, readOnlyList) {
return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED || return exception.enforcement ==
this.allSites || !readOnlyList; 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. * @param {boolean} readOnlyList Whether the site exception list is read-only.
* @return {boolean} * @return {boolean}
* @private * @private
*/ */
isActionMenuHidden_: function(enforcement, readOnlyList) { shouldHideActionMenu_: function(exception, readOnlyList) {
return enforcement == chrome.settingsPrivate.Enforcement.ENFORCED || return exception.enforcement ==
this.allSites || readOnlyList; chrome.settingsPrivate.Enforcement.ENFORCED ||
this.allSites || readOnlyList || !!exception.embeddingOrigin;
}, },
/** /**
......
...@@ -126,6 +126,29 @@ var prefsMixedProvider = { ...@@ -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. * An example pref with mixed origin and pattern.
* @type {SiteSettingsPref} * @type {SiteSettingsPref}
...@@ -139,7 +162,7 @@ var prefsMixedOriginAndPattern = { ...@@ -139,7 +162,7 @@ var prefsMixedOriginAndPattern = {
geolocation: [ geolocation: [
{ {
origin: 'https://foo.com', origin: 'https://foo.com',
embeddingOrigin: '*', embeddingOrigin: 'https://example.com',
setting: 'allow', setting: 'allow',
source: 'preference', source: 'preference',
}, },
...@@ -148,7 +171,7 @@ var prefsMixedOriginAndPattern = { ...@@ -148,7 +171,7 @@ var prefsMixedOriginAndPattern = {
javascript: [ javascript: [
{ {
origin: 'https://[*.]foo.com', origin: 'https://[*.]foo.com',
embeddingOrigin: '*', embeddingOrigin: '',
setting: 'allow', setting: 'allow',
source: 'preference', source: 'preference',
}, },
...@@ -177,14 +200,14 @@ var prefsVarious = { ...@@ -177,14 +200,14 @@ var prefsVarious = {
cookies: [], cookies: [],
geolocation: [ geolocation: [
{ {
embeddingOrigin: 'https://foo.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://foo.com', origin: 'https://foo.com',
setting: 'allow', setting: 'allow',
source: 'preference', source: 'preference',
}, },
{ {
embeddingOrigin: 'https://bar.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://bar.com', origin: 'https://bar.com',
setting: 'block', setting: 'block',
...@@ -197,21 +220,21 @@ var prefsVarious = { ...@@ -197,21 +220,21 @@ var prefsVarious = {
midiDevices: [], midiDevices: [],
notifications: [ notifications: [
{ {
embeddingOrigin: 'https://google.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://google.com', origin: 'https://google.com',
setting: 'block', setting: 'block',
source: 'preference', source: 'preference',
}, },
{ {
embeddingOrigin: 'https://bar.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://bar.com', origin: 'https://bar.com',
setting: 'block', setting: 'block',
source: 'preference', source: 'preference',
}, },
{ {
embeddingOrigin: 'https://foo.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://foo.com', origin: 'https://foo.com',
setting: 'block', setting: 'block',
...@@ -234,7 +257,7 @@ var prefsOneEnabled = { ...@@ -234,7 +257,7 @@ var prefsOneEnabled = {
exceptions: { exceptions: {
geolocation: [ geolocation: [
{ {
embeddingOrigin: 'https://foo-allow.com:443', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://foo-allow.com:443', origin: 'https://foo-allow.com:443',
setting: 'allow', setting: 'allow',
...@@ -252,7 +275,7 @@ var prefsOneDisabled = { ...@@ -252,7 +275,7 @@ var prefsOneDisabled = {
exceptions: { exceptions: {
geolocation: [ geolocation: [
{ {
embeddingOrigin: 'https://foo-block.com:443', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'https://foo-block.com:443', origin: 'https://foo-block.com:443',
setting: 'block', setting: 'block',
...@@ -270,21 +293,21 @@ var prefsSessionOnly = { ...@@ -270,21 +293,21 @@ var prefsSessionOnly = {
exceptions: { exceptions: {
cookies: [ cookies: [
{ {
embeddingOrigin: 'http://foo-block.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'http://foo-block.com', origin: 'http://foo-block.com',
setting: 'block', setting: 'block',
source: 'preference', source: 'preference',
}, },
{ {
embeddingOrigin: 'http://foo-allow.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'http://foo-allow.com', origin: 'http://foo-allow.com',
setting: 'allow', setting: 'allow',
source: 'preference', source: 'preference',
}, },
{ {
embeddingOrigin: 'http://foo-session.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'http://foo-session.com', origin: 'http://foo-session.com',
setting: 'session_only', setting: 'session_only',
...@@ -303,13 +326,13 @@ var prefsIncognito = { ...@@ -303,13 +326,13 @@ var prefsIncognito = {
cookies: [ cookies: [
// foo.com is blocked for regular sessions. // foo.com is blocked for regular sessions.
{ {
embeddingOrigin: 'http://foo.com', embeddingOrigin: '',
incognito: false, incognito: false,
origin: 'http://foo.com', origin: 'http://foo.com',
setting: 'block', setting: 'block',
source: 'preference', source: 'preference',
}, },
// bar.com is an allowed incognito item without an embedder. // bar.com is an allowed incognito item.
{ {
embeddingOrigin: '', embeddingOrigin: '',
incognito: true, incognito: true,
...@@ -319,7 +342,7 @@ var prefsIncognito = { ...@@ -319,7 +342,7 @@ var prefsIncognito = {
}, },
// foo.com is allowed in incognito (overridden). // foo.com is allowed in incognito (overridden).
{ {
embeddingOrigin: 'http://foo.com', embeddingOrigin: '',
incognito: true, incognito: true,
origin: 'http://foo.com', origin: 'http://foo.com',
setting: 'allow', setting: 'allow',
...@@ -683,7 +706,7 @@ suite('SiteList', function() { ...@@ -683,7 +706,7 @@ suite('SiteList', function() {
}) })
.then(function(args) { .then(function(args) {
assertEquals('http://foo.com', args[0]); assertEquals('http://foo.com', args[0]);
assertEquals('http://foo.com', args[1]); assertEquals('', args[1]);
assertEquals(contentType, args[2]); assertEquals(contentType, args[2]);
assertFalse(args[3]); // Incognito. assertFalse(args[3]); // Incognito.
}); });
...@@ -721,7 +744,7 @@ suite('SiteList', function() { ...@@ -721,7 +744,7 @@ suite('SiteList', function() {
}) })
.then(function(args) { .then(function(args) {
assertEquals('http://foo.com', args[0]); assertEquals('http://foo.com', args[0]);
assertEquals('http://foo.com', args[1]); assertEquals('', args[1]);
assertEquals(contentType, args[2]); assertEquals(contentType, args[2]);
assertTrue(args[3]); // Incognito. assertTrue(args[3]); // Incognito.
}); });
...@@ -763,7 +786,7 @@ suite('SiteList', function() { ...@@ -763,7 +786,7 @@ suite('SiteList', function() {
}) })
.then(function(args) { .then(function(args) {
assertEquals('https://foo-allow.com:443', args[0]); assertEquals('https://foo-allow.com:443', args[0]);
assertEquals('https://foo-allow.com:443', args[1]); assertEquals('', args[1]);
assertEquals(contentType, args[2]); assertEquals(contentType, args[2]);
}); });
}); });
...@@ -1012,6 +1035,25 @@ suite('SiteList', function() { ...@@ -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() { test('Mixed schemes (present and absent)', function() {
// Prefs: One item with scheme and one without. // Prefs: One item with scheme and one without.
setUpCategory( 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