Commit 86a57c84 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Only check Chrome OS only policies on Chrome OS

Only use color and duplex setByPolicy on Chrome OS, since these
policies aren't implemented on other platforms.

To make this simpler, move logic for computing whether any setting on
the page is managed out of header.js and into model.js. This is also
more reasonable since model.js is responsible for tracking the settings
and is the only element where settings' |setByPolicy| field is updated.

Change-Id: Ie682c38ffd775cccc4f47c15b66fa85a46761e20
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1500785Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#637584}
parent b2857a80
...@@ -81,7 +81,8 @@ ...@@ -81,7 +81,8 @@
</style> </style>
<print-preview-state id="state" state="{{state}}"></print-preview-state> <print-preview-state id="state" state="{{state}}"></print-preview-state>
<print-preview-model id="model" settings="{{settings}}" <print-preview-model id="model" settings="{{settings}}"
destination="{{destination_}}" document-settings="[[documentSettings_]]" controls-managed="{{controlsManaged_}}" destination="{{destination_}}"
document-settings="[[documentSettings_]]"
margins="[[margins_]]" page-size="[[pageSize_]]" margins="[[margins_]]" page-size="[[pageSize_]]"
recent-destinations="{{recentDestinations_}}" recent-destinations="{{recentDestinations_}}"
on-save-sticky-settings="onSaveStickySettings_"> on-save-sticky-settings="onSaveStickySettings_">
...@@ -98,7 +99,7 @@ ...@@ -98,7 +99,7 @@
<div id="sidebar" on-setting-valid-changed="onSettingValidChanged_"> <div id="sidebar" on-setting-valid-changed="onSettingValidChanged_">
<print-preview-header destination="[[destination_]]" state="[[state]]" <print-preview-header destination="[[destination_]]" state="[[state]]"
error-message="[[errorMessage_]]" settings="[[settings]]" error-message="[[errorMessage_]]" settings="[[settings]]"
on-print-requested="onPrintRequested_" managed="[[controlsManaged_]]" on-print-requested="onPrintRequested_"
on-cancel-requested="onCancelRequested_"> on-cancel-requested="onCancelRequested_">
</print-preview-header> </print-preview-header>
<div id="container"> <div id="container">
......
...@@ -56,6 +56,9 @@ Polymer({ ...@@ -56,6 +56,9 @@ Polymer({
computed: 'computeControlsDisabled_(state)', computed: 'computeControlsDisabled_(state)',
}, },
/** @private {boolean} */
controlsManaged_: Boolean,
/** @private {print_preview.Destination} */ /** @private {print_preview.Destination} */
destination_: { destination_: {
type: Object, type: Object,
...@@ -423,9 +426,11 @@ Polymer({ ...@@ -423,9 +426,11 @@ Polymer({
this.$.model.applyStickySettings(); this.$.model.applyStickySettings();
} }
// <if expr="chromeos">
if (this.destination_) { if (this.destination_) {
this.$.model.applyDestinationSpecificPolicies(); this.$.model.applyDestinationSpecificPolicies();
} }
// </if>
if (this.state == print_preview_new.State.NOT_READY || if (this.state == print_preview_new.State.NOT_READY ||
this.state == print_preview_new.State.INVALID_PRINTER) { this.state == print_preview_new.State.INVALID_PRINTER) {
......
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
</style> </style>
<div class="title-container"> <div class="title-container">
<h1 class="title">$i18n{title}</h1> <h1 class="title">$i18n{title}</h1>
<iron-icon hidden$="[[!managed_]]" icon="print-preview:business" <iron-icon hidden$="[[!managed]]" icon="print-preview:business"
alt="" title="$i18n{managedSettings}"> alt="" title="$i18n{managedSettings}">
</iron-icon> </iron-icon>
</div> </div>
......
...@@ -30,14 +30,7 @@ Polymer({ ...@@ -30,14 +30,7 @@ Polymer({
value: false, value: false,
}, },
/** @private */ managed: Boolean,
managed_: {
type: Boolean,
computed: 'computeManaged_(settings.headerFooter.setByPolicy, ' +
'settings.headerFooter.available, settings.color.setByPolicy, ' +
'settings.color.available, settings.duplex.setByPolicy, ' +
'settings.duplex.available)',
},
/** @private */ /** @private */
printButtonLabel_: { printButtonLabel_: {
...@@ -196,16 +189,4 @@ Polymer({ ...@@ -196,16 +189,4 @@ Polymer({
'printPreviewSummaryFormatShort', labelInfo.numSheets.toLocaleString(), 'printPreviewSummaryFormatShort', labelInfo.numSheets.toLocaleString(),
labelInfo.summaryLabel); labelInfo.summaryLabel);
}, },
/**
* @return {boolean} Whether any setting on the page is managed by enterprise
* policy.
* @private
*/
computeManaged_: function() {
return ['color', 'duplex', 'headerFooter'].some(settingName => {
const setting = this.getSetting(settingName);
return setting.available && setting.setByPolicy;
});
},
}); });
...@@ -297,6 +297,12 @@ Polymer({ ...@@ -297,6 +297,12 @@ Polymer({
}, },
}, },
controlsManaged: {
type: Boolean,
notify: true,
value: false,
},
/** @type {print_preview.Destination} */ /** @type {print_preview.Destination} */
destination: { destination: {
type: Object, type: Object,
...@@ -740,11 +746,13 @@ Polymer({ ...@@ -740,11 +746,13 @@ Polymer({
} }
} }
this.initialized_ = true; this.initialized_ = true;
this.updateManaged_();
this.stickySettings_ = null; this.stickySettings_ = null;
this.updateRecentDestinations_(); this.updateRecentDestinations_();
this.stickySettingsChanged_(); this.stickySettingsChanged_();
}, },
// <if expr="chromeos">
/** /**
* Restricts settings and applies defaults as defined by policy applicable to * Restricts settings and applies defaults as defined by policy applicable to
* current destination. * current destination.
...@@ -770,6 +778,20 @@ Polymer({ ...@@ -770,6 +778,20 @@ Polymer({
duplexValue != print_preview.DuplexModeRestriction.SIMPLEX); duplexValue != print_preview.DuplexModeRestriction.SIMPLEX);
} }
this.set('settings.duplex.setByPolicy', !!duplexPolicy); this.set('settings.duplex.setByPolicy', !!duplexPolicy);
this.updateManaged_();
},
// </if>
/** @private */
updateManaged_: function() {
let managedSettings = ['headerFooter'];
// <if expr="chromeos">
managedSettings = managedSettings.concat(['color', 'duplex']);
// </if>
this.controlsManaged = managedSettings.some(settingName => {
const setting = this.getSetting(settingName);
return setting.available && setting.setByPolicy;
});
}, },
/** @return {boolean} Whether the model has been initialized. */ /** @return {boolean} Whether the model has been initialized. */
......
...@@ -25,14 +25,6 @@ cr.define('header_test', function() { ...@@ -25,14 +25,6 @@ cr.define('header_test', function() {
// whether to show the enterprise managed icon, and pages, copies, and // whether to show the enterprise managed icon, and pages, copies, and
// duplex to compute the number of sheets of paper. // duplex to compute the number of sheets of paper.
const settings = { const settings = {
color: {
value: true, /* color */
unavailableValue: false,
valid: true,
available: true,
setByPolicy: false,
key: 'isColorEnabled',
},
copies: { copies: {
value: '1', value: '1',
unavailableValue: '1', unavailableValue: '1',
...@@ -49,14 +41,6 @@ cr.define('header_test', function() { ...@@ -49,14 +41,6 @@ cr.define('header_test', function() {
setByPolicy: false, setByPolicy: false,
key: 'isDuplexEnabled', key: 'isDuplexEnabled',
}, },
headerFooter: {
value: true,
unavailableValue: false,
valid: true,
available: true,
setByPolicy: false,
key: 'isHeaderFooterEnabled',
},
pages: { pages: {
value: [1], value: [1],
unavailableValue: [], unavailableValue: [],
...@@ -76,6 +60,7 @@ cr.define('header_test', function() { ...@@ -76,6 +60,7 @@ cr.define('header_test', function() {
print_preview.DestinationConnectionStatus.ONLINE); print_preview.DestinationConnectionStatus.ONLINE);
header.errorMessage = ''; header.errorMessage = '';
header.state = print_preview_new.State.READY; header.state = print_preview_new.State.READY;
header.managed = false;
document.body.appendChild(header); document.body.appendChild(header);
}); });
...@@ -186,13 +171,9 @@ cr.define('header_test', function() { ...@@ -186,13 +171,9 @@ cr.define('header_test', function() {
// Tests that enterprise badge shows up if any setting is managed. // Tests that enterprise badge shows up if any setting is managed.
test(assert(TestNames.EnterprisePolicy), function() { test(assert(TestNames.EnterprisePolicy), function() {
['color', 'duplex', 'headerFooter'].forEach(settingName => { assertTrue(header.$$('iron-icon').hidden);
assertTrue(header.$$('iron-icon').hidden); header.managed = true;
header.set(`settings.${settingName}.available`, true); assertFalse(header.$$('iron-icon').hidden);
header.set(`settings.${settingName}.setByPolicy`, true);
assertFalse(header.$$('iron-icon').hidden);
header.set(`settings.${settingName}.setByPolicy`, false);
});
}); });
}); });
......
...@@ -281,6 +281,7 @@ cr.define('settings_sections_tests', function() { ...@@ -281,6 +281,7 @@ cr.define('settings_sections_tests', function() {
colorDefault: print_preview.ColorMode.COLOR, colorDefault: print_preview.ColorMode.COLOR,
expectedValue: true, expectedValue: true,
expectedHidden: true, expectedHidden: true,
expectedManaged: false,
}, },
{ {
// Policy contradicts actual capabilities and is ignored. // Policy contradicts actual capabilities and is ignored.
...@@ -289,6 +290,7 @@ cr.define('settings_sections_tests', function() { ...@@ -289,6 +290,7 @@ cr.define('settings_sections_tests', function() {
colorDefault: print_preview.ColorMode.GRAY, colorDefault: print_preview.ColorMode.GRAY,
expectedValue: true, expectedValue: true,
expectedHidden: true, expectedHidden: true,
expectedManaged: false,
}, },
{ {
// Policy overrides default. // Policy overrides default.
...@@ -330,6 +332,7 @@ cr.define('settings_sections_tests', function() { ...@@ -330,6 +332,7 @@ cr.define('settings_sections_tests', function() {
page.set('destination_.policies', policies); page.set('destination_.policies', policies);
page.set('destination_.capabilities', capabilities); page.set('destination_.capabilities', capabilities);
page.$$('print-preview-model').applyDestinationSpecificPolicies(); page.$$('print-preview-model').applyDestinationSpecificPolicies();
assertEquals(subtestParams.expectedManaged, page.controlsManaged_);
assertEquals( assertEquals(
subtestParams.expectedValue, page.getSettingValue('color')); subtestParams.expectedValue, page.getSettingValue('color'));
assertEquals(subtestParams.expectedHidden, colorElement.hidden); assertEquals(subtestParams.expectedHidden, colorElement.hidden);
...@@ -360,6 +363,7 @@ cr.define('settings_sections_tests', function() { ...@@ -360,6 +363,7 @@ cr.define('settings_sections_tests', function() {
duplexDefault: print_preview.DuplexModeRestriction.SIMPLEX, duplexDefault: print_preview.DuplexModeRestriction.SIMPLEX,
expectedValue: false, expectedValue: false,
expectedHidden: true, expectedHidden: true,
expectedManaged: false,
}, },
{ {
// Policy contradicts actual capabilities and is ignored. // Policy contradicts actual capabilities and is ignored.
...@@ -368,6 +372,7 @@ cr.define('settings_sections_tests', function() { ...@@ -368,6 +372,7 @@ cr.define('settings_sections_tests', function() {
duplexDefault: print_preview.DuplexModeRestriction.LONG_EDGE, duplexDefault: print_preview.DuplexModeRestriction.LONG_EDGE,
expectedValue: false, expectedValue: false,
expectedHidden: true, expectedHidden: true,
expectedManaged: false,
}, },
{ {
// Policy overrides default. // Policy overrides default.
...@@ -409,6 +414,7 @@ cr.define('settings_sections_tests', function() { ...@@ -409,6 +414,7 @@ cr.define('settings_sections_tests', function() {
page.set('destination_.policies', policies); page.set('destination_.policies', policies);
page.set('destination_.capabilities', capabilities); page.set('destination_.capabilities', capabilities);
page.$$('print-preview-model').applyDestinationSpecificPolicies(); page.$$('print-preview-model').applyDestinationSpecificPolicies();
assertEquals(subtestParams.expectedManaged, page.controlsManaged_);
assertEquals( assertEquals(
subtestParams.expectedValue, page.getSettingValue('duplex')); subtestParams.expectedValue, page.getSettingValue('duplex'));
assertEquals( assertEquals(
......
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