-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(no-autoplay-audio): don't timeout for preload=none media elements
- Loading branch information
Showing
6 changed files
with
226 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,119 +1,126 @@ | ||
describe('no-autoplay-audio', function () { | ||
'use strict'; | ||
describe('no-autoplay-audio', () => { | ||
const check = checks['no-autoplay-audio']; | ||
const checkSetup = axe.testUtils.checkSetup; | ||
const checkContext = axe.testUtils.MockCheckContext(); | ||
const preloadOptions = { preload: { assets: ['media'] } }; | ||
|
||
var check; | ||
var fixture = document.getElementById('fixture'); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
var checkContext = axe.testUtils.MockCheckContext(); | ||
var preloadOptions = { preload: { assets: ['media'] } }; | ||
|
||
before(function () { | ||
check = checks['no-autoplay-audio']; | ||
}); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
axe._tree = undefined; | ||
afterEach(() => { | ||
checkContext.reset(); | ||
}); | ||
|
||
it('returns undefined when <audio> has no source (duration cannot be interpreted)', function (done) { | ||
var checkArgs = checkSetup('<audio id="target"></audio>'); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isUndefined(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
it('returns undefined when <audio> has no source (duration cannot be interpreted)', async () => { | ||
const checkArgs = checkSetup('<audio id="target"></audio>'); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isUndefined(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns undefined when <video> has no source (duration cannot be interpreted)', function (done) { | ||
var checkArgs = checkSetup('<video id="target"><source src=""/></video>'); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isUndefined(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
it('returns undefined when <video> has no source (duration cannot be interpreted)', async () => { | ||
const checkArgs = checkSetup('<video id="target"><source src=""/></video>'); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isUndefined(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns false when <audio> can autoplay and has no controls mechanism', function (done) { | ||
var checkArgs = checkSetup( | ||
it('returns false when <audio> can autoplay and has no controls mechanism', async () => { | ||
const checkArgs = checkSetup( | ||
'<audio id="target" src="/test/assets/moon-speech.mp3" autoplay="true"></audio>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns false when <video> can autoplay and has no controls mechanism', function (done) { | ||
var checkArgs = checkSetup( | ||
'<video id="target" autoplay="true">' + | ||
'<source src="/test/assets/video.webm" type="video/webm" />' + | ||
'<source src="/test/assets/video.mp4" type="video/mp4" />' + | ||
'</video>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
it('returns false when <video> can autoplay and has no controls mechanism', async () => { | ||
const checkArgs = checkSetup(` | ||
<video id="target" autoplay="true"> | ||
<source src="/test/assets/video.webm" type="video/webm" /> | ||
<source src="/test/assets/video.mp4" type="video/mp4" /> | ||
</video> | ||
`); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns false when <audio> plays less than allowed dutation but loops', function (done) { | ||
var checkArgs = checkSetup( | ||
it('returns false when <audio> plays less than allowed dutation but loops', async () => { | ||
const checkArgs = checkSetup( | ||
'<audio id="target" src="/test/assets/moon-speech.mp3#t=2,4" autoplay="true" loop="true"></audio>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> can autoplay and duration is below allowed duration (by passing options)', function (done) { | ||
var checkArgs = checkSetup( | ||
'<video id="target" autoplay="true">' + | ||
'<source src="/test/assets/video.webm" type="video/webm" />' + | ||
'<source src="/test/assets/video.mp4" type="video/mp4" />' + | ||
'</video>', | ||
{ allowedDuration: 15 } | ||
it('returns false when <video> loops and has no controls mechanism when duration is unknown', () => { | ||
const checkArgs = checkSetup(` | ||
<video id="target" loop> | ||
<source src="/test/assets/video.webm#t=7,9" type="video/webm" /> | ||
<source src="/test/assets/video.mp4#t=7,9" type="video/mp4" /> | ||
</video> | ||
`); | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns false when <audio> loops and has no controls mechanism when duration is unknown', () => { | ||
const checkArgs = checkSetup( | ||
'<audio id="target" src="/test/assets/moon-speech.mp3#t=2,4" loop="true"></audio>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
assert.isFalse(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> can autoplay and duration is below allowed duration (by setting playback range)', function (done) { | ||
var checkArgs = checkSetup( | ||
'<video id="target" autoplay="true">' + | ||
'<source src="/test/assets/video.webm#t=7,9" type="video/webm" />' + | ||
'<source src="/test/assets/video.mp4#t=7,9" type="video/mp4" />' + | ||
'</video>' | ||
// Note: default allowed duration is 3s | ||
it('returns true when <video> can autoplay and duration is below allowed duration (by passing options)', async () => { | ||
const checkArgs = checkSetup( | ||
` | ||
<video id="target" autoplay="true"> | ||
<source src="/test/assets/video.webm" type="video/webm" /> | ||
<source src="/test/assets/video.mp4" type="video/mp4" /> | ||
</video>`, | ||
{ allowedDuration: 15 } | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> can autoplay and duration is below allowed duration (by setting playback range)', async () => { | ||
const checkArgs = checkSetup(` | ||
<video id="target" autoplay="true"> | ||
<source src="/test/assets/video.webm#t=7,9" type="video/webm" /> | ||
<source src="/test/assets/video.mp4#t=7,9" type="video/mp4" /> | ||
</video>`); | ||
// Note: default allowed duration is 3s | ||
await axe.utils.preload(preloadOptions); | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <audio> can autoplay but has controls mechanism', function (done) { | ||
var checkArgs = checkSetup( | ||
it('returns true when <audio> can autoplay but has controls mechanism', async () => { | ||
const checkArgs = checkSetup( | ||
'<audio id="target" src="/test/assets/moon-speech.mp3" autoplay="true" controls></audio>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
done(); | ||
}); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> can autoplay and has controls mechanism', async () => { | ||
const checkArgs = checkSetup(` | ||
<video id="target" autoplay="true" controls> | ||
<source src="/test/assets/video.webm" type="video/webm" /> | ||
<source src="/test/assets/video.mp4" type="video/mp4" /> | ||
</video> | ||
`); | ||
await axe.utils.preload(preloadOptions); | ||
assert.isTrue(check.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> loops and has controls mechanism when duration is unknown', () => { | ||
const checkArgs = checkSetup(` | ||
<video id="target" loop controls> | ||
<source src="/test/assets/video.webm#t=7,9" type="video/webm" /> | ||
<source src="/test/assets/video.mp4#t=7,9" type="video/mp4" /> | ||
</video> | ||
`); | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
|
||
it('returns true when <video> can autoplay and has controls mechanism', function (done) { | ||
var checkArgs = checkSetup( | ||
'<video id="target" autoplay="true" controls>' + | ||
'<source src="/test/assets/video.webm" type="video/webm" />' + | ||
'<source src="/test/assets/video.mp4" type="video/mp4" />' + | ||
'</video>' | ||
it('returns true when <audio> loops and has controls mechanism when duration is unknown', () => { | ||
const checkArgs = checkSetup( | ||
'<audio id="target" src="/test/assets/moon-speech.mp3#t=2,4" controls="true" loop="true"></audio>' | ||
); | ||
axe.utils.preload(preloadOptions).then(function () { | ||
assert.isTrue(check.evaluate.apply(null, checkArgs)); | ||
done(); | ||
}); | ||
assert.isTrue(check.evaluate.apply(checkContext, checkArgs)); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.