Convert the Driver
class to ES6 syntax in test/driver.js
This commit is contained in:
parent
3264d72e60
commit
a58700b0dc
@ -393,17 +393,12 @@ var rasterizeXfaLayer = (function rasterizeXfaLayerClosure() {
|
||||
* @property {HTMLDivElement} end - Container for a completion message.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @class
|
||||
*/
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
var Driver = (function DriverClosure() {
|
||||
class Driver {
|
||||
/**
|
||||
* @constructs Driver
|
||||
* @param {DriverOptions} options
|
||||
*/
|
||||
// eslint-disable-next-line no-shadow
|
||||
function Driver(options) {
|
||||
constructor(options) {
|
||||
// Configure the global worker options.
|
||||
GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
||||
|
||||
@ -428,13 +423,12 @@ var Driver = (function DriverClosure() {
|
||||
this.canvas = document.createElement("canvas");
|
||||
}
|
||||
|
||||
Driver.prototype = {
|
||||
_getQueryStringParameters: function Driver_getQueryStringParameters() {
|
||||
_getQueryStringParameters() {
|
||||
const queryString = window.location.search.substring(1);
|
||||
return Object.fromEntries(new URLSearchParams(queryString).entries());
|
||||
},
|
||||
}
|
||||
|
||||
run: function Driver_run() {
|
||||
run() {
|
||||
var self = this;
|
||||
window.onerror = function (message, source, line, column, error) {
|
||||
self._info(
|
||||
@ -483,7 +477,7 @@ var Driver = (function DriverClosure() {
|
||||
setTimeout(function () {
|
||||
r.send(null);
|
||||
}, this.delay);
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
* A debugging tool to log to the terminal while tests are running.
|
||||
@ -501,7 +495,7 @@ var Driver = (function DriverClosure() {
|
||||
}
|
||||
|
||||
this._info(`${id}: ${msg}`);
|
||||
},
|
||||
}
|
||||
|
||||
_nextTask() {
|
||||
let failure = "";
|
||||
@ -570,13 +564,11 @@ var Driver = (function DriverClosure() {
|
||||
}
|
||||
|
||||
task.pdfDoc = doc;
|
||||
task.optionalContentConfigPromise =
|
||||
doc.getOptionalContentConfig();
|
||||
task.optionalContentConfigPromise = doc.getOptionalContentConfig();
|
||||
|
||||
if (task.optionalContent) {
|
||||
const entries = Object.entries(task.optionalContent),
|
||||
optionalContentConfig =
|
||||
await task.optionalContentConfigPromise;
|
||||
optionalContentConfig = await task.optionalContentConfigPromise;
|
||||
for (const [id, visible] of entries) {
|
||||
optionalContentConfig.setVisibility(id, visible);
|
||||
}
|
||||
@ -595,7 +587,7 @@ var Driver = (function DriverClosure() {
|
||||
}
|
||||
this._nextPage(task, failure);
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
_cleanup() {
|
||||
// Clear out all the stylesheets since a new one is created for each font.
|
||||
@ -620,9 +612,9 @@ var Driver = (function DriverClosure() {
|
||||
}
|
||||
}
|
||||
return Promise.all(destroyedPromises);
|
||||
},
|
||||
}
|
||||
|
||||
_exceptionToString: function Driver_exceptionToString(e) {
|
||||
_exceptionToString(e) {
|
||||
if (typeof e !== "object") {
|
||||
return String(e);
|
||||
}
|
||||
@ -630,9 +622,9 @@ var Driver = (function DriverClosure() {
|
||||
return JSON.stringify(e);
|
||||
}
|
||||
return e.message + ("stack" in e ? " at " + e.stack.split("\n")[0] : "");
|
||||
},
|
||||
}
|
||||
|
||||
_getLastPageNumber: function Driver_getLastPageNumber(task) {
|
||||
_getLastPageNumber(task) {
|
||||
if (!task.pdfDoc) {
|
||||
return task.firstPage || 1;
|
||||
}
|
||||
@ -641,9 +633,9 @@ var Driver = (function DriverClosure() {
|
||||
lastPageNumber = task.pdfDoc.numPages;
|
||||
}
|
||||
return lastPageNumber;
|
||||
},
|
||||
}
|
||||
|
||||
_nextPage: function Driver_nextPage(task, loadError) {
|
||||
_nextPage(task, loadError) {
|
||||
var self = this;
|
||||
var failure = loadError || "";
|
||||
var ctx;
|
||||
@ -673,11 +665,7 @@ var Driver = (function DriverClosure() {
|
||||
|
||||
if (task.skipPages && task.skipPages.includes(task.pageNum)) {
|
||||
this._log(
|
||||
" Skipping page " +
|
||||
task.pageNum +
|
||||
"/" +
|
||||
task.pdfDoc.numPages +
|
||||
"...\n"
|
||||
" Skipping page " + task.pageNum + "/" + task.pdfDoc.numPages + "...\n"
|
||||
);
|
||||
task.pageNum++;
|
||||
this._nextPage(task);
|
||||
@ -687,11 +675,7 @@ var Driver = (function DriverClosure() {
|
||||
if (!failure) {
|
||||
try {
|
||||
this._log(
|
||||
" Loading page " +
|
||||
task.pageNum +
|
||||
"/" +
|
||||
task.pdfDoc.numPages +
|
||||
"... "
|
||||
" Loading page " + task.pageNum + "/" + task.pdfDoc.numPages + "... "
|
||||
);
|
||||
this.canvas.mozOpaque = true;
|
||||
ctx = this.canvas.getContext("2d", { alpha: false });
|
||||
@ -879,15 +863,15 @@ var Driver = (function DriverClosure() {
|
||||
this._snapshot(task, failure);
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_clearCanvas: function Driver_clearCanvas() {
|
||||
_clearCanvas() {
|
||||
var ctx = this.canvas.getContext("2d", { alpha: false });
|
||||
ctx.beginPath();
|
||||
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||
},
|
||||
}
|
||||
|
||||
_snapshot: function Driver_snapshot(task, failure) {
|
||||
_snapshot(task, failure) {
|
||||
var self = this;
|
||||
this._log("Snapshotting... ");
|
||||
|
||||
@ -899,9 +883,9 @@ var Driver = (function DriverClosure() {
|
||||
task.pageNum++;
|
||||
self._nextPage(task);
|
||||
});
|
||||
},
|
||||
}
|
||||
|
||||
_quit: function Driver_quit() {
|
||||
_quit() {
|
||||
this._log("Done !");
|
||||
this.end.textContent = "Tests finished. Close this window!";
|
||||
|
||||
@ -914,9 +898,9 @@ var Driver = (function DriverClosure() {
|
||||
}
|
||||
};
|
||||
r.send(null);
|
||||
},
|
||||
}
|
||||
|
||||
_info: function Driver_info(message) {
|
||||
_info(message) {
|
||||
this._send(
|
||||
"/info",
|
||||
JSON.stringify({
|
||||
@ -924,9 +908,9 @@ var Driver = (function DriverClosure() {
|
||||
message,
|
||||
})
|
||||
);
|
||||
},
|
||||
}
|
||||
|
||||
_log: function Driver_log(message) {
|
||||
_log(message) {
|
||||
// Using insertAdjacentHTML yields a large performance gain and
|
||||
// reduces runtime significantly.
|
||||
if (this.output.insertAdjacentHTML) {
|
||||
@ -940,18 +924,18 @@ var Driver = (function DriverClosure() {
|
||||
// Scroll to the bottom of the page
|
||||
this.output.scrollTop = this.output.scrollHeight;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_done: function Driver_done() {
|
||||
_done() {
|
||||
if (this.inFlightRequests > 0) {
|
||||
this.inflight.textContent = this.inFlightRequests;
|
||||
setTimeout(this._done.bind(this), WAITING_TIME);
|
||||
} else {
|
||||
setTimeout(this._quit.bind(this), WAITING_TIME);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
_sendResult: function Driver_sendResult(snapshot, task, failure, callback) {
|
||||
_sendResult(snapshot, task, failure, callback) {
|
||||
var result = JSON.stringify({
|
||||
browser: this.browser,
|
||||
id: task.id,
|
||||
@ -965,9 +949,9 @@ var Driver = (function DriverClosure() {
|
||||
stats: task.stats.times,
|
||||
});
|
||||
this._send("/submit_task_results", result, callback);
|
||||
},
|
||||
}
|
||||
|
||||
_send: function Driver_send(url, message, callback) {
|
||||
_send(url, message, callback) {
|
||||
var self = this;
|
||||
var r = new XMLHttpRequest();
|
||||
r.open("POST", url, true);
|
||||
@ -989,8 +973,5 @@ var Driver = (function DriverClosure() {
|
||||
};
|
||||
this.inflight.textContent = this.inFlightRequests++;
|
||||
r.send(message);
|
||||
},
|
||||
};
|
||||
|
||||
return Driver;
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user