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

Diagnostics: Implement a fake SystemDataProvider

-Implemented the first method getSystemInfo()

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I57ec7aedb0dbc990e9d62f4dbd18ec26a469e542
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2417509
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808581}
parent 3b9565aa
......@@ -8,6 +8,7 @@ import 'chrome://diagnostics/diagnostics_app.js';
import {SystemDataProviderInterface} from 'chrome://diagnostics/diagnostics_types.js';
import {FakeMethodResolver} from 'chrome://diagnostics/fake_method_resolver.js';
import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js';
import {getSystemDataProvider, setSystemDataProviderForTesting} from 'chrome://diagnostics/mojo_interface_provider.js';
suite('DiagnosticsFakeMethodResolver', () => {
......@@ -80,3 +81,43 @@ suite('FakeMojoProviderTest', () => {
assertEquals(fake_provider, getSystemDataProvider());
});
});
suite('FakeSystemDataProviderTest', () => {
/** @type {?FakeSystemDataProvider} */
let provider = null;
setup(function() {
provider = new FakeSystemDataProvider();
});
teardown(function() {
provider = null;
});
test('GetSystemInfo', () => {
/** @type {!DeviceCapabilities} */
const capabilities = {
has_battery: true,
};
/** @type {!VersionInfo} */
const version = {
milestone_version: 'M97',
};
/** @type {!SystemInfo} */
const expected = {
board_name: 'BestBoard',
cpu_model: 'SuperFast CPU',
total_memory_kib: 9999,
cores_number: 4,
version_info: version,
device_capabilities: capabilities,
};
provider.setFakeSystemInfo(expected);
return provider.getSystemInfo().then((systemInfo) => {
assertDeepEquals(expected, systemInfo);
});
});
});
......@@ -14,6 +14,7 @@ js_type_check("closure_compile_module") {
":diagnostics_card",
":diagnostics_types",
":fake_method_resolver",
":fake_system_data_provider",
":mojo_interface_provider",
]
}
......@@ -38,6 +39,10 @@ js_library("fake_method_resolver") {
deps = [ "//ui/webui/resources/js:cr.m" ]
}
js_library("fake_system_data_provider") {
deps = [ "//ui/webui/resources/js:cr.m" ]
}
js_library("mojo_interface_provider") {
deps = [ "//ui/webui/resources/js:cr.m" ]
}
......
......@@ -17,6 +17,7 @@
<include name="IDR_DIAGNOSTICS_APP_INDEX_HTML" file="index.html" type="BINDATA" />
<include name="IDR_DIAGNOSTICS_APP_JS" file="${root_gen_dir}/chromeos/components/diagnostics_ui/resources/diagnostics_app.js" use_base_dir="false" type="BINDATA"/>
<include name="IDR_DIAGNOSTICS_FAKE_METHOD_RESOLVER_JS" file="fake_method_resolver.js" type="BINDATA"/>
<include name="IDR_DIAGNOSTICS_FAKE_SYSTEM_DATA_PROVIDER_JS" file="fake_system_data_provider.js" type="BINDATA"/>
<include name="IDR_DIAGNOSTICS_MOJO_INTERFACE_PROVIDER_JS" file="mojo_interface_provider.js" type="BINDATA"/>
<include name="IDR_DIAGNOSTICS_SHARED_CSS_JS" file="${root_gen_dir}/chromeos/components/diagnostics_ui/resources/diagnostics_shared_css.js" use_base_dir="false" type="BINDDATA"/>
<include name="IDR_DIAGNOSTICS_TYPES_JS" file="diagnostics_types.js" type="BINDATA"/>
......
......@@ -16,3 +16,32 @@
* @typedef {!Object}
*/
export let SystemDataProviderInterface;
/**
* Type alias for DeviceCapabilities.
* @typedef {{
* has_battery: boolean,
* }}
*/
export let DeviceCapabilities;
/**
* Type alias for VersionInfo.
* @typedef {{
* milestone_version: string,
* }}
*/
export let VersionInfo;
/**
* Type alias for SystemInfo.
* @typedef {{
* board_name: string,
* cpu_model_name: string,
* cpu_threads_count: number,
* device_capabilities: DeviceCapabilities,
* total_memory_kib: number,
* version: VersionInfo,
* }}
*/
export let SystemInfo;
// Copyright 2020 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 {SystemInfo} from './diagnostics_types.js';
import {FakeMethodResolver} from './fake_method_resolver.js';
/**
* @fileoverview
* Implements a fake version of the SystemDataProvider mojo interface.
*/
export class FakeSystemDataProvider {
constructor() {
/** @private {!FakeMethodResolver} */
this.methods_ = new FakeMethodResolver();
// Setup method resolvers.
this.methods_.register('getSystemInfo');
}
/**
* @return {!Promise<!SystemInfo>}
*/
getSystemInfo() {
return this.methods_.resolveMethod('getSystemInfo');
}
/**
* Sets the value that will be returned when calling getSystemInfo().
* @param {!SystemInfo} systemInfo
*/
setFakeSystemInfo(systemInfo) {
this.methods_.setResult('getSystemInfo', systemInfo);
}
}
......@@ -3,7 +3,8 @@
// found in the LICENSE file.
import {assert} from 'chrome://resources/js/assert.m.js';
import {SystemDataProviderInterface} from './diagnostics_types.js'
import {SystemDataProviderInterface, SystemInfo} from './diagnostics_types.js'
import {FakeMethodResolver} from './fake_method_resolver.js'
/**
* @fileoverview
......
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