Commit 74ebdcc0 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Prevent user from saving invalid printer configuration input

-Disable the Add button so the user can't save a printer if the
 Manufacturer or Model dropdowns have incorrect values.

Fixed: 950887
Change-Id: I533748488b777eca7ac2329d2cb2e5402cca72be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2018093Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737371}
parent 605d16a2
...@@ -140,14 +140,16 @@ ...@@ -140,14 +140,16 @@
<cr-searchable-drop-down id="manufacturerDropdown" <cr-searchable-drop-down id="manufacturerDropdown"
items="[[manufacturerList]]" items="[[manufacturerList]]"
label="$i18n{printerManufacturer}" label="$i18n{printerManufacturer}"
value="{{activePrinter.ppdManufacturer}}"> value="{{activePrinter.ppdManufacturer}}"
invalid="{{isManufacturerInvalid_}}">
</cr-searchable-drop-down> </cr-searchable-drop-down>
</div> </div>
<div class="settings-box two-line"> <div class="settings-box two-line">
<cr-searchable-drop-down id="modelDropdown" <cr-searchable-drop-down id="modelDropdown"
items="[[modelList]]" items="[[modelList]]"
label="$i18n{printerModel}" label="$i18n{printerModel}"
value="{{activePrinter.ppdModel}}"> value="{{activePrinter.ppdModel}}"
invalid="{{isModelInvalid_}}">
</cr-searchable-drop-down> </cr-searchable-drop-down>
</div> </div>
<div id="ppdLabel" class="cr-form-field-label"> <div id="ppdLabel" class="cr-form-field-label">
...@@ -180,7 +182,9 @@ ...@@ -180,7 +182,9 @@
disabled="[[!canAddPrinter_(activePrinter.ppdManufacturer, disabled="[[!canAddPrinter_(activePrinter.ppdManufacturer,
activePrinter.ppdModel, activePrinter.ppdModel,
activePrinter.printerPPDPath, activePrinter.printerPPDPath,
addPrinterInProgress_)]]" addPrinterInProgress_,
isManufacturerInvalid_,
isModelInvalid_)]]"
on-click="addPrinter_"> on-click="addPrinter_">
$i18n{addPrinterButtonText} $i18n{addPrinterButtonText}
</cr-button> </cr-button>
......
...@@ -275,6 +275,20 @@ Polymer({ ...@@ -275,6 +275,20 @@ Polymer({
type: String, type: String,
value: '', value: '',
}, },
/**
* Indicates whether the value in the Manufacturer dropdown is a valid
* printer manufacturer.
* @private
*/
isManufacturerInvalid_: Boolean,
/**
* Indicates whether the value in the Model dropdown is a valid printer
* model.
* @private
*/
isModelInvalid_: Boolean,
}, },
observers: [ observers: [
...@@ -444,10 +458,12 @@ Polymer({ ...@@ -444,10 +458,12 @@ Polymer({
* @return {boolean} Whether we have enough information to set up the printer * @return {boolean} Whether we have enough information to set up the printer
* @private * @private
*/ */
canAddPrinter_(ppdManufacturer, ppdModel, printerPPDPath) { canAddPrinter_(ppdManufacturer, ppdModel, printerPPDPath,
return !this.addPrinterInProgress_ && addPrinterInProgress, isManufacturerInvalid, isModelInvalid) {
return !addPrinterInProgress &&
settings.printing.isPPDInfoValid( settings.printing.isPPDInfoValid(
ppdManufacturer, ppdModel, printerPPDPath); ppdManufacturer, ppdModel, printerPPDPath) &&
!isManufacturerInvalid && !isModelInvalid;
}, },
}); });
......
...@@ -530,6 +530,64 @@ suite('CupsAddPrinterDialogTests', function() { ...@@ -530,6 +530,64 @@ suite('CupsAddPrinterDialogTests', function() {
assertFalse(dialog.showManuallyAddDialog_); assertFalse(dialog.showManuallyAddDialog_);
}); });
}); });
/**
* Test that the add button of the manufacturer dialog is disabled when the
* manufacturer or model dropdown has an incorrect value.
*/
test('AddButtonDisabledAfterClicking', function() {
// From the add manually dialog, click the add button to advance to the
// manufacturer dialog.
const addDialog = dialog.$$('add-printer-manually-dialog');
assertTrue(!!addDialog);
Polymer.dom.flush();
fillAddManuallyDialog(addDialog);
clickAddButton(addDialog);
Polymer.dom.flush();
return cupsPrintersBrowserProxy
.whenCalled('getCupsPrinterManufacturersList')
.then(function() {
const manufacturerDialog =
dialog.$$('add-printer-manufacturer-model-dialog');
assertTrue(!!manufacturerDialog);
const manufacturerDropdown =
manufacturerDialog.$$('#manufacturerDropdown');
const modelDropdown =
manufacturerDialog.$$('#modelDropdown');
const addButton = manufacturerDialog.$$('#addPrinterButton');
// Set the starting values for manufacturer and model dropdown.
manufacturerDropdown.value = 'make';
modelDropdown.value = 'model';
assertFalse(addButton.disabled);
// Mimic typing in random input. Make sure the Add button becomes
// disabled.
manufacturerDropdown.$$('#search').value = 'hlrRkJQkNsh';
manufacturerDropdown.$$('#search').fire('input');
assertTrue(addButton.disabled);
// Then mimic typing in the original value to re-enable the Add
// button.
manufacturerDropdown.$$('#search').value = 'make';
manufacturerDropdown.$$('#search').fire('input');
assertFalse(addButton.disabled);
// Mimic typing in random input. Make sure the Add button becomes
// disabled.
modelDropdown.$$('#search').value = 'hlrRkJQkNsh';
modelDropdown.$$('#search').fire('input');
assertTrue(addButton.disabled);
// Then mimic typing in the original value to re-enable the Add
// button.
modelDropdown.$$('#search').value = 'model';
modelDropdown.$$('#search').fire('input');
assertFalse(addButton.disabled);
});
});
}); });
suite('EditPrinterDialog', function() { suite('EditPrinterDialog', 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