-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ShadowDOM support for media checks
- Loading branch information
1 parent
6f53279
commit 0f21574
Showing
4 changed files
with
54 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
var tracks = node.querySelectorAll('track'); | ||
var tracks = axe.utils.querySelectorAll(virtualNode, 'track'); | ||
|
||
if (tracks.length) { | ||
for (var i=0; i<tracks.length; i++) { | ||
var kind = tracks[i].getAttribute('kind'); | ||
if (kind && kind === 'captions') { | ||
// only return for matching track, in case there are multiple | ||
return false; | ||
} | ||
} | ||
return true; | ||
// return false if any track has kind === 'caption' | ||
return !tracks.some(({ actualNode }) => ( | ||
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; |
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,12 +1,12 @@ | ||
var tracks = node.querySelectorAll('track'); | ||
var tracks = axe.utils.querySelectorAll(virtualNode, 'track'); | ||
|
||
if (tracks.length) { | ||
for (var i=0; i<tracks.length; i++) { | ||
var kind = tracks[i].getAttribute('kind'); | ||
if (kind && kind === 'descriptions') { | ||
// only return for matching track, in case there are multiple | ||
return false; | ||
} | ||
} | ||
return true; | ||
// return false if any track has kind === 'description' | ||
var out = !tracks.some(({ actualNode }) => ( | ||
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; |
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,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 = '<video></video>'; | ||
var node = fixture.querySelector('video'); | ||
|
||
assert.isUndefined(checks.description.evaluate(node)); | ||
var checkArgs = checkSetup('<video></video>', 'video'); | ||
assert.isUndefined(checks.description.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should fail if there is no kind=descriptions attribute', function () { | ||
fixture.innerHTML = '<video><track kind=captions></video>'; | ||
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><track kind=captions></video>', 'video'); | ||
assert.isTrue(checks.description.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
it('should pass if there is a kind=descriptions attribute', function () { | ||
fixture.innerHTML = '<video><track kind=descriptions></video>'; | ||
var node = fixture.querySelector('video'); | ||
var checkArgs = checkSetup('<video><track kind=descriptions></video>', '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 = '<track kind=descriptions>'; | ||
var shadow = node.attachShadow({ mode: 'open' }); | ||
shadow.innerHTML = '<video><slot></slot></video>'; | ||
|
||
var checkArgs = checkSetup(node, {}, 'video'); | ||
axe.log(checkArgs); | ||
assert.isFalse(checks.description.evaluate.apply(null, checkArgs)); | ||
}); | ||
|
||
}); |