feat(role): add more tests for accessible name (#13154)
This commit is contained in:
parent
54f6e5db19
commit
6b48631eed
|
|
@ -459,7 +459,9 @@ function getElementAccessibleNameInternal(element: Element, options: AccessibleN
|
||||||
const title = element.getAttribute('title') || '';
|
const title = element.getAttribute('title') || '';
|
||||||
if (title.trim())
|
if (title.trim())
|
||||||
return title;
|
return title;
|
||||||
return 'Submit Query';
|
// SPEC DIFFERENCE.
|
||||||
|
// Spec says return localized "Submit Query", but browsers and axe-core insist on "Sumbit".
|
||||||
|
return 'Submit';
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-url-and-textarea-element
|
// https://w3c.github.io/html-aam/#input-type-text-input-type-password-input-type-search-input-type-tel-input-type-url-and-textarea-element
|
||||||
|
|
@ -538,6 +540,11 @@ function getElementAccessibleNameInternal(element: Element, options: AccessibleN
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// SPEC DIFFERENCE.
|
// SPEC DIFFERENCE.
|
||||||
|
// Spec does not say a word about <table summary="...">, but all browsers actually support it.
|
||||||
|
const summary = element.getAttribute('summary') || '';
|
||||||
|
if (summary)
|
||||||
|
return summary;
|
||||||
|
// SPEC DIFFERENCE.
|
||||||
// Spec says "if the table element has a title attribute, then use that attribute".
|
// Spec says "if the table element has a title attribute, then use that attribute".
|
||||||
// We ignore title to pass "name_from_content-manual.html".
|
// We ignore title to pass "name_from_content-manual.html".
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,4 +4,5 @@ Includes:
|
||||||
- `LICENSE`
|
- `LICENSE`
|
||||||
|
|
||||||
Modifed:
|
Modifed:
|
||||||
- `implicit-role.js` contains extracted test cases from `/test/commons/aria/implicit-role.js`
|
- `implicit-role.js` contains test cases extracted from `/test/commons/aria/implicit-role.js`
|
||||||
|
- `accessible-text.js` contains test cases extracted from `/test/commons/aria/accessible-text.js`
|
||||||
|
|
|
||||||
1119
tests/assets/axe-core/accessible-text.js
Normal file
1119
tests/assets/axe-core/accessible-text.js
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -80,7 +80,7 @@ test('wpt accname', async ({ page, asset, server, browserName }) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('axe-core implicit role', async ({ page, asset, server }) => {
|
test('axe-core implicit-role', async ({ page, asset, server }) => {
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await page.goto(server.EMPTY_PAGE);
|
||||||
const testCases = require(asset('axe-core/implicit-role'));
|
const testCases = require(asset('axe-core/implicit-role'));
|
||||||
for (const testCase of testCases) {
|
for (const testCase of testCases) {
|
||||||
|
|
@ -101,3 +101,41 @@ test('axe-core implicit role', async ({ page, asset, server }) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('axe-core accessible-text', async ({ page, asset, server }) => {
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
const testCases = require(asset('axe-core/accessible-text'));
|
||||||
|
for (const testCase of testCases) {
|
||||||
|
await test.step(`checking ${JSON.stringify(testCase)}`, async () => {
|
||||||
|
await page.setContent(`
|
||||||
|
<body>
|
||||||
|
${testCase.html}
|
||||||
|
</body>
|
||||||
|
<script>
|
||||||
|
for (const template of document.querySelectorAll("template[shadow]")) {
|
||||||
|
const shadowRoot = template.parentElement.attachShadow({ mode: 'open' });
|
||||||
|
shadowRoot.appendChild(template.content);
|
||||||
|
template.remove();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
`);
|
||||||
|
// Use $eval to force injected script.
|
||||||
|
const targets = toArray(testCase.target);
|
||||||
|
const expected = toArray(testCase.accessibleText);
|
||||||
|
const received = await page.$eval('body', (_, selectors) => {
|
||||||
|
return selectors.map(selector => {
|
||||||
|
const injected = (window as any).__injectedScript;
|
||||||
|
const element = injected.querySelector(injected.parseSelector('css=' + selector), document, false);
|
||||||
|
if (!element)
|
||||||
|
throw new Error(`Unable to resolve "${selector}"`);
|
||||||
|
return injected.getElementAccessibleName(element);
|
||||||
|
});
|
||||||
|
}, targets);
|
||||||
|
expect(received, `checking ${JSON.stringify(testCase)}`).toEqual(expected);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function toArray(x: any): any[] {
|
||||||
|
return Array.isArray(x) ? x : [x];
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue