Commit b56b05e8 authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

Diagnostics: Add support for observing battery health

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: Ie9ae99bb4a06167a424fd9bd79d26d30e6531b9e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422139
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809773}
parent 93078527
...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; ...@@ -7,7 +7,7 @@ import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://diagnostics/diagnostics_app.js'; import 'chrome://diagnostics/diagnostics_app.js';
import {SystemDataProviderInterface} from 'chrome://diagnostics/diagnostics_types.js'; import {SystemDataProviderInterface} from 'chrome://diagnostics/diagnostics_types.js';
import {fakeBatteryInfo, fakeCpuUsage, fakeSystemInfo} from 'chrome://diagnostics/fake_data.js'; import {fakeBatteryHealth, fakeBatteryInfo, fakeCpuUsage, fakeSystemInfo} from 'chrome://diagnostics/fake_data.js';
import {FakeMethodResolver} from 'chrome://diagnostics/fake_method_resolver.js'; import {FakeMethodResolver} from 'chrome://diagnostics/fake_method_resolver.js';
import {FakeObservables} from 'chrome://diagnostics/fake_observables.js'; import {FakeObservables} from 'chrome://diagnostics/fake_observables.js';
import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js'; import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js';
...@@ -391,6 +391,19 @@ suite('FakeSystemDataProviderTest', () => { ...@@ -391,6 +391,19 @@ suite('FakeSystemDataProviderTest', () => {
}); });
}); });
test('ObserveBatteryHealth', () => {
provider.setFakeBatteryHealth(fakeBatteryHealth);
/** @type {!BatteryHealthObserver} */
const batteryHealthObserverRemote = {
onBatteryHealthUpdated: (batteryHealth) => {
assertDeepEquals(fakeBatteryHealth[0], batteryHealth);
}
};
return provider.observeBatteryHealth(batteryHealthObserverRemote);
});
test('ObserveCpuUsage', () => { test('ObserveCpuUsage', () => {
provider.setFakeCpuUsage(fakeCpuUsage); provider.setFakeCpuUsage(fakeCpuUsage);
......
...@@ -10,6 +10,12 @@ ...@@ -10,6 +10,12 @@
* re-aliased to the corresponding mojo types, or replaced by them. * re-aliased to the corresponding mojo types, or replaced by them.
*/ */
/**
* Type of SystemDataProviderInterface.ObserveBatteryHealth function.
* @typedef {!function(!BatteryHealthObserver): !Promise}
*/
export let ObserveBatteryHealthFunction;
/** /**
* Type of SystemDataProviderInterface.ObserveCpuUsage function. * Type of SystemDataProviderInterface.ObserveCpuUsage function.
* @typedef {!function(!CpuUsageObserver): !Promise} * @typedef {!function(!CpuUsageObserver): !Promise}
...@@ -22,6 +28,7 @@ export let ObserveCpuUsageFunction; ...@@ -22,6 +28,7 @@ export let ObserveCpuUsageFunction;
* @typedef {{ * @typedef {{
* getBatteryInfo: !function(): !Promise<!BatteryInfo>, * getBatteryInfo: !function(): !Promise<!BatteryInfo>,
* getSystemInfo: !function(): !Promise<!SystemInfo>, * getSystemInfo: !function(): !Promise<!SystemInfo>,
* observeBatteryHealth: !ObserveBatteryHealthFunction,
* observeCpuUsage: !ObserveCpuUsageFunction, * observeCpuUsage: !ObserveCpuUsageFunction,
* }} * }}
*/ */
...@@ -82,3 +89,22 @@ export let CpuUsageObserver; ...@@ -82,3 +89,22 @@ export let CpuUsageObserver;
* }} * }}
*/ */
export let CpuUsage; export let CpuUsage;
/**
* Type alias for BatteryHealthObserver.
* @typedef {{
* onBatteryHealthUpdated: !function(!BatteryHealth)
* }}
*/
export let BatteryHealthObserver;
/**
* Type alias for BatteryHealth.
* @typedef {{
* battery_wear_percentage: number,
* charge_full_design_milliamp_hours: number,
* charge_full_now_milliamp_hours: number,
* cycle_count: number,
* }}
*/
export let BatteryHealth;
...@@ -2,7 +2,15 @@ ...@@ -2,7 +2,15 @@
// 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.
import {CpuUsage, SystemInfo} from './diagnostics_types.js' import {BatteryHealth, CpuUsage, SystemInfo} from './diagnostics_types.js'
/* @type {!Array<!BatteryHealth>} */
export const fakeBatteryHealth = [{
battery_wear_percentage: 7,
charge_full_design_milliamp_hours: 6000,
charge_full_now_milliamp_hours: 5700,
cycle_count: 73,
}];
/* @type {!BatteryInfo} */ /* @type {!BatteryInfo} */
export const fakeBatteryInfo = { export const fakeBatteryInfo = {
......
...@@ -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.
import {BatteryInfo, CpuUsage, CpuUsageObserver, SystemInfo} from './diagnostics_types.js'; import {BatteryHealth, BatteryInfo, CpuUsage, CpuUsageObserver, SystemInfo} from './diagnostics_types.js';
import {FakeMethodResolver} from './fake_method_resolver.js'; import {FakeMethodResolver} from './fake_method_resolver.js';
import {FakeObservables} from './fake_observables.js'; import {FakeObservables} from './fake_observables.js';
...@@ -24,6 +24,7 @@ export class FakeSystemDataProvider { ...@@ -24,6 +24,7 @@ export class FakeSystemDataProvider {
this.methods_.register('getBatteryInfo'); this.methods_.register('getBatteryInfo');
// Setup observables. // Setup observables.
this.observables_.register('BatteryHealthObserver_onBatteryHealthUpdated');
this.observables_.register('CpuUsageObserver_onCpuUsageUpdated'); this.observables_.register('CpuUsageObserver_onCpuUsageUpdated');
} }
...@@ -58,6 +59,33 @@ export class FakeSystemDataProvider { ...@@ -58,6 +59,33 @@ export class FakeSystemDataProvider {
this.methods_.setResult('getBatteryInfo', batteryInfo); this.methods_.setResult('getBatteryInfo', batteryInfo);
} }
/*
* Implements SystemDataProviderInterface.ObserveBatteryHealth.
* @param {!BatteryHealthObserver} remote
* @return {!Promise}
*/
observeBatteryHealth(remote) {
return new Promise((resolve) => {
this.observables_.observe(
'BatteryHealthObserver_onBatteryHealthUpdated', (batteryHealth) => {
remote.onBatteryHealthUpdated(
/** @type {!BatteryHealth} */ (batteryHealth));
});
this.observables_.trigger('BatteryHealthObserver_onBatteryHealthUpdated');
resolve();
});
}
/**
* Sets the values that will observed from observeBatteryHealth.
* @param {!Array<!BatteryHealth>} batteryHealthList
*/
setFakeBatteryHealth(batteryHealthList) {
this.observables_.setObservableData(
'BatteryHealthObserver_onBatteryHealthUpdated', batteryHealthList);
}
/* /*
* Implements SystemDataProviderInterface.ObserveCpuUsage. * Implements SystemDataProviderInterface.ObserveCpuUsage.
* @param {!CpuUsageObserver} remote * @param {!CpuUsageObserver} remote
......
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