pdf.js now exposes table structure attributes, so the struct tree reported for the table in testBasic includes Scope, Headers and element ids. Differential Revision: https://phabricator.services.mozilla.com/D318946
363 lines
9.1 KiB
JavaScript
363 lines
9.1 KiB
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
"use strict";
|
|
|
|
addPdfStructTreeTest(
|
|
"testBasic",
|
|
`
|
|
<h1>h1</h1>
|
|
<p>p1</p>
|
|
<div role="heading" aria-level="2">h2</div>
|
|
<ul>
|
|
<li>uli1</li>
|
|
<li>uli2</li>
|
|
</ul>
|
|
<ol>
|
|
<li>oli</li>
|
|
</ol>
|
|
<table>
|
|
<tr><th>tc1</th><th>tc2</th></tr>
|
|
<tr><th>tc3</th><td>tc4</td></tr>
|
|
</table>
|
|
`,
|
|
[
|
|
{
|
|
role: "Root",
|
|
children: [
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "H1",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["h1"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "P",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["p1"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "H2",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["h2"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "L",
|
|
children: [
|
|
{
|
|
role: "LI",
|
|
children: [
|
|
{ role: "Lbl", children: [{ content: ["•"] }] },
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "uli1"] }],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "LI",
|
|
children: [
|
|
{ role: "Lbl", children: [{ content: ["•"] }] },
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "uli2"] }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "L",
|
|
children: [
|
|
{
|
|
role: "LI",
|
|
children: [
|
|
{ role: "Lbl", children: [{ content: ["1."] }] },
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "oli"] }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "Table",
|
|
children: [
|
|
{
|
|
role: "TR",
|
|
children: [
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["tc1"] }] },
|
|
],
|
|
scope: "Column",
|
|
},
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "tc2"] }],
|
|
},
|
|
],
|
|
structId: "id1",
|
|
scope: "Column",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "TR",
|
|
children: [
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["tc3"] }] },
|
|
],
|
|
structId: "id2",
|
|
scope: "Row",
|
|
},
|
|
{
|
|
role: "TD",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "tc4"] }],
|
|
},
|
|
],
|
|
headers: ["id1", "id2"],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
{ chrome: true, topLevel: true }
|
|
);
|
|
|
|
// A headers attribute naming only a column header retains implicit row headers.
|
|
addPdfStructTreeTest(
|
|
"testTableExplicitHeaders",
|
|
`
|
|
<table>
|
|
<tr><th>c1</th><th id="ch">c2</th></tr>
|
|
<tr><th>r1</th><td headers="ch">d</td></tr>
|
|
</table>
|
|
`,
|
|
[
|
|
{
|
|
role: "Root",
|
|
children: [
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "Table",
|
|
children: [
|
|
{
|
|
role: "TR",
|
|
children: [
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["c1"] }] },
|
|
],
|
|
scope: "Column",
|
|
},
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "c2"] }],
|
|
},
|
|
],
|
|
structId: "id1",
|
|
scope: "Column",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "TR",
|
|
children: [
|
|
{
|
|
role: "TH",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["r1"] }] },
|
|
],
|
|
structId: "id2",
|
|
scope: "Row",
|
|
},
|
|
{
|
|
role: "TD",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: [" ", "d"] }],
|
|
},
|
|
],
|
|
headers: ["id1", "id2"],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
{ chrome: true, topLevel: true }
|
|
);
|
|
|
|
addPdfStructTreeTest(
|
|
"testIframe",
|
|
`<h1>inside</h1>`,
|
|
[
|
|
{
|
|
role: "Root",
|
|
children: [
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "NonStruct", // iframe
|
|
children: [
|
|
// XXX We render an empty marked content sequence before an
|
|
// iframe document for some unknown reason. This is inconsequential.
|
|
{ content: [] },
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "H1",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: ["inside"] }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
{ topLevel: false, iframe: true, remoteIframe: true }
|
|
);
|
|
|
|
addPdfStructTreeTest(
|
|
"testIframeWithSurroundingContent",
|
|
`
|
|
<h1>before</h1>
|
|
<iframe src="data:text/html,<h2>inside</h2>"></iframe>
|
|
<h3>after</h3>
|
|
`,
|
|
[
|
|
{
|
|
role: "Root",
|
|
children: [
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "H1",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["before"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "NonStruct", // iframe
|
|
children: [
|
|
{ content: [] },
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "H2",
|
|
children: [
|
|
{
|
|
role: "NonStruct",
|
|
children: [{ content: ["inside"] }],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
{
|
|
role: "H3",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["after"] }] },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
]
|
|
);
|
|
|
|
addPdfStructTreeTest(
|
|
"testAriaOwns",
|
|
`
|
|
<div aria-owns="h3 h2 h1">
|
|
<h1 id="h1">h1</h1>
|
|
<h2 id="h2">h2</h2>
|
|
</div>
|
|
<h3 id="h3">h3</h3>
|
|
`,
|
|
[
|
|
{
|
|
role: "Root",
|
|
children: [
|
|
{
|
|
role: "Document",
|
|
children: [
|
|
{
|
|
role: "NonStruct", // div
|
|
children: [
|
|
{
|
|
role: "H3",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["h3"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "H2",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["h2"] }] },
|
|
],
|
|
},
|
|
{
|
|
role: "H1",
|
|
children: [
|
|
{ role: "NonStruct", children: [{ content: ["h1"] }] },
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
],
|
|
{ chrome: true, topLevel: true }
|
|
);
|