Commit 80c3a1ba authored by Zentaro Kavanagh's avatar Zentaro Kavanagh Committed by Commit Bot

Diagnostics: Add fields for RoutineResultEntry

- Uses a temporary function to map an enum to it's name
- Test names will be localized in future CL

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I0e2159fdb6b1115559af073b49818b45cab072e3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2462234
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Auto-Submit: Zentaro Kavanagh <zentaro@chromium.org>
Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818005}
parent a725122e
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
// TODO(jimmyxgong): Use es6 module for mojo binding (crbug/1004256). // TODO(jimmyxgong): Use es6 module for mojo binding (crbug/1004256).
import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js'; import 'chrome://resources/mojo/mojo/public/js/mojo_bindings_lite.js';
import 'chrome://diagnostics/routine_result_entry.js'; import 'chrome://diagnostics/routine_result_entry.js';
import {RoutineName, RoutineResult, StandardRoutineResult} from 'chrome://diagnostics/diagnostics_types.js';
import {ExecutionProgress, ResultStatusItem} from 'chrome://diagnostics/routine_list_executor.js';
import {flushTasks} from 'chrome://test/test_util.m.js'; import {flushTasks} from 'chrome://test/test_util.m.js';
suite('RoutineResultEntryTest', () => { suite('RoutineResultEntryTest', () => {
...@@ -33,6 +36,71 @@ suite('RoutineResultEntryTest', () => { ...@@ -33,6 +36,71 @@ suite('RoutineResultEntryTest', () => {
return flushTasks(); return flushTasks();
} }
/**
* Updates the item in the element.
* @param {!ResultStatusItem} item
* @return {!Promise}
*/
function updateItem(item) {
routineResultEntryElement.item = item;
return flushTasks();
}
/**
* Initializes the entry then updates the item.
* @param {!ResultStatusItem} item
* @return {!Promise}
*/
function initializeEntryWithItem(item) {
return initializeRoutineResultEntry().then(() => {
return updateItem(item);
});
}
/**
* Creates a result status item without a final result.
* @param {!RoutineName} routine
* @param {!ExecutionProgress} progress
* @return {!ResultStatusItem}
*/
function createIncompleteStatus(routine, progress) {
let status = new ResultStatusItem(routine);
status.progress = progress;
return status;
}
/**
* Creates a completed result status item with a result.
* @param {!RoutineName} routine
* @param {!RoutineResult} result
* @return {!ResultStatusItem}
*/
function createCompletedStatus(routine, result) {
let status = createIncompleteStatus(routine, ExecutionProgress.kCompleted);
status.result = result;
return status;
}
/**
* Returns the routine name element text content.
* @return {string}
*/
function getNameText() {
const name = routineResultEntryElement.$$('#routine');
assertTrue(!!name);
return name.textContent.trim();
}
/**
* Returns the status element text content.
* @return {string}
*/
function getStatusText() {
const status = routineResultEntryElement.$$('#status');
assertTrue(!!status);
return status.textContent.trim();
}
test('ElementRendered', () => { test('ElementRendered', () => {
return initializeRoutineResultEntry().then(() => { return initializeRoutineResultEntry().then(() => {
// Verify the element rendered. // Verify the element rendered.
...@@ -40,4 +108,54 @@ suite('RoutineResultEntryTest', () => { ...@@ -40,4 +108,54 @@ suite('RoutineResultEntryTest', () => {
assertTrue(!!div); assertTrue(!!div);
}); });
}); });
test('NotStartedTest', () => {
const item = createIncompleteStatus(
RoutineName.kCpuStress, ExecutionProgress.kNotStarted);
return initializeEntryWithItem(item).then(() => {
// TODO(zentaro): Localize the test.
assertEquals(getNameText(), 'kCpuStress');
// Status should be empty if the test is not started.
assertEquals(getStatusText(), '');
});
});
test('RunningTest', () => {
const item = createIncompleteStatus(
RoutineName.kCpuStress, ExecutionProgress.kRunning);
return initializeEntryWithItem(item).then(() => {
// TODO(zentaro): Localize the test.
assertEquals(getNameText(), 'kCpuStress');
// Status should be running.
assertEquals(getStatusText(), 'kRunning');
});
});
test('PassedTest', () => {
const item = createCompletedStatus(
RoutineName.kCpuStress,
{simple_result: StandardRoutineResult.kTestPassed});
return initializeEntryWithItem(item).then(() => {
// TODO(zentaro): Localize the test.
assertEquals(getNameText(), 'kCpuStress');
// Status should show the passed result.
assertEquals(getStatusText(), 'kTestPassed');
});
});
test('FailedTest', () => {
const item = createCompletedStatus(
RoutineName.kCpuStress,
{simple_result: StandardRoutineResult.kTestFailed});
return initializeEntryWithItem(item).then(() => {
// TODO(zentaro): Localize the test.
assertEquals(getNameText(), 'kCpuStress');
// Status should show the passed result.
assertEquals(getStatusText(), 'kTestFailed');
});
});
}); });
<style include="diagnostics-shared"> <style include="diagnostics-shared">
.entryRow {
display: flex;
flex-direction: row;
justify-content: space-between;
}
</style> </style>
<div class="entryRow"> <div class="entryRow">
<!-- TODO(zentaro): Create mapping to localized strings. -->
<div id="routine">[[routineName_]]</div>
<div id="status">[[status_]]</div>
</div> </div>
...@@ -5,7 +5,31 @@ ...@@ -5,7 +5,31 @@
import './diagnostics_card.js'; import './diagnostics_card.js';
import './diagnostics_shared_css.js'; import './diagnostics_shared_css.js';
import {assert} from 'chrome://resources/js/assert.m.js';
import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, Polymer} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {RoutineName, RoutineResult, StandardRoutineResult} from './diagnostics_types.js';
import {ExecutionProgress, ResultStatusItem} from './routine_list_executor.js';
/**
* Resolves an enum value to the string name. This is used temporarily to
* provide a human readable string until the final mapping of enum values to
* localized strings is finalized.
* TODO(zentaro): Remove this function when strings are finalized.
* @param {!Object} enumType
* @param {number} enumValue
* @return {string}
*/
function lookupEnumValueName(enumType, enumValue) {
for (const [key, value] of Object.entries(enumType)) {
if (value === enumValue) {
return key;
}
}
// Values should always be found in the enum.
assert(false);
return '';
}
/** /**
* @fileoverview * @fileoverview
...@@ -16,7 +40,56 @@ Polymer({ ...@@ -16,7 +40,56 @@ Polymer({
_template: html`{__html_template__}`, _template: html`{__html_template__}`,
properties: {}, properties: {
/** @type {!ResultStatusItem} */
item: {
type: Object,
},
/** @private */
routineName_: {
type: String,
computed: 'getRoutineName_(item.routine)',
},
/** @private */
status_: {
type: String,
computed: 'getRoutineStatus_(item.progress, item.result)',
},
},
/**
* Get the string name for the routine.
* TODO(zentaro): Replace with a mapping to localized string when they are
* finalized.
* @param {!RoutineName} routine
* @return {string}
*/
getRoutineName_(routine) {
return lookupEnumValueName(RoutineName, routine);
},
/**
* Get the status for the routine. This is a combination of progress and
* result.
* TODO(zentaro): Replace with a mapping to localized string when they are
* finalized.
* @param {!ExecutionProgress} progress
* @param {!RoutineResult} result
* @return {string}
*/
getRoutineStatus_(progress, result) {
if (progress === ExecutionProgress.kNotStarted) {
return '';
}
if (progress === ExecutionProgress.kRunning) {
return lookupEnumValueName(ExecutionProgress, ExecutionProgress.kRunning);
}
return lookupEnumValueName(StandardRoutineResult, result.simple_result);
},
/** @override */ /** @override */
created() {}, created() {},
......
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