Commit 0646a5b4 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Use new printer status icon in destination dropdown

In destination dropdown replace printer-status-icon-cros element with
new printer status icons.

Screenshot: http://screen/8SUKwKANZWKfgpR

Bug: 1123754
Change-Id: I5da99ab07512c50c10ab30d5b1ef9e945e910162
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2433027
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811562}
parent 625a317e
...@@ -104,14 +104,7 @@ ...@@ -104,14 +104,7 @@
aria-description$="[[destinationStatusText]]"> aria-description$="[[destinationStatusText]]">
<div id="destination-display-container"> <div id="destination-display-container">
<div id="destination-icon-box"> <div id="destination-icon-box">
<iron-icon icon="[[destinationIcon]]" <iron-icon icon="[[destinationIcon]]"></iron-icon>
hidden="[[isCurrentDestinationCrosLocal]]">
</iron-icon>
<printer-status-icon-cros id="destination-badge"
hidden="[[!isCurrentDestinationCrosLocal]]"
icon-location="[[IconLocation.DISPLAY]]"
printer-state="[[computePrinterState_( value.printerStatusReason)]]">
</printer-status-icon-cros>
</div> </div>
<div id="destination-display" title="[[value.displayName]]"> <div id="destination-display" title="[[value.displayName]]">
[[value.displayName]] [[value.displayName]]
...@@ -131,11 +124,9 @@ ...@@ -131,11 +124,9 @@
highlightedIndex_)]]" highlightedIndex_)]]"
aria-description$="[[getPrinterStatusErrorString_( aria-description$="[[getPrinterStatusErrorString_(
item.printerStatusReason)]]"> item.printerStatusReason)]]">
<printer-status-icon-cros icon-location="[[IconLocation.DROPDOWN]]" <iron-icon icon="[[getPrinterStatusIcon_(
printer-state="[[computePrinterState_( item.printerStatusReason)]]">
item.printerStatusReason)]]" </iron-icon>
class$="[[getHighlightedClass_(item.key, highlightedIndex_)]]">
</printer-status-icon-cros>
<span class="printer-display-name">[[item.displayName]]</span> <span class="printer-display-name">[[item.displayName]]</span>
</button> </button>
</template> </template>
......
...@@ -9,13 +9,12 @@ import 'chrome://resources/polymer/v3_0/iron-dropdown/iron-dropdown.js'; ...@@ -9,13 +9,12 @@ import 'chrome://resources/polymer/v3_0/iron-dropdown/iron-dropdown.js';
import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js'; import 'chrome://resources/polymer/v3_0/iron-icon/iron-icon.js';
import './print_preview_vars_css.js'; import './print_preview_vars_css.js';
import './printer_status_icon_cros.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js'; import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {Destination, DestinationOrigin} from '../data/destination.js'; import {Destination, DestinationOrigin} from '../data/destination.js';
import {computePrinterState, ERROR_STRING_KEY_MAP, IconLocation, PrinterState, PrinterStatusReason} from '../data/printer_status_cros.js'; import {ERROR_STRING_KEY_MAP, getPrinterStatusIcon, PrinterStatusReason} from '../data/printer_status_cros.js';
Polymer({ Polymer({
is: 'print-preview-destination-dropdown-cros', is: 'print-preview-destination-dropdown-cros',
...@@ -52,17 +51,12 @@ Polymer({ ...@@ -52,17 +51,12 @@ Polymer({
destinationIcon: String, destinationIcon: String,
isCurrentDestinationCrosLocal: Boolean,
/** /**
* Index of the highlighted item in the dropdown. * Index of the highlighted item in the dropdown.
* @private * @private
*/ */
highlightedIndex_: Number, highlightedIndex_: Number,
/** Mirroring the enum so that it can be used from HTML bindings. */
IconLocation: Object,
/** @private */ /** @private */
dropdownLength_: { dropdownLength_: {
type: Number, type: Number,
...@@ -80,7 +74,6 @@ Polymer({ ...@@ -80,7 +74,6 @@ Polymer({
/** @override */ /** @override */
attached() { attached() {
this.updateTabIndex_(); this.updateTabIndex_();
this.IconLocation = IconLocation;
}, },
/** /**
...@@ -260,15 +253,6 @@ Polymer({ ...@@ -260,15 +253,6 @@ Polymer({
.filter(item => !item.hidden); .filter(item => !item.hidden);
}, },
/**
* @param {?PrinterStatusReason} printerStatusReason
* @return {number}
* @private
*/
computePrinterState_(printerStatusReason) {
return computePrinterState(printerStatusReason);
},
/** /**
* Sets tabindex to -1 when dropdown is disabled to prevent the dropdown from * Sets tabindex to -1 when dropdown is disabled to prevent the dropdown from
* being focusable. * being focusable.
...@@ -340,4 +324,13 @@ Polymer({ ...@@ -340,4 +324,13 @@ Polymer({
const errorStringKey = ERROR_STRING_KEY_MAP.get(printerStatusReason); const errorStringKey = ERROR_STRING_KEY_MAP.get(printerStatusReason);
return errorStringKey ? this.i18n(errorStringKey) : ''; return errorStringKey ? this.i18n(errorStringKey) : '';
}, },
/**
* @param {!PrinterStatusReason} printerStatusReason
* @return {string}
* @private
*/
getPrinterStatusIcon_(printerStatusReason) {
return getPrinterStatusIcon(printerStatusReason);
}
}); });
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
no-destinations="[[noDestinations]]" no-destinations="[[noDestinations]]"
pdf-printer-disabled="[[pdfPrinterDisabled]]" pdf-printer-disabled="[[pdfPrinterDisabled]]"
destination-icon="[[destinationIcon_]]" disabled="[[disabled]]" destination-icon="[[destinationIcon_]]" disabled="[[disabled]]"
is-current-destination-cros-local="[[isCurrentDestinationCrosLocal_]]"
on-dropdown-value-selected="onDropdownValueSelected_" on-dropdown-value-selected="onDropdownValueSelected_"
destination-status-text="[[statusText_]]"> destination-status-text="[[statusText_]]">
</print-preview-destination-dropdown-cros> </print-preview-destination-dropdown-cros>
......
...@@ -22,7 +22,7 @@ import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; ...@@ -22,7 +22,7 @@ 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 {CloudOrigins, Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from '../data/destination.js'; import {CloudOrigins, Destination, DestinationOrigin, PDF_DESTINATION_KEY, RecentDestination, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from '../data/destination.js';
import {ERROR_STRING_KEY_MAP, getStatusReasonFromPrinterStatus, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity} from '../data/printer_status_cros.js'; import {ERROR_STRING_KEY_MAP, getPrinterStatusIcon, PrinterStatusReason} from '../data/printer_status_cros.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';
...@@ -87,7 +87,8 @@ Polymer({ ...@@ -87,7 +87,8 @@ Polymer({
/** @private {string} */ /** @private {string} */
destinationIcon_: { destinationIcon_: {
type: String, type: String,
computed: 'computeDestinationIcon_(selectedValue, destination)', computed:
'computeDestinationIcon_(selectedValue, destination, destination.printerStatusReason)',
}, },
/** @private */ /** @private */
...@@ -155,6 +156,11 @@ Polymer({ ...@@ -155,6 +156,11 @@ Polymer({
// If the destination matches the selected value, pull the icon from the // If the destination matches the selected value, pull the icon from the
// destination. // destination.
if (this.destination && this.destination.key === this.selectedValue) { if (this.destination && this.destination.key === this.selectedValue) {
if (this.printerStatusFlagEnabled_ &&
this.isCurrentDestinationCrosLocal_) {
return getPrinterStatusIcon(this.destination.printerStatusReason);
}
return this.destination.icon; return this.destination.icon;
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, NativeLayer, NativeLayerImpl, PrinterState, PrinterStatusReason, PrinterStatusSeverity} from 'chrome://print/print_preview.js'; import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
import {keyDownOn, move} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js'; import {keyDownOn, move} from 'chrome://resources/polymer/v3_0/iron-test-helpers/mock-interactions.js';
import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
...@@ -10,7 +10,6 @@ import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min ...@@ -10,7 +10,6 @@ import {flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min
import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js'; import {assertEquals, assertFalse, assertTrue} from '../chai_assert.js';
import {eventToPromise} from '../test_util.m.js'; import {eventToPromise} from '../test_util.m.js';
import {NativeLayerStub} from './native_layer_stub.js';
import {getGoogleDriveDestination, getSaveAsPdfDestination} from './print_preview_test_utils.js'; import {getGoogleDriveDestination, getSaveAsPdfDestination} from './print_preview_test_utils.js';
window.destination_dropdown_cros_test = {}; window.destination_dropdown_cros_test = {};
...@@ -27,8 +26,6 @@ destination_dropdown_cros_test.TestNames = { ...@@ -27,8 +26,6 @@ destination_dropdown_cros_test.TestNames = {
EnterOpensCloses: 'enter opens and closes dropdown', EnterOpensCloses: 'enter opens and closes dropdown',
HighlightedFollowsMouse: 'highlighted follows mouse', HighlightedFollowsMouse: 'highlighted follows mouse',
Disabled: 'disabled', Disabled: 'disabled',
NewStatusUpdatesDestinationIcon: 'new status updates destination icon',
ChangingDestinationUpdatesIcon: 'changing destination updates icon',
HighlightedWhenOpened: 'highlighted when opened', HighlightedWhenOpened: 'highlighted when opened',
}; };
...@@ -36,9 +33,6 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -36,9 +33,6 @@ suite(destination_dropdown_cros_test.suiteName, function() {
/** @type {!PrintPreviewDestinationDropdownCrosElement} */ /** @type {!PrintPreviewDestinationDropdownCrosElement} */
let dropdown; let dropdown;
/** @type {?NativeLayerStub} */
let nativeLayer = null;
/** @param {!Array<!Destination>} items */ /** @param {!Array<!Destination>} items */
function setItemList(items) { function setItemList(items) {
dropdown.itemList = items; dropdown.itemList = items;
...@@ -98,42 +92,10 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -98,42 +92,10 @@ suite(destination_dropdown_cros_test.suiteName, function() {
DestinationConnectionStatus.ONLINE); DestinationConnectionStatus.ONLINE);
} }
function setNativeLayerPrinterStatusMap() {
[{
printerId: 'One',
statusReasons: [{
reason: PrinterStatusReason.NO_ERROR,
severity: PrinterStatusSeverity.UNKNOWN_SEVERITY
}],
},
{
printerId: 'Two',
statusReasons: [{
reason: PrinterStatusReason.OUT_OF_INK,
severity: PrinterStatusSeverity.ERROR
}],
},
{
printerId: 'Three',
statusReasons: [{
reason: PrinterStatusReason.UNKNOWN_REASON,
severity: PrinterStatusSeverity.UNKNOWN_SEVERITY
}],
}]
.forEach(
status =>
nativeLayer.addPrinterStatusToMap(status.printerId, status));
}
/** @override */ /** @override */
setup(function() { setup(function() {
document.body.innerHTML = ''; document.body.innerHTML = '';
// Stub out native layer.
nativeLayer = new NativeLayerStub();
NativeLayerImpl.instance_ = nativeLayer;
setNativeLayerPrinterStatusMap();
dropdown = dropdown =
/** @type {!PrintPreviewDestinationDropdownCrosElement} */ /** @type {!PrintPreviewDestinationDropdownCrosElement} */
(document.createElement('print-preview-destination-dropdown-cros')); (document.createElement('print-preview-destination-dropdown-cros'));
...@@ -299,53 +261,6 @@ suite(destination_dropdown_cros_test.suiteName, function() { ...@@ -299,53 +261,6 @@ suite(destination_dropdown_cros_test.suiteName, function() {
'0', dropdown.$$('#destination-dropdown').getAttribute('tabindex')); '0', dropdown.$$('#destination-dropdown').getAttribute('tabindex'));
}); });
test(
assert(destination_dropdown_cros_test.TestNames
.NewStatusUpdatesDestinationIcon),
function() {
const destinationBadge = dropdown.$$('#destination-badge');
dropdown.value = createDestination('Two', DestinationOrigin.CROS);
assertEquals(PrinterState.UNKNOWN, destinationBadge.printerState);
return dropdown.value.requestPrinterStatus().then(() => {
// After printer stauts is updated the state will still be UNKNOWN.
assertEquals(PrinterState.UNKNOWN, destinationBadge.printerState);
// Only after the path is notified will the state update to ERROR.
dropdown.notifyPath(`value.printerStatusReason`);
assertEquals(PrinterState.ERROR, destinationBadge.printerState);
});
});
test(
assert(destination_dropdown_cros_test.TestNames
.ChangingDestinationUpdatesIcon),
function() {
const goodDestination =
createDestination('One', DestinationOrigin.CROS);
const errorDestination =
createDestination('Two', DestinationOrigin.CROS);
const unknownDestination =
createDestination('Three', DestinationOrigin.CROS);
const destinationBadge = dropdown.$$('#destination-badge');
return goodDestination.requestPrinterStatus()
.then(() => {
dropdown.value = goodDestination;
assertEquals(PrinterState.GOOD, destinationBadge.printerState);
return errorDestination.requestPrinterStatus();
})
.then(() => {
dropdown.value = errorDestination;
assertEquals(PrinterState.ERROR, destinationBadge.printerState);
return unknownDestination.requestPrinterStatus();
})
.then(() => {
dropdown.value = unknownDestination;
assertEquals(PrinterState.UNKNOWN, destinationBadge.printerState);
});
});
test( test(
assert(destination_dropdown_cros_test.TestNames.HighlightedWhenOpened), assert(destination_dropdown_cros_test.TestNames.HighlightedWhenOpened),
function() { function() {
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground, NativeLayer, NativeLayerImpl, PrinterState, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from 'chrome://print/print_preview.js'; import {Destination, DestinationConnectionStatus, DestinationOrigin, DestinationType, getSelectDropdownBackground, NativeLayer, NativeLayerImpl, PrinterStatus, PrinterStatusReason, PrinterStatusSeverity, SAVE_TO_DRIVE_CROS_DESTINATION_KEY} from 'chrome://print/print_preview.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.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, flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {Base, flush} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
...@@ -199,33 +199,33 @@ suite(printer_status_test_cros.suiteName, function() { ...@@ -199,33 +199,33 @@ suite(printer_status_test_cros.suiteName, function() {
.then(() => { .then(() => {
const dropdown = destinationSelect.$$('#dropdown'); const dropdown = destinationSelect.$$('#dropdown');
assertEquals( assertEquals(
PrinterState.GOOD, 'print-preview:printer-status-green',
dropdown.$$(`#${escapeForwardSlahes(destination1.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination1.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.GOOD, 'print-preview:printer-status-green',
dropdown.$$(`#${escapeForwardSlahes(destination2.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination2.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.GOOD, 'print-preview:printer-status-green',
dropdown.$$(`#${escapeForwardSlahes(destination3.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination3.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.ERROR, 'print-preview:printer-status-red',
dropdown.$$(`#${escapeForwardSlahes(destination4.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination4.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.ERROR, 'print-preview:printer-status-red',
dropdown.$$(`#${escapeForwardSlahes(destination5.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination5.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.ERROR, 'print-preview:printer-status-red',
dropdown.$$(`#${escapeForwardSlahes(destination6.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination6.key)}`)
.firstChild.printerState); .firstChild.icon);
assertEquals( assertEquals(
PrinterState.UNKNOWN, 'print-preview:printer-status-grey',
dropdown.$$(`#${escapeForwardSlahes(destination7.key)}`) dropdown.$$(`#${escapeForwardSlahes(destination7.key)}`)
.firstChild.printerState); .firstChild.icon);
}); });
}); });
...@@ -311,6 +311,8 @@ suite(printer_status_test_cros.suiteName, function() { ...@@ -311,6 +311,8 @@ suite(printer_status_test_cros.suiteName, function() {
return waitBeforeNextRender(destinationSelect).then(() => { return waitBeforeNextRender(destinationSelect).then(() => {
const localCrosPrinter = const localCrosPrinter =
createDestination('ID1', 'One', DestinationOrigin.CROS); createDestination('ID1', 'One', DestinationOrigin.CROS);
const localNonCrosPrinter =
createDestination('ID2', 'Two', DestinationOrigin.LOCAL);
const saveToDrive = getGoogleDriveDestination('account'); const saveToDrive = getGoogleDriveDestination('account');
const saveAsPdf = getSaveAsPdfDestination(); const saveAsPdf = getSaveAsPdfDestination();
...@@ -323,6 +325,11 @@ suite(printer_status_test_cros.suiteName, function() { ...@@ -323,6 +325,11 @@ suite(printer_status_test_cros.suiteName, function() {
destinationSelect.destination = localCrosPrinter; destinationSelect.destination = localCrosPrinter;
destinationSelect.updateDestination(); destinationSelect.updateDestination();
assertEquals(
'print-preview:printer-status-grey', dropdown.destinationIcon);
destinationSelect.destination = localNonCrosPrinter;
destinationSelect.updateDestination();
assertEquals('print-preview:print', dropdown.destinationIcon); assertEquals('print-preview:print', dropdown.destinationIcon);
destinationSelect.destination = saveToDrive; destinationSelect.destination = saveToDrive;
......
...@@ -1438,20 +1438,6 @@ TEST_F('PrintPreviewDestinationDropdownCrosTest', 'Disabled', function() { ...@@ -1438,20 +1438,6 @@ TEST_F('PrintPreviewDestinationDropdownCrosTest', 'Disabled', function() {
this.runMochaTest(destination_dropdown_cros_test.TestNames.Disabled); this.runMochaTest(destination_dropdown_cros_test.TestNames.Disabled);
}); });
TEST_F(
'PrintPreviewDestinationDropdownCrosTest',
'NewStatusUpdatesDestinationIcon', function() {
this.runMochaTest(destination_dropdown_cros_test.TestNames
.NewStatusUpdatesDestinationIcon);
});
TEST_F(
'PrintPreviewDestinationDropdownCrosTest', 'ChangingDestinationUpdatesIcon',
function() {
this.runMochaTest(destination_dropdown_cros_test.TestNames
.ChangingDestinationUpdatesIcon);
});
TEST_F( TEST_F(
'PrintPreviewDestinationDropdownCrosTest', 'HighlightedWhenOpened', 'PrintPreviewDestinationDropdownCrosTest', 'HighlightedWhenOpened',
function() { function() {
......
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