Enable the no-var
linting rule in test/driver.js
This is done automatically with the `gulp lint --fix` command with the only exception of the `annotationLayerContext` variable.
This commit is contained in:
parent
5fd4276dcf
commit
33dc0628a0
@ -12,7 +12,6 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
/* eslint-disable no-var */
|
|
||||||
/* globals pdfjsLib, pdfjsViewer */
|
/* globals pdfjsLib, pdfjsViewer */
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -148,7 +147,7 @@ async function resolveImages(node, silentErrors = false) {
|
|||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
const rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
||||||
const styles = {
|
const styles = {
|
||||||
common: {
|
common: {
|
||||||
file: "./text_layer_test.css",
|
file: "./text_layer_test.css",
|
||||||
@ -165,22 +164,25 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
// Building SVG with size of the viewport.
|
// Building SVG with size of the viewport.
|
||||||
var svg = document.createElementNS(SVG_NS, "svg:svg");
|
const svg = document.createElementNS(SVG_NS, "svg:svg");
|
||||||
svg.setAttribute("width", viewport.width + "px");
|
svg.setAttribute("width", viewport.width + "px");
|
||||||
svg.setAttribute("height", viewport.height + "px");
|
svg.setAttribute("height", viewport.height + "px");
|
||||||
// items are transformed to have 1px font size
|
// items are transformed to have 1px font size
|
||||||
svg.setAttribute("font-size", 1);
|
svg.setAttribute("font-size", 1);
|
||||||
|
|
||||||
// Adding element to host our HTML (style + text layer div).
|
// Adding element to host our HTML (style + text layer div).
|
||||||
var foreignObject = document.createElementNS(SVG_NS, "svg:foreignObject");
|
const foreignObject = document.createElementNS(
|
||||||
|
SVG_NS,
|
||||||
|
"svg:foreignObject"
|
||||||
|
);
|
||||||
foreignObject.setAttribute("x", "0");
|
foreignObject.setAttribute("x", "0");
|
||||||
foreignObject.setAttribute("y", "0");
|
foreignObject.setAttribute("y", "0");
|
||||||
foreignObject.setAttribute("width", viewport.width + "px");
|
foreignObject.setAttribute("width", viewport.width + "px");
|
||||||
foreignObject.setAttribute("height", viewport.height + "px");
|
foreignObject.setAttribute("height", viewport.height + "px");
|
||||||
var style = document.createElement("style");
|
const style = document.createElement("style");
|
||||||
var stylePromise = loadStyles(styles);
|
const stylePromise = loadStyles(styles);
|
||||||
foreignObject.appendChild(style);
|
foreignObject.appendChild(style);
|
||||||
var div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.className = "textLayer";
|
div.className = "textLayer";
|
||||||
foreignObject.appendChild(div);
|
foreignObject.appendChild(div);
|
||||||
|
|
||||||
@ -188,7 +190,7 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
|||||||
style.textContent = cssRules;
|
style.textContent = cssRules;
|
||||||
|
|
||||||
// Rendering text layer as HTML.
|
// Rendering text layer as HTML.
|
||||||
var task = renderTextLayer({
|
const task = renderTextLayer({
|
||||||
textContent,
|
textContent,
|
||||||
container: div,
|
container: div,
|
||||||
viewport,
|
viewport,
|
||||||
@ -211,7 +213,7 @@ var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
|||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
const rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
||||||
/**
|
/**
|
||||||
* For the reference tests, the entire annotation layer must be visible. To
|
* For the reference tests, the entire annotation layer must be visible. To
|
||||||
* achieve this, we load the common styles as used by the viewer and extend
|
* achieve this, we load the common styles as used by the viewer and extend
|
||||||
@ -244,32 +246,35 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
// Building SVG with size of the viewport.
|
// Building SVG with size of the viewport.
|
||||||
var svg = document.createElementNS(SVG_NS, "svg:svg");
|
const svg = document.createElementNS(SVG_NS, "svg:svg");
|
||||||
svg.setAttribute("width", viewport.width + "px");
|
svg.setAttribute("width", viewport.width + "px");
|
||||||
svg.setAttribute("height", viewport.height + "px");
|
svg.setAttribute("height", viewport.height + "px");
|
||||||
|
|
||||||
// Adding element to host our HTML (style + annotation layer div).
|
// Adding element to host our HTML (style + annotation layer div).
|
||||||
var foreignObject = document.createElementNS(SVG_NS, "svg:foreignObject");
|
const foreignObject = document.createElementNS(
|
||||||
|
SVG_NS,
|
||||||
|
"svg:foreignObject"
|
||||||
|
);
|
||||||
foreignObject.setAttribute("x", "0");
|
foreignObject.setAttribute("x", "0");
|
||||||
foreignObject.setAttribute("y", "0");
|
foreignObject.setAttribute("y", "0");
|
||||||
foreignObject.setAttribute("width", viewport.width + "px");
|
foreignObject.setAttribute("width", viewport.width + "px");
|
||||||
foreignObject.setAttribute("height", viewport.height + "px");
|
foreignObject.setAttribute("height", viewport.height + "px");
|
||||||
var style = document.createElement("style");
|
const style = document.createElement("style");
|
||||||
var stylePromise = loadStyles(styles);
|
const stylePromise = loadStyles(styles);
|
||||||
foreignObject.appendChild(style);
|
foreignObject.appendChild(style);
|
||||||
var div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
div.className = "annotationLayer";
|
div.className = "annotationLayer";
|
||||||
|
|
||||||
// Rendering annotation layer as HTML.
|
// Rendering annotation layer as HTML.
|
||||||
const [common, overrides] = await stylePromise;
|
const [common, overrides] = await stylePromise;
|
||||||
style.textContent = common + "\n" + overrides;
|
style.textContent = common + "\n" + overrides;
|
||||||
|
|
||||||
var annotation_viewport = viewport.clone({ dontFlip: true });
|
const annotation_viewport = viewport.clone({ dontFlip: true });
|
||||||
const annotationImageMap = await convertCanvasesToImages(
|
const annotationImageMap = await convertCanvasesToImages(
|
||||||
annotationCanvasMap
|
annotationCanvasMap
|
||||||
);
|
);
|
||||||
|
|
||||||
var parameters = {
|
const parameters = {
|
||||||
viewport: annotation_viewport,
|
viewport: annotation_viewport,
|
||||||
div,
|
div,
|
||||||
annotations,
|
annotations,
|
||||||
@ -298,7 +303,7 @@ var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
|||||||
/**
|
/**
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var rasterizeXfaLayer = (function rasterizeXfaLayerClosure() {
|
const rasterizeXfaLayer = (function rasterizeXfaLayerClosure() {
|
||||||
const styles = {
|
const styles = {
|
||||||
common: {
|
common: {
|
||||||
file: "../web/xfa_layer_builder.css",
|
file: "../web/xfa_layer_builder.css",
|
||||||
@ -390,7 +395,7 @@ class Driver {
|
|||||||
this.end = options.end;
|
this.end = options.end;
|
||||||
|
|
||||||
// Set parameters from the query string
|
// Set parameters from the query string
|
||||||
var parameters = this._getQueryStringParameters();
|
const parameters = this._getQueryStringParameters();
|
||||||
this.browser = parameters.browser;
|
this.browser = parameters.browser;
|
||||||
this.manifestFile = parameters.manifestFile;
|
this.manifestFile = parameters.manifestFile;
|
||||||
this.delay = parameters.delay | 0 || 0;
|
this.delay = parameters.delay | 0 || 0;
|
||||||
@ -428,7 +433,7 @@ class Driver {
|
|||||||
this._log(`Harness thinks this browser is ${this.browser}\n`);
|
this._log(`Harness thinks this browser is ${this.browser}\n`);
|
||||||
this._log('Fetching manifest "' + this.manifestFile + '"... ');
|
this._log('Fetching manifest "' + this.manifestFile + '"... ');
|
||||||
|
|
||||||
var r = new XMLHttpRequest();
|
const r = new XMLHttpRequest();
|
||||||
r.open("GET", this.manifestFile, false);
|
r.open("GET", this.manifestFile, false);
|
||||||
r.onreadystatechange = () => {
|
r.onreadystatechange = () => {
|
||||||
if (r.readyState === 4) {
|
if (r.readyState === 4) {
|
||||||
@ -608,7 +613,7 @@ class Driver {
|
|||||||
if (!task.pdfDoc) {
|
if (!task.pdfDoc) {
|
||||||
return task.firstPage || 1;
|
return task.firstPage || 1;
|
||||||
}
|
}
|
||||||
var lastPageNumber = task.lastPage || 0;
|
let lastPageNumber = task.lastPage || 0;
|
||||||
if (!lastPageNumber || lastPageNumber > task.pdfDoc.numPages) {
|
if (!lastPageNumber || lastPageNumber > task.pdfDoc.numPages) {
|
||||||
lastPageNumber = task.pdfDoc.numPages;
|
lastPageNumber = task.pdfDoc.numPages;
|
||||||
}
|
}
|
||||||
@ -616,11 +621,11 @@ class Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_nextPage(task, loadError) {
|
_nextPage(task, loadError) {
|
||||||
var failure = loadError || "";
|
let failure = loadError || "";
|
||||||
var ctx;
|
let ctx;
|
||||||
|
|
||||||
if (!task.pdfDoc) {
|
if (!task.pdfDoc) {
|
||||||
var dataUrl = this.canvas.toDataURL("image/png");
|
const dataUrl = this.canvas.toDataURL("image/png");
|
||||||
this._sendResult(dataUrl, task, failure, () => {
|
this._sendResult(dataUrl, task, failure, () => {
|
||||||
this._log(
|
this._log(
|
||||||
"done" + (failure ? " (failed !: " + failure + ")" : "") + "\n"
|
"done" + (failure ? " (failed !: " + failure + ")" : "") + "\n"
|
||||||
@ -660,7 +665,7 @@ class Driver {
|
|||||||
ctx = this.canvas.getContext("2d", { alpha: false });
|
ctx = this.canvas.getContext("2d", { alpha: false });
|
||||||
task.pdfDoc.getPage(task.pageNum).then(
|
task.pdfDoc.getPage(task.pageNum).then(
|
||||||
page => {
|
page => {
|
||||||
var viewport = page.getViewport({
|
const viewport = page.getViewport({
|
||||||
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
scale: PixelsPerInch.PDF_TO_CSS_UNITS,
|
||||||
});
|
});
|
||||||
this.canvas.width = viewport.width;
|
this.canvas.width = viewport.width;
|
||||||
@ -668,7 +673,7 @@ class Driver {
|
|||||||
this._clearCanvas();
|
this._clearCanvas();
|
||||||
|
|
||||||
// Initialize various `eq` test subtypes, see comment below.
|
// Initialize various `eq` test subtypes, see comment below.
|
||||||
var renderAnnotations = false,
|
let renderAnnotations = false,
|
||||||
renderForms = false,
|
renderForms = false,
|
||||||
renderPrint = false,
|
renderPrint = false,
|
||||||
renderXfa = false,
|
renderXfa = false,
|
||||||
@ -682,8 +687,8 @@ class Driver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var textLayerCanvas, annotationLayerCanvas;
|
let textLayerCanvas, annotationLayerCanvas, annotationLayerContext;
|
||||||
var initPromise;
|
let initPromise;
|
||||||
if (task.type === "text") {
|
if (task.type === "text") {
|
||||||
// Using a dummy canvas for PDF context drawing operations
|
// Using a dummy canvas for PDF context drawing operations
|
||||||
textLayerCanvas = this.textLayerCanvas;
|
textLayerCanvas = this.textLayerCanvas;
|
||||||
@ -693,14 +698,14 @@ class Driver {
|
|||||||
}
|
}
|
||||||
textLayerCanvas.width = viewport.width;
|
textLayerCanvas.width = viewport.width;
|
||||||
textLayerCanvas.height = viewport.height;
|
textLayerCanvas.height = viewport.height;
|
||||||
var textLayerContext = textLayerCanvas.getContext("2d");
|
const textLayerContext = textLayerCanvas.getContext("2d");
|
||||||
textLayerContext.clearRect(
|
textLayerContext.clearRect(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
textLayerCanvas.width,
|
textLayerCanvas.width,
|
||||||
textLayerCanvas.height
|
textLayerCanvas.height
|
||||||
);
|
);
|
||||||
var enhanceText = !!task.enhance;
|
const enhanceText = !!task.enhance;
|
||||||
// The text builder will draw its content on the test canvas
|
// The text builder will draw its content on the test canvas
|
||||||
initPromise = page
|
initPromise = page
|
||||||
.getTextContent({
|
.getTextContent({
|
||||||
@ -734,8 +739,7 @@ class Driver {
|
|||||||
}
|
}
|
||||||
annotationLayerCanvas.width = viewport.width;
|
annotationLayerCanvas.width = viewport.width;
|
||||||
annotationLayerCanvas.height = viewport.height;
|
annotationLayerCanvas.height = viewport.height;
|
||||||
var annotationLayerContext =
|
annotationLayerContext = annotationLayerCanvas.getContext("2d");
|
||||||
annotationLayerCanvas.getContext("2d");
|
|
||||||
annotationLayerContext.clearRect(
|
annotationLayerContext.clearRect(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
@ -765,7 +769,7 @@ class Driver {
|
|||||||
initPromise = Promise.resolve();
|
initPromise = Promise.resolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var renderContext = {
|
const renderContext = {
|
||||||
canvasContext: ctx,
|
canvasContext: ctx,
|
||||||
viewport,
|
viewport,
|
||||||
optionalContentConfigPromise: task.optionalContentConfigPromise,
|
optionalContentConfigPromise: task.optionalContentConfigPromise,
|
||||||
@ -780,7 +784,7 @@ class Driver {
|
|||||||
renderContext.intent = "print";
|
renderContext.intent = "print";
|
||||||
}
|
}
|
||||||
|
|
||||||
var completeRender = error => {
|
const completeRender = error => {
|
||||||
// if text layer is present, compose it on top of the page
|
// if text layer is present, compose it on top of the page
|
||||||
if (textLayerCanvas) {
|
if (textLayerCanvas) {
|
||||||
ctx.save();
|
ctx.save();
|
||||||
@ -845,7 +849,7 @@ class Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_clearCanvas() {
|
_clearCanvas() {
|
||||||
var ctx = this.canvas.getContext("2d", { alpha: false });
|
const ctx = this.canvas.getContext("2d", { alpha: false });
|
||||||
ctx.beginPath();
|
ctx.beginPath();
|
||||||
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
}
|
}
|
||||||
@ -853,7 +857,7 @@ class Driver {
|
|||||||
_snapshot(task, failure) {
|
_snapshot(task, failure) {
|
||||||
this._log("Snapshotting... ");
|
this._log("Snapshotting... ");
|
||||||
|
|
||||||
var dataUrl = this.canvas.toDataURL("image/png");
|
const dataUrl = this.canvas.toDataURL("image/png");
|
||||||
this._sendResult(dataUrl, task, failure, () => {
|
this._sendResult(dataUrl, task, failure, () => {
|
||||||
this._log(
|
this._log(
|
||||||
"done" + (failure ? " (failed !: " + failure + ")" : "") + "\n"
|
"done" + (failure ? " (failed !: " + failure + ")" : "") + "\n"
|
||||||
@ -868,7 +872,7 @@ class Driver {
|
|||||||
this.end.textContent = "Tests finished. Close this window!";
|
this.end.textContent = "Tests finished. Close this window!";
|
||||||
|
|
||||||
// Send the quit request
|
// Send the quit request
|
||||||
var r = new XMLHttpRequest();
|
const r = new XMLHttpRequest();
|
||||||
r.open("POST", `/tellMeToQuit?browser=${escape(this.browser)}`, false);
|
r.open("POST", `/tellMeToQuit?browser=${escape(this.browser)}`, false);
|
||||||
r.onreadystatechange = function (e) {
|
r.onreadystatechange = function (e) {
|
||||||
if (r.readyState === 4) {
|
if (r.readyState === 4) {
|
||||||
@ -914,7 +918,7 @@ class Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_sendResult(snapshot, task, failure, callback) {
|
_sendResult(snapshot, task, failure, callback) {
|
||||||
var result = JSON.stringify({
|
const result = JSON.stringify({
|
||||||
browser: this.browser,
|
browser: this.browser,
|
||||||
id: task.id,
|
id: task.id,
|
||||||
numPages: task.pdfDoc ? task.lastPage || task.pdfDoc.numPages : 0,
|
numPages: task.pdfDoc ? task.lastPage || task.pdfDoc.numPages : 0,
|
||||||
@ -930,7 +934,7 @@ class Driver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_send(url, message, callback) {
|
_send(url, message, callback) {
|
||||||
var r = new XMLHttpRequest();
|
const r = new XMLHttpRequest();
|
||||||
r.open("POST", url, true);
|
r.open("POST", url, true);
|
||||||
r.setRequestHeader("Content-Type", "application/json");
|
r.setRequestHeader("Content-Type", "application/json");
|
||||||
r.onreadystatechange = e => {
|
r.onreadystatechange = e => {
|
||||||
|
Loading…
Reference in New Issue
Block a user