Commit b0f2b836 authored by rbpotter's avatar rbpotter Committed by Commit Bot

Print Preview: Fix duplex defaults

Check the internals of the duplex capability, instead of only checking
for its existence, to determine whether to display the duplex checkbox.
Pull default value from the printer if it is available.

Currently a speculative fix, as have not been able to identify a
printer which sets the duplex capability field but does not actually
support duplex.

Bug: 896244
Change-Id: Iebafc3878a1e7658b821465439ee172c479ce413
Reviewed-on: https://chromium-review.googlesource.com/c/1290145
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601790}
parent 0e04db34
......@@ -55,6 +55,16 @@ print_preview_new.DuplexMode = {
UNKNOWN_DUPLEX_MODE: -1
};
/**
* Values matching the types of duplex in a CDD.
* @enum {string}
*/
print_preview_new.DuplexType = {
NO_DUPLEX: 'NO_DUPLEX',
LONG_EDGE: 'LONG_EDGE',
SHORT_EDGE: 'SHORT_EDGE'
};
(function() {
'use strict';
......@@ -380,7 +390,15 @@ Polymer({
'settings.dpi.available',
!!caps && !!caps.dpi && !!caps.dpi.option &&
caps.dpi.option.length > 1);
this.set('settings.duplex.available', !!caps && !!caps.duplex);
this.set(
'settings.duplex.available',
!!caps && !!caps.duplex && !!caps.duplex.option &&
caps.duplex.option.some(
o => o.type == print_preview_new.DuplexType.LONG_EDGE) &&
caps.duplex.option.some(
o => o.type == print_preview_new.DuplexType.NO_DUPLEX));
this.set(
'settings.vendorItems.available', !!caps && !!caps.vendor_capability);
......@@ -546,6 +564,24 @@ Polymer({
this.set('settings.color.unavailableValue', false);
}
if (this.settings.duplex.available) {
const defaultOption = caps.duplex.option.find(o => !!o.is_default);
this.setSetting(
'duplex',
defaultOption ?
defaultOption.type == print_preview_new.DuplexType.LONG_EDGE :
false);
} else if (
caps && caps.duplex && caps.duplex.option &&
!caps.duplex.option.some(
o => o.type != print_preview_new.DuplexType.LONG_EDGE)) {
// If the only option available is long edge, the value should always be
// true.
this.set('settings.duplex.unavailableValue', true);
} else { // If no duplex capability is reported, assume false.
this.set('settings.duplex.unavailableValue', false);
}
if (this.settings.vendorItems.available) {
const vendorSettings = {};
for (const item of caps.vendor_capability) {
......@@ -818,7 +854,9 @@ Polymer({
cjt.print.copies = {copies: parseInt(this.getSettingValue('copies'), 10)};
if (this.settings.duplex.available) {
cjt.print.duplex = {
type: this.settings.duplex.value ? 'LONG_EDGE' : 'NO_DUPLEX'
type: this.settings.duplex.value ?
print_preview_new.DuplexType.LONG_EDGE :
print_preview_new.DuplexType.NO_DUPLEX,
};
}
if (this.settings.mediaSize.available) {
......
......@@ -430,6 +430,19 @@ cr.define('settings_sections_tests', function() {
assertFalse(optionsElement.hidden);
assertTrue(isSectionHidden(duplex));
// Set a duplex capability with only 1 type, no duplex.
capabilities =
print_preview_test_utils.getCddTemplate('FooPrinter').capabilities;
delete capabilities.printer.duplex;
capabilities.printer.duplex = {
option:
[{type: print_preview_new.DuplexType.NO_DUPLEX, is_default: true}]
};
page.set('destination_.capabilities', capabilities);
Polymer.dom.flush();
assertFalse(optionsElement.hidden);
assertTrue(isSectionHidden(duplex));
// PDF
initDocumentInfo(true, false);
Polymer.dom.flush();
......@@ -1023,7 +1036,9 @@ cr.define('settings_sections_tests', function() {
return testOptionCheckbox('headerFooter', true)
.then(function() {
return testOptionCheckbox('duplex', true);
// Duplex defaults to false, since the printer sets no duplex as the
// default in the CDD (see print_preview_test_utils.js).
return testOptionCheckbox('duplex', false);
})
.then(function() {
return testOptionCheckbox('cssBackground', false);
......
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