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

Diagnostics: Run routines and update status

- Wires up the routine result list and section to run tests
- Add tests for both

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I92e5e033b861b65ce49f16940210e29135ed0bf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2469877Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Commit-Queue: Zentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#822465}
parent 9caf4ee6
......@@ -4,7 +4,7 @@
import 'chrome://diagnostics/routine_result_list.js';
import {RoutineName} from 'chrome://diagnostics/diagnostics_types.js';
import {RoutineName, 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';
......@@ -110,4 +110,82 @@ export function routineResultListTestSuite() {
assertEquals(0, getEntries().length);
});
});
test('VerifyStatusUpdates', () => {
/** @type {!Array<!RoutineName>} */
const routines = [
RoutineName.kCpuCache,
RoutineName.kFloatingPoint,
];
return initializeRoutineResultList(routines).then(() => {
// Verify the starting state.
assertEquals(routines.length, getEntries().length);
getEntries().forEach((entry, index) => {
// Routines are initialized in the unstarted state.
let status = new ResultStatusItem(routines[index]);
status.progress = ExecutionProgress.kNotStarted;
assertDeepEquals(status, entry.item);
});
let status = new ResultStatusItem(routines[0]);
status.progress = ExecutionProgress.kRunning;
routineResultListElement.onStatusUpdate(status);
return flushTasks()
.then(() => {
// Verify first routine is running.
assertEquals(
ExecutionProgress.kRunning, getEntries()[0].item.progress);
assertEquals(null, getEntries()[0].item.result);
// Move the first routine to completed state.
status = new ResultStatusItem(routines[0]);
status.progress = ExecutionProgress.kCompleted;
status.result = {simple_result: StandardRoutineResult.kTestPassed};
routineResultListElement.onStatusUpdate(status);
return flushTasks();
})
.then(() => {
// Verify the first routine is completed.
assertEquals(
ExecutionProgress.kCompleted, getEntries()[0].item.progress);
assertNotEquals(null, getEntries()[0].item.result);
assertEquals(
StandardRoutineResult.kTestPassed,
getEntries()[0].item.result.simple_result);
status = new ResultStatusItem(routines[1]);
status.progress = ExecutionProgress.kRunning;
routineResultListElement.onStatusUpdate(status);
return flushTasks();
})
.then(() => {
// Verify second routine is running.
assertEquals(
ExecutionProgress.kRunning, getEntries()[1].item.progress);
assertEquals(null, getEntries()[1].item.result);
// Move the second routine to completed state.
status = new ResultStatusItem(routines[1]);
status.progress = ExecutionProgress.kCompleted;
status.result = {simple_result: StandardRoutineResult.kTestPassed};
routineResultListElement.onStatusUpdate(status);
return flushTasks();
})
.then(() => {
// Verify the second routine is completed.
assertEquals(
ExecutionProgress.kCompleted, getEntries()[1].item.progress);
assertNotEquals(null, getEntries()[1].item.result);
assertEquals(
StandardRoutineResult.kTestPassed,
getEntries()[0].item.result.simple_result);
return flushTasks();
});
});
});
}
......@@ -6,6 +6,8 @@ import 'chrome://diagnostics/routine_result_entry.js';
import 'chrome://diagnostics/routine_section.js';
import {RoutineName} from 'chrome://diagnostics/diagnostics_types.js';
import {FakeSystemRoutineController} from 'chrome://diagnostics/fake_system_routine_controller.js';
import {setSystemRoutineControllerForTesting} from 'chrome://diagnostics/mojo_interface_provider.js';
import {ExecutionProgress} from 'chrome://diagnostics/routine_list_executor.js';
import {flushTasks} from 'chrome://test/test_util.m.js';
......@@ -15,8 +17,17 @@ export function routineSectionTestSuite() {
/** @type {?HTMLElement} */
let routineSectionElement = null;
/** @type {!FakeSystemRoutineController} */
let routineController;
setup(function() {
PolymerTest.clearBody();
// Setup a fake routine controller so that nothing resolves unless
// done explicitly.
routineController = new FakeSystemRoutineController();
routineController.setDelayTimeInMillisecondsForTesting(-1);
setSystemRoutineControllerForTesting(routineController);
});
teardown(function() {
......@@ -129,10 +140,50 @@ export function routineSectionTestSuite() {
.then(() => {
const entries = getEntries();
assertEquals(routines.length, entries.length);
entries.forEach((entry, index) => {
assertEquals(routines[index], entry.item.routine);
assertEquals(ExecutionProgress.kNotStarted, entry.item.progress);
});
// First routine should be running.
assertEquals(routines[0], entries[0].item.routine);
assertEquals(ExecutionProgress.kRunning, entries[0].item.progress);
// Second routine is not started.
assertEquals(routines[1], entries[1].item.routine);
assertEquals(ExecutionProgress.kNotStarted, entries[1].item.progress);
// Resolve the running test.
return routineController.resolveRoutineForTesting();
})
.then(() => {
return flushTasks();
})
.then(() => {
const entries = getEntries();
assertEquals(routines.length, entries.length);
// First routine should be completed.
assertEquals(routines[0], entries[0].item.routine);
assertEquals(ExecutionProgress.kCompleted, entries[0].item.progress);
// Second routine should be running.
assertEquals(routines[1], entries[1].item.routine);
assertEquals(ExecutionProgress.kRunning, entries[1].item.progress);
// Resolve the running test.
return routineController.resolveRoutineForTesting();
})
.then(() => {
return flushTasks();
})
.then(() => {
const entries = getEntries();
assertEquals(routines.length, entries.length);
// First routine should be completed.
assertEquals(routines[0], entries[0].item.routine);
assertEquals(ExecutionProgress.kCompleted, entries[0].item.progress);
// Second routine should be completed.
assertEquals(routines[1], entries[1].item.routine);
assertEquals(ExecutionProgress.kCompleted, entries[1].item.progress);
});
});
}
......@@ -6,6 +6,7 @@ import './diagnostics_card.js';
import './diagnostics_shared_css.js';
import './routine_result_entry.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 {RoutineName} from './diagnostics_types.js';
import {ResultStatusItem} from './routine_list_executor.js'
......@@ -56,6 +57,32 @@ Polymer({
this.push('results_', new ResultStatusItem(routine));
},
/**
* Updates the routine's status in the results_ list.
* @param {number} index
* @param {!ResultStatusItem} status
* @private
*/
updateRoutineStatus_(index, status) {
assert(index < this.results_.length);
this.splice('results_', index, 1, status);
},
/**
* Receives the callback from RoutineListExecutor whenever the status of a
* routine changed.
* @param {!ResultStatusItem} status
*/
onStatusUpdate(status) {
assert(this.results_.length > 0);
this.results_.forEach((result, index) => {
if (result.routine == status.routine) {
this.updateRoutineStatus_(index, status);
return;
}
});
},
/** @override */
created() {},
});
......@@ -9,6 +9,8 @@ import './routine_result_list.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 {RoutineName} from './diagnostics_types.js';
import {getSystemRoutineController} from './mojo_interface_provider.js';
import {RoutineListExecutor} from './routine_list_executor.js'
/**
* @fileoverview
......@@ -21,6 +23,11 @@ Polymer({
_template: html`{__html_template__}`,
/**
* @private {?RoutineListExecutor}
*/
executor_: null,
properties: {
/** @type {!Array<!RoutineName>} */
routines: {
......@@ -38,13 +45,23 @@ Polymer({
/** @private */
onRunTestsClicked_() {
this.isRunTestsDisabled_ = true;
this.getListElem_().initializeTestRun(this.routines);
const resultListElem = this.getResultListElem_();
resultListElem.initializeTestRun(this.routines);
// TODO(zentaro): Run tests which will also reenable button on completion.
this.executor_ = new RoutineListExecutor(getSystemRoutineController());
this.executor_
.runRoutines(
this.routines, resultListElem.onStatusUpdate.bind(resultListElem))
.then(() => {
this.isRunTestsDisabled_ = false;
});
},
/** @return {!HTMLElement} */
getListElem_() {
/**
* @return {!HTMLElement}
* @private
**/
getResultListElem_() {
return /** @type {!HTMLElement} */ (this.$$('routine-result-list'));
},
......
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