Skip to content

Commit

Permalink
feat(rules): report data on fallback mechanisms with no a11y support
Browse files Browse the repository at this point in the history
Report the following Package properties in the `properties` section:
- `hasBindings` will report the presence of a `bindings` element in the Package Doc
- `hasManifestFallbacks` will report the presence of any manifest fallback

Report the following Content Doc elements in the `data` sections:
- `epub:trigger` elements in the `data['epub-triggers']` array
- `epub:switch` elements in the `data['epub-switches']` array

Closes #76
  • Loading branch information
rdeltour committed Oct 29, 2017
1 parent 5680386 commit b18740a
Show file tree
Hide file tree
Showing 26 changed files with 357 additions and 10 deletions.
10 changes: 9 additions & 1 deletion src/checker/checker-epub.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,16 @@ function check(epub, report) {
checkPageSource(assertion, epub);

report.addAssertions(assertion.build());
// Report the Nav Doc

// Report the Nav Doc
report.addEPUBNav(epub.navDoc);

// Report package properties
report.addProperties({
hasManifestFallbacks: epub.hasManifestFallbacks,
hasBindings: epub.hasBindings,
});

return Promise.resolve();
}

Expand Down
3 changes: 3 additions & 0 deletions src/epub/epub-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ EpubParser.prototype.parseData = function(packageDocPath, epubDir) {
const navDocFullPath = path.join(path.dirname(packageDocPath), navDocPath);
this.navDoc = parseNavDoc(navDocFullPath, epubDir);
}

this.hasBindings = select('//opf:bindings', doc).length > 0;
this.hasManifestFallbacks = select('//opf:item[@fallback]', doc).length > 0;
};

EpubParser.prototype.parseContentDocTitle = function(filepath) {
Expand Down
34 changes: 33 additions & 1 deletion src/scripts/ace-extraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ ace.createReport = function(report) {
reportData('audios', ace.getAudios());
reportData('canvases', ace.getCanvases());
reportData('embeds', ace.getEmbeds());
reportData('epub-triggers', ace.getEPUBTriggers());
reportData('epub-switches', ace.getEPUBSwitches());
reportData('iframes', ace.getIframes());
reportData('maps', ace.getMaps());
reportData('scripts`', ace.getScripts());
reportData('scripts', ace.getScripts());
reportData('videos', ace.getVideos());
report.properties = report.properties || {};
report.properties.hasFormElements = ace.hasFormElements();
Expand Down Expand Up @@ -90,6 +92,36 @@ ace.getEmbeds = function() {
return embeds;
}

ace.getEPUBSwitches = function() {
let switchElems = document.querySelectorAll('*|switch');
let switches = [];
switchElems.forEach(function(elem) {
if (elem.namespaceURI === 'http://www.idpf.org/2007/ops') {
let obj = {
cfi: window.daisy.epub.createCFI(elem),
}
if (elem.hasAttribute('id')) obj.id = elem.getAttribute('id');
switches.push(obj);
}
});
return switches;
}

ace.getEPUBTriggers = function() {
let triggerElems = document.querySelectorAll('*|trigger');
let triggers = [];
triggerElems.forEach(function(elem) {
if (elem.namespaceURI === 'http://www.idpf.org/2007/ops') {
let obj = {
cfi: window.daisy.epub.createCFI(elem),
}
if (elem.hasAttribute('id')) obj.id = elem.getAttribute('id');
triggers.push(obj);
}
});
return triggers;
}

ace.getHTMLOutline = function() {
return HTML5Outline(document.body).asHTML();
}
Expand Down
40 changes: 40 additions & 0 deletions src/scripts/ace-extraction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,46 @@ describe('extracting embeds', () => {
});
});

describe('extracting epub:switch', () => {
test('switch with id', async () => {
const results = await run('getEPUBSwitches', '<epub:switch id="foo" />');
expect(results.length).toBe(1);
expect(results[0].html).toBeUndefined();
expect(results[0].id).toEqual('foo');
});

test('embed with no id', async () => {
const results = await run('getEPUBSwitches', '<epub:switch />');
expect(results.length).toBe(1);
expect(results[0].id).toBeUndefined();
});

test('switch in other namespace', async () => {
const results = await run('getEPUBSwitches', '<ex:switch id="foo" xmlns:ex="https://example.com"/>');
expect(results.length).toBe(0);
});
});

describe('extracting epub:trigger', () => {
test('trigger with id', async () => {
const results = await run('getEPUBTriggers', '<epub:trigger id="foo" />');
expect(results.length).toBe(1);
expect(results[0].html).toBeUndefined();
expect(results[0].id).toEqual('foo');
});

test('embed with no id', async () => {
const results = await run('getEPUBTriggers', '<epub:trigger />');
expect(results.length).toBe(1);
expect(results[0].id).toBeUndefined();
});

test('trigger in other namespace', async () => {
const results = await run('getEPUBTriggers', '<ex:trigger id="foo" xmlns:ex="https://example.com"/>');
expect(results.length).toBe(0);
});
});

