Commit 19c42880 authored by Michael Checo's avatar Michael Checo Committed by Commit Bot

Diagnostics: Make all "run tests" buttons disabled while any are running

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I739d658e711973a9b10277f09aff07a6678dc712
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2547943
Commit-Queue: Michael Checo <michaelcheco@google.com>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#830194}
parent 4e3897a7
...@@ -7,11 +7,42 @@ import 'chrome://diagnostics/diagnostics_app.js'; ...@@ -7,11 +7,42 @@ import 'chrome://diagnostics/diagnostics_app.js';
import {BatteryChargeStatus, BatteryHealth, BatteryInfo, CpuUsage, MemoryUsage, SystemInfo} from 'chrome://diagnostics/diagnostics_types.js'; import {BatteryChargeStatus, BatteryHealth, BatteryInfo, CpuUsage, MemoryUsage, SystemInfo} from 'chrome://diagnostics/diagnostics_types.js';
import {fakeBatteryChargeStatus, fakeBatteryHealth, fakeBatteryInfo, fakeCpuUsage, fakeMemoryUsage, fakeSystemInfo, fakeSystemInfoWithoutBattery} from 'chrome://diagnostics/fake_data.js'; import {fakeBatteryChargeStatus, fakeBatteryHealth, fakeBatteryInfo, fakeCpuUsage, fakeMemoryUsage, fakeSystemInfo, fakeSystemInfoWithoutBattery} from 'chrome://diagnostics/fake_data.js';
import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js'; import {FakeSystemDataProvider} from 'chrome://diagnostics/fake_system_data_provider.js';
import {FakeSystemRoutineController} from 'chrome://diagnostics/fake_system_routine_controller.js';
import {setSystemDataProviderForTesting} from 'chrome://diagnostics/mojo_interface_provider.js'; import {setSystemDataProviderForTesting} from 'chrome://diagnostics/mojo_interface_provider.js';
import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js'; import {assertEquals, assertFalse, assertTrue} from '../../chai_assert.js';
import {flushTasks} from '../../test_util.m.js'; import {flushTasks} from '../../test_util.m.js';
import * as dx_utils from './diagnostics_test_utils.js';
/**
* @param {Array<?T>} cards
* @template T
* @throws {!Error}
*/
function assertRunTestButtonsDisabled(cards) {
cards.forEach((card) => {
const routineSection = dx_utils.getRoutineSection(card);
const runTestsButton =
dx_utils.getRunTestsButtonFromSection(routineSection);
assertTrue(runTestsButton.disabled);
});
}
/**
* @param {Array<?T>} cards
* @template T
* @throws {!Error}
*/
function assertRunTestButtonsEnabled(cards) {
cards.forEach((card) => {
const routineSection = dx_utils.getRoutineSection(card);
const runTestsButton =
dx_utils.getRunTestsButtonFromSection(routineSection);
assertFalse(runTestsButton.disabled);
});
}
export function appTestSuite() { export function appTestSuite() {
/** @type {?DiagnosticsAppElement} */ /** @type {?DiagnosticsAppElement} */
let page = null; let page = null;
...@@ -102,4 +133,28 @@ export function appTestSuite() { ...@@ -102,4 +133,28 @@ export function appTestSuite() {
assertFalse(!!batteryStatus); assertFalse(!!batteryStatus);
}); });
}); });
test('AllRunTestsButtonsDisabledWhileRunning', () => {
let cards = null;
let memoryRoutinesSection = null;
return initializeDiagnosticsApp(
fakeSystemInfo, fakeBatteryChargeStatus, fakeBatteryHealth,
fakeBatteryInfo, fakeCpuUsage, fakeMemoryUsage)
.then(() => {
const batteryStatusCard = page.$$('battery-status-card');
const cpuCard = page.$$('cpu-card');
const memoryCard = page.$$('memory-card');
cards = [batteryStatusCard, cpuCard, memoryCard];
memoryRoutinesSection = dx_utils.getRoutineSection(memoryCard);
memoryRoutinesSection.isTestRunning = true;
return flushTasks();
})
.then(() => {
assertRunTestButtonsDisabled(cards);
memoryRoutinesSection.isTestRunning = false;
return flushTasks();
})
.then(() => assertRunTestButtonsEnabled(cards));
});
} }
...@@ -137,3 +137,15 @@ export function getDiagnosticsCard(element) { ...@@ -137,3 +137,15 @@ export function getDiagnosticsCard(element) {
return /** @type {!DiagnosticsCardElement} */ ( return /** @type {!DiagnosticsCardElement} */ (
element.shadowRoot.querySelector('diagnostics-card')); element.shadowRoot.querySelector('diagnostics-card'));
} }
/**
* Helper function for getting the routine-section from an element.
* @param {?Element} element
* @return {!RoutineSectionElement}
*/
export function getRoutineSection(element) {
const routineSection =
/** @type {!RoutineSectionElement} */ (element.$$('routine-section'));
assertTrue(!!routineSection);
return routineSection;
}
...@@ -61,6 +61,7 @@ export function routineSectionTestSuite() { ...@@ -61,6 +61,7 @@ export function routineSectionTestSuite() {
// Assign the routines to the property. // Assign the routines to the property.
routineSectionElement.routines = routines; routineSectionElement.routines = routines;
routineSectionElement.isTestRunning = false;
return flushTasks(); return flushTasks();
} }
...@@ -173,10 +174,12 @@ export function routineSectionTestSuite() { ...@@ -173,10 +174,12 @@ export function routineSectionTestSuite() {
return initializeRoutineSection(routines) return initializeRoutineSection(routines)
.then(() => { .then(() => {
assertFalse(isRunTestsButtonDisabled()); assertFalse(isRunTestsButtonDisabled());
assertFalse(routineSectionElement.isTestRunning);
return clickRunTestsButton(); return clickRunTestsButton();
}) })
.then(() => { .then(() => {
assertTrue(isRunTestsButtonDisabled()); assertTrue(isRunTestsButtonDisabled());
assertTrue(routineSectionElement.isTestRunning);
}); });
}); });
......
...@@ -24,5 +24,7 @@ ...@@ -24,5 +24,7 @@
value="[[getCurrentNow_(batteryChargeStatus_.currentNowMilliamps)]]"> value="[[getCurrentNow_(batteryChargeStatus_.currentNowMilliamps)]]">
</data-point> </data-point>
<routine-section slot="routines" routines="[[routines_]]"></routine-section> <routine-section slot="routines" routines="[[routines_]]"
is-test-running="{{isTestRunning}}">
</routine-section>
</diagnostics-card> </diagnostics-card>
...@@ -81,6 +81,12 @@ Polymer({ ...@@ -81,6 +81,12 @@ Polymer({
type: String, type: String,
computed: 'decodeString16_(batteryChargeStatus_.powerTime)', computed: 'decodeString16_(batteryChargeStatus_.powerTime)',
}, },
/** @type {boolean} */
isTestRunning: {
type: Boolean,
notify: true,
},
}, },
/** @override */ /** @override */
......
...@@ -24,5 +24,7 @@ ...@@ -24,5 +24,7 @@
<data-point slot="body" id="cpuTemp" header="[[i18n('cpuSpeedLabel')]]" <data-point slot="body" id="cpuTemp" header="[[i18n('cpuSpeedLabel')]]"
value=""> value="">
</data-point> </data-point>
<routine-section slot="routines" routines="[[routines_]]"></routine-section> <routine-section slot="routines" routines="[[routines_]]"
is-test-running="{{isTestRunning}}">
</routine-section>
</diagnostics-card> </diagnostics-card>
...@@ -63,6 +63,12 @@ Polymer({ ...@@ -63,6 +63,12 @@ Polymer({
type: String, type: String,
value: '', value: '',
}, },
/** @type {boolean} */
isTestRunning: {
type: Boolean,
notify: true,
}
}, },
/** @override */ /** @override */
......
...@@ -38,10 +38,16 @@ ...@@ -38,10 +38,16 @@
</div> </div>
<div class="diagonstics-cards-container"> <div class="diagonstics-cards-container">
<template is="dom-if" if="[[showBatteryStatusCard_]]" restamp> <template is="dom-if" if="[[showBatteryStatusCard_]]" restamp>
<battery-status-card id="batteryStatusCard"></battery-status-card> <battery-status-card id="batteryStatusCard"
is-test-running="{{isTestRunning}}">
</battery-status-card>
</template> </template>
<cpu-card id="cpuCard"></cpu-card> <cpu-card id="cpuCard"
<memory-card id="memoryCard"></memory-card> is-test-running="{{isTestRunning}}">
</cpu-card>
<memory-card id="memoryCard"
is-test-running="{{isTestRunning}}">
</memory-card>
</div> </div>
<div class="session-log-container"> <div class="session-log-container">
<cr-button class="session-log-button"> <cr-button class="session-log-button">
......
...@@ -40,6 +40,12 @@ Polymer({ ...@@ -40,6 +40,12 @@ Polymer({
type: Boolean, type: Boolean,
value: false, value: false,
}, },
/** @type {boolean} */
isTestRunning: {
type: Boolean,
value: false,
},
}, },
/** @override */ /** @override */
......
...@@ -8,5 +8,7 @@ ...@@ -8,5 +8,7 @@
value="[[getTotalUsedMemory_(memoryUsage_)]]" value="[[getTotalUsedMemory_(memoryUsage_)]]"
max="[[memoryUsage_.totalMemoryKib]]"> max="[[memoryUsage_.totalMemoryKib]]">
</percent-bar-chart> </percent-bar-chart>
<routine-section slot="routines" routines="[[routines_]]"></routine-section> <routine-section slot="routines" routines="[[routines_]]"
is-test-running="{{isTestRunning}}">
</routine-section>
</diagnostics-card> </diagnostics-card>
...@@ -55,6 +55,12 @@ Polymer({ ...@@ -55,6 +55,12 @@ Polymer({
memoryUsage_: { memoryUsage_: {
type: Object, type: Object,
}, },
/** @type {boolean} */
isTestRunning: {
type: Boolean,
notify: true,
}
}, },
/** @override */ /** @override */
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<div id="routineSection"> <div id="routineSection">
<cr-button id="runTestsButton" class="action-button" on-click="onRunTestsClicked_" <cr-button id="runTestsButton" class="action-button" on-click="onRunTestsClicked_"
disabled="[[isRunTestsDisabled_]]"> disabled="[[isTestRunning]]">
<!-- TODO(zentaro): Localize this string. --> <!-- TODO(zentaro): Localize this string. -->
Run Tests Run Tests
</cr-button> </cr-button>
......
...@@ -36,12 +36,6 @@ Polymer({ ...@@ -36,12 +36,6 @@ Polymer({
*/ */
executor_: null, executor_: null,
/**
* @type {boolean}
* @private
*/
isRunTestsDisabled_: false,
/** /**
* Boolean whether last run had at least one failure, * Boolean whether last run had at least one failure,
* @type {boolean} * @type {boolean}
...@@ -78,10 +72,10 @@ Polymer({ ...@@ -78,10 +72,10 @@ Polymer({
value: '', value: '',
}, },
/** @private {boolean} */ /** @type {boolean} */
isRunTestsDisabled_: { isTestRunning: {
type: Boolean, type: Boolean,
value: false, notify: true,
}, },
/** @private {boolean} */ /** @private {boolean} */
...@@ -99,7 +93,7 @@ Polymer({ ...@@ -99,7 +93,7 @@ Polymer({
/** @private */ /** @private */
onRunTestsClicked_() { onRunTestsClicked_() {
this.isRunTestsDisabled_ = true; this.isTestRunning = true;
this.hasTestFailure_ = false; this.hasTestFailure_ = false;
this.systemRoutineController_ = getSystemRoutineController(); this.systemRoutineController_ = getSystemRoutineController();
...@@ -133,7 +127,7 @@ Polymer({ ...@@ -133,7 +127,7 @@ Polymer({
.then(() => { .then(() => {
this.executionStatus_ = ExecutionProgress.kCompleted; this.executionStatus_ = ExecutionProgress.kCompleted;
this.systemRoutineController_ = null; this.systemRoutineController_ = null;
this.isRunTestsDisabled_ = false; this.isTestRunning = false;
}); });
}); });
}, },
......
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