Commit 96df7de7 authored by Gavin Williams's avatar Gavin Williams Committed by Chromium LUCI CQ

scanning: Remove custom sort function

Remove customSort() as scan settings only uses alphabetical sort or
numeric sort.

Bug: 1168346
Change-Id: I7f0151de3945ebdb752f467a4dff0f4c48b2576b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2638793
Commit-Queue: Gavin Williams <gavinwill@chromium.org>
Reviewed-by: default avatarJesse Schettler <jschettler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#845332}
parent a3bc17ec
...@@ -53,7 +53,7 @@ ScanningAppBrowserTest.prototype = { ...@@ -53,7 +53,7 @@ ScanningAppBrowserTest.prototype = {
const debug_suites_list = [ const debug_suites_list = [
'ColorModeSelect', 'FileTypeSelect', 'PageSizeSelect', 'ResolutionSelect', 'ColorModeSelect', 'FileTypeSelect', 'PageSizeSelect', 'ResolutionSelect',
'ScanApp', 'ScanDoneSection', 'ScannerSelect', 'ScanPreview', 'ScanToSelect', 'ScanApp', 'ScanDoneSection', 'ScannerSelect', 'ScanPreview', 'ScanToSelect',
'SelectBehavior', 'SourceSelect' 'SourceSelect'
]; ];
TEST_F('ScanningAppBrowserTest', 'All', function() { TEST_F('ScanningAppBrowserTest', 'All', function() {
......
...@@ -19,7 +19,6 @@ import {scanPreviewTest} from './scan_preview_test.js'; ...@@ -19,7 +19,6 @@ import {scanPreviewTest} from './scan_preview_test.js';
import {scanToSelectTest} from './scan_to_select_test.js'; import {scanToSelectTest} from './scan_to_select_test.js';
import {scannerSelectTest} from './scanner_select_test.js'; import {scannerSelectTest} from './scanner_select_test.js';
import {scanningAppTest} from './scanning_app_test.js'; import {scanningAppTest} from './scanning_app_test.js';
import {selectBehaviorTest} from './select_behavior_test.js';
import {sourceSelectTest} from './source_select_test.js'; import {sourceSelectTest} from './source_select_test.js';
window.test_suites_list = []; window.test_suites_list = [];
...@@ -38,5 +37,4 @@ runSuite('ScanDoneSection', scanDoneSectionTest); ...@@ -38,5 +37,4 @@ runSuite('ScanDoneSection', scanDoneSectionTest);
runSuite('ScannerSelect', scannerSelectTest); runSuite('ScannerSelect', scannerSelectTest);
runSuite('ScanPreview', scanPreviewTest); runSuite('ScanPreview', scanPreviewTest);
runSuite('ScanToSelect', scanToSelectTest); runSuite('ScanToSelect', scanToSelectTest);
runSuite('SelectBehavior', selectBehaviorTest);
runSuite('SourceSelect', sourceSelectTest); runSuite('SourceSelect', sourceSelectTest);
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {flush, html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {alphabeticalCompare} from 'chrome://scanning/scanning_app_util.js';
import {SelectBehavior} from 'chrome://scanning/select_behavior.js';
import * as utils from './scanning_app_test_utils.js';
export function selectBehaviorTest() {
/** @type {?TestSelectElement} */
let testSelect = null;
suiteSetup(function() {
Polymer({
is: 'test-select',
_template: html`
<select></select>
`,
behaviors: [SelectBehavior],
});
});
setup(() => {
testSelect = document.createElement('test-select');
document.body.innerHTML = '';
document.body.appendChild(testSelect);
});
teardown(() => {
if (testSelect) {
testSelect.remove();
}
testSelect = null;
});
test('SortWithConversionFunctionProvided', () => {
testSelect.arr = [{value: 'C'}, {value: 'A'}, {value: 'B'}];
const conversionFn = (item) => item.value;
flush();
testSelect.customSort(testSelect.arr, alphabeticalCompare, conversionFn);
flush();
utils.assertOrderedAlphabetically(testSelect.arr, conversionFn);
});
test('SortWithNoConversionFunction', () => {
testSelect.arr = ['C', 'D', 'F', 'B', 'A'];
flush();
testSelect.customSort(testSelect.arr, alphabeticalCompare);
flush();
utils.assertOrderedAlphabetically(testSelect.arr);
});
test('SortWithDuplicateValues', () => {
testSelect.arr = ['C', 'C', 'B', 'B', 'A'];
flush();
testSelect.customSort(testSelect.arr, alphabeticalCompare);
flush();
utils.assertOrderedAlphabetically(testSelect.arr);
});
}
...@@ -75,9 +75,10 @@ Polymer({ ...@@ -75,9 +75,10 @@ Polymer({
*/ */
onColorModesChange_() { onColorModesChange_() {
if (this.colorModes.length > 1) { if (this.colorModes.length > 1) {
this.colorModes = this.customSort( this.colorModes.sort((a, b) => {
this.colorModes, alphabeticalCompare, return alphabeticalCompare(
(colorMode) => getColorModeString(colorMode)); getColorModeString(a), getColorModeString(b));
});
} }
if (this.colorModes.length > 0) { if (this.colorModes.length > 0) {
......
...@@ -72,9 +72,9 @@ Polymer({ ...@@ -72,9 +72,9 @@ Polymer({
*/ */
onPageSizesChange_() { onPageSizesChange_() {
if (this.pageSizes.length > 1) { if (this.pageSizes.length > 1) {
this.pageSizes = this.customSort( this.pageSizes.sort((a, b) => {
this.pageSizes, alphabeticalCompare, return alphabeticalCompare(getPageSizeString(a), getPageSizeString(b));
(pageSize) => getPageSizeString(pageSize)); });
// If the fit to scan area option exists, move it to the end of the page // If the fit to scan area option exists, move it to the end of the page
// sizes array. // sizes array.
......
...@@ -73,9 +73,10 @@ Polymer({ ...@@ -73,9 +73,10 @@ Polymer({
*/ */
onScannersChange_() { onScannersChange_() {
if (this.scanners.length > 1) { if (this.scanners.length > 1) {
this.scanners = this.customSort( this.scanners.sort((a, b) => {
this.scanners, alphabeticalCompare, return alphabeticalCompare(
(scanner) => getScannerDisplayName(scanner)); getScannerDisplayName(a), getScannerDisplayName(b));
});
} }
// If it exists, select the first option in the sorted array as the default. // If it exists, select the first option in the sorted array as the default.
......
...@@ -14,14 +14,4 @@ export const SelectBehavior = { ...@@ -14,14 +14,4 @@ export const SelectBehavior = {
/** @type {boolean} */ /** @type {boolean} */
disabled: Boolean, disabled: Boolean,
}, },
/**
* @param {!Array} arr
* @param {!function(string, string): number} compareFn
* @param {!function(T): string} conversionFn
* @template T
*/
customSort(arr, compareFn, conversionFn = (val) => val) {
return arr.sort((a, b) => compareFn(conversionFn(a), conversionFn(b)));
},
}; };
...@@ -69,9 +69,10 @@ Polymer({ ...@@ -69,9 +69,10 @@ Polymer({
*/ */
onSourcesChange_() { onSourcesChange_() {
if (this.sources.length > 1) { if (this.sources.length > 1) {
this.sources = this.customSort( this.sources.sort((a, b) => {
this.sources, alphabeticalCompare, return alphabeticalCompare(
(source) => getSourceTypeString(source.type)); getSourceTypeString(a.type), getSourceTypeString(b.type));
});
} }
if (this.sources.length > 0) { if (this.sources.length > 0) {
......
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