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") {
"braille_ime:closure_compile",
"camera/src/js:closure_compile",
"crostini_installer:closure_compile",
"emulator:closure_compile",
"internet_config_dialog:closure_compile",
"internet_detail_dialog: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 @@
/**
* An audio node. Based on the struct AudioNode found in audio_node.h.
* @constructor
* @suppress {checkTypes}
*/
var AudioNode = function() {
// Whether node will input or output audio.
......@@ -52,13 +53,11 @@ Polymer({
properties: {
/**
* An AudioNode which is currently being edited.
* @type {AudioNode}
* @type {?AudioNode}
*/
currentEditableObject: {
type: Object,
value: function() {
return {};
}
value: null,
},
/**
......@@ -138,7 +137,7 @@ Polymer({
/**
* 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.
*/
insertAudioNode: function(e) {
......@@ -150,10 +149,8 @@ Polymer({
/**
* This adds/modifies the audio node |nodes[currentEditIndex]| to/from the
* 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
// in |node|.
var node = this.nodes[this.currentEditIndex];
......@@ -163,8 +160,8 @@ Polymer({
/**
* Removes the audio node with id |id|.
* @param {model: {index: number}} e Event with a model containing
* the index in |nodes| to add.
* @param {{model: {index: number}}} e Event with a model containing
* the index in |nodes| to remove.
*/
removeAudioNode: function(e) {
var info = this.nodes[e.model.index];
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var BatterySettings = Polymer({
Polymer({
is: 'battery-settings',
properties: {
......@@ -115,11 +115,11 @@ var BatterySettings = Polymer({
/** The ID of the current power source, or the empty string. */
selectedPowerSourceId: String,
/** A string representing the time left until the battery is discharged. */
timeUntilEmpty: String,
/** A number representing the time left until the battery is discharged. */
timeUntilEmpty: Number,
/** A string representing the time left until the battery is at 100%. */
timeUntilFull: String,
/** A number representing the time left until the battery is at 100%. */
timeUntilFull: Number,
},
observers: [
......@@ -131,7 +131,7 @@ var BatterySettings = Polymer({
},
onBatteryPercentChange: function(e) {
this.percent = parseInt(e.target.value);
this.percent = parseInt(e.target.value, 10);
if (!isNaN(this.percent))
chrome.send('updateBatteryPercent', [this.percent]);
},
......@@ -161,13 +161,13 @@ var BatterySettings = Polymer({
},
onTimeUntilEmptyChange: function(e) {
this.timeUntilEmpty = parseInt(e.target.value);
this.timeUntilEmpty = parseInt(e.target.value, 10);
if (!isNaN(this.timeUntilEmpty))
chrome.send('updateTimeToEmpty', [this.timeUntilEmpty]);
},
onTimeUntilFullChange: function(e) {
this.timeUntilFull = parseInt(e.target.value);
this.timeUntilFull = parseInt(e.target.value, 10);
if (!isNaN(this.timeUntilFull))
chrome.send('updateTimeToFull', [this.timeUntilFull]);
},
......@@ -176,13 +176,21 @@ var BatterySettings = Polymer({
e.model.set('item.power', e.target.value);
},
updatePowerProperties: function(power_properties) {
this.batteryPercent = power_properties.battery_percent;
this.batteryState =
this.batteryStateOptions[power_properties.battery_state];
this.timeUntilEmpty = power_properties.battery_time_to_empty_sec;
this.timeUntilFull = power_properties.battery_time_to_full_sec;
this.selectedPowerSourceId = power_properties.external_power_source_id;
/**
* @param {{
* battery_percent: number,
* battery_state: number,
* battery_time_to_empty_sec: number,
* battery_time_to_full_sec: number,
* 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() {
......
......@@ -68,7 +68,7 @@ Polymer({
/**
* A set of predefined bluetooth devices.
* @type !Array<!Bluetooth>
* @type !Array<!BluetoothDevice>
*/
predefinedDevices: {
type: Array,
......@@ -79,13 +79,11 @@ Polymer({
/**
* A bluetooth device object which is currently being edited.
* @type {BluetoothDevice}
* @type {?BluetoothDevice}
*/
currentEditableObject: {
type: Object,
value: function() {
return {};
}
value: null,
},
/**
......@@ -104,7 +102,7 @@ Polymer({
* A set of options for the possible bluetooth device classes/types.
* Object |value| attribute comes from values in the WebUI, set in
* setDeviceClassOptions.
* @type !Array<! {text: string, value: int} >
* @type !Array<!{text: string, value: number}>
*/
deviceClassOptions: {
type: Array,
......@@ -270,13 +268,17 @@ Polymer({
* @return {boolean} Whether the PIN/passkey input field should be shown.
*/
showAuthToken: function(pairMethod) {
return pairMethod && pairMethod != 'None';
return !!pairMethod && pairMethod != 'None';
},
/**
* Called by the WebUI which provides a list of devices which are connected
* 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(
predefinedDevices, loadedCustomDevices, pairingMethodOptions,
......@@ -289,7 +291,7 @@ Polymer({
/**
* 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.
* @param {boolean} predefined Whether or not the device is a predefined one.
*/
......@@ -522,6 +524,7 @@ Polymer({
if (this.deviceClassOptions[i].value == classValue)
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