@e2e-dev/electron 0.0.1-nightly-20261130030410 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -2
- package/dist/.build.json +1 -1
- package/dist/app-process.d.ts +3 -1
- package/dist/app-process.js +68 -18
- package/dist/dialogs.d.ts +3 -1
- package/dist/dialogs.js +10 -3
- package/dist/errors.js +4 -3
- package/dist/executable.js +65 -14
- package/dist/ffmpeg.js +2 -1
- package/dist/fields.js +80 -7
- package/dist/in-page/node-ops.js +8 -7
- package/dist/install-lock.d.ts +15 -0
- package/dist/install-lock.js +165 -0
- package/dist/install-process.d.ts +7 -0
- package/dist/install-process.js +37 -0
- package/dist/launcher.d.ts +2 -2
- package/dist/launcher.js +14 -2
- package/dist/snapshot.d.ts +69 -4
- package/dist/snapshot.js +214 -18
- package/dist/surface.js +71 -19
- package/dist/video.d.ts +13 -0
- package/dist/video.js +75 -22
- package/package.json +5 -5
package/dist/snapshot.js
CHANGED
|
@@ -12,6 +12,34 @@ export const MASKED_TAGS = ['IFRAME', 'FRAME', 'WEBVIEW', 'EMBED', 'OBJECT'];
|
|
|
12
12
|
const CONTROL_TAGS = new Set(['A', 'BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'SUMMARY']);
|
|
13
13
|
/** `Node.TEXT_NODE`. */
|
|
14
14
|
const TEXT_NODE = 3;
|
|
15
|
+
/** `Node.ELEMENT_NODE`. */
|
|
16
|
+
const ELEMENT_NODE = 1;
|
|
17
|
+
/**
|
|
18
|
+
* The concrete WAI-ARIA roles, as the web engine's `ARIA_ROLES` in
|
|
19
|
+
* `packages/web/src/in-page/read-semantics.ts` lists them: a `role` token
|
|
20
|
+
* outside it is skipped.
|
|
21
|
+
*/
|
|
22
|
+
const ARIA_ROLES = new Set([
|
|
23
|
+
'alert', 'alertdialog', 'application', 'article', 'banner', 'blockquote', 'button', 'caption',
|
|
24
|
+
'cell', 'checkbox', 'code', 'columnheader', 'combobox', 'complementary', 'contentinfo', 'definition',
|
|
25
|
+
'deletion', 'dialog', 'directory', 'document', 'emphasis', 'feed', 'figure', 'form',
|
|
26
|
+
'generic', 'grid', 'gridcell', 'group', 'heading', 'img', 'insertion', 'link',
|
|
27
|
+
'list', 'listbox', 'listitem', 'log', 'main', 'mark', 'marquee', 'math',
|
|
28
|
+
'meter', 'menu', 'menubar', 'menuitem', 'menuitemcheckbox', 'menuitemradio', 'navigation', 'none',
|
|
29
|
+
'note', 'option', 'paragraph', 'presentation', 'progressbar', 'radio', 'radiogroup', 'region',
|
|
30
|
+
'row', 'rowgroup', 'rowheader', 'scrollbar', 'search', 'searchbox', 'separator', 'slider',
|
|
31
|
+
'spinbutton', 'status', 'strong', 'subscript', 'superscript', 'switch', 'tab', 'table',
|
|
32
|
+
'tablist', 'tabpanel', 'term', 'textbox', 'time', 'timer', 'toolbar', 'tooltip',
|
|
33
|
+
'tree', 'treegrid', 'treeitem',
|
|
34
|
+
]);
|
|
35
|
+
/**
|
|
36
|
+
* An element's explicit role: the first token of its `role` that names a
|
|
37
|
+
* concrete WAI-ARIA role, as the web engine's `explicitRole` reads it (case
|
|
38
|
+
* as written), so `role="x-foo button"` is a button.
|
|
39
|
+
*/
|
|
40
|
+
export function explicitRoleOf(attributes) {
|
|
41
|
+
return (attributes['role'] ?? '').split(/[ \t\n\f\r]+/).find((role) => ARIA_ROLES.has(role));
|
|
42
|
+
}
|
|
15
43
|
/** A password input: it reports no value and no text, and a screenshot paints it over. */
|
|
16
44
|
export function isSecureField(nodeName, attributes) {
|
|
17
45
|
return nodeName === 'INPUT' && attributes['type']?.toLowerCase() === 'password';
|
|
@@ -39,6 +67,18 @@ export class DomSnapshot {
|
|
|
39
67
|
blanks = [];
|
|
40
68
|
/** Per node, its nearest table cell, or -1. */
|
|
41
69
|
cells = [];
|
|
70
|
+
/**
|
|
71
|
+
* The nodes inside a shadow tree. The snapshot has no node for a shadow
|
|
72
|
+
* root: every node in one carries its type, and the root's children have
|
|
73
|
+
* the host as their parent.
|
|
74
|
+
*/
|
|
75
|
+
inShadowTree;
|
|
76
|
+
/** The nodes whose computed `visibility` is `hidden` or `collapse`. */
|
|
77
|
+
invisible = new Set();
|
|
78
|
+
/** Per element, its element children in order; built on the first table cell's read. */
|
|
79
|
+
elementChildren;
|
|
80
|
+
/** Per table, how many rows it lists; filled as lone headers ask. */
|
|
81
|
+
rowCounts = new Map();
|
|
42
82
|
constructor(document, strings) {
|
|
43
83
|
const { nodes, layout } = document;
|
|
44
84
|
this.strings = strings;
|
|
@@ -49,7 +89,9 @@ export class DomSnapshot {
|
|
|
49
89
|
this.backendIds = nodes.backendNodeId ?? [];
|
|
50
90
|
this.attributePairs = nodes.attributes ?? [];
|
|
51
91
|
this.rendered = new Set(layout.nodeIndex);
|
|
52
|
-
|
|
92
|
+
const shadowRoots = this.rare(nodes.shadowRootType);
|
|
93
|
+
this.inShadowTree = new Set(shadowRoots.keys());
|
|
94
|
+
this.closedShadow = new Set([...shadowRoots].filter(([, type]) => type === 'closed').map(([node]) => node));
|
|
53
95
|
this.types.forEach((_, index) => this.blanks.push((this.blanks[index - 1] ?? 0) + (/^\s+$/.test(this.sourceText(index) ?? '') ? 1 : 0)));
|
|
54
96
|
// A parent precedes its children, so its cell is known first.
|
|
55
97
|
this.names.forEach((_, index) => {
|
|
@@ -113,15 +155,18 @@ export class DomSnapshot {
|
|
|
113
155
|
*/
|
|
114
156
|
drawnByLabel(index) {
|
|
115
157
|
const id = this.attributesAt(index)['id'];
|
|
116
|
-
// An empty `for` names no element, as `label.control` reads it.
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
158
|
+
// An empty `for` names no element, as `label.control` reads it; a `for` names an element in its own tree only.
|
|
159
|
+
const scope = this.scopeOf(index);
|
|
160
|
+
const labels = id === undefined || id === '' ? [] : (this.labelsFor.get(id) ?? []).filter((label) => this.scopeOf(label) === scope);
|
|
161
|
+
// A label around the control is its label only when it has no `for`, which names another control or none, and is in
|
|
162
|
+
// its tree: a label around a shadow host labels nothing inside its shadow tree.
|
|
163
|
+
for (const at of this.ancestorsInTree(index))
|
|
120
164
|
if (this.nameAt(at) === 'LABEL' && !('for' in this.attributesAt(at)))
|
|
121
165
|
labels.push(at);
|
|
122
166
|
return labels.some((label) => {
|
|
123
167
|
const box = this.boxes.get(label);
|
|
124
|
-
|
|
168
|
+
// A label that draws nothing (no box, or visibility hidden) puts no control on screen.
|
|
169
|
+
if (box === undefined || (box[2] ?? 0) === 0 || (box[3] ?? 0) === 0 || this.invisible.has(label))
|
|
125
170
|
return false;
|
|
126
171
|
for (const at of this.subtree(label))
|
|
127
172
|
if (at !== index && at !== label && this.isControl(at))
|
|
@@ -129,6 +174,35 @@ export class DomSnapshot {
|
|
|
129
174
|
return true;
|
|
130
175
|
});
|
|
131
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* The node's ancestors in its own tree, nearest first: the snapshot follows
|
|
179
|
+
* the tree as drawn, where a slotted node's parent is its slot, so the
|
|
180
|
+
* nodes of a shadow tree it is slotted through are passed over to reach its
|
|
181
|
+
* host and the host's own ancestors. A node in a shadow tree stops at its
|
|
182
|
+
* host.
|
|
183
|
+
*/
|
|
184
|
+
*ancestorsInTree(index) {
|
|
185
|
+
const scope = this.scopeOf(index);
|
|
186
|
+
for (let at = this.parents[index] ?? -1; at >= 0; at = this.parents[at] ?? -1) {
|
|
187
|
+
if (this.scopeOf(at) === scope)
|
|
188
|
+
yield at;
|
|
189
|
+
else if (scope !== -1)
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* The tree a node is in: the host of the shadow tree it is in, or -1 for
|
|
195
|
+
* the document's own. A shadow tree inside another one's is taken as the
|
|
196
|
+
* outer one: the snapshot marks the nodes of both alike.
|
|
197
|
+
*/
|
|
198
|
+
scopeOf(index) {
|
|
199
|
+
if (!this.inShadowTree.has(index))
|
|
200
|
+
return -1;
|
|
201
|
+
let at = index;
|
|
202
|
+
while (this.inShadowTree.has(this.parents[at] ?? -1))
|
|
203
|
+
at = this.parents[at] ?? -1;
|
|
204
|
+
return this.parents[at] ?? -1;
|
|
205
|
+
}
|
|
132
206
|
/**
|
|
133
207
|
* How many rendered elements a screenshot must paint over and a selector
|
|
134
208
|
* cannot reach: password inputs and nested documents inside a closed shadow
|
|
@@ -180,11 +254,13 @@ export class DomSnapshot {
|
|
|
180
254
|
indexFacts(nodes, layout) {
|
|
181
255
|
const inputValues = this.rare(nodes.inputValue);
|
|
182
256
|
const textValues = this.rare(nodes.textValue);
|
|
183
|
-
const
|
|
257
|
+
const optionValues = this.optionValues();
|
|
258
|
+
const selectValues = this.selectValues(nodes.optionSelected?.index ?? [], optionValues);
|
|
184
259
|
const checked = new Set(nodes.inputChecked?.index ?? []);
|
|
260
|
+
const selectedOptions = new Set(nodes.optionSelected?.index ?? []);
|
|
185
261
|
const withText = this.nodesWithText();
|
|
186
262
|
const bounds = this.boxes;
|
|
187
|
-
const invisible =
|
|
263
|
+
const { invisible } = this;
|
|
188
264
|
layout.nodeIndex.forEach((node, at) => {
|
|
189
265
|
if (!bounds.has(node))
|
|
190
266
|
bounds.set(node, layout.bounds[at]);
|
|
@@ -199,7 +275,10 @@ export class DomSnapshot {
|
|
|
199
275
|
const input = inputValues.get(index);
|
|
200
276
|
const text = textValues.get(index);
|
|
201
277
|
const selected = selectValues.get(index);
|
|
278
|
+
const option = optionValues.get(index);
|
|
202
279
|
const box = bounds.get(index);
|
|
280
|
+
const editable = this.attributesAt(index)['contenteditable'];
|
|
281
|
+
const editor = editable === undefined || editable.toLowerCase() === 'false' ? undefined : [...this.subtree(index)].map((at) => this.sourceText(at) ?? '').join('');
|
|
203
282
|
this.facts.set(backendNodeId, {
|
|
204
283
|
index,
|
|
205
284
|
nodeName: this.nameAt(index),
|
|
@@ -207,13 +286,124 @@ export class DomSnapshot {
|
|
|
207
286
|
hasText: withText.has(index),
|
|
208
287
|
invisible: invisible.has(index),
|
|
209
288
|
checked: checked.has(index),
|
|
289
|
+
selected: selectedOptions.has(index),
|
|
290
|
+
ariaDisabled: this.ariaDisabled(index),
|
|
291
|
+
inheritsDisabled: this.inheritsDisabled(index),
|
|
210
292
|
...(input === undefined ? {} : { inputValue: input }),
|
|
211
293
|
...(text === undefined ? {} : { textValue: text }),
|
|
294
|
+
...(editor === undefined ? {} : { editorText: editor }),
|
|
212
295
|
...(selected === undefined ? {} : { selectValue: selected }),
|
|
296
|
+
...(option === undefined ? {} : { optionValue: option }),
|
|
213
297
|
...(box === undefined ? {} : { bounds: box }),
|
|
298
|
+
...(this.nameAt(index) === 'TD' || this.nameAt(index) === 'TH' ? { cellRole: () => this.cellRoleOf(index, withText) } : {}),
|
|
214
299
|
});
|
|
215
300
|
});
|
|
216
301
|
}
|
|
302
|
+
/** See `DomFacts.cellRole`; undefined for a header with no role. `withText` holds the nodes whose text is not blank. */
|
|
303
|
+
cellRoleOf(index, withText) {
|
|
304
|
+
const name = this.nameAt(index);
|
|
305
|
+
let table = -1;
|
|
306
|
+
for (const at of this.ancestorsInTree(index)) {
|
|
307
|
+
if (this.nameAt(at) === 'TABLE') {
|
|
308
|
+
table = at;
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
if (name === 'TD') {
|
|
313
|
+
const role = table === -1 ? undefined : explicitRoleOf(this.attributesAt(table));
|
|
314
|
+
return role === 'grid' || role === 'treegrid' ? 'gridcell' : 'cell';
|
|
315
|
+
}
|
|
316
|
+
const scope = (this.attributesAt(index)['scope'] ?? '').toLowerCase();
|
|
317
|
+
if (scope === 'row' || scope === 'rowgroup')
|
|
318
|
+
return 'rowheader';
|
|
319
|
+
if (scope === 'col' || scope === 'colgroup')
|
|
320
|
+
return 'columnheader';
|
|
321
|
+
const parent = this.parents[index] ?? -1;
|
|
322
|
+
const siblings = this.childrenOf(parent);
|
|
323
|
+
const at = siblings.indexOf(index);
|
|
324
|
+
const previous = siblings[at - 1];
|
|
325
|
+
const next = siblings[at + 1];
|
|
326
|
+
if (previous === undefined && next === undefined) {
|
|
327
|
+
const inRow = parent >= 0 && this.nameAt(parent) === 'TR' && table !== -1;
|
|
328
|
+
return inRow && this.rowCount(table) <= 1 ? undefined : 'columnheader';
|
|
329
|
+
}
|
|
330
|
+
if (previous !== undefined && next !== undefined && this.nameAt(previous) === 'TH' && this.nameAt(next) === 'TH')
|
|
331
|
+
return 'columnheader';
|
|
332
|
+
const isData = (cell) => cell !== undefined && this.nameAt(cell) === 'TD' && (withText.has(cell) || this.childrenOf(cell).length > 0);
|
|
333
|
+
return isData(previous) || isData(next) ? 'rowheader' : 'columnheader';
|
|
334
|
+
}
|
|
335
|
+
/** A node's element children, in order. */
|
|
336
|
+
childrenOf(index) {
|
|
337
|
+
if (this.elementChildren === undefined) {
|
|
338
|
+
const children = new Map();
|
|
339
|
+
this.parents.forEach((parent, at) => {
|
|
340
|
+
if (this.types[at] !== undefined && this.types[at] !== ELEMENT_NODE)
|
|
341
|
+
return;
|
|
342
|
+
const list = children.get(parent);
|
|
343
|
+
if (list === undefined)
|
|
344
|
+
children.set(parent, [at]);
|
|
345
|
+
else
|
|
346
|
+
list.push(at);
|
|
347
|
+
});
|
|
348
|
+
this.elementChildren = children;
|
|
349
|
+
}
|
|
350
|
+
return this.elementChildren.get(index) ?? [];
|
|
351
|
+
}
|
|
352
|
+
/** How many rows `HTMLTableElement.rows` lists: the table's own rows and those of its row groups. Counted once per table. */
|
|
353
|
+
rowCount(table) {
|
|
354
|
+
const known = this.rowCounts.get(table);
|
|
355
|
+
if (known !== undefined)
|
|
356
|
+
return known;
|
|
357
|
+
let count = 0;
|
|
358
|
+
for (const child of this.childrenOf(table)) {
|
|
359
|
+
const name = this.nameAt(child);
|
|
360
|
+
if (name === 'TR')
|
|
361
|
+
count += 1;
|
|
362
|
+
else if (name === 'THEAD' || name === 'TBODY' || name === 'TFOOT')
|
|
363
|
+
count += this.childrenOf(child).filter((row) => this.nameAt(row) === 'TR').length;
|
|
364
|
+
}
|
|
365
|
+
this.rowCounts.set(table, count);
|
|
366
|
+
return count;
|
|
367
|
+
}
|
|
368
|
+
/** See `DomFacts.ariaDisabled`. */
|
|
369
|
+
ariaDisabled(index) {
|
|
370
|
+
for (let at = index; at >= 0; at = this.parents[at] ?? -1) {
|
|
371
|
+
const aria = this.attributesAt(at)['aria-disabled'];
|
|
372
|
+
if (aria !== undefined)
|
|
373
|
+
return aria.toLowerCase() === 'true';
|
|
374
|
+
}
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
/** See `DomFacts.inheritsDisabled`. */
|
|
378
|
+
inheritsDisabled(index) {
|
|
379
|
+
if (this.nameAt(index) === 'OPTION') {
|
|
380
|
+
const group = this.parents[index] ?? -1;
|
|
381
|
+
return group >= 0 && this.nameAt(group) === 'OPTGROUP' && 'disabled' in this.attributesAt(group);
|
|
382
|
+
}
|
|
383
|
+
// A fieldset disables the form controls in it, in its own tree only: not one in a shadow tree whose host it holds. An
|
|
384
|
+
// optgroup is no form control. A control in a shadow tree keeps its own attribute's answer: the snapshot marks nested
|
|
385
|
+
// shadow trees alike, so a fieldset in a component's shadow tree would pass for one in the tree of a control slotted
|
|
386
|
+
// into it from an outer one, which it does not disable.
|
|
387
|
+
if (this.nameAt(index) === 'OPTGROUP' || this.scopeOf(index) !== -1)
|
|
388
|
+
return false;
|
|
389
|
+
// `child` is the ancestor before `at` in the control's tree: a fieldset's child, when `at` is a fieldset.
|
|
390
|
+
let child = index;
|
|
391
|
+
for (const at of this.ancestorsInTree(index)) {
|
|
392
|
+
const disabled = this.nameAt(at) === 'FIELDSET' && 'disabled' in this.attributesAt(at);
|
|
393
|
+
if (disabled && this.nameAt(child) !== 'LEGEND')
|
|
394
|
+
return true;
|
|
395
|
+
if (disabled) {
|
|
396
|
+
// Children follow their parent in the snapshot, in order: the first LEGEND whose parent is the fieldset is its first legend.
|
|
397
|
+
let first = at + 1;
|
|
398
|
+
while (first < this.parents.length && !(this.parents[first] === at && this.nameAt(first) === 'LEGEND'))
|
|
399
|
+
first += 1;
|
|
400
|
+
if (first !== child)
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
child = at;
|
|
404
|
+
}
|
|
405
|
+
return false;
|
|
406
|
+
}
|
|
217
407
|
/** The node indices whose text content holds anything but white space: every ancestor of such a text node. */
|
|
218
408
|
nodesWithText() {
|
|
219
409
|
const marked = new Set();
|
|
@@ -226,18 +416,16 @@ export class DomSnapshot {
|
|
|
226
416
|
return marked;
|
|
227
417
|
}
|
|
228
418
|
/**
|
|
229
|
-
* Each
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
* under it, with ASCII white space collapsed and no other: a no-break
|
|
419
|
+
* Each option's value, by node index: its `value` attribute or else its
|
|
420
|
+
* text, as `HTMLOptionElement.value` reads it. An option's text is all the
|
|
421
|
+
* text under it, with ASCII white space collapsed and no other: a no-break
|
|
233
422
|
* space stays one.
|
|
234
423
|
*/
|
|
235
|
-
|
|
236
|
-
const values = new Map();
|
|
237
|
-
if (selected.length === 0)
|
|
238
|
-
return values;
|
|
424
|
+
optionValues() {
|
|
239
425
|
const texts = new Map();
|
|
240
|
-
this.
|
|
426
|
+
this.names.forEach((_, index) => {
|
|
427
|
+
if (this.nameAt(index) === 'OPTION')
|
|
428
|
+
texts.set(index, texts.get(index) ?? '');
|
|
241
429
|
const text = this.sourceText(index);
|
|
242
430
|
if (text === undefined)
|
|
243
431
|
return;
|
|
@@ -247,13 +435,21 @@ export class DomSnapshot {
|
|
|
247
435
|
if (option >= 0)
|
|
248
436
|
texts.set(option, (texts.get(option) ?? '') + text);
|
|
249
437
|
});
|
|
438
|
+
const values = new Map();
|
|
439
|
+
for (const [option, text] of texts)
|
|
440
|
+
values.set(option, this.attributesAt(option)['value'] ?? text.replace(/[\t\n\f\r ]+/g, ' ').replace(/^ | $/g, ''));
|
|
441
|
+
return values;
|
|
442
|
+
}
|
|
443
|
+
/** Each select's value, by node index: what its first selected option submits, as `HTMLSelectElement.value` reads it. */
|
|
444
|
+
selectValues(selected, optionValues) {
|
|
445
|
+
const values = new Map();
|
|
250
446
|
for (const option of selected.toSorted((a, b) => a - b)) {
|
|
251
447
|
let select = this.parents[option] ?? -1;
|
|
252
448
|
while (select >= 0 && this.nameAt(select) !== 'SELECT')
|
|
253
449
|
select = this.parents[select] ?? -1;
|
|
254
450
|
if (select < 0 || values.has(select))
|
|
255
451
|
continue;
|
|
256
|
-
values.set(select,
|
|
452
|
+
values.set(select, optionValues.get(option) ?? '');
|
|
257
453
|
}
|
|
258
454
|
return values;
|
|
259
455
|
}
|
package/dist/surface.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
import { copyFileSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';
|
|
14
14
|
import { tmpdir } from 'node:os';
|
|
15
15
|
import path from 'node:path';
|
|
16
|
-
import { ConfigurationError, Deadline, EngineError, pollCondition, sleep, TestError, validateComputedStyleProperties } from '@e2e-dev/core/engine';
|
|
16
|
+
import { ConfigurationError, Deadline, EngineError, pollCondition, raceAbort, sleep, TestError, validateComputedStyleProperties, withTimeout } from '@e2e-dev/core/engine';
|
|
17
17
|
import { performAtPoint, performOnNode, pressKey, swipeWindow, typeText } from './actions.js';
|
|
18
18
|
import { AppProcess, DISCARD_CLOSE_MS, RESTART_CLOSE_MS } from './app-process.js';
|
|
19
19
|
import { answerWithin, Budget, withBudget } from './budget.js';
|
|
@@ -102,16 +102,22 @@ export class ElectronSurface {
|
|
|
102
102
|
this.recorder = undefined;
|
|
103
103
|
await uncollected?.abandon().catch(() => undefined);
|
|
104
104
|
await this.app.serialized(() => this.app.quit(context, DISCARD_CLOSE_MS));
|
|
105
|
-
|
|
106
|
-
if (this.userDataDir !== undefined)
|
|
107
|
-
rmSync(this.userDataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
105
|
+
const { userDataDir, uploadsDir } = this;
|
|
108
106
|
this.userDataDir = undefined;
|
|
109
|
-
if (this.uploadsDir !== undefined)
|
|
110
|
-
rmSync(this.uploadsDir, { recursive: true, force: true });
|
|
111
107
|
this.uploadsDir = undefined;
|
|
112
108
|
this.attempt = undefined;
|
|
113
109
|
// settleAttempt reported what the attempt's dialogs left; its handlers go with it.
|
|
114
110
|
this.dialogs.reset();
|
|
111
|
+
try {
|
|
112
|
+
// Retried: Chromium's helper processes can still be closing their files in it.
|
|
113
|
+
if (userDataDir !== undefined)
|
|
114
|
+
rmSync(userDataDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
115
|
+
}
|
|
116
|
+
finally {
|
|
117
|
+
// Removed even when the user-data directory could not be, so the next attempt never finds this one's files.
|
|
118
|
+
if (uploadsDir !== undefined)
|
|
119
|
+
rmSync(uploadsDir, { recursive: true, force: true });
|
|
120
|
+
}
|
|
115
121
|
}
|
|
116
122
|
/** A dialog the test's last step opened has no next step to fail: the attempt fails with it, as a step would. */
|
|
117
123
|
async settleAttempt(context) {
|
|
@@ -414,8 +420,14 @@ export class ElectronSurface {
|
|
|
414
420
|
/** `window.activate()`: reads and acts in the window from now on. */
|
|
415
421
|
async activateWindow(window, operation) {
|
|
416
422
|
this.failOnDialog();
|
|
417
|
-
|
|
418
|
-
|
|
423
|
+
await withBudget(operation, 'activate window', async (budget) => {
|
|
424
|
+
// A call cancelled meanwhile (a waitForWindow whose trigger outlasted the step) shows no other window, one cancelled
|
|
425
|
+
// while the window is raised included: the window `screen` reads changes last.
|
|
426
|
+
budget.check();
|
|
427
|
+
await window.page.bringToFront().catch(() => undefined);
|
|
428
|
+
budget.check();
|
|
429
|
+
this.windowList.activate(window);
|
|
430
|
+
});
|
|
419
431
|
}
|
|
420
432
|
/** `window.close()`: any window, the app's last one too. */
|
|
421
433
|
async closeWindow(window, operation) {
|
|
@@ -462,19 +474,22 @@ export class ElectronSurface {
|
|
|
462
474
|
if (!this.app.running)
|
|
463
475
|
throw this.app.notRunning();
|
|
464
476
|
const before = new Set(this.windowList.open());
|
|
465
|
-
const
|
|
466
|
-
await trigger
|
|
467
|
-
const
|
|
477
|
+
const deadline = new Deadline(operation.timeoutMs);
|
|
478
|
+
const triggerMs = await runTrigger(trigger, deadline, 'electron.waitForWindow', operation);
|
|
479
|
+
const timedOut = () => new TestError('ACTION_FAILED', `no window opened within ${operation.timeoutMs}ms; the trigger resolved after ${triggerMs}ms`);
|
|
480
|
+
// The wait includes the trigger's own time: a window it opened after that ran out is not taken.
|
|
481
|
+
if (deadline.expired())
|
|
482
|
+
throw timedOut();
|
|
468
483
|
let opened;
|
|
469
484
|
await pollCondition({
|
|
470
|
-
deadline
|
|
485
|
+
deadline,
|
|
471
486
|
signal: operation.signal,
|
|
472
487
|
negated: false,
|
|
473
488
|
evaluate: () => {
|
|
474
489
|
opened = this.windowList.open().find((window) => !before.has(window));
|
|
475
490
|
return Promise.resolve(opened !== undefined);
|
|
476
491
|
},
|
|
477
|
-
onTimeout:
|
|
492
|
+
onTimeout: timedOut,
|
|
478
493
|
});
|
|
479
494
|
if (opened === undefined)
|
|
480
495
|
throw invalidState('the window was lost');
|
|
@@ -594,22 +609,42 @@ export class ElectronSurface {
|
|
|
594
609
|
if (attempt === undefined)
|
|
595
610
|
throw invalidState('a download is waited for inside a test');
|
|
596
611
|
this.failOnDialog();
|
|
597
|
-
const
|
|
598
|
-
|
|
612
|
+
const deadline = new Deadline(operation.timeoutMs);
|
|
613
|
+
const unanswered = () => new TestError('ACTION_FAILED', `no download finished within ${operation.timeoutMs}ms: the app's main process did not answer`);
|
|
614
|
+
// Read in the main process, which a busy app keeps from answering: each read ends with the wait. Its timeout is an
|
|
615
|
+
// operation timeout, which the poll takes for a read the deadline cut off when it started with under a tick left.
|
|
616
|
+
const readTimedOut = () => new EngineError('OPERATION_TIMEOUT', 'electron.waitForDownload: the app\'s main process did not answer', { retryable: false });
|
|
617
|
+
// A step cancelled while the app was asked ends then, as cancelled.
|
|
618
|
+
const downloads = () => raceAbort(() => withTimeout(this.app.downloads(), Math.max(1, deadline.remaining()), readTimedOut), operation.signal, 'electron.waitForDownload');
|
|
619
|
+
// Any other read that timed out had time to answer in: the main process did not.
|
|
620
|
+
const blocked = (cause) => (cause instanceof EngineError && cause.code === 'OPERATION_TIMEOUT' ? unanswered() : cause);
|
|
621
|
+
const before = (await downloads().catch((cause) => Promise.reject(blocked(cause)))).length;
|
|
622
|
+
// A trigger never runs once the wait is out of time, or its step was cancelled while the app was asked.
|
|
623
|
+
// Worded as raceAbort words the same cancel.
|
|
624
|
+
if (operation.signal.aborted)
|
|
625
|
+
throw new EngineError('CANCELLED', 'electron.waitForDownload cancelled', { retryable: false });
|
|
626
|
+
if (deadline.expired())
|
|
627
|
+
throw unanswered();
|
|
628
|
+
const triggerMs = await runTrigger(trigger, deadline, 'electron.waitForDownload', operation);
|
|
629
|
+
const timedOut = () => new TestError('ACTION_FAILED', `no download finished within ${operation.timeoutMs}ms; the trigger resolved after ${triggerMs}ms`);
|
|
630
|
+
// The wait includes the trigger's own time, as the window wait's does.
|
|
631
|
+
if (deadline.expired())
|
|
632
|
+
throw timedOut();
|
|
599
633
|
let finished;
|
|
634
|
+
// The last read starts at the deadline with almost no time: the poll ends that one with the ordinary timeout.
|
|
600
635
|
await pollCondition({
|
|
601
|
-
deadline
|
|
636
|
+
deadline,
|
|
602
637
|
signal: operation.signal,
|
|
603
638
|
negated: false,
|
|
604
639
|
evaluate: async () => {
|
|
605
|
-
const next = (await
|
|
640
|
+
const next = (await downloads())[before];
|
|
606
641
|
if (next === undefined || next.state === 'progressing')
|
|
607
642
|
return false;
|
|
608
643
|
finished = next;
|
|
609
644
|
return true;
|
|
610
645
|
},
|
|
611
|
-
onTimeout:
|
|
612
|
-
});
|
|
646
|
+
onTimeout: timedOut,
|
|
647
|
+
}).catch((cause) => Promise.reject(blocked(cause)));
|
|
613
648
|
if (finished === undefined)
|
|
614
649
|
throw invalidState('the download was lost');
|
|
615
650
|
if (finished.state !== 'completed')
|
|
@@ -654,3 +689,20 @@ export class ElectronSurface {
|
|
|
654
689
|
return (await recorder?.stop()) ?? [];
|
|
655
690
|
}
|
|
656
691
|
}
|
|
692
|
+
/**
|
|
693
|
+
* Runs a wait's trigger, test code, within the wait's deadline, and returns
|
|
694
|
+
* how long it took. A trigger still running at the deadline fails the wait
|
|
695
|
+
* and is left to finish on its own; its error, before then, is its own.
|
|
696
|
+
*/
|
|
697
|
+
async function runTrigger(trigger, deadline, api, operation) {
|
|
698
|
+
const started = Date.now();
|
|
699
|
+
// A step cancelled before its trigger runs never runs it; one cancelled while it runs ends then, as cancelled, not at
|
|
700
|
+
// its timeout.
|
|
701
|
+
await raceAbort(() => {
|
|
702
|
+
// Test code: a trigger written in JavaScript, or one that does not return its promise, returns none.
|
|
703
|
+
const running = (async () => await trigger())();
|
|
704
|
+
running.catch(() => undefined);
|
|
705
|
+
return withTimeout(running, Math.max(1, deadline.remaining()), () => new TestError('ACTION_FAILED', `${api} exceeded its timeout of ${operation.timeoutMs}ms while its trigger ran`));
|
|
706
|
+
}, operation.signal, api);
|
|
707
|
+
return Date.now() - started;
|
|
708
|
+
}
|
package/dist/video.d.ts
CHANGED
|
@@ -31,6 +31,19 @@ export declare class Recorder {
|
|
|
31
31
|
* ever shown.
|
|
32
32
|
*/
|
|
33
33
|
stop(): Promise<readonly VideoFile[]>;
|
|
34
|
+
/**
|
|
35
|
+
* Waits for the window switch in progress, for at most `SWITCH_WAIT_MS`: a
|
|
36
|
+
* window that does not answer the switch's DevTools calls holds it up for
|
|
37
|
+
* good. A switch that answers later backs out (`stopped`).
|
|
38
|
+
*/
|
|
39
|
+
private settleSwitching;
|
|
40
|
+
/**
|
|
41
|
+
* Runs the end of a recording with the encoder killed once it has had
|
|
42
|
+
* `CLOSE_TIMEOUT_MS`: an ffmpeg that stops reading holds a frame's write,
|
|
43
|
+
* and the window switch and the last snapshot that wait on it, before its
|
|
44
|
+
* own close would start a timer.
|
|
45
|
+
*/
|
|
46
|
+
private withinCloseTime;
|
|
34
47
|
/**
|
|
35
48
|
* Adds the shown window as it stands to the video. A screencast sends a
|
|
36
49
|
* frame only when the window repaints, so a still window is captured here:
|