@e2e-dev/electron 0.0.0 → 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 +12 -4
- package/dist/.build.json +1 -1
- package/dist/app-process.d.ts +10 -1
- package/dist/app-process.js +89 -22
- package/dist/dialogs.d.ts +3 -1
- package/dist/dialogs.js +10 -3
- package/dist/electron.js +5 -1
- package/dist/engine-entry.d.ts +1 -1
- package/dist/errors.js +4 -3
- package/dist/executable.js +65 -14
- package/dist/expectation.d.ts +30 -0
- package/dist/expectation.js +167 -0
- package/dist/ffmpeg.js +2 -1
- package/dist/fields.js +80 -7
- package/dist/fixtures.d.ts +29 -3
- 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/options.js +4 -4
- package/dist/snapshot.d.ts +69 -4
- package/dist/snapshot.js +214 -18
- package/dist/surface.d.ts +13 -1
- package/dist/surface.js +125 -19
- package/dist/video.d.ts +13 -0
- package/dist/video.js +75 -22
- package/package.json +3 -3
package/dist/options.js
CHANGED
|
@@ -98,7 +98,7 @@ export function checkCwd(label, projectRoot, cwd, code) {
|
|
|
98
98
|
if (statSync(resolved, { throwIfNoEntry: false })?.isDirectory() !== true)
|
|
99
99
|
throw refusal(code, `${label} names ${resolved}, which is not a directory`);
|
|
100
100
|
}
|
|
101
|
-
const LAUNCH_KEYS = ['
|
|
101
|
+
const LAUNCH_KEYS = ['launchArguments', 'env', 'cwd', 'timeout'];
|
|
102
102
|
/** What `electron.launch()` was given, checked: the arguments, variables, and directory one test adds to its launches. */
|
|
103
103
|
export function checkLaunchOptions(options, projectRoot) {
|
|
104
104
|
const label = 'electron.launch()';
|
|
@@ -107,12 +107,12 @@ export function checkLaunchOptions(options, projectRoot) {
|
|
|
107
107
|
if (typeof options !== 'object' || options === null || Array.isArray(options))
|
|
108
108
|
throw refusal('INVALID_ARGUMENT', `${label} takes an object of options`);
|
|
109
109
|
rejectUnknownKeys(`${label} options`, options, LAUNCH_KEYS, 'INVALID_ARGUMENT');
|
|
110
|
-
const { args = [], env, cwd } = options;
|
|
110
|
+
const { launchArguments: args = [], env, cwd } = options;
|
|
111
111
|
if (!Array.isArray(args) || args.some((argument) => typeof argument !== 'string'))
|
|
112
|
-
throw refusal('INVALID_ARGUMENT', 'electron.launch({
|
|
112
|
+
throw refusal('INVALID_ARGUMENT', 'electron.launch({ launchArguments }) must be a list of strings');
|
|
113
113
|
const owned = args.map(ownedArgument).find((reason) => reason !== undefined);
|
|
114
114
|
if (owned !== undefined)
|
|
115
|
-
throw refusal('INVALID_ARGUMENT', `electron.launch({
|
|
115
|
+
throw refusal('INVALID_ARGUMENT', `electron.launch({ launchArguments }) ${owned}`);
|
|
116
116
|
checkEnv('electron.launch({ env })', env, 'INVALID_ARGUMENT');
|
|
117
117
|
checkCwdShape('electron.launch({ cwd })', cwd, 'INVALID_ARGUMENT');
|
|
118
118
|
checkCwd('electron.launch({ cwd })', projectRoot, cwd, 'INVALID_ARGUMENT');
|
package/dist/snapshot.d.ts
CHANGED
|
@@ -43,6 +43,12 @@ export interface SnapshotDocument {
|
|
|
43
43
|
export declare const SNAPSHOT_STYLES: readonly string[];
|
|
44
44
|
/** Elements a screenshot paints over besides a secure field's value: the nested documents the engine does not read. */
|
|
45
45
|
export declare const MASKED_TAGS: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* An element's explicit role: the first token of its `role` that names a
|
|
48
|
+
* concrete WAI-ARIA role, as the web engine's `explicitRole` reads it (case
|
|
49
|
+
* as written), so `role="x-foo button"` is a button.
|
|
50
|
+
*/
|
|
51
|
+
export declare function explicitRoleOf(attributes: Readonly<Record<string, string>>): string | undefined;
|
|
46
52
|
/** One element's facts from the snapshot. */
|
|
47
53
|
export interface DomFacts {
|
|
48
54
|
/** The node's position in the snapshot, its document order. */
|
|
@@ -55,14 +61,36 @@ export interface DomFacts {
|
|
|
55
61
|
readonly textValue?: string;
|
|
56
62
|
/** Whether the node's text content holds anything but white space, as `textContent` reads it. */
|
|
57
63
|
readonly hasText: boolean;
|
|
64
|
+
/** An editing host's (`contenteditable`) text content, white space as written. */
|
|
65
|
+
readonly editorText?: string;
|
|
58
66
|
/** A select's value: what its first selected option submits. */
|
|
59
67
|
readonly selectValue?: string;
|
|
68
|
+
/** An option's value: its value attribute, else its text. */
|
|
69
|
+
readonly optionValue?: string;
|
|
70
|
+
/** An option that is selected now. */
|
|
71
|
+
readonly selected: boolean;
|
|
60
72
|
/** A checkbox or radio that is checked now, whatever its `checked` attribute says. */
|
|
61
73
|
readonly checked: boolean;
|
|
62
74
|
/** Device-pixel document bounds; none for a node with no layout box. */
|
|
63
75
|
readonly bounds?: readonly number[];
|
|
64
76
|
/** Its computed `visibility` is `hidden` or `collapse`. */
|
|
65
77
|
readonly invisible: boolean;
|
|
78
|
+
/** The nearest aria-disabled, its own included, says true: a nearer "false" enables it again. */
|
|
79
|
+
readonly ariaDisabled: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* A native control disabled by what holds it: for an option, a disabled
|
|
82
|
+
* optgroup; for another control in the document's tree, a disabled fieldset
|
|
83
|
+
* there holding it outside its first legend.
|
|
84
|
+
*/
|
|
85
|
+
readonly inheritsDisabled: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* A `td`'s or `th`'s role from its table, as the web engine's `tagRole`
|
|
88
|
+
* reads it: `gridcell` in a grid's or treegrid's table, else `cell`;
|
|
89
|
+
* `rowheader` or `columnheader`, or none for a lone header in a table of
|
|
90
|
+
* one row. Absent on any other element. Worked out only when asked: only
|
|
91
|
+
* an element the accessibility tree leaves out needs it.
|
|
92
|
+
*/
|
|
93
|
+
readonly cellRole?: () => string | undefined;
|
|
66
94
|
}
|
|
67
95
|
/** A password input: it reports no value and no text, and a screenshot paints it over. */
|
|
68
96
|
export declare function isSecureField(nodeName: string, attributes: Readonly<Record<string, string>>): boolean;
|
|
@@ -87,6 +115,18 @@ export declare class DomSnapshot {
|
|
|
87
115
|
private readonly blanks;
|
|
88
116
|
/** Per node, its nearest table cell, or -1. */
|
|
89
117
|
private readonly cells;
|
|
118
|
+
/**
|
|
119
|
+
* The nodes inside a shadow tree. The snapshot has no node for a shadow
|
|
120
|
+
* root: every node in one carries its type, and the root's children have
|
|
121
|
+
* the host as their parent.
|
|
122
|
+
*/
|
|
123
|
+
private readonly inShadowTree;
|
|
124
|
+
/** The nodes whose computed `visibility` is `hidden` or `collapse`. */
|
|
125
|
+
private readonly invisible;
|
|
126
|
+
/** Per element, its element children in order; built on the first table cell's read. */
|
|
127
|
+
private elementChildren;
|
|
128
|
+
/** Per table, how many rows it lists; filled as lone headers ask. */
|
|
129
|
+
private readonly rowCounts;
|
|
90
130
|
constructor(document: SnapshotDocument, strings: readonly string[]);
|
|
91
131
|
/** The element with this backend DOM node id, if the snapshot holds it. */
|
|
92
132
|
element(backendNodeId: number): DomFacts | undefined;
|
|
@@ -115,6 +155,20 @@ export declare class DomSnapshot {
|
|
|
115
155
|
* screen as the label, as the web reads it.
|
|
116
156
|
*/
|
|
117
157
|
drawnByLabel(index: number): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* The node's ancestors in its own tree, nearest first: the snapshot follows
|
|
160
|
+
* the tree as drawn, where a slotted node's parent is its slot, so the
|
|
161
|
+
* nodes of a shadow tree it is slotted through are passed over to reach its
|
|
162
|
+
* host and the host's own ancestors. A node in a shadow tree stops at its
|
|
163
|
+
* host.
|
|
164
|
+
*/
|
|
165
|
+
private ancestorsInTree;
|
|
166
|
+
/**
|
|
167
|
+
* The tree a node is in: the host of the shadow tree it is in, or -1 for
|
|
168
|
+
* the document's own. A shadow tree inside another one's is taken as the
|
|
169
|
+
* outer one: the snapshot marks the nodes of both alike.
|
|
170
|
+
*/
|
|
171
|
+
private scopeOf;
|
|
118
172
|
/**
|
|
119
173
|
* How many rendered elements a screenshot must paint over and a selector
|
|
120
174
|
* cannot reach: password inputs and nested documents inside a closed shadow
|
|
@@ -129,15 +183,26 @@ export declare class DomSnapshot {
|
|
|
129
183
|
private attributesAt;
|
|
130
184
|
private rare;
|
|
131
185
|
private indexFacts;
|
|
186
|
+
/** See `DomFacts.cellRole`; undefined for a header with no role. `withText` holds the nodes whose text is not blank. */
|
|
187
|
+
private cellRoleOf;
|
|
188
|
+
/** A node's element children, in order. */
|
|
189
|
+
private childrenOf;
|
|
190
|
+
/** How many rows `HTMLTableElement.rows` lists: the table's own rows and those of its row groups. Counted once per table. */
|
|
191
|
+
private rowCount;
|
|
192
|
+
/** See `DomFacts.ariaDisabled`. */
|
|
193
|
+
private ariaDisabled;
|
|
194
|
+
/** See `DomFacts.inheritsDisabled`. */
|
|
195
|
+
private inheritsDisabled;
|
|
132
196
|
/** The node indices whose text content holds anything but white space: every ancestor of such a text node. */
|
|
133
197
|
private nodesWithText;
|
|
134
198
|
/**
|
|
135
|
-
* Each
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* under it, with ASCII white space collapsed and no other: a no-break
|
|
199
|
+
* Each option's value, by node index: its `value` attribute or else its
|
|
200
|
+
* text, as `HTMLOptionElement.value` reads it. An option's text is all the
|
|
201
|
+
* text under it, with ASCII white space collapsed and no other: a no-break
|
|
139
202
|
* space stays one.
|
|
140
203
|
*/
|
|
204
|
+
private optionValues;
|
|
205
|
+
/** Each select's value, by node index: what its first selected option submits, as `HTMLSelectElement.value` reads it. */
|
|
141
206
|
private selectValues;
|
|
142
207
|
}
|
|
143
208
|
export {};
|
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.d.ts
CHANGED
|
@@ -83,7 +83,7 @@ export declare class ElectronSurface {
|
|
|
83
83
|
/** Why the window is not one to observe, trace, or capture: it shows a local file outside the app's directory. */
|
|
84
84
|
private leftApp;
|
|
85
85
|
/** Fails the step that follows a dialog nothing answered, or whose handler failed. */
|
|
86
|
-
|
|
86
|
+
failOnDialog(): void;
|
|
87
87
|
private requireWindow;
|
|
88
88
|
/**
|
|
89
89
|
* Every action goes through here: its input within the operation's budget,
|
|
@@ -133,6 +133,18 @@ export declare class ElectronSurface {
|
|
|
133
133
|
* does not. Either is a title `electron.window({ title })` matches.
|
|
134
134
|
*/
|
|
135
135
|
windowTitle(window: AppWindow, operation: OperationContext): Promise<string>;
|
|
136
|
+
/**
|
|
137
|
+
* The title `expect(electron).toHaveTitle` polls: the document's, read
|
|
138
|
+
* within the operation so a read the deadline cuts off is a timeout and
|
|
139
|
+
* never another title, else the OS window's for a document with none. A
|
|
140
|
+
* window whose renderer crashed is waited on as `readShown` waits on it:
|
|
141
|
+
* briefly, for the app to load it again, and then said to have crashed.
|
|
142
|
+
*/
|
|
143
|
+
currentTitle(window: AppWindow, operation: OperationContext): Promise<string>;
|
|
144
|
+
/** Whether the shown window's renderer crashed: a wait on the window ends with that, where a closing window is waited through. */
|
|
145
|
+
get shownCrashed(): boolean;
|
|
146
|
+
/** Whether the app is running: a wait on its window goes on through a window closing or loading, and ends when the app is gone. */
|
|
147
|
+
get appRunning(): boolean;
|
|
136
148
|
/** `electron.onDialog()`: answers the app's dialogs from now on, until what it returns is called. */
|
|
137
149
|
onDialog(handler: DialogHandler): () => void;
|
|
138
150
|
/** Runs a function in the app's main process. */
|