-
Notifications
You must be signed in to change notification settings - Fork 849
fix(no-autoplay-audio): don't timeout for preload=none media elements #4684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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"> | ||
straker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <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', () => { | ||
straker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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)); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.