Commit d80b3457 authored by Ravi Chandra Sadineni's avatar Ravi Chandra Sadineni Committed by Commit Bot

[CrOS Settings] Fix current battery Idle Setting

Recently an additional dropdown has been added to allow setting
battery idle behavior differently from AC idle behavior. This
setting is visible only when battery is present and is hidden
behind a dom-if template. For some reason setting a value property
on select HTML element that is under dom-if does not work properly.
But setting selected boolean property on the option HTML element seem
to work fine. Thus changing to setting the selected boolean property
on option HTM element.

BUG=b:148105990, 1065050, b:154167105
Test= Run browser_tests and manual tests.

Change-Id: I83aeb7cd8640c4774853dcdd30f5acaf32ddd038
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2153604Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Commit-Queue: Ravi Chandra Sadineni <ravisadineni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#760234}
parent 0ec92892
......@@ -73,10 +73,11 @@
<select id="acIdleSelect" class="md-select"
on-change="onAcIdleSelectChange_"
disabled="[[shouldAcIdleSelectBeDisabled_]]"
aria-label="$i18n{powerIdleWhileChargingAriaLabel}"
value="{{currAcIdleBehavior_}}">
aria-label="$i18n{powerIdleWhileChargingAriaLabel}">
<template is="dom-repeat" items="[[acIdleOptions_]]">
<option value="[[item.value]]">[[item.name]]</option>
<option value="[[item.value]]" selected="[[item.selected]]">
[[item.name]]
</option>
</template>
</select>
</div>
......@@ -95,10 +96,11 @@
<select id="batteryIdleSelect" class="md-select"
on-change="onBatteryIdleSelectChange_"
disabled="[[shouldBatteryIdleSelectBeDisabled_]]"
aria-label="$i18n{powerIdleWhileOnBatteryAriaLabel}"
value="{{currBatteryIdleBehavior_}}">
aria-label="$i18n{powerIdleWhileOnBatteryAriaLabel}">
<template is="dom-repeat" items="[[batteryIdleOptions_]]">
<option value="[[item.value]]">[[item.name]]</option>
<option value="[[item.value]]" selected="[[item.selected]]">
[[item.name]]
</option>
</template>
</select>
</div>
......
......@@ -42,12 +42,6 @@ Polymer({
/** @private {boolean} Whether the system possesses a lid. */
hasLid_: Boolean,
/** @private {number} Current AC idle behavior */
currAcIdleBehavior_: Number,
/** @private {number} Current battery idle behavior */
currBatteryIdleBehavior_: Number,
/**
* List of available dual-role power sources, if enablePowerSettings is on.
* @private {!Array<!settings.PowerSource>|undefined}
......@@ -77,7 +71,10 @@ Polymer({
computed: 'computePowerSourceName_(powerSources_, lowPowerCharger_)',
},
/** @private {Array<!{value: settings.IdleBehavior, name: string}>} */
/**
@private {Array<!{value: settings.IdleBehavior, name: string, selected:
boolean}>}
*/
acIdleOptions_: {
type: Array,
value() {
......@@ -85,7 +82,10 @@ Polymer({
},
},
/** @private {Array<!{value: settings.IdleBehavior, name: string}>} */
/**
@private {Array<!{value: settings.IdleBehavior, name: string, selected:
boolean}>}
*/
batteryIdleOptions_: {
type: Array,
value() {
......@@ -280,31 +280,37 @@ Polymer({
/**
* @param {!settings.IdleBehavior} idleBehavior
* @return {{value: settings.IdleBehavior, name: string}} Idle option
* object that maps to idleBehavior.
* @param {!settings.IdleBehavior} currIdleBehavior
* @return {{value: settings.IdleBehavior, name: string, selected:boolean }}
* Idle option object that maps to idleBehavior.
* @private
*/
getIdleOption_(idleBehavior) {
getIdleOption_(idleBehavior, currIdleBehavior) {
const selected = idleBehavior == currIdleBehavior;
switch (idleBehavior) {
case settings.IdleBehavior.DISPLAY_OFF_SLEEP:
return {
value: idleBehavior,
name: loadTimeData.getString('powerIdleDisplayOffSleep')
name: loadTimeData.getString('powerIdleDisplayOffSleep'),
selected: selected
};
case settings.IdleBehavior.DISPLAY_OFF:
return {
value: idleBehavior,
name: loadTimeData.getString('powerIdleDisplayOff')
name: loadTimeData.getString('powerIdleDisplayOff'),
selected: selected
};
case settings.IdleBehavior.DISPLAY_ON:
return {
value: idleBehavior,
name: loadTimeData.getString('powerIdleDisplayOn')
name: loadTimeData.getString('powerIdleDisplayOn'),
selected: selected
};
case settings.IdleBehavior.OTHER:
return {
value: idleBehavior,
name: loadTimeData.getString('powerIdleOther')
name: loadTimeData.getString('powerIdleOther'),
selected: selected
};
default:
assertNotReached('Unknown IdleBehavior type');
......@@ -316,13 +322,15 @@ Polymer({
* @param {!Array<!settings.IdleBehavior>} batteryIdleBehaviors
* @private
*/
updateIdleOptions_(acIdleBehaviors, batteryIdleBehaviors) {
updateIdleOptions_(
acIdleBehaviors, batteryIdleBehaviors, currAcIdleBehavior,
currBatteryIdleBehavior) {
this.acIdleOptions_ = acIdleBehaviors.map((idleBehavior) => {
return this.getIdleOption_(idleBehavior);
return this.getIdleOption_(idleBehavior, currAcIdleBehavior);
});
this.batteryIdleOptions_ = batteryIdleBehaviors.map((idleBehavior) => {
return this.getIdleOption_(idleBehavior);
return this.getIdleOption_(idleBehavior, currBatteryIdleBehavior);
});
},
......@@ -334,19 +342,15 @@ Polymer({
powerManagementSettingsChanged_(powerManagementSettings) {
this.updateIdleOptions_(
powerManagementSettings.possibleAcIdleBehaviors || [],
powerManagementSettings.possibleBatteryIdleBehaviors || []);
powerManagementSettings.possibleBatteryIdleBehaviors || [],
powerManagementSettings.currentAcIdleBehavior,
powerManagementSettings.currentBatteryIdleBehavior);
this.acIdleManaged_ = powerManagementSettings.acIdleManaged;
this.batteryIdleManaged_ = powerManagementSettings.batteryIdleManaged;
this.hasLid_ = powerManagementSettings.hasLid;
this.updateLidClosedLabelAndPref_(
powerManagementSettings.lidClosedBehavior,
powerManagementSettings.lidClosedControlled);
// Make sure that the option is there before we potentially try to select
// it.
Polymer.dom.flush();
this.currAcIdleBehavior_ = powerManagementSettings.currentAcIdleBehavior;
this.currBatteryIdleBehavior_ =
powerManagementSettings.currentBatteryIdleBehavior;
},
/**
......
......@@ -1288,18 +1288,7 @@ cr.define('device_page_tests', function() {
test('display idle and lid behavior', function() {
return new Promise(function(resolve) {
// Indicate battery presence so that idle settings box while
// on battery is visible.
const batteryStatus = {
present: true,
charging: false,
calculating: false,
percent: 50,
statusText: '5 hours left',
};
cr.webUIListenerCallback(
'battery-status-changed',
Object.assign({}, batteryStatus));
// Send power management settings first.
sendPowerManagementSettings(
[
settings.IdleBehavior.DISPLAY_OFF_SLEEP,
......@@ -1320,9 +1309,32 @@ cr.define('device_page_tests', function() {
powerPage.async(resolve);
})
.then(function() {
// Indicate battery presence so that battery idle settings
// box becomes visible. Default option should be selected
// properly even when battery idle settings box is stamped
// later.
const batteryStatus = {
present: true,
charging: false,
calculating: false,
percent: 50,
statusText: '5 hours left',
};
cr.webUIListenerCallback(
'battery-status-changed', Object.assign({}, batteryStatus));
return new Promise(function(resolve) {
powerPage.async(resolve);
});
})
.then(function() {
const batteryIdleSelect =
assert(powerPage.$$('#batteryIdleSelect'));
expectEquals(
settings.IdleBehavior.DISPLAY_ON.toString(),
acIdleSelect.value);
expectEquals(
settings.IdleBehavior.DISPLAY_OFF.toString(),
batteryIdleSelect.value);
expectFalse(acIdleSelect.disabled);
expectEquals(null, powerPage.$$('#acIdleManagedIndicator'));
expectEquals(
......
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