From 4455627d4e681490602d78db210fda7cdd6ddf32 Mon Sep 17 00:00:00 2001 From: Yury Petrov Date: Mon, 26 Jan 2015 14:00:53 -0800 Subject: [PATCH] Fixing audio without controls rule and adding a test for it. --- src/audits/AudioWithoutControls.js | 3 +-- test/audits/audio-without-controls-test.js | 14 ++++++++++++++ test/index.html | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 test/audits/audio-without-controls-test.js diff --git a/src/audits/AudioWithoutControls.js b/src/audits/AudioWithoutControls.js index 69790068..bf072838 100644 --- a/src/audits/AudioWithoutControls.js +++ b/src/audits/AudioWithoutControls.js @@ -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' }; diff --git a/test/audits/audio-without-controls-test.js b/test/audits/audio-without-controls-test.js new file mode 100644 index 00000000..9404efc7 --- /dev/null +++ b/test/audits/audio-without-controls-test.js @@ -0,0 +1,14 @@ +module("Audio"); + +test("Audio has no controls attribute.", function() { + // Setup fixture + var fixture = document.getElementById('qunit-fixture'); + fixture.innerHTML = ""; + var audio = document.querySelector('audio'); + audio.addEventListener('canplay', function() { + deepEqual( + axs.AuditRules.getRule('audioWithoutControls').run({ scope: fixture }), + { elements: [ audio ], result: axs.constants.AuditResult.FAIL } + ); + }) +}); \ No newline at end of file diff --git a/test/index.html b/test/index.html index 00025b52..0af8bcd5 100644 --- a/test/index.html +++ b/test/index.html @@ -42,6 +42,7 @@ +