cherry-pick(#34525): fix: follow the pseudo attr value in firefox computed
This commit is contained in:
parent
92916b8e91
commit
0213cf57bd
|
|
@ -354,27 +354,34 @@ export function getPseudoContent(element: Element, pseudo: '::before' | '::after
|
||||||
if (cache?.has(element))
|
if (cache?.has(element))
|
||||||
return cache?.get(element) || '';
|
return cache?.get(element) || '';
|
||||||
const pseudoStyle = getElementComputedStyle(element, pseudo);
|
const pseudoStyle = getElementComputedStyle(element, pseudo);
|
||||||
const content = getPseudoContentImpl(pseudoStyle);
|
const content = getPseudoContentImpl(element, pseudoStyle);
|
||||||
if (cache)
|
if (cache)
|
||||||
cache.set(element, content);
|
cache.set(element, content);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPseudoContentImpl(pseudoStyle: CSSStyleDeclaration | undefined) {
|
function getPseudoContentImpl(element: Element, pseudoStyle: CSSStyleDeclaration | undefined) {
|
||||||
// Note: all browsers ignore display:none and visibility:hidden pseudos.
|
// Note: all browsers ignore display:none and visibility:hidden pseudos.
|
||||||
if (!pseudoStyle || pseudoStyle.display === 'none' || pseudoStyle.visibility === 'hidden')
|
if (!pseudoStyle || pseudoStyle.display === 'none' || pseudoStyle.visibility === 'hidden')
|
||||||
return '';
|
return '';
|
||||||
const content = pseudoStyle.content;
|
const content = pseudoStyle.content;
|
||||||
|
let resolvedContent: string | undefined;
|
||||||
if ((content[0] === '\'' && content[content.length - 1] === '\'') ||
|
if ((content[0] === '\'' && content[content.length - 1] === '\'') ||
|
||||||
(content[0] === '"' && content[content.length - 1] === '"')) {
|
(content[0] === '"' && content[content.length - 1] === '"')) {
|
||||||
const unquoted = content.substring(1, content.length - 1);
|
resolvedContent = content.substring(1, content.length - 1);
|
||||||
|
} else if (content.startsWith('attr(') && content.endsWith(')')) {
|
||||||
|
// Firefox does not resolve attribute accessors in content.
|
||||||
|
const attrName = content.substring('attr('.length, content.length - 1).trim();
|
||||||
|
resolvedContent = element.getAttribute(attrName) || '';
|
||||||
|
}
|
||||||
|
if (resolvedContent !== undefined) {
|
||||||
// SPEC DIFFERENCE.
|
// SPEC DIFFERENCE.
|
||||||
// Spec says "CSS textual content, without a space", but we account for display
|
// Spec says "CSS textual content, without a space", but we account for display
|
||||||
// to pass "name_file-label-inline-block-styles-manual.html"
|
// to pass "name_file-label-inline-block-styles-manual.html"
|
||||||
const display = pseudoStyle.display || 'inline';
|
const display = pseudoStyle.display || 'inline';
|
||||||
if (display !== 'inline')
|
if (display !== 'inline')
|
||||||
return ' ' + unquoted + ' ';
|
return ' ' + resolvedContent + ' ';
|
||||||
return unquoted;
|
return resolvedContent;
|
||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -495,6 +495,21 @@ test('should not include hidden pseudo into accessible name', async ({ page }) =
|
||||||
expect.soft(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello hello' });
|
expect.soft(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello hello' });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should resolve pseudo content from attr', async ({ page }) => {
|
||||||
|
await page.setContent(`
|
||||||
|
<style>
|
||||||
|
.stars:before {
|
||||||
|
display: block;
|
||||||
|
content: attr(data-hello);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<a href="http://example.com">
|
||||||
|
<div class="stars" data-hello="hello">world</div>
|
||||||
|
</a>
|
||||||
|
`);
|
||||||
|
expect(await getNameAndRole(page, 'a')).toEqual({ role: 'link', name: 'hello world' });
|
||||||
|
});
|
||||||
|
|
||||||
test('should ignore invalid aria-labelledby', async ({ page }) => {
|
test('should ignore invalid aria-labelledby', async ({ page }) => {
|
||||||
await page.setContent(`
|
await page.setContent(`
|
||||||
<label>
|
<label>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue