Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Fixing audio without controls rule and adding a test for it. #139

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/audits/AudioWithoutControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ axs.AuditRule.specs.audioWithoutControls = {
return axs.browserUtils.matchSelector(element, 'audio[autoplay]');
},
test: function(audio) {
var controls = audio.querySelectorAll('[controls]');
return !controls.length && audio.duration > 3;
return !audio.hasAttribute('controls') && audio.duration > 3;
},
code: 'AX_AUDIO_01'
};
14 changes: 14 additions & 0 deletions test/audits/audio-without-controls-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module("Audio");

test("Audio has no controls attribute.", function() {
// Setup fixture
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML = "<audio src=\"http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg\" autoplay></audio>";
var audio = document.querySelector('audio');
audio.addEventListener('canplay', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we need to come up with a way to block this test finishing until this assertion has run. Check out the QUnit doc: http://api.qunitjs.com/

deepEqual(
axs.AuditRules.getRule('audioWithoutControls').run({ scope: fixture }),
{ elements: [ audio ], result: axs.constants.AuditResult.FAIL }
);
})
});
1 change: 1 addition & 0 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<script src="./js/audit-configuration-test.js"></script>
<script src="./js/audit-rule-test.js"></script>
<script src="./audits/aria-owns-descendant-test.js"></script>
<script src="./audits/audio-without-controls-test.js"></script>
<script src="./audits/bad-aria-role-test.js"></script>
<script src="./audits/bad-aria-attribute-value-test.js"></script>
<script src="./audits/controls-without-label-test.js"></script>
Expand Down