-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
50 lines (46 loc) · 1.54 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo: can-autoplay</title>
</head>
<body>
<h1>can-autoplay</h1>
<ul>
<li class='video'>video</li>
<li class='videoMuted'>video muted</li>
<li class='videoInline'>video inline</li>
<li class='videoInlineMuted'>video inline muted</li>
<li class='audio'>audio</li>
<li class='audioMuted'>audio muted</li>
</ul>
<button type="button">Rerun Tests</button>
<script src="./build/can-autoplay.js"></script>
<script>
const $ = document.querySelector.bind(document)
let tests = [
{selector: '.video', method: 'video', params: null},
{selector: '.videoMuted', method: 'video', params: {muted: true}},
{selector: '.videoInline', method: 'video', params: {inline: true}},
{selector: '.videoInlineMuted', method: 'video', params: {inline: true, muted: true}},
{selector: '.audio', method: 'audio', params: null},
{selector: '.audioMuted', method: 'audio', params: {muted: true}}
]
const runTests = () => {
tests.reduce((testSequence, test) => {
return testSequence
.then(() => {
return canAutoplay[test.method](test.params).then(({result, error}) => {
$(test.selector).innerText += (result === true) ? ' ✅' : (' 🚫 ' + `( Error "${error.name}": ${error.message}) `)
})
})
.then(() => {
return new Promise(resolve => setTimeout(resolve, 1000))
})
}, Promise.resolve());
}
$('button').addEventListener('click', runTests);
runTests();
</script>
</body>
</html>