Commit 10f2faae authored by Jesse Schettler's avatar Jesse Schettler Committed by Commit Bot

scanning: Fix property annotations

The value of a select element is always a string, so the Polymer
properties bound to select element values are also strings. Fix the
annotations for these properties to indicate the correct types.

Bug: 1059779
Change-Id: I4ee229694f7925ac152d7de838779d36b9e9b56c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2481051
Commit-Queue: Jesse Schettler <jschettler@chromium.org>
Reviewed-by: default avatarJimmy Gong <jimmyxgong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818156}
parent b9a5f02a
...@@ -251,11 +251,13 @@ suite('ScanningAppTest', () => { ...@@ -251,11 +251,13 @@ suite('ScanningAppTest', () => {
tokenToString(firstScannerId), scanningApp.selectedScannerId); tokenToString(firstScannerId), scanningApp.selectedScannerId);
assertEquals( assertEquals(
firstCapabilities.sources[0].name, scanningApp.selectedSource); firstCapabilities.sources[0].name, scanningApp.selectedSource);
assertEquals(FileType.PDF, scanningApp.selectedFileType); assertEquals(FileType.PDF.toString(), scanningApp.selectedFileType);
assertEquals( assertEquals(
firstCapabilities.colorModes[0], scanningApp.selectedColorMode); firstCapabilities.colorModes[0].toString(),
scanningApp.selectedColorMode);
assertEquals( assertEquals(
firstCapabilities.resolutions[0], scanningApp.selectedResolution); firstCapabilities.resolutions[0].toString(),
scanningApp.selectedResolution);
// Before the scan button is clicked, the settings and scan button // Before the scan button is clicked, the settings and scan button
// should be enabled, and there should be no scan status. // should be enabled, and there should be no scan status.
......
...@@ -30,9 +30,9 @@ Polymer({ ...@@ -30,9 +30,9 @@ Polymer({
value: () => [], value: () => [],
}, },
/** @type {chromeos.scanning.mojom.ColorMode|undefined} */ /** @type {?string} */
selectedColorMode: { selectedColorMode: {
type: chromeos.scanning.mojom.ColorMode, type: String,
notify: true, notify: true,
}, },
}, },
......
...@@ -23,9 +23,9 @@ Polymer({ ...@@ -23,9 +23,9 @@ Polymer({
behaviors: [I18nBehavior, SelectBehavior], behaviors: [I18nBehavior, SelectBehavior],
properties: { properties: {
/** @type {chromeos.scanning.mojom.FileType|undefined} */ /** @type {?string} */
selectedFileType: { selectedFileType: {
type: chromeos.scanning.mojom.FileType, type: String,
notify: true, notify: true,
}, },
}, },
......
...@@ -30,9 +30,9 @@ Polymer({ ...@@ -30,9 +30,9 @@ Polymer({
value: () => [], value: () => [],
}, },
/** @type {number|undefined} */ /** @type {?string} */
selectedResolution: { selectedResolution: {
type: Number, type: String,
notify: true, notify: true,
}, },
}, },
......
...@@ -12,11 +12,12 @@ import './resolution_select.js'; ...@@ -12,11 +12,12 @@ import './resolution_select.js';
import './scanner_select.js'; import './scanner_select.js';
import './source_select.js'; import './source_select.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.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 {getScanService} from './mojo_interface_provider.js'; import {getScanService} from './mojo_interface_provider.js';
import {ScannerArr} from './scanning_app_types.js'; import {ScannerArr} from './scanning_app_types.js';
import {tokenToString} from './scanning_app_util.js'; import {colorModeFromString, tokenToString} from './scanning_app_util.js';
/** /**
* @fileoverview * @fileoverview
...@@ -57,14 +58,14 @@ Polymer({ ...@@ -57,14 +58,14 @@ Polymer({
/** @type {?string} */ /** @type {?string} */
selectedSource: String, selectedSource: String,
/** @type {chromeos.scanning.mojom.FileType|undefined} */ /** @type {?string} */
selectedFileType: chromeos.scanning.mojom.FileType, selectedFileType: String,
/** @type {chromeos.scanning.mojom.ColorMode|undefined} */ /** @type {?string} */
selectedColorMode: chromeos.scanning.mojom.ColorMode, selectedColorMode: String,
/** @type {number|undefined} */ /** @type {?string} */
selectedResolution: Number, selectedResolution: String,
/** /**
* @type {?string} * @type {?string}
...@@ -117,11 +118,11 @@ Polymer({ ...@@ -117,11 +118,11 @@ Polymer({
// Set the first options as the selected options since they will be the // Set the first options as the selected options since they will be the
// first options in the dropdowns. // first options in the dropdowns.
this.selectedSource = this.capabilities_.sources[0].name; this.selectedSource = this.capabilities_.sources[0].name;
this.selectedColorMode = this.capabilities_.colorModes[0]; this.selectedColorMode = this.capabilities_.colorModes[0].toString();
this.selectedResolution = this.capabilities_.resolutions[0]; this.selectedResolution = this.capabilities_.resolutions[0].toString();
// PDF is the default file type. // PDF is the default file type.
this.selectedFileType = chromeos.scanning.mojom.FileType.kPdf; this.selectedFileType = chromeos.scanning.mojom.FileType.kPdf.toString();
this.scanButtonDisabled_ = false; this.scanButtonDisabled_ = false;
}, },
...@@ -171,9 +172,8 @@ Polymer({ ...@@ -171,9 +172,8 @@ Polymer({
/** @private */ /** @private */
onScanClick_() { onScanClick_() {
if (!this.selectedScannerId || !this.selectedSource || if (!this.selectedScannerId || !this.selectedSource ||
this.selectedFileType === undefined || !this.selectedFileType || !this.selectedColorMode ||
this.selectedColorMode === undefined || !this.selectedResolution) {
this.selectedResolution === undefined) {
// TODO(jschettler): Replace status text with finalized i18n strings. // TODO(jschettler): Replace status text with finalized i18n strings.
this.statusText_ = 'Failed to start scan.'; this.statusText_ = 'Failed to start scan.';
return; return;
...@@ -188,8 +188,8 @@ Polymer({ ...@@ -188,8 +188,8 @@ Polymer({
const settings = { const settings = {
'sourceName': this.selectedSource, 'sourceName': this.selectedSource,
'fileType': chromeos.scanning.mojom.FileType.kPng, 'fileType': chromeos.scanning.mojom.FileType.kPng,
'colorMode': this.selectedColorMode, 'colorMode': colorModeFromString(this.selectedColorMode),
'resolutionDpi': this.selectedResolution, 'resolutionDpi': Number(this.selectedResolution),
}; };
this.scanService_ this.scanService_
.scan(this.scannerIds_.get(this.selectedScannerId), settings) .scan(this.scannerIds_.get(this.selectedScannerId), settings)
......
...@@ -4,6 +4,26 @@ ...@@ -4,6 +4,26 @@
import {assertNotReached} from 'chrome://resources/js/assert.m.js'; import {assertNotReached} from 'chrome://resources/js/assert.m.js';
/**
* Converts a chromeos.scanning.mojom.ColorMode string to the corresponding enum
* value.
* @param {!string} colorModeString
* @return {chromeos.scanning.mojom.ColorMode}
*/
export function colorModeFromString(colorModeString) {
switch (colorModeString) {
case chromeos.scanning.mojom.ColorMode.kBlackAndWhite.toString():
return chromeos.scanning.mojom.ColorMode.kBlackAndWhite;
case chromeos.scanning.mojom.ColorMode.kGrayscale.toString():
return chromeos.scanning.mojom.ColorMode.kGrayscale;
case chromeos.scanning.mojom.ColorMode.kColor.toString():
return chromeos.scanning.mojom.ColorMode.kColor;
default:
assertNotReached();
return chromeos.scanning.mojom.ColorMode.kColor;
}
}
/** /**
* Converts a chromeos.scanning.mojom.ColorMode to a string that can be * Converts a chromeos.scanning.mojom.ColorMode to a string that can be
* displayed in the color mode dropdown. * displayed in the color mode dropdown.
......
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