Commit 2975f8a3 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Show printer errors in Print Preview

This error message will be displayed only on Chrome OS in Print Preview
whenever the currently selected printer is in an error state.

Bug: 1059607
Change-Id: I14449ff21892c21106b7319b8f99bc421897b8b4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2227860
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarRebekah Potter <rbpotter@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781337}
parent 384ce7d5
...@@ -21,13 +21,32 @@ import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js'; ...@@ -21,13 +21,32 @@ import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {Base, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {Base, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination} from '../data/destination.js'; import {CloudOrigins, Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination} from '../data/destination.js';
import {PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from '../data/printer_status_cros.js'; import {PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from '../data/printer_status_cros.js';
import {NativeLayer, NativeLayerImpl} from '../native_layer.js'; import {NativeLayer, NativeLayerImpl} from '../native_layer.js';
import {getSelectDropdownBackground} from '../print_preview_utils.js'; import {getSelectDropdownBackground} from '../print_preview_utils.js';
import {SelectBehavior} from './select_behavior.js'; import {SelectBehavior} from './select_behavior.js';
/** @const {!Map<!PrinterStatusReason, string>} */
const ERROR_STRING_KEY_MAP = new Map([
[PrinterStatusReason.CONNECTING_TO_DEVICE, 'printerStatusConnectingToDevice'],
[PrinterStatusReason.DEVICE_ERROR, 'printerStatusDeviceError'],
[PrinterStatusReason.DOOR_OPEN, 'printerStatusDoorOpen'],
[PrinterStatusReason.LOW_ON_INK, 'printerStatusLowOnInk'],
[PrinterStatusReason.LOW_ON_PAPER, 'printerStatusLowOnPaper'],
[PrinterStatusReason.OUT_OF_INK, 'printerStatusOutOfInk'],
[PrinterStatusReason.OUT_OF_PAPER, 'printerStatusOutOfPaper'],
[PrinterStatusReason.OUTPUT_ALMOST_FULL, 'printerStatusOutputAlmostFull'],
[PrinterStatusReason.OUTPUT_FULL, 'printerStatusOutputFull'],
[PrinterStatusReason.PAPER_JAM, 'printerStatusPaperJam'],
[PrinterStatusReason.PAUSED, 'printerStatusPaused'],
[PrinterStatusReason.PRINTER_QUEUE_FULL, 'printerStatusPrinterQueueFull'],
[PrinterStatusReason.PRINTER_UNREACHABLE, 'printerStatusPrinterUnreachable'],
[PrinterStatusReason.STOPPED, 'printerStatusStopped'],
[PrinterStatusReason.TRAY_MISSING, 'printerStatusTrayMissing'],
]);
Polymer({ Polymer({
is: 'print-preview-destination-select-cros', is: 'print-preview-destination-select-cros',
...@@ -41,7 +60,11 @@ Polymer({ ...@@ -41,7 +60,11 @@ Polymer({
dark: Boolean, dark: Boolean,
/** @type {!Destination} */ /** @type {!Destination} */
destination: Object, destination: {
type: Object,
observer: 'updateStatusText_',
},
disabled: Boolean, disabled: Boolean,
...@@ -65,11 +88,8 @@ Polymer({ ...@@ -65,11 +88,8 @@ Polymer({
value: PDF_DESTINATION_KEY, value: PDF_DESTINATION_KEY,
}, },
/** @private {string} */ /** @private */
statusText_: { statusText_: String,
type: String,
computed: 'computeStatusText_(destination)',
},
/** @private {string} */ /** @private {string} */
backgroundImages_: { backgroundImages_: {
...@@ -98,7 +118,7 @@ Polymer({ ...@@ -98,7 +118,7 @@ Polymer({
* destination.key. This map is needed to track which destinations have had * destination.key. This map is needed to track which destinations have had
* statuses requested while also giving quick look up of destination id to * statuses requested while also giving quick look up of destination id to
* the corresponding destination key. * the corresponding destination key.
* @type {!Map<string, string>} * @private {!Map<string, string>}
*/ */
statusRequestedMap_: Map, statusRequestedMap_: Map,
}, },
...@@ -190,21 +210,6 @@ Polymer({ ...@@ -190,21 +210,6 @@ Polymer({
this.fire('selected-option-change', value); this.fire('selected-option-change', value);
}, },
/**
* @return {string} The connection status text to display.
* @private
*/
computeStatusText_() {
// |destination| can be either undefined, or null here.
if (!this.destination) {
return '';
}
return this.destination.shouldShowInvalidCertificateError ?
this.i18n('noLongerSupportedFragment') :
this.destination.connectionStatusText;
},
/** /**
* @param {!Event} e * @param {!Event} e
* @private * @private
...@@ -278,6 +283,12 @@ Polymer({ ...@@ -278,6 +283,12 @@ Polymer({
// Set the new printer status reason then use notifyPath to trigger the // Set the new printer status reason then use notifyPath to trigger the
// dropdown printer status icons to recalculate their badge color. // dropdown printer status icons to recalculate their badge color.
this.notifyPath(`recentDestinationList.${indexFound}.printerStatusReason`); this.notifyPath(`recentDestinationList.${indexFound}.printerStatusReason`);
// Update the status text if this printer status is for the
// currently selected printer.
if (this.destination && this.destination.key === destinationKey) {
this.updateStatusText_();
}
}, },
/** /**
...@@ -317,4 +328,62 @@ Polymer({ ...@@ -317,4 +328,62 @@ Polymer({
return seenNoErrorReason ? PrinterStatusReason.NO_ERROR : return seenNoErrorReason ? PrinterStatusReason.NO_ERROR :
PrinterStatusReason.UNKNOWN_REASON; PrinterStatusReason.UNKNOWN_REASON;
}, },
/**
* Check the current destination for an error status then set |statusText_|
* appropriately. If no error status exists, unset |statusText_|.
* @private
*/
updateStatusText_: function() {
// |destination| can be either undefined, or null here.
if (!this.destination) {
this.statusText_ = '';
return;
}
// Cloudprint destinations contain their own status text.
if (CloudOrigins.some(origin => origin === this.destination.origin)) {
this.statusText_ = this.destination.shouldShowInvalidCertificateError ?
this.i18n('noLongerSupportedFragment') :
this.destination.connectionStatusText;
return;
}
// Only when the flag is enabled do we need to fetch a local printer status
// error string.
if (!this.printerStatusFlagEnabled_) {
this.statusText_ = '';
return;
}
const printerStatusReason = this.destination.printerStatusReason;
if (!printerStatusReason ||
printerStatusReason === PrinterStatusReason.NO_ERROR ||
printerStatusReason === PrinterStatusReason.UNKNOWN_REASON) {
this.statusText_ = '';
return;
}
this.statusText_ = this.getErrorString_(printerStatusReason);
},
/**
* @param {!PrinterStatusReason} printerStatusReason
* @return {!string}
* @private
*/
getErrorString_: function(printerStatusReason) {
const errorTextKey = ERROR_STRING_KEY_MAP.get(printerStatusReason);
return errorTextKey ?
this.i18n(errorTextKey, this.destination.displayName) :
'';
},
/**
* @return {!boolean}
* @private
*/
shouldShowStatus_: function() {
return !!this.statusText_;
},
}); });
...@@ -19,6 +19,7 @@ printer_status_test_cros.suiteName = 'PrinterStatusTestCros'; ...@@ -19,6 +19,7 @@ printer_status_test_cros.suiteName = 'PrinterStatusTestCros';
printer_status_test_cros.TestNames = { printer_status_test_cros.TestNames = {
PrinterStatusUpdatesColor: 'printer status updates color', PrinterStatusUpdatesColor: 'printer status updates color',
SendStatusRequestOnce: 'send status request once', SendStatusRequestOnce: 'send status request once',
HiddenStatusText: 'hidden status text',
}; };
suite(printer_status_test_cros.suiteName, function() { suite(printer_status_test_cros.suiteName, function() {
...@@ -245,6 +246,31 @@ suite(printer_status_test_cros.suiteName, function() { ...@@ -245,6 +246,31 @@ suite(printer_status_test_cros.suiteName, function() {
3, nativeLayer.getCallCount('requestPrinterStatusUpdate')); 3, nativeLayer.getCallCount('requestPrinterStatusUpdate'));
}); });
}); });
test(assert(printer_status_test_cros.TestNames.HiddenStatusText), function() {
return waitBeforeNextRender(destinationSelect).then(() => {
const destinationWithoutErrorStatus =
createDestination('ID1', 'One', DestinationOrigin.CROS);
// Destination with ID4 will return an error printer status that will
// trigger the error text being populated.
const destinationWithErrorStatus =
createDestination('ID4', 'Four', DestinationOrigin.CROS);
destinationSelect.recentDestinationList = [
destinationWithoutErrorStatus,
destinationWithErrorStatus,
];
destinationSelect.destination = destinationWithoutErrorStatus;
assertTrue(destinationSelect.$$('.destination-additional-info').hidden);
destinationSelect.destination = destinationWithErrorStatus;
return nativeLayer.whenCalled('requestPrinterStatusUpdate').then(() => {
assertFalse(
destinationSelect.$$('.destination-additional-info').hidden);
});
});
});
}); });
window.destination_select_test_cros = {}; window.destination_select_test_cros = {};
......
...@@ -1119,6 +1119,10 @@ TEST_F( ...@@ -1119,6 +1119,10 @@ TEST_F(
printer_status_test_cros.TestNames.SendStatusRequestOnce); printer_status_test_cros.TestNames.SendStatusRequestOnce);
}); });
TEST_F('PrintPreviewPrinterStatusTestCros', 'HiddenStatusText', function() {
this.runMochaTest(printer_status_test_cros.TestNames.HiddenStatusText);
});
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var PrintPreviewDestinationDropdownCrosTest = class extends PrintPreviewTest { var PrintPreviewDestinationDropdownCrosTest = class extends PrintPreviewTest {
/** @override */ /** @override */
......
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