Commit e09f06d3 authored by Michael Checo's avatar Michael Checo Committed by Chromium LUCI CQ

Diagnostics: Refactor routine section badge and status logic

Bug: 1125150
Test: browser_tests --gtest_filter=DiagnosticsApp*
Change-Id: I4b02fe1d0f5625a1c1562339f08f792a63b622e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2616741Reviewed-by: default avatarBailey Berro <baileyberro@chromium.org>
Reviewed-by: default avatarJoon Ahn <joonbug@chromium.org>
Commit-Queue: Michael Checo <michaelcheco@google.com>
Cr-Commit-Position: refs/heads/master@{#844872}
parent 5d998440
...@@ -194,6 +194,25 @@ export function routineResultEntryTestSuite() { ...@@ -194,6 +194,25 @@ export function routineResultEntryTestSuite() {
}); });
}); });
test('StoppedTest', () => {
const item = createIncompleteStatus(
chromeos.diagnostics.mojom.RoutineType.kCpuStress,
ExecutionProgress.kCancelled);
return initializeEntryWithItem(item).then(() => {
assertEquals(
getNameText(),
loadTimeData.getStringF(
'routineEntryText',
loadTimeData.getString('cpuStressRoutineText')));
// Status should show that the test was stopped.
assertEquals(
getStatusBadge().value,
loadTimeData.getString('testStoppedBadgeText'));
assertEquals(getStatusBadge().badgeType, BadgeType.STOPPED);
});
});
test('PowerTest', () => { test('PowerTest', () => {
const item = createCompletedStatus( const item = createCompletedStatus(
chromeos.diagnostics.mojom.RoutineType.kBatteryCharge, chromeos.diagnostics.mojom.RoutineType.kBatteryCharge,
......
...@@ -746,6 +746,9 @@ Try tapping the mic to ask me anything. ...@@ -746,6 +746,9 @@ Try tapping the mic to ask me anything.
<message name="IDS_DIAGNOSTICS_TEST_QUEUED_BADGE_TEXT" desc="The text displayed to indicate that a test is currently queued."> <message name="IDS_DIAGNOSTICS_TEST_QUEUED_BADGE_TEXT" desc="The text displayed to indicate that a test is currently queued.">
QUEUED QUEUED
</message> </message>
<message name="IDS_DIAGNOSTICS_TEST_STOPPED_BADGE_TEXT" desc="The text displayed to indicate that a test has been stopped.">
STOPPED
</message>
<message name="IDS_DIAGNOSTICS_TEST_RUNNING_TEXT" desc="The text displayed while a test is running."> <message name="IDS_DIAGNOSTICS_TEST_RUNNING_TEXT" desc="The text displayed while a test is running.">
Test running Test running
</message> </message>
...@@ -782,6 +785,9 @@ Try tapping the mic to ask me anything. ...@@ -782,6 +785,9 @@ Try tapping the mic to ask me anything.
<message name="IDS_DIAGNOSTICS_MEMORY_AVAILABLE_TEXT" desc="The text that displays the amount of memory available on a users' device."> <message name="IDS_DIAGNOSTICS_MEMORY_AVAILABLE_TEXT" desc="The text that displays the amount of memory available on a users' device.">
<ph name="AVAILABLE_MEMORY">$1<ex>13.12</ex></ph> GB of <ph name="TOTAL_MEMORY">$2<ex>16</ex></ph> GB available. <ph name="AVAILABLE_MEMORY">$1<ex>13.12</ex></ph> GB of <ph name="TOTAL_MEMORY">$2<ex>16</ex></ph> GB available.
</message> </message>
<message name="IDS_DIAGNOSTICS_CANCELLED_TEST_TEXT" desc="The text that displays the test that was cancelled.">
<ph name="TEST_NAME">$1<ex>Stress</ex></ph> Test has been cancelled
</message>
<!-- Quick Answers --> <!-- Quick Answers -->
<message name="IDS_QUICK_ANSWERS_DEFINITION_TITLE_TEXT" desc="The title text format string used for Quick Answers definition result card. The first placeholder contains the source query text and the second placeholder contains the phonetics."> <message name="IDS_QUICK_ANSWERS_DEFINITION_TITLE_TEXT" desc="The title text format string used for Quick Answers definition result card. The first placeholder contains the source query text and the second placeholder contains the phonetics.">
......
7ec77363d51ed3c714bfc410cbad2b152bae037f
\ No newline at end of file
7ec77363d51ed3c714bfc410cbad2b152bae037f
\ No newline at end of file
...@@ -87,11 +87,13 @@ void AddDiagnosticsStrings(content::WebUIDataSource* html_source) { ...@@ -87,11 +87,13 @@ void AddDiagnosticsStrings(content::WebUIDataSource* html_source) {
{"seeReportText", IDS_DIAGNOSTICS_SEE_REPORT_TEXT}, {"seeReportText", IDS_DIAGNOSTICS_SEE_REPORT_TEXT},
{"sessionLog", IDS_DIAGNOSTICS_SESSION_LOG_LABEL}, {"sessionLog", IDS_DIAGNOSTICS_SESSION_LOG_LABEL},
{"stopTestButtonText", IDS_DIAGNOSTICS_STOP_TEST_BUTTON_TEXT}, {"stopTestButtonText", IDS_DIAGNOSTICS_STOP_TEST_BUTTON_TEXT},
{"testCancelledText", IDS_DIAGNOSTICS_CANCELLED_TEST_TEXT},
{"testFailure", IDS_DIAGNOSTICS_TEST_FAILURE_TEXT}, {"testFailure", IDS_DIAGNOSTICS_TEST_FAILURE_TEXT},
{"testFailedBadgeText", IDS_DIAGNOSTICS_TEST_FAILURE_BADGE_TEXT}, {"testFailedBadgeText", IDS_DIAGNOSTICS_TEST_FAILURE_BADGE_TEXT},
{"testQueuedBadgeText", IDS_DIAGNOSTICS_TEST_QUEUED_BADGE_TEXT}, {"testQueuedBadgeText", IDS_DIAGNOSTICS_TEST_QUEUED_BADGE_TEXT},
{"testRunning", IDS_DIAGNOSTICS_TEST_RUNNING_TEXT}, {"testRunning", IDS_DIAGNOSTICS_TEST_RUNNING_TEXT},
{"testRunningBadgeText", IDS_DIAGNOSTICS_TEST_RUNNING_BADGE_TEXT}, {"testRunningBadgeText", IDS_DIAGNOSTICS_TEST_RUNNING_BADGE_TEXT},
{"testStoppedBadgeText", IDS_DIAGNOSTICS_TEST_STOPPED_BADGE_TEXT},
{"testSuccess", IDS_DIAGNOSTICS_TEST_SUCCESS_TEXT}, {"testSuccess", IDS_DIAGNOSTICS_TEST_SUCCESS_TEXT},
{"testSucceededBadgeText", IDS_DIAGNOSTICS_TEST_SUCCESS_BADGE_TEXT}, {"testSucceededBadgeText", IDS_DIAGNOSTICS_TEST_SUCCESS_BADGE_TEXT},
}; };
......
...@@ -115,7 +115,6 @@ Polymer({ ...@@ -115,7 +115,6 @@ Polymer({
* @private * @private
*/ */
entryStatusChanged_() { entryStatusChanged_() {
// TODO(michaelcheco): Display "STOPPED" state when routines are cancelled.
switch (this.item.progress) { switch (this.item.progress) {
case ExecutionProgress.kNotStarted: case ExecutionProgress.kNotStarted:
this.setBadgeTypeAndText_( this.setBadgeTypeAndText_(
...@@ -125,6 +124,10 @@ Polymer({ ...@@ -125,6 +124,10 @@ Polymer({
this.setBadgeTypeAndText_( this.setBadgeTypeAndText_(
BadgeType.RUNNING, loadTimeData.getString('testRunningBadgeText')); BadgeType.RUNNING, loadTimeData.getString('testRunningBadgeText'));
break; break;
case ExecutionProgress.kCancelled:
this.setBadgeTypeAndText_(
BadgeType.STOPPED, loadTimeData.getString('testStoppedBadgeText'));
break;
case ExecutionProgress.kCompleted: case ExecutionProgress.kCompleted:
const testPassed = this.item.result && const testPassed = this.item.result &&
getSimpleResult(this.item.result) === getSimpleResult(this.item.result) ===
......
...@@ -50,13 +50,13 @@ ...@@ -50,13 +50,13 @@
<div id="routineSection" class="routine-container"> <div id="routineSection" class="routine-container">
<div class="routine-status-container"> <div class="routine-status-container">
<text-badge id="testStatusBadge" <text-badge id="testStatusBadge"
badge-type="[[getBadgeType_(executionStatus_)]]" badge-type="[[badgeType_]]"
hidden="[[isStatusHidden_(executionStatus_)]]" hidden="[[isStatusHidden_(executionStatus_)]]"
value="[[getBadgeText_(executionStatus_)]]"> value="[[badgeText_]]">
</text-badge> </text-badge>
<span id="testStatusText" <span id="testStatusText"
hidden$="[[isStatusHidden_(executionStatus_)]]"> hidden$="[[isStatusHidden_(executionStatus_)]]">
[[getTextStatus_(executionStatus_, currentTestName_)]] [[statusText_]]
</span> </span>
<span id="learnMoreText" <span id="learnMoreText"
hidden$="[[isLearnMoreHidden_(executionStatus_)]]" hidden$="[[isLearnMoreHidden_(executionStatus_)]]"
......
...@@ -9,7 +9,7 @@ import './routine_result_list.js'; ...@@ -9,7 +9,7 @@ import './routine_result_list.js';
import './text_badge.js'; import './text_badge.js';
import './strings.m.js'; import './strings.m.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert, assertNotReached} from 'chrome://resources/js/assert.m.js';
import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js'; import {I18nBehavior} from 'chrome://resources/js/i18n_behavior.m.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.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';
...@@ -97,8 +97,28 @@ Polymer({ ...@@ -97,8 +97,28 @@ Polymer({
type: String, type: String,
value: '', value: '',
}, },
/** @private {!BadgeType} */
badgeType_: {
type: String,
value: BadgeType.RUNNING,
},
/** @private {string} */
badgeText_: {
type: String,
value: '',
},
/** @private {string} */
statusText_: {
type: String,
value: '',
},
}, },
observers: ['routineStatusChanged_(executionStatus_, currentTestName_)'],
/** @private */ /** @private */
getResultListElem_() { getResultListElem_() {
return /** @type {!RoutineResultListElement} */ ( return /** @type {!RoutineResultListElement} */ (
...@@ -125,8 +145,9 @@ Polymer({ ...@@ -125,8 +145,9 @@ Polymer({
.runRoutines( .runRoutines(
filteredRoutines, filteredRoutines,
(status) => { (status) => {
this.currentTestName_ = loadTimeData.getStringF( if (status.result && status.result.powerResult) {
'routineNameText', getRoutineType(status.routine)); this.powerRoutineResult_ = status.result.powerResult;
}
if (status.result && if (status.result &&
getSimpleResult(status.result) !== getSimpleResult(status.result) !==
...@@ -135,11 +156,9 @@ Polymer({ ...@@ -135,11 +156,9 @@ Polymer({
this.hasTestFailure_ = true; this.hasTestFailure_ = true;
} }
resultListElem.onStatusUpdate.call(resultListElem, status); this.currentTestName_ = getRoutineType(status.routine);
if (status.result && status.result.powerResult) { resultListElem.onStatusUpdate.call(resultListElem, status);
this.powerRoutineResult_ = status.result.powerResult;
}
}) })
.then(() => { .then(() => {
this.executionStatus_ = ExecutionProgress.kCompleted; this.executionStatus_ = ExecutionProgress.kCompleted;
...@@ -197,40 +216,46 @@ Polymer({ ...@@ -197,40 +216,46 @@ Polymer({
}, },
/** @protected */ /** @protected */
getBadgeType_() { routineStatusChanged_() {
if (this.executionStatus_ === ExecutionProgress.kCompleted) { switch (this.executionStatus_) {
if (this.hasTestFailure_) { case ExecutionProgress.kNotStarted:
return BadgeType.ERROR; // Do nothing since status is hidden when tests have not been started.
} break;
return BadgeType.SUCCESS; case ExecutionProgress.kRunning:
this.setBadgeAndStatusText_(
BadgeType.RUNNING, loadTimeData.getString('testRunning'),
loadTimeData.getStringF('routineNameText', this.currentTestName_));
break;
case ExecutionProgress.kCancelled:
this.setBadgeAndStatusText_(
BadgeType.STOPPED, loadTimeData.getString('testStoppedBadgeText'),
loadTimeData.getStringF(
'testCancelledText', this.currentTestName_));
break;
case ExecutionProgress.kCompleted:
const isPowerRoutine = this.isPowerRoutine || this.powerRoutineResult_;
if (this.hasTestFailure_) {
this.setBadgeAndStatusText_(
BadgeType.ERROR, loadTimeData.getString('testFailedBadgeText'),
loadTimeData.getString('testFailure'));
} else {
this.setBadgeAndStatusText_(
BadgeType.SUCCESS,
loadTimeData.getString('testSucceededBadgeText'),
isPowerRoutine ? this.getPowerRoutineString_() :
loadTimeData.getString('testSuccess'));
}
break;
default:
assertNotReached();
} }
return BadgeType.RUNNING;
}, },
/** @protected */ /**
getBadgeText_() { * @private
if (this.executionStatus_ === ExecutionProgress.kRunning) { * @return {string}
return loadTimeData.getString('testRunning'); */
} getPowerRoutineString_() {
return loadTimeData.getString(
this.hasTestFailure_ ? 'testFailedBadgeText' :
'testSucceededBadgeText');
},
/** @protected */
getTextStatus_() {
if (this.executionStatus_ === ExecutionProgress.kRunning) {
return this.currentTestName_;
}
if (this.hasTestFailure_) {
return loadTimeData.getString('testFailure');
}
if (this.isPowerRoutine === false || this.powerRoutineResult_ === null) {
return loadTimeData.getString('testSuccess');
}
const stringId = const stringId =
this.routines.includes( this.routines.includes(
chromeos.diagnostics.mojom.RoutineType.kBatteryCharge) ? chromeos.diagnostics.mojom.RoutineType.kBatteryCharge) ?
...@@ -239,10 +264,21 @@ Polymer({ ...@@ -239,10 +264,21 @@ Polymer({
const percentText = loadTimeData.getStringF( const percentText = loadTimeData.getStringF(
'percentageLabel', this.powerRoutineResult_.percentChange.toFixed(2)); 'percentageLabel', this.powerRoutineResult_.percentChange.toFixed(2));
return loadTimeData.getStringF( return loadTimeData.getStringF(
stringId, stringId, percentText, this.powerRoutineResult_.timeElapsedSeconds);
percentText, },
this.powerRoutineResult_.timeElapsedSeconds
); /**
* @param {!BadgeType} badgeType
* @param {string} badgeText
* @param {string} statusText
* @private
*/
setBadgeAndStatusText_(badgeType, badgeText, statusText) {
this.setProperties({
badgeType_: badgeType,
badgeText_: badgeText,
statusText_: statusText
});
}, },
/** @override */ /** @override */
......
...@@ -16,6 +16,11 @@ ...@@ -16,6 +16,11 @@
color: var(--google-blue-600); color: var(--google-blue-600);
} }
.stopped {
background-color: var(--google-yellow-50);
color: var(--google-yellow-600);
}
.success { .success {
background-color: var(--google-green-50); background-color: var(--google-green-50);
color: var(--google-green-600); color: var(--google-green-600);
......
...@@ -15,6 +15,7 @@ export const BadgeType = { ...@@ -15,6 +15,7 @@ export const BadgeType = {
ERROR: 'error', ERROR: 'error',
QUEUED: 'queued', QUEUED: 'queued',
RUNNING: 'running', RUNNING: 'running',
STOPPED: 'stopped',
SUCCESS: 'success', SUCCESS: 'success',
}; };
......
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