2018-11-02 01:54:51 +00:00
|
|
|
/**
|
|
|
|
* Copyright 2018 Google Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-06-23 05:18:46 +00:00
|
|
|
import expect from 'expect';
|
|
|
|
import {
|
2020-05-07 10:54:55 +00:00
|
|
|
getTestState,
|
|
|
|
setupTestBrowserHooks,
|
|
|
|
setupTestPageAndContextHooks,
|
2020-06-23 05:18:46 +00:00
|
|
|
describeFailsFirefox,
|
2020-07-13 09:22:26 +00:00
|
|
|
} from './mocha-utils'; // eslint-disable-line import/extensions
|
2018-11-02 01:54:51 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
describeFailsFirefox('Accessibility', function () {
|
2020-04-09 05:56:25 +00:00
|
|
|
setupTestBrowserHooks();
|
|
|
|
setupTestPageAndContextHooks();
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should work', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
2018-11-02 01:54:51 +00:00
|
|
|
<head>
|
|
|
|
<title>Accessibility Test</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div>Hello World</div>
|
|
|
|
<h1>Inputs</h1>
|
|
|
|
<input placeholder="Empty input" autofocus />
|
|
|
|
<input placeholder="readonly input" readonly />
|
|
|
|
<input placeholder="disabled input" disabled />
|
|
|
|
<input aria-label="Input with whitespace" value=" " />
|
|
|
|
<input value="value only" />
|
|
|
|
<input aria-placeholder="placeholder" value="and a value" />
|
|
|
|
<div aria-hidden="true" id="desc">This is a description!</div>
|
|
|
|
<input aria-placeholder="placeholder" value="and a value" aria-describedby="desc" />
|
|
|
|
<select>
|
|
|
|
<option>First Option</option>
|
|
|
|
<option>Second Option</option>
|
|
|
|
</select>
|
|
|
|
</body>`);
|
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
await page.focus('[placeholder="Empty input"]');
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'document',
|
|
|
|
name: 'Accessibility Test',
|
|
|
|
children: [
|
|
|
|
{ role: 'text leaf', name: 'Hello World' },
|
|
|
|
{ role: 'heading', name: 'Inputs', level: 1 },
|
|
|
|
{ role: 'entry', name: 'Empty input', focused: true },
|
|
|
|
{ role: 'entry', name: 'readonly input', readonly: true },
|
|
|
|
{ role: 'entry', name: 'disabled input', disabled: true },
|
|
|
|
{ role: 'entry', name: 'Input with whitespace', value: ' ' },
|
|
|
|
{ role: 'entry', name: '', value: 'value only' },
|
|
|
|
{ role: 'entry', name: '', value: 'and a value' }, // firefox doesn't use aria-placeholder for the name
|
|
|
|
{
|
|
|
|
role: 'entry',
|
|
|
|
name: '',
|
|
|
|
value: 'and a value',
|
|
|
|
description: 'This is a description!',
|
|
|
|
}, // and here
|
|
|
|
{
|
|
|
|
role: 'combobox',
|
|
|
|
name: '',
|
|
|
|
value: 'First Option',
|
|
|
|
haspopup: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'combobox option',
|
|
|
|
name: 'First Option',
|
|
|
|
selected: true,
|
|
|
|
},
|
|
|
|
{ role: 'combobox option', name: 'Second Option' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'RootWebArea',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'Accessibility Test',
|
|
|
|
children: [
|
2021-05-26 16:44:29 +00:00
|
|
|
{ role: 'StaticText', name: 'Hello World' },
|
2020-05-07 10:54:55 +00:00
|
|
|
{ role: 'heading', name: 'Inputs', level: 1 },
|
|
|
|
{ role: 'textbox', name: 'Empty input', focused: true },
|
|
|
|
{ role: 'textbox', name: 'readonly input', readonly: true },
|
|
|
|
{ role: 'textbox', name: 'disabled input', disabled: true },
|
|
|
|
{ role: 'textbox', name: 'Input with whitespace', value: ' ' },
|
|
|
|
{ role: 'textbox', name: '', value: 'value only' },
|
|
|
|
{ role: 'textbox', name: 'placeholder', value: 'and a value' },
|
|
|
|
{
|
|
|
|
role: 'textbox',
|
|
|
|
name: 'placeholder',
|
|
|
|
value: 'and a value',
|
|
|
|
description: 'This is a description!',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'combobox',
|
|
|
|
name: '',
|
|
|
|
value: 'First Option',
|
|
|
|
children: [
|
|
|
|
{ role: 'menuitem', name: 'First Option', selected: true },
|
|
|
|
{ role: 'menuitem', name: 'Second Option' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(await page.accessibility.snapshot()).toEqual(golden);
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should report uninteresting nodes', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`<textarea>hi</textarea>`);
|
|
|
|
await page.focus('textarea');
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'entry',
|
|
|
|
name: '',
|
|
|
|
value: 'hi',
|
|
|
|
focused: true,
|
|
|
|
multiline: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'text leaf',
|
|
|
|
name: 'hi',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'textbox',
|
|
|
|
name: '',
|
|
|
|
value: 'hi',
|
|
|
|
focused: true,
|
|
|
|
multiline: true,
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'generic',
|
|
|
|
name: '',
|
|
|
|
children: [
|
|
|
|
{
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'StaticText',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'hi',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
|
|
|
expect(
|
|
|
|
findFocusedNode(
|
|
|
|
await page.accessibility.snapshot({ interestingOnly: false })
|
|
|
|
)
|
|
|
|
).toEqual(golden);
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('roledescription', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
await page.setContent(
|
|
|
|
'<div tabIndex=-1 aria-roledescription="foo">Hi</div>'
|
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
2021-11-23 07:19:14 +00:00
|
|
|
// See https://chromium-review.googlesource.com/c/chromium/src/+/3088862
|
|
|
|
expect(snapshot.children[0].roledescription).toEqual(undefined);
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('orientation', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
await page.setContent(
|
|
|
|
'<a href="" role="slider" aria-orientation="vertical">11</a>'
|
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0].orientation).toEqual('vertical');
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('autocomplete', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent('<input type="number" aria-autocomplete="list" />');
|
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0].autocomplete).toEqual('list');
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('multiselectable', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
await page.setContent(
|
|
|
|
'<div role="grid" tabIndex=-1 aria-multiselectable=true>hey</div>'
|
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0].multiselectable).toEqual(true);
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('keyshortcuts', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
await page.setContent(
|
|
|
|
'<div role="grid" tabIndex=-1 aria-keyshortcuts="foo">hey</div>'
|
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0].keyshortcuts).toEqual('foo');
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
describe('filtering children of leaf nodes', function () {
|
|
|
|
it('should not report text nodes inside controls', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
|
|
|
<div role="tablist">
|
|
|
|
<div role="tab" aria-selected="true"><b>Tab1</b></div>
|
|
|
|
<div role="tab">Tab2</div>
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'document',
|
|
|
|
name: '',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'pagetab',
|
|
|
|
name: 'Tab1',
|
|
|
|
selected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'pagetab',
|
|
|
|
name: 'Tab2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'RootWebArea',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: '',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'tab',
|
|
|
|
name: 'Tab1',
|
|
|
|
selected: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'tab',
|
|
|
|
name: 'Tab2',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2019-02-26 05:57:33 +00:00
|
|
|
expect(await page.accessibility.snapshot()).toEqual(golden);
|
2018-11-02 01:54:51 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('rich text editable fields should have children', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
|
|
|
<div contenteditable="true">
|
|
|
|
Edit this image: <img src="fakeimage.png" alt="my fake image">
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'section',
|
|
|
|
name: '',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'text leaf',
|
|
|
|
name: 'Edit this image: ',
|
|
|
|
},
|
|
|
|
{
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'StaticText',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'my fake image',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'generic',
|
|
|
|
name: '',
|
|
|
|
value: 'Edit this image: ',
|
|
|
|
children: [
|
|
|
|
{
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'StaticText',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'Edit this image:',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'img',
|
|
|
|
name: 'my fake image',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2019-02-26 05:57:33 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(snapshot.children[0]).toEqual(golden);
|
2019-02-26 05:57:33 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('rich text editable fields with role should have children', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
|
|
|
<div contenteditable="true" role='textbox'>
|
|
|
|
Edit this image: <img src="fakeimage.png" alt="my fake image">
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'entry',
|
|
|
|
name: '',
|
|
|
|
value: 'Edit this image: my fake image',
|
|
|
|
children: [
|
|
|
|
{
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'StaticText',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'my fake image',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'textbox',
|
|
|
|
name: '',
|
|
|
|
value: 'Edit this image: ',
|
2021-05-26 16:44:29 +00:00
|
|
|
multiline: true,
|
2020-05-07 10:54:55 +00:00
|
|
|
children: [
|
|
|
|
{
|
2021-05-26 16:44:29 +00:00
|
|
|
role: 'StaticText',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'Edit this image:',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'img',
|
|
|
|
name: 'my fake image',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2019-02-26 05:57:33 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(snapshot.children[0]).toEqual(golden);
|
2018-11-02 01:54:51 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
// Firefox does not support contenteditable="plaintext-only".
|
2020-05-07 10:54:55 +00:00
|
|
|
describeFailsFirefox('plaintext contenteditable', function () {
|
|
|
|
it('plain text field with role should not have children', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
2018-11-02 01:54:51 +00:00
|
|
|
await page.setContent(`
|
2020-04-09 05:56:25 +00:00
|
|
|
<div contenteditable="plaintext-only" role='textbox'>Edit this image:<img src="fakeimage.png" alt="my fake image"></div>`);
|
2019-02-26 05:57:33 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
2020-04-09 05:56:25 +00:00
|
|
|
expect(snapshot.children[0]).toEqual({
|
2018-11-02 01:54:51 +00:00
|
|
|
role: 'textbox',
|
|
|
|
name: '',
|
2020-05-07 10:54:55 +00:00
|
|
|
value: 'Edit this image:',
|
2021-05-26 16:44:29 +00:00
|
|
|
multiline: true,
|
2018-11-02 01:54:51 +00:00
|
|
|
});
|
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('non editable textbox with role and tabIndex and label should not have children', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
2018-11-02 01:54:51 +00:00
|
|
|
<div role="textbox" tabIndex=0 aria-checked="true" aria-label="my favorite textbox">
|
|
|
|
this is the inner content
|
|
|
|
<img alt="yo" src="fakeimg.png">
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'entry',
|
|
|
|
name: 'my favorite textbox',
|
|
|
|
value: 'this is the inner content yo',
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'textbox',
|
|
|
|
name: 'my favorite textbox',
|
|
|
|
value: 'this is the inner content ',
|
|
|
|
};
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0]).toEqual(golden);
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('checkbox with and tabIndex and label should not have children', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
2018-11-02 01:54:51 +00:00
|
|
|
<div role="checkbox" tabIndex=0 aria-checked="true" aria-label="my favorite checkbox">
|
|
|
|
this is the inner content
|
|
|
|
<img alt="yo" src="fakeimg.png">
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'checkbutton',
|
|
|
|
name: 'my favorite checkbox',
|
|
|
|
checked: true,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'checkbox',
|
|
|
|
name: 'my favorite checkbox',
|
|
|
|
checked: true,
|
|
|
|
};
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0]).toEqual(golden);
|
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('checkbox without label should not have children', async () => {
|
|
|
|
const { page, isFirefox } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
2018-11-02 01:54:51 +00:00
|
|
|
<div role="checkbox" aria-checked="true">
|
|
|
|
this is the inner content
|
|
|
|
<img alt="yo" src="fakeimg.png">
|
|
|
|
</div>`);
|
2020-05-07 10:54:55 +00:00
|
|
|
const golden = isFirefox
|
|
|
|
? {
|
|
|
|
role: 'checkbutton',
|
|
|
|
name: 'this is the inner content yo',
|
|
|
|
checked: true,
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
role: 'checkbox',
|
|
|
|
name: 'this is the inner content yo',
|
|
|
|
checked: true,
|
|
|
|
};
|
2020-04-09 05:56:25 +00:00
|
|
|
const snapshot = await page.accessibility.snapshot();
|
|
|
|
expect(snapshot.children[0]).toEqual(golden);
|
|
|
|
});
|
|
|
|
|
2020-05-07 10:54:55 +00:00
|
|
|
describe('root option', function () {
|
|
|
|
it('should work a button', async () => {
|
|
|
|
const { page } = getTestState();
|
2019-05-10 06:39:42 +00:00
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
await page.setContent(`<button>My Button</button>`);
|
2019-05-10 06:39:42 +00:00
|
|
|
|
2021-03-25 11:40:34 +00:00
|
|
|
const button = await page.$<HTMLButtonElement>('button');
|
2020-05-07 10:54:55 +00:00
|
|
|
expect(await page.accessibility.snapshot({ root: button })).toEqual({
|
2020-04-09 05:56:25 +00:00
|
|
|
role: 'button',
|
2020-05-07 10:54:55 +00:00
|
|
|
name: 'My Button',
|
2019-05-10 06:39:42 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should work an input', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`<input title="My Input" value="My Value">`);
|
2019-05-10 06:39:42 +00:00
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
const input = await page.$('input');
|
2020-05-07 10:54:55 +00:00
|
|
|
expect(await page.accessibility.snapshot({ root: input })).toEqual({
|
2020-04-09 05:56:25 +00:00
|
|
|
role: 'textbox',
|
|
|
|
name: 'My Input',
|
2020-05-07 10:54:55 +00:00
|
|
|
value: 'My Value',
|
2019-05-10 06:39:42 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should work a menu', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`
|
2019-05-10 06:39:42 +00:00
|
|
|
<div role="menu" title="My Menu">
|
|
|
|
<div role="menuitem">First Item</div>
|
|
|
|
<div role="menuitem">Second Item</div>
|
|
|
|
<div role="menuitem">Third Item</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
2020-04-09 05:56:25 +00:00
|
|
|
const menu = await page.$('div[role="menu"]');
|
2020-05-07 10:54:55 +00:00
|
|
|
expect(await page.accessibility.snapshot({ root: menu })).toEqual({
|
2020-04-09 05:56:25 +00:00
|
|
|
role: 'menu',
|
|
|
|
name: 'My Menu',
|
2020-05-07 10:54:55 +00:00
|
|
|
children: [
|
|
|
|
{ role: 'menuitem', name: 'First Item' },
|
|
|
|
{ role: 'menuitem', name: 'Second Item' },
|
|
|
|
{ role: 'menuitem', name: 'Third Item' },
|
|
|
|
],
|
2019-05-10 06:39:42 +00:00
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should return null when the element is no longer in DOM', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`<button>My Button</button>`);
|
|
|
|
const button = await page.$('button');
|
2020-05-07 10:54:55 +00:00
|
|
|
await page.$eval('button', (button) => button.remove());
|
|
|
|
expect(await page.accessibility.snapshot({ root: button })).toEqual(
|
|
|
|
null
|
|
|
|
);
|
2020-04-09 05:56:25 +00:00
|
|
|
});
|
2020-05-07 10:54:55 +00:00
|
|
|
it('should support the interestingOnly option', async () => {
|
|
|
|
const { page } = getTestState();
|
2020-04-09 05:56:25 +00:00
|
|
|
|
|
|
|
await page.setContent(`<div><button>My Button</button></div>`);
|
|
|
|
const div = await page.$('div');
|
2020-05-07 10:54:55 +00:00
|
|
|
expect(await page.accessibility.snapshot({ root: div })).toEqual(null);
|
|
|
|
expect(
|
|
|
|
await page.accessibility.snapshot({
|
|
|
|
root: div,
|
|
|
|
interestingOnly: false,
|
|
|
|
})
|
|
|
|
).toEqual({
|
2020-04-09 05:56:25 +00:00
|
|
|
role: 'generic',
|
|
|
|
name: '',
|
|
|
|
children: [
|
|
|
|
{
|
|
|
|
role: 'button',
|
|
|
|
name: 'My Button',
|
2021-05-26 16:44:29 +00:00
|
|
|
children: [{ role: 'StaticText', name: 'My Button' }],
|
2020-04-09 05:56:25 +00:00
|
|
|
},
|
|
|
|
],
|
2019-05-10 06:39:42 +00:00
|
|
|
});
|
|
|
|
});
|
2018-11-02 01:54:51 +00:00
|
|
|
});
|
|
|
|
});
|
2020-04-09 05:56:25 +00:00
|
|
|
function findFocusedNode(node) {
|
2020-05-07 10:54:55 +00:00
|
|
|
if (node.focused) return node;
|
2020-04-09 05:56:25 +00:00
|
|
|
for (const child of node.children || []) {
|
|
|
|
const focusedChild = findFocusedNode(child);
|
2020-05-07 10:54:55 +00:00
|
|
|
if (focusedChild) return focusedChild;
|
2020-04-09 05:56:25 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|