| 1 |
<!DOCTYPE html> |
| 2 |
<html lang="en"> |
| 3 |
<head> |
| 4 |
<meta charset="utf-8"> |
| 5 |
<title></title> |
| 6 |
<link rel="help" href="https://www.w3.org/TR/selectors-4/#the-focus-visible-pseudo"> |
| 7 |
<link rel="stylesheet" href="/test/browser.expect.css"> |
| 8 |
<script src="https://unpkg.com/[email protected]/dist/focus-visible.min.js"></script> |
| 9 |
</head> |
| 10 |
<body> |
| 11 |
<input type="text" id="a" aria-label=""> |
| 12 |
<input type="text" id="b" aria-label=""> |
| 13 |
<button id="c" type="button">Click Me</button> |
| 14 |
|
| 15 |
<script type="module"> |
| 16 |
const purple = 'rgb(128, 0, 128)'; |
| 17 |
const a = document.getElementById('a'); |
| 18 |
const b = document.getElementById('b'); |
| 19 |
const c = document.getElementById('c'); |
| 20 |
const elements = { |
| 21 |
a, |
| 22 |
b, |
| 23 |
c, |
| 24 |
}; |
| 25 |
|
| 26 |
self.checkElement = async function checkElement(testName, element, shouldBeStyled) { |
| 27 |
const input = elements[element]; |
| 28 |
const hasFocus = document.activeElement === input; |
| 29 |
|
| 30 |
if (!hasFocus && shouldBeStyled) { |
| 31 |
throw new Error(`${testName}: ${element} should have focus to be tested.`); |
| 32 |
} |
| 33 |
|
| 34 |
const background = getComputedStyle(input).backgroundColor; |
| 35 |
|
| 36 |
if (shouldBeStyled) { |
| 37 |
if (background !== purple) { |
| 38 |
throw new Error(`${testName}: ${element} should have :focus-visible styles.`); |
| 39 |
} |
| 40 |
} else if (background === purple) { |
| 41 |
throw new Error(`${testName}: ${element} should not have :focus-visible styles.`); |
| 42 |
} |
| 43 |
}; |
| 44 |
</script> |
| 45 |
</body> |
| 46 |
</html> |