describe('extracting headings', () => {
test('simple h1', async () => {
const results = await run('getHeadings', '<h1>title 1</h1>');
Expand Down
49 changes: 41 additions & 8 deletions tests/__tests__/report_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,35 @@ describe('check properties', () => {
test('defaults', async () => {
const report = await ace(path.join(__dirname, '../data/base-epub-30'));
expect(report.properties).toMatchObject({
hasBindings: false,
hasManifestFallbacks: false,
hasMathML: false,
hasPageBreaks: false,
hasFormElements: false,
});
});

test('with bindings element', async () => {
const report = await ace(path.join(__dirname, '../data/feat-bindings'));
expect(report.properties).toMatchObject({
hasBindings: true,
});
});

test('with form elements', async () => {
const report = await ace(path.join(__dirname, '../data/feat-forms'));
expect(report.properties).toMatchObject({
hasFormElements: true,
});
});

test('with manifest fallbacks', async () => {
const report = await ace(path.join(__dirname, '../data/feat-manifest-fallbacks'));
expect(report.properties).toMatchObject({
hasManifestFallbacks: true,
});
});

test('with mathml', async () => {
const report = await ace(path.join(__dirname, '../data/feat-mathml'));
expect(report.properties).toMatchObject({
Expand All @@ -97,20 +113,34 @@ describe('check data', () => {
expect(report.data).toEqual({});
});

test('extract images', async () => {
const report = await ace(path.join(__dirname, '../data/feat-image'));
test('extract audios', async () => {
const report = await ace(path.join(__dirname, '../data/feat-audio'));
expect(report.data).toMatchObject({
images: [{
src: 'EPUB/image_001.jpg',
audios: [{
src: 'EPUB/audio_001.mp3',
}],
});
});

test('extract audios', async () => {
const report = await ace(path.join(__dirname, '../data/feat-audio'));
test('extract epub:switch elements', async () => {
const report = await ace(path.join(__dirname, '../data/feat-epub-switch'));
expect(report.data).toMatchObject({
audios: [{
src: 'EPUB/audio_001.mp3',
'epub-switches': [{}],
});
});

test('extract epub:trigger elements', async () => {
const report = await ace(path.join(__dirname, '../data/feat-epub-trigger'));
expect(report.data).toMatchObject({
'epub-triggers': [{}],
});
});

test('extract images', async () => {
const report = await ace(path.join(__dirname, '../data/feat-image'));
expect(report.data).toMatchObject({
images: [{
src: 'EPUB/image_001.jpg',
}],
});
});
Expand All @@ -132,4 +162,7 @@ describe('check data', () => {
}],
});
});

//FIXME extract switch
//FIXME extract trigger
});
10 changes: 10 additions & 0 deletions tests/data/feat-bindings/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
<script></script>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/feat-bindings/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
26 changes: 26 additions & 0 deletions tests/data/feat-bindings/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" properties="scripted"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
<bindings>
<mediaType handler="content_001" media-type="application/x-demo-slideshow"/>
</bindings>
</package>
6 changes: 6 additions & 0 deletions tests/data/feat-bindings/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/feat-bindings/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
17 changes: 17 additions & 0 deletions tests/data/feat-epub-switch/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal EPUB</title>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<epub:switch>
<epub:case required-namespace="http://www.xml-cml.org/schema">
<cml xmlns="http://www.xml-cml.org/schema"/>
</epub:case>
<epub:default>
<div></div>
</epub:default>
</epub:switch>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/feat-epub-switch/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
23 changes: 23 additions & 0 deletions tests/data/feat-epub-switch/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml" properties="switch"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
6 changes: 6 additions & 0 deletions tests/data/feat-epub-switch/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/feat-epub-switch/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
13 changes: 13 additions & 0 deletions tests/data/feat-epub-trigger/EPUB/content_001.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"
xmlns:ev="http://www.w3.org/2001/xml-events" xml:lang="en">
<head>
<title>Minimal EPUB</title>
<epub:trigger ev:observer="pause" ev:event="click" action="pause" ref="test"/>
</head>
<body>
<h1>Loomings</h1>
<p>Call me Ishmael.</p>
<div id="test"></div>
<div id="pause"></div>
</body>
</html>
12 changes: 12 additions & 0 deletions tests/data/feat-epub-trigger/EPUB/nav.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="en">
<head>
<title>Minimal Nav</title>
</head>
<body>
<nav epub:type="toc">
<ol>
<li><a href="content_001.xhtml">content 001</a></li>
</ol>
</nav>
</body>
</html>
23 changes: 23 additions & 0 deletions tests/data/feat-epub-trigger/EPUB/package.opf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="en" unique-identifier="uid">
<metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title id="title">Minimal EPUB 3.0</dc:title>
<dc:language>en</dc:language>
<dc:identifier id="uid">NOID</dc:identifier>
<meta property="dcterms:modified">2017-01-01T00:00:01Z</meta>
<meta property="schema:accessibilityFeature">structuralNavigation</meta>
<meta property="schema:accessibilitySummary">everything OK!</meta>
<meta property="schema:accessibilityHazard">noFlashingHazard</meta>
<meta property="schema:accessibilityHazard">noSoundHazard</meta>
<meta property="schema:accessibilityHazard">noMotionSimulationHazard</meta>
<meta property="schema:accessMode">textual</meta>
<meta property="schema:accessModeSufficient">textual</meta>
</metadata>
<manifest>
<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>
<item id="content_001" href="content_001.xhtml" media-type="application/xhtml+xml"/>
</manifest>
<spine>
<itemref idref="content_001" />
</spine>
</package>
6 changes: 6 additions & 0 deletions tests/data/feat-epub-trigger/META-INF/container.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="EPUB/package.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
1 change: 1 addition & 0 deletions tests/data/feat-epub-trigger/mimetype
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
application/epub+zip
Loading

0 comments on commit b18740a

Please sign in to comment.