-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy path_browser_replace.html
84 lines (73 loc) · 2.54 KB
/
_browser_replace.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<link rel="help" href="https://www.w3.org/TR/selectors-4/#blank">
<link rel="stylesheet" href="/test/browser.replacewith.expect.css">
<script src="/dist/browser-global.js"></script>
<script>self._cssBlankPseudoInit = cssBlankPseudoInit</script>
</head>
<body>
<input type="tel" id="tel-input" aria-label="">
<input type="text" id="text-input" aria-label="" value="something">
<input type="number" id="number-input" aria-label="">
<input type="password" id="password-input" aria-label="">
<textarea id="textarea" aria-label=""></textarea>
<select id="select" aria-label="">
<option value="" selected>Empty</option>
<option value="non-empty">Non Empty</option>
</select>
<script type="module">
const purple = 'rgb(128, 0, 128)';
const tel = document.getElementById('tel-input');
const text = document.getElementById('text-input');
const number = document.getElementById('number-input');
const password = document.getElementById('password-input');
const textarea = document.getElementById('textarea');
const select = document.getElementById('select');
function rafP(callback) {
return new Promise((resolve) => {
requestAnimationFrame(() => {
requestAnimationFrame(() => {
callback();
resolve();
});
});
});
}
function isBlank(element) {
const containsAttribute = element.hasAttribute('blank') || element.classList.contains('css-blank');
const background = getComputedStyle(element).backgroundColor;
return containsAttribute && background === purple;
}
function isNotBlank(element) {
return !isBlank(element);
}
function testBlankState(testName, element, shouldBeBlank) {
const testFunction = shouldBeBlank ? isBlank : isNotBlank;
const wording = shouldBeBlank ? 'to be' : 'not to be';
const result = testFunction(element);
if (result !== true) {
throw new Error(testName + ': ' + element.id + ' expected ' + wording + ' blank');
}
return result;
}
self.runTest = async function runTest() {
self._cssBlankPseudoInit({ replaceWith: '.css-blank' });
return await testBlank();
}
async function testBlank() {
await rafP(() => {
testBlankState('replace with', tel, true);
testBlankState('replace with', text, false);
testBlankState('replace with', number, true);
testBlankState('replace with', password, true);
testBlankState('replace with', textarea, true);
testBlankState('replace with', select, true);
});
return true;
}
</script>
</body>
</html>