1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
ash / webui / diagnostics_ui / resources / routine_result_list.ts [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import './diagnostics_card.js';
import './diagnostics_shared.css.js';
import './routine_result_entry.js';
import {assert} from 'chrome://resources/js/assert.js';
import {PolymerElementProperties} from 'chrome://resources/polymer/v3_0/polymer/interfaces.js';
import {PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {RoutineGroup} from './routine_group.js';
import {ExecutionProgress, ResultStatusItem} from './routine_list_executor.js';
import {getTemplate} from './routine_result_list.html.js';
import {RoutineType} from './system_routine_controller.mojom-webui.js';
export const isRoutineGroupArray =
(arr: RoutineGroup[]|RoutineType[]): arr is RoutineGroup[] =>
(arr as RoutineGroup[])[0].groupName !== undefined;
export const isRoutineTypeArray =
(arr: RoutineGroup[]|RoutineType[]): arr is RoutineType[] =>
Object.values(RoutineType).includes(arr[0] as RoutineType);
type ResultsType = RoutineGroup[]|ResultStatusItem[];
/**
* @fileoverview
* 'routine-result-list' shows a list of routine result entries.
*/
export class RoutineResultListElement extends PolymerElement {
static get is(): 'routine-result-list' {
return 'routine-result-list' as const;
}
static get template(): HTMLTemplateElement {
return getTemplate();
}
static get properties(): PolymerElementProperties {
return {
results: {
type: Array,
value: () => [],
},
hidden: {
type: Boolean,
value: false,
},
hideVerticalLines: {
type: Boolean,
value: false,
},
usingRoutineGroups: {
type: Boolean,
value: false,
},
/**
* Only used with routine groups.
*/
ignoreRoutineStatusUpdates: {
type: Boolean,
value: false,
},
};
}
override hidden: boolean;
hideVerticalLines: boolean;
usingRoutineGroups: boolean;
ignoreRoutineStatusUpdates: boolean;
private results: ResultsType;
/**
* Resets the list and creates a new list with all routines in the unstarted
* state. Called by the parent RoutineResultSection when the user starts
* a test run.
*/
initializeTestRun(routines: RoutineGroup[]|RoutineType[]): void {
this.clearRoutines();
if (routines.length === 0) {
return;
}
if (this.usingRoutineGroups && isRoutineGroupArray(routines)) {
this.set('results', routines);
} else {
assert(isRoutineTypeArray(routines));
this.addRoutines(routines);
}
}
/**
* Removes all the routines from the list.
*/
clearRoutines(): void {
this.splice('results', 0, this.results.length);
}
/**
* Creates a list of unstarted routines.
*/
private addRoutines(routines: RoutineType[]): void {
for (const routine of routines) {
this.push('results', new ResultStatusItem(routine));
}
}
/**
* Updates the routine's status in the results list.
*/
private updateRoutineStatus(
index: number, status: RoutineGroup|ResultStatusItem): void {
assert(index < this.results.length);
this.splice('results', index, 1, status);
}
/**
* Receives the callback from RoutineListExecutor whenever the status of a
* routine changed.
*/
onStatusUpdate(status: ResultStatusItem): void {
if (this.ignoreRoutineStatusUpdates) {
return;
}
assert(this.results.length > 0);
this.results.forEach(
(result: RoutineGroup|ResultStatusItem, idx: number) => {
if (result instanceof RoutineGroup &&
result.routines.includes(status.routine)) {
result.setStatus(status);
const shouldUpdateRoutineUI = result.hasBlockingFailure();
this.hideVerticalLines = shouldUpdateRoutineUI;
this.updateRoutineStatus(idx, result.clone());
// Whether we should skip the remaining routines (true when a
// blocking routine fails) or not.
if (shouldUpdateRoutineUI) {
this.ignoreRoutineStatusUpdates = true;
this.updateRoutineUiAfterFailure();
}
return;
}
if (result instanceof ResultStatusItem) {
if (status.routine === result.routine) {
this.updateRoutineStatus(idx, status);
return;
}
}
});
}
protected shouldHideVerticalLines({value}: {
value: RoutineGroup|ResultStatusItem,
}): boolean {
return this.hideVerticalLines ||
value === this.results[this.results.length - 1];
}
/**
* When a test in a routine group fails, we stop sending status updates to the
* UI and display 'SKIPPED' for the remaining routine groups.
*/
updateRoutineUiAfterFailure(): void {
assert(this.usingRoutineGroups);
this.results.forEach(
(routineGroup: RoutineGroup|ResultStatusItem, i: number) => {
assert(routineGroup instanceof RoutineGroup);
if (routineGroup.progress === ExecutionProgress.NOT_STARTED) {
routineGroup.progress = ExecutionProgress.SKIPPED;
this.updateRoutineStatus(i, routineGroup.clone());
}
});
}
/**
* Called from 'routine-section' after all routines have finished running.
*/
resetIgnoreStatusUpdatesFlag(): void {
this.ignoreRoutineStatusUpdates = false;
}
}
declare global {
interface HTMLElementTagNameMap {
[RoutineResultListElement.is]: RoutineResultListElement;
}
}
customElements.define(RoutineResultListElement.is, RoutineResultListElement);