Commit 4fd0eb78 authored by dpapad's avatar dpapad Committed by Commit Bot

Add type-checking for chrome://device-emulator

This is in preparation of migrating this page to Polymer3.

Bug: 1015241
Change-Id: Id8533d89043f288fee6aaa45fcbde5ef48bda51a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1865266Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706964}
parent a12ff6d7
...@@ -66,6 +66,7 @@ group("closure_compile") { ...@@ -66,6 +66,7 @@ group("closure_compile") {
"braille_ime:closure_compile", "braille_ime:closure_compile",
"camera/src/js:closure_compile", "camera/src/js:closure_compile",
"crostini_installer:closure_compile", "crostini_installer:closure_compile",
"emulator:closure_compile",
"internet_config_dialog:closure_compile", "internet_config_dialog:closure_compile",
"internet_detail_dialog:closure_compile", "internet_detail_dialog:closure_compile",
"login:closure_compile", "login:closure_compile",
......
# Copyright 2018 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("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [
":audio_settings",
":battery_settings",
":bluetooth_settings",
":device_emulator_pages",
":input_device_settings",
]
}
js_library("audio_settings") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("bluetooth_settings") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("battery_settings") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("input_device_settings") {
externs_list = [ "$externs_path/chrome_send.js" ]
}
js_library("device_emulator_pages") {
deps = [
"//ui/webui/resources/js:cr",
]
externs_list = [ "$externs_path/chrome_send.js" ]
}
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
/** /**
* An audio node. Based on the struct AudioNode found in audio_node.h. * An audio node. Based on the struct AudioNode found in audio_node.h.
* @constructor * @constructor
* @suppress {checkTypes}
*/ */
var AudioNode = function() { var AudioNode = function() {
// Whether node will input or output audio. // Whether node will input or output audio.
...@@ -52,13 +53,11 @@ Polymer({ ...@@ -52,13 +53,11 @@ Polymer({
properties: { properties: {
/** /**
* An AudioNode which is currently being edited. * An AudioNode which is currently being edited.
* @type {AudioNode} * @type {?AudioNode}
*/ */
currentEditableObject: { currentEditableObject: {
type: Object, type: Object,
value: function() { value: null,
return {};
}
}, },
/** /**
...@@ -138,7 +137,7 @@ Polymer({ ...@@ -138,7 +137,7 @@ Polymer({
/** /**
* This adds or modifies an audio node to the AudioNodeList. * This adds or modifies an audio node to the AudioNodeList.
* @param {model: {index: number}} e Event with a model containing * @param {{model: {index: number}}} e Event with a model containing
* the index in |nodes| to add. * the index in |nodes| to add.
*/ */
insertAudioNode: function(e) { insertAudioNode: function(e) {
...@@ -150,10 +149,8 @@ Polymer({ ...@@ -150,10 +149,8 @@ Polymer({
/** /**
* This adds/modifies the audio node |nodes[currentEditIndex]| to/from the * This adds/modifies the audio node |nodes[currentEditIndex]| to/from the
* AudioNodeList. * AudioNodeList.
* @param {model: {index: number}} e Event with a model containing
* the index in |nodes| to add.
*/ */
insertEditedAudioNode: function(e) { insertEditedAudioNode: function() {
// Insert a new node or update an existing node using all the properties // Insert a new node or update an existing node using all the properties
// in |node|. // in |node|.
var node = this.nodes[this.currentEditIndex]; var node = this.nodes[this.currentEditIndex];
...@@ -163,8 +160,8 @@ Polymer({ ...@@ -163,8 +160,8 @@ Polymer({
/** /**
* Removes the audio node with id |id|. * Removes the audio node with id |id|.
* @param {model: {index: number}} e Event with a model containing * @param {{model: {index: number}}} e Event with a model containing
* the index in |nodes| to add. * the index in |nodes| to remove.
*/ */
removeAudioNode: function(e) { removeAudioNode: function(e) {
var info = this.nodes[e.model.index]; var info = this.nodes[e.model.index];
......
...@@ -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.
var BatterySettings = Polymer({ Polymer({
is: 'battery-settings', is: 'battery-settings',
properties: { properties: {
...@@ -115,11 +115,11 @@ var BatterySettings = Polymer({ ...@@ -115,11 +115,11 @@ var BatterySettings = Polymer({
/** The ID of the current power source, or the empty string. */ /** The ID of the current power source, or the empty string. */
selectedPowerSourceId: String, selectedPowerSourceId: String,
/** A string representing the time left until the battery is discharged. */ /** A number representing the time left until the battery is discharged. */
timeUntilEmpty: String, timeUntilEmpty: Number,
/** A string representing the time left until the battery is at 100%. */ /** A number representing the time left until the battery is at 100%. */
timeUntilFull: String, timeUntilFull: Number,
}, },
observers: [ observers: [
...@@ -131,7 +131,7 @@ var BatterySettings = Polymer({ ...@@ -131,7 +131,7 @@ var BatterySettings = Polymer({
}, },
onBatteryPercentChange: function(e) { onBatteryPercentChange: function(e) {
this.percent = parseInt(e.target.value); this.percent = parseInt(e.target.value, 10);
if (!isNaN(this.percent)) if (!isNaN(this.percent))
chrome.send('updateBatteryPercent', [this.percent]); chrome.send('updateBatteryPercent', [this.percent]);
}, },
...@@ -161,13 +161,13 @@ var BatterySettings = Polymer({ ...@@ -161,13 +161,13 @@ var BatterySettings = Polymer({
}, },
onTimeUntilEmptyChange: function(e) { onTimeUntilEmptyChange: function(e) {
this.timeUntilEmpty = parseInt(e.target.value); this.timeUntilEmpty = parseInt(e.target.value, 10);
if (!isNaN(this.timeUntilEmpty)) if (!isNaN(this.timeUntilEmpty))
chrome.send('updateTimeToEmpty', [this.timeUntilEmpty]); chrome.send('updateTimeToEmpty', [this.timeUntilEmpty]);
}, },
onTimeUntilFullChange: function(e) { onTimeUntilFullChange: function(e) {
this.timeUntilFull = parseInt(e.target.value); this.timeUntilFull = parseInt(e.target.value, 10);
if (!isNaN(this.timeUntilFull)) if (!isNaN(this.timeUntilFull))
chrome.send('updateTimeToFull', [this.timeUntilFull]); chrome.send('updateTimeToFull', [this.timeUntilFull]);
}, },
...@@ -176,13 +176,21 @@ var BatterySettings = Polymer({ ...@@ -176,13 +176,21 @@ var BatterySettings = Polymer({
e.model.set('item.power', e.target.value); e.model.set('item.power', e.target.value);
}, },
updatePowerProperties: function(power_properties) { /**
this.batteryPercent = power_properties.battery_percent; * @param {{
this.batteryState = * battery_percent: number,
this.batteryStateOptions[power_properties.battery_state]; * battery_state: number,
this.timeUntilEmpty = power_properties.battery_time_to_empty_sec; * battery_time_to_empty_sec: number,
this.timeUntilFull = power_properties.battery_time_to_full_sec; * battery_time_to_full_sec: number,
this.selectedPowerSourceId = power_properties.external_power_source_id; * external_power_source_id: string,
* }} properties
*/
updatePowerProperties: function(properties) {
this.batteryPercent = properties.battery_percent;
this.batteryState = this.batteryStateOptions[properties.battery_state];
this.timeUntilEmpty = properties.battery_time_to_empty_sec;
this.timeUntilFull = properties.battery_time_to_full_sec;
this.selectedPowerSourceId = properties.external_power_source_id;
}, },
isBatteryPresent: function() { isBatteryPresent: function() {
......
...@@ -68,7 +68,7 @@ Polymer({ ...@@ -68,7 +68,7 @@ Polymer({
/** /**
* A set of predefined bluetooth devices. * A set of predefined bluetooth devices.
* @type !Array<!Bluetooth> * @type !Array<!BluetoothDevice>
*/ */
predefinedDevices: { predefinedDevices: {
type: Array, type: Array,
...@@ -79,13 +79,11 @@ Polymer({ ...@@ -79,13 +79,11 @@ Polymer({
/** /**
* A bluetooth device object which is currently being edited. * A bluetooth device object which is currently being edited.
* @type {BluetoothDevice} * @type {?BluetoothDevice}
*/ */
currentEditableObject: { currentEditableObject: {
type: Object, type: Object,
value: function() { value: null,
return {};
}
}, },
/** /**
...@@ -104,7 +102,7 @@ Polymer({ ...@@ -104,7 +102,7 @@ Polymer({
* A set of options for the possible bluetooth device classes/types. * A set of options for the possible bluetooth device classes/types.
* Object |value| attribute comes from values in the WebUI, set in * Object |value| attribute comes from values in the WebUI, set in
* setDeviceClassOptions. * setDeviceClassOptions.
* @type !Array<! {text: string, value: int} > * @type !Array<!{text: string, value: number}>
*/ */
deviceClassOptions: { deviceClassOptions: {
type: Array, type: Array,
...@@ -270,13 +268,17 @@ Polymer({ ...@@ -270,13 +268,17 @@ Polymer({
* @return {boolean} Whether the PIN/passkey input field should be shown. * @return {boolean} Whether the PIN/passkey input field should be shown.
*/ */
showAuthToken: function(pairMethod) { showAuthToken: function(pairMethod) {
return pairMethod && pairMethod != 'None'; return !!pairMethod && pairMethod != 'None';
}, },
/** /**
* Called by the WebUI which provides a list of devices which are connected * Called by the WebUI which provides a list of devices which are connected
* to the main adapter. * to the main adapter.
* @param {!Array<!BluetoothDevice>} devices A list of bluetooth devices. * @param {!Array<!BluetoothDevice>} predefinedDevices A list of bluetooth
* devices.
* @param {!Array<!BluetoothDevice>} loadedCustomDevices
* @param {!Array<string>} pairingMethodOptions
* @param {!Array<string>} pairingActionOptions
*/ */
updateBluetoothInfo: function( updateBluetoothInfo: function(
predefinedDevices, loadedCustomDevices, pairingMethodOptions, predefinedDevices, loadedCustomDevices, pairingMethodOptions,
...@@ -289,7 +291,7 @@ Polymer({ ...@@ -289,7 +291,7 @@ Polymer({
/** /**
* Builds complete BluetoothDevice objects for each element in |devices_list|. * Builds complete BluetoothDevice objects for each element in |devices_list|.
* @param {!Array<!BluetoothDevice>} devices_list A list of incomplete * @param {!Array<!BluetoothDevice>} devices A list of incomplete
* BluetoothDevice provided by the C++ WebUI. * BluetoothDevice provided by the C++ WebUI.
* @param {boolean} predefined Whether or not the device is a predefined one. * @param {boolean} predefined Whether or not the device is a predefined one.
*/ */
...@@ -522,6 +524,7 @@ Polymer({ ...@@ -522,6 +524,7 @@ Polymer({
if (this.deviceClassOptions[i].value == classValue) if (this.deviceClassOptions[i].value == classValue)
return this.deviceClassOptions[i].text; return this.deviceClassOptions[i].text;
} }
return '';
}, },
/** /**
......
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