Commit e5e77879 authored by Gavin Williams's avatar Gavin Williams Committed by Commit Bot

Change the sort ordering for nearby printers

-New sort order is printers with automatic configuration sorted
alphabetically first then printers that need manual configuration
sorted alphabetically next

-Added new test case to confirm nearby printers sorted correctly

Bug: 993820
Change-Id: Idf730c8111bc6e835b659e899e3a478d719e04a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1767604
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#690885}
parent e7821b46
...@@ -15,6 +15,8 @@ let PrinterListEntry; ...@@ -15,6 +15,8 @@ let PrinterListEntry;
* These values correspond to the different types of printers available. Refer * These values correspond to the different types of printers available. Refer
* to cups_printer_management.md for more information about the different * to cups_printer_management.md for more information about the different
* categories of printers. * categories of printers.
*
* The types are numbered in desired sorting order for display.
*/ */
const PrinterType = { const PrinterType = {
SAVED: 0, SAVED: 0,
......
...@@ -59,15 +59,29 @@ Polymer({ ...@@ -59,15 +59,29 @@ Polymer({
item =>this.matchesSearchTerm_(item.printerInfo,this.searchTerm)) : item =>this.matchesSearchTerm_(item.printerInfo,this.searchTerm)) :
this.printers.slice(); this.printers.slice();
updatedPrinters.sort((first, second) => { updatedPrinters.sort(this.sortPrinters_);
return settings.printing.alphabeticalSort(
first.printerInfo, second.printerInfo);
});
this.updateList('filteredPrinters_', printer => printer.printerInfo, this.updateList('filteredPrinters_', printer => printer.printerInfo,
updatedPrinters); updatedPrinters);
}, },
/**
* @param {!PrinterListEntry} first
* @param {!PrinterListEntry} second
* @return {number}
* @private
*/
sortPrinters_: function(first, second) {
if (first.printerType == second.printerType) {
return settings.printing.alphabeticalSort(
first.printerInfo, second.printerInfo);
}
// PrinterType sort order maintained in cups_printer_types.js
return first.printerType - second.printerType;
},
/** /**
* @param {!CupsPrinterInfo} printer * @param {!CupsPrinterInfo} printer
* @param {string} searchTerm * @param {string} searchTerm
......
...@@ -509,6 +509,53 @@ suite('CupsNearbyPrintersTests', function() { ...@@ -509,6 +509,53 @@ suite('CupsNearbyPrintersTests', function() {
}); });
}); });
test('nearbyPrintersSortOrderAutoFirstThenDiscovered', function() {
let discoveredPrinterA =
createCupsPrinterInfo('printerNameA', 'printerAddress1', 'printerId1');
let discoveredPrinterB =
createCupsPrinterInfo('printerNameB', 'printerAddress2', 'printerId2');
let discoveredPrinterC =
createCupsPrinterInfo('printerNameC', 'printerAddress3', 'printerId3');
let autoPrinterD =
createCupsPrinterInfo('printerNameD', 'printerAddress4', 'printerId4');
let autoPrinterE =
createCupsPrinterInfo('printerNameE', 'printerAddress5', 'printerId5');
let autoPrinterF =
createCupsPrinterInfo('printerNameF', 'printerAddress6', 'printerId6');
// Add printers in a non-alphabetical order to test sorting.
const automaticPrinterList = [autoPrinterF, autoPrinterD, autoPrinterE];
const discoveredPrinterList =
[discoveredPrinterC, discoveredPrinterA, discoveredPrinterB];
// Expected sort order is to sort automatic printers first then
// sort discovered printers
const expectedPrinterList = [
autoPrinterD, autoPrinterE, autoPrinterF, discoveredPrinterA,
discoveredPrinterB, discoveredPrinterC
];
return test_util.flushTasks().then(() => {
nearbyPrintersElement = page.$$('settings-cups-nearby-printers');
assertTrue(!!nearbyPrintersElement);
// Assert that no printers have been detected.
let nearbyPrinterEntries = getPrinterEntries(nearbyPrintersElement);
assertEquals(0, nearbyPrinterEntries.length);
// Simuluate finding nearby printers.
cr.webUIListenerCallback(
'on-nearby-printers-changed', automaticPrinterList,
discoveredPrinterList);
Polymer.dom.flush();
nearbyPrinterEntries = getPrinterEntries(nearbyPrintersElement);
verifyPrintersList(nearbyPrinterEntries, expectedPrinterList);
});
});
test('addingAutomaticPrinterIsSuccessful', function() { test('addingAutomaticPrinterIsSuccessful', function() {
const automaticPrinterList = [createCupsPrinterInfo('test1', '1', 'id1')]; const automaticPrinterList = [createCupsPrinterInfo('test1', '1', 'id1')];
const discoveredPrinterList = []; const discoveredPrinterList = [];
......
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