From 0f215746cd98b9a7280c6e22d65689a6a04cf133 Mon Sep 17 00:00:00 2001 From: Wilco Fiers Date: Fri, 14 Jul 2017 13:53:29 +0200 Subject: [PATCH] feat: ShadowDOM support for media checks --- lib/checks/media/caption.js | 17 +++++++--------- lib/checks/media/description.js | 18 ++++++++-------- test/checks/media/caption.js | 28 +++++++++++++++---------- test/checks/media/description.js | 35 +++++++++++++++++++------------- 4 files changed, 54 insertions(+), 44 deletions(-) diff --git a/lib/checks/media/caption.js b/lib/checks/media/caption.js index 65bd8c8871..80b6af6372 100644 --- a/lib/checks/media/caption.js +++ b/lib/checks/media/caption.js @@ -1,13 +1,10 @@ -var tracks = node.querySelectorAll('track'); +var tracks = axe.utils.querySelectorAll(virtualNode, 'track'); + if (tracks.length) { - for (var i=0; i ( + actualNode.getAttribute('kind').toLowerCase() === 'captions' + )); } -// for multiple track elements, return the first one that matches +// Undefined if there are no tracks - media may be decorative return undefined; diff --git a/lib/checks/media/description.js b/lib/checks/media/description.js index 8f57000b94..65e29cd3b2 100644 --- a/lib/checks/media/description.js +++ b/lib/checks/media/description.js @@ -1,12 +1,12 @@ -var tracks = node.querySelectorAll('track'); +var tracks = axe.utils.querySelectorAll(virtualNode, 'track'); + if (tracks.length) { - for (var i=0; i ( + actualNode.getAttribute('kind').toLowerCase() === 'descriptions' + )); + axe.log(tracks.map(t => t.actualNode.getAttribute('kind')), out); + return out; } +// Undefined if there are no tracks - media may be decorative return undefined; diff --git a/test/checks/media/caption.js b/test/checks/media/caption.js index c6e49af73a..3c313ed72c 100644 --- a/test/checks/media/caption.js +++ b/test/checks/media/caption.js @@ -2,29 +2,35 @@ describe('caption', function () { 'use strict'; var fixture = document.getElementById('fixture'); + var shadowSupport = axe.testUtils.shadowSupport; + var checkSetup = axe.testUtils.checkSetup; afterEach(function () { fixture.innerHTML = ''; }); it('should return undefined if there is no track element', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('audio'); - - assert.isUndefined(checks.caption.evaluate(node)); + var checkArgs = checkSetup('', 'audio'); + assert.isUndefined(checks.caption.evaluate.apply(null, checkArgs)); }); it('should fail if there is no kind=captions attribute', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('audio'); - - assert.isTrue(checks.caption.evaluate(node)); + var checkArgs = checkSetup('', 'audio'); + assert.isTrue(checks.caption.evaluate.apply(null, checkArgs)); }); it('should pass if there is a kind=captions attribute', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('audio'); + var checkArgs = checkSetup('', 'audio'); + assert.isFalse(checks.caption.evaluate.apply(null, checkArgs)); + }); + + (shadowSupport.v1 ? it : xit)('should get track from composed tree', function () { + var node = document.createElement('div'); + node.innerHTML = ''; + var shadow = node.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; - assert.isFalse(checks.caption.evaluate(node)); + var checkArgs = checkSetup(node, {}, 'audio'); + assert.isTrue(checks.caption.evaluate.apply(null, checkArgs)); }); }); diff --git a/test/checks/media/description.js b/test/checks/media/description.js index 168b1120f7..a423e1f98b 100644 --- a/test/checks/media/description.js +++ b/test/checks/media/description.js @@ -1,30 +1,37 @@ describe('description', function () { 'use strict'; - var fixture = document.getElementById('fixture'); + var shadowSupport = axe.testUtils.shadowSupport; + var checkSetup = axe.testUtils.checkSetup; afterEach(function () { - fixture.innerHTML = ''; + document.getElementById('fixture').innerHTML = ''; }); it('should return undefined if there is no track element', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('video'); - - assert.isUndefined(checks.description.evaluate(node)); + var checkArgs = checkSetup('', 'video'); + assert.isUndefined(checks.description.evaluate.apply(null, checkArgs)); }); - it('should fail if there is no kind=descriptions attribute', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('video'); - - assert.isTrue(checks.description.evaluate(node)); + it('should fail if there is no kind=captions attribute', function () { + var checkArgs = checkSetup('', 'video'); + assert.isTrue(checks.description.evaluate.apply(null, checkArgs)); }); it('should pass if there is a kind=descriptions attribute', function () { - fixture.innerHTML = ''; - var node = fixture.querySelector('video'); + var checkArgs = checkSetup('', 'video'); + assert.isFalse(checks.description.evaluate.apply(null, checkArgs)); + }); - assert.isFalse(checks.description.evaluate(node)); + (shadowSupport.v1 ? it : xit)('should get track from composed tree', function () { + var node = document.createElement('div'); + node.innerHTML = ''; + var shadow = node.attachShadow({ mode: 'open' }); + shadow.innerHTML = ''; + + var checkArgs = checkSetup(node, {}, 'video'); + axe.log(checkArgs); + assert.isFalse(checks.description.evaluate.apply(null, checkArgs)); }); + });