compile with typescript
This commit is contained in:
parent
7530007466
commit
3cb4d27550
|
|
@ -59,8 +59,8 @@ export interface AXNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Accessibility {
|
export class Accessibility {
|
||||||
private _getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle?: AXNode}>;
|
private _getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle: AXNode | null}>;
|
||||||
constructor(getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle?: AXNode}>) {
|
constructor(getAXTree: (needle?: dom.ElementHandle) => Promise<{tree: AXNode, needle: AXNode | null}>) {
|
||||||
this._getAXTree = getAXTree;
|
this._getAXTree = getAXTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +81,7 @@ export class Accessibility {
|
||||||
|
|
||||||
const interestingNodes: Set<AXNode> = new Set();
|
const interestingNodes: Set<AXNode> = new Set();
|
||||||
collectInterestingNodes(interestingNodes, tree, false);
|
collectInterestingNodes(interestingNodes, tree, false);
|
||||||
if (root && !interestingNodes.has(needle))
|
if (root && (!needle || !interestingNodes.has(needle)))
|
||||||
return null;
|
return null;
|
||||||
return serializeTree(needle || tree, interestingNodes)[0];
|
return serializeTree(needle || tree, interestingNodes)[0];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,12 +20,12 @@ import { Protocol } from './protocol';
|
||||||
import * as dom from '../dom';
|
import * as dom from '../dom';
|
||||||
import * as accessibility from '../accessibility';
|
import * as accessibility from '../accessibility';
|
||||||
|
|
||||||
export async function getAccessibilityTree(client: CRSession, needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle?: accessibility.AXNode}> {
|
export async function getAccessibilityTree(client: CRSession, needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
|
||||||
const {nodes} = await client.send('Accessibility.getFullAXTree');
|
const {nodes} = await client.send('Accessibility.getFullAXTree');
|
||||||
const tree = CRAXNode.createTree(client, nodes);
|
const tree = CRAXNode.createTree(client, nodes);
|
||||||
return {
|
return {
|
||||||
tree,
|
tree,
|
||||||
needle: needle && await tree._findElement(needle)
|
needle: needle ? await tree._findElement(needle) : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,13 +20,13 @@ import { FFSession } from './ffConnection';
|
||||||
import { Protocol } from './protocol';
|
import { Protocol } from './protocol';
|
||||||
import * as dom from '../dom';
|
import * as dom from '../dom';
|
||||||
|
|
||||||
export async function getAccessibilityTree(session: FFSession, needle: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle?: accessibility.AXNode}> {
|
export async function getAccessibilityTree(session: FFSession, needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
|
||||||
const objectId = needle ? needle._remoteObject.objectId : undefined;
|
const objectId = needle ? needle._remoteObject.objectId : undefined;
|
||||||
const { tree } = await session.send('Accessibility.getFullAXTree', { objectId });
|
const { tree } = await session.send('Accessibility.getFullAXTree', { objectId });
|
||||||
const axNode = new FFAXNode(tree);
|
const axNode = new FFAXNode(tree);
|
||||||
return {
|
return {
|
||||||
tree: axNode,
|
tree: axNode,
|
||||||
needle: needle && axNode._findNeedle()
|
needle: needle ? axNode._findNeedle() : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ const FFRoleToARIARole = new Map(Object.entries({
|
||||||
|
|
||||||
class FFAXNode implements accessibility.AXNode {
|
class FFAXNode implements accessibility.AXNode {
|
||||||
_children: FFAXNode[];
|
_children: FFAXNode[];
|
||||||
private _payload: Protocol.AXTree;
|
private _payload: Protocol.Accessibility.AXTree;
|
||||||
private _editable: boolean;
|
private _editable: boolean;
|
||||||
private _richlyEditable: boolean;
|
private _richlyEditable: boolean;
|
||||||
private _focusable: boolean;
|
private _focusable: boolean;
|
||||||
|
|
@ -203,7 +203,7 @@ class FFAXNode implements accessibility.AXNode {
|
||||||
role: FFRoleToARIARole.get(this._role) || this._role,
|
role: FFRoleToARIARole.get(this._role) || this._role,
|
||||||
name: this._name || ''
|
name: this._name || ''
|
||||||
};
|
};
|
||||||
const userStringProperties: Array<keyof accessibility.SerializedAXNode> = [
|
const userStringProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Accessibility.AXTree> = [
|
||||||
'name',
|
'name',
|
||||||
'value',
|
'value',
|
||||||
'description',
|
'description',
|
||||||
|
|
@ -216,7 +216,7 @@ class FFAXNode implements accessibility.AXNode {
|
||||||
continue;
|
continue;
|
||||||
node[userStringProperty] = this._payload[userStringProperty];
|
node[userStringProperty] = this._payload[userStringProperty];
|
||||||
}
|
}
|
||||||
const booleanProperties: Array<keyof accessibility.SerializedAXNode> = [
|
const booleanProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Accessibility.AXTree> = [
|
||||||
'disabled',
|
'disabled',
|
||||||
'expanded',
|
'expanded',
|
||||||
'focused',
|
'focused',
|
||||||
|
|
@ -235,7 +235,7 @@ class FFAXNode implements accessibility.AXNode {
|
||||||
continue;
|
continue;
|
||||||
node[booleanProperty] = value;
|
node[booleanProperty] = value;
|
||||||
}
|
}
|
||||||
const tristateProperties: Array<keyof accessibility.SerializedAXNode> = [
|
const tristateProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Accessibility.AXTree> = [
|
||||||
'checked',
|
'checked',
|
||||||
'pressed',
|
'pressed',
|
||||||
];
|
];
|
||||||
|
|
@ -245,7 +245,7 @@ class FFAXNode implements accessibility.AXNode {
|
||||||
const value = this._payload[tristateProperty];
|
const value = this._payload[tristateProperty];
|
||||||
node[tristateProperty] = value;
|
node[tristateProperty] = value;
|
||||||
}
|
}
|
||||||
const numericalProperties: Array<keyof accessibility.SerializedAXNode> = [
|
const numericalProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Accessibility.AXTree> = [
|
||||||
'level'
|
'level'
|
||||||
];
|
];
|
||||||
for (const numericalProperty of numericalProperties) {
|
for (const numericalProperty of numericalProperties) {
|
||||||
|
|
@ -253,7 +253,7 @@ class FFAXNode implements accessibility.AXNode {
|
||||||
continue;
|
continue;
|
||||||
node[numericalProperty] = this._payload[numericalProperty];
|
node[numericalProperty] = this._payload[numericalProperty];
|
||||||
}
|
}
|
||||||
const tokenProperties: Array<keyof accessibility.SerializedAXNode> = [
|
const tokenProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Accessibility.AXTree> = [
|
||||||
'autocomplete',
|
'autocomplete',
|
||||||
'haspopup',
|
'haspopup',
|
||||||
'invalid',
|
'invalid',
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ export interface PageDelegate {
|
||||||
setInputFiles(handle: dom.ElementHandle<HTMLInputElement>, files: types.FilePayload[]): Promise<void>;
|
setInputFiles(handle: dom.ElementHandle<HTMLInputElement>, files: types.FilePayload[]): Promise<void>;
|
||||||
getBoundingBox(handle: dom.ElementHandle): Promise<types.Rect | null>;
|
getBoundingBox(handle: dom.ElementHandle): Promise<types.Rect | null>;
|
||||||
|
|
||||||
getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle?: accessibility.AXNode}>;
|
getAccessibilityTree(needle?: dom.ElementHandle): Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}>;
|
||||||
pdf?: (options?: types.PDFOptions) => Promise<platform.BufferType>;
|
pdf?: (options?: types.PDFOptions) => Promise<platform.BufferType>;
|
||||||
coverage(): Coverage | undefined;
|
coverage(): Coverage | undefined;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ export async function getAccessibilityTree(session: WKSession, needle?: dom.Elem
|
||||||
const tree = new WKAXNode(axNode);
|
const tree = new WKAXNode(axNode);
|
||||||
return {
|
return {
|
||||||
tree,
|
tree,
|
||||||
needle: needle && tree._findNeedle()
|
needle: needle ? tree._findNeedle() : null
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -184,22 +184,17 @@ class WKAXNode implements accessibility.AXNode {
|
||||||
if ('value' in this._payload && this._payload.role !== 'text')
|
if ('value' in this._payload && this._payload.role !== 'text')
|
||||||
node.value = this._payload.value;
|
node.value = this._payload.value;
|
||||||
|
|
||||||
type AXPropertyOfType<Type> = {
|
const userStringProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Page.AXNode> = [
|
||||||
[Key in keyof Protocol.Page.AXNode]:
|
|
||||||
Protocol.Page.AXNode[Key] extends Type ? Key : never
|
|
||||||
}[keyof Protocol.Page.AXNode];
|
|
||||||
|
|
||||||
const userStringProperties: string[] = [
|
|
||||||
'keyshortcuts',
|
'keyshortcuts',
|
||||||
'valuetext'
|
'valuetext'
|
||||||
];
|
];
|
||||||
for (const userStringProperty of userStringProperties) {
|
for (const userStringProperty of userStringProperties) {
|
||||||
if (!(userStringProperty in this._payload))
|
if (!(userStringProperty in this._payload))
|
||||||
continue;
|
continue;
|
||||||
(node as any)[userStringProperty] = (this._payload as any)[userStringProperty];
|
(node as any)[userStringProperty] = this._payload[userStringProperty];
|
||||||
}
|
}
|
||||||
|
|
||||||
const booleanProperties: string[] = [
|
const booleanProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Page.AXNode> = [
|
||||||
'disabled',
|
'disabled',
|
||||||
'expanded',
|
'expanded',
|
||||||
'focused',
|
'focused',
|
||||||
|
|
@ -215,7 +210,7 @@ class WKAXNode implements accessibility.AXNode {
|
||||||
// not whether focus is specifically on the root node.
|
// not whether focus is specifically on the root node.
|
||||||
if (booleanProperty === 'focused' && (this._payload.role === 'WebArea' || this._payload.role === 'ScrollArea'))
|
if (booleanProperty === 'focused' && (this._payload.role === 'WebArea' || this._payload.role === 'ScrollArea'))
|
||||||
continue;
|
continue;
|
||||||
const value = (this._payload as any)[booleanProperty];
|
const value = this._payload[booleanProperty];
|
||||||
if (!value)
|
if (!value)
|
||||||
continue;
|
continue;
|
||||||
(node as any)[booleanProperty] = value;
|
(node as any)[booleanProperty] = value;
|
||||||
|
|
@ -231,7 +226,7 @@ class WKAXNode implements accessibility.AXNode {
|
||||||
const value = this._payload[tristateProperty];
|
const value = this._payload[tristateProperty];
|
||||||
node[tristateProperty] = value === 'mixed' ? 'mixed' : value === 'true' ? true : false;
|
node[tristateProperty] = value === 'mixed' ? 'mixed' : value === 'true' ? true : false;
|
||||||
}
|
}
|
||||||
const numericalProperties: string[] = [
|
const numericalProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Page.AXNode> = [
|
||||||
'level',
|
'level',
|
||||||
'valuemax',
|
'valuemax',
|
||||||
'valuemin',
|
'valuemin',
|
||||||
|
|
@ -241,7 +236,7 @@ class WKAXNode implements accessibility.AXNode {
|
||||||
continue;
|
continue;
|
||||||
(node as any)[numericalProperty] = (this._payload as any)[numericalProperty];
|
(node as any)[numericalProperty] = (this._payload as any)[numericalProperty];
|
||||||
}
|
}
|
||||||
const tokenProperties: string[] = [
|
const tokenProperties: Array<keyof accessibility.SerializedAXNode & keyof Protocol.Page.AXNode> = [
|
||||||
'autocomplete',
|
'autocomplete',
|
||||||
'haspopup',
|
'haspopup',
|
||||||
'invalid',
|
'invalid',
|
||||||
|
|
|
||||||
|
|
@ -497,7 +497,7 @@ export class WKPage implements PageDelegate {
|
||||||
return to._createHandle(result.object) as dom.ElementHandle<T>;
|
return to._createHandle(result.object) as dom.ElementHandle<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAccessibilityTree(needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle?: accessibility.AXNode}> {
|
async getAccessibilityTree(needle?: dom.ElementHandle) : Promise<{tree: accessibility.AXNode, needle: accessibility.AXNode | null}> {
|
||||||
return getAccessibilityTree(this._session, needle);
|
return getAccessibilityTree(this._session, needle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue