Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report form elems + unsuppored fallback mechanisms #101

Merged
merged 2 commits into from
Oct 29, 2017
Merged
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
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
39 changes: 38 additions & 1 deletion src/scripts/ace-extraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ 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();
report.properties.hasMathML = ace.hasMathML();
report.properties.hasPageBreaks = ace.hasPageBreaks();
};
Expand Down Expand Up @@ -89,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 Expand Up @@ -237,6 +270,10 @@ ace.getVideos = function() {
return videos;
}

ace.hasFormElements = function() {
return document.querySelectorAll('form, input, button, select, datalist, textarea, option, output, progress, meter').length > 0;
}

ace.hasMathML = function() {
return document.querySelectorAll('math').length > 0;
}
Expand Down
97 changes: 97 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 Expand Up @@ -336,3 +376,60 @@ describe('finding pagebreaks', () => {
expect(results).toBe(true);
});
});

describe('finding form elements', () => {
test('no form elements', async () => {
const results = await run('hasFormElements', '<p>foo</p>');
expect(results).toBe(false);
});

test('form', async () => {
const results = await run('hasFormElements', '<form/>');
expect(results).toBe(true);
});

test('input', async () => {
const results = await run('hasFormElements', '<input/>');
expect(results).toBe(true);
});

test('button', async () => {
const results = await run('hasFormElements', '<button/>');
expect(results).toBe(true);
});

test('select', async () => {
const results = await run('hasFormElements', '<select/>');
expect(results).toBe(true);
});

test('datalist', async () => {
const results = await run('hasFormElements', '<datalist/>');
expect(results).toBe(true);
});

test('textarea', async () => {
const results = await run('hasFormElements', '<textarea/>');
expect(results).toBe(true);
});

test('output', async () => {
const results = await run('hasFormElements', '<output/>');
expect(results).toBe(true);
});

test('progress', async () => {
const results = await run('hasFormElements', '<progress/>');
expect(results).toBe(true);
});

test('meter', async () => {
const results = await run('hasFormElements', '<meter/>');
expect(results).toBe(true);
});

test('option', async () => {
const results = await run('hasFormElements', '<option/>');
expect(results).toBe(true);
});
});
65 changes: 50 additions & 15 deletions tests/__tests__/report_json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,24 +60,42 @@ describe('check assertions', () => {
});

describe('check properties', () => {
test('without mathml', async () => {
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 mathml', async () => {
const report = await ace(path.join(__dirname, '../data/feat-mathml'));
test('with bindings element', async () => {
const report = await ace(path.join(__dirname, '../data/feat-bindings'));
expect(report.properties).toMatchObject({
hasMathML: true,
hasBindings: true,
});
});

test('without page breaks', async () => {
const report = await ace(path.join(__dirname, '../data/base-epub-30'));
test('with form elements', async () => {
const report = await ace(path.join(__dirname, '../data/feat-forms'));
expect(report.properties).toMatchObject({
hasPageBreaks: false,
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({
hasMathML: true,
});
});

Expand All @@ -95,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 @@ -130,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>
Loading