2012-09-01 07:48:21 +09:00
|
|
|
/* Copyright 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2018-03-16 05:49:28 +09:00
|
|
|
/* globals pdfjsLib, pdfjsViewer */
|
2012-09-01 07:48:21 +09:00
|
|
|
|
|
|
|
'use strict';
|
2011-07-11 15:21:13 +09:00
|
|
|
|
2018-02-14 22:49:24 +09:00
|
|
|
const WAITING_TIME = 100; // ms
|
|
|
|
const PDF_TO_CSS_UNITS = 96.0 / 72.0;
|
2018-02-18 00:57:24 +09:00
|
|
|
const CMAP_URL = '../external/bcmaps/';
|
|
|
|
const CMAP_PACKED = true;
|
2018-02-13 21:17:11 +09:00
|
|
|
const IMAGE_RESOURCES_PATH = '/web/images/';
|
2018-02-14 22:49:24 +09:00
|
|
|
const WORKER_SRC = '../build/generic/build/pdf.worker.js';
|
2015-05-15 22:54:48 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
/**
|
|
|
|
* @class
|
2011-07-05 06:17:23 +09:00
|
|
|
*/
|
2015-11-20 02:03:52 +09:00
|
|
|
var rasterizeTextLayer = (function rasterizeTextLayerClosure() {
|
|
|
|
var SVG_NS = 'http://www.w3.org/2000/svg';
|
2011-11-16 07:43:05 +09:00
|
|
|
|
2015-11-20 02:03:52 +09:00
|
|
|
var textLayerStylePromise = null;
|
|
|
|
function getTextLayerStyle() {
|
|
|
|
if (textLayerStylePromise) {
|
|
|
|
return textLayerStylePromise;
|
|
|
|
}
|
|
|
|
textLayerStylePromise = new Promise(function (resolve) {
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', './text_layer_test.css');
|
|
|
|
xhr.onload = function () {
|
|
|
|
resolve(xhr.responseText);
|
|
|
|
};
|
|
|
|
xhr.send(null);
|
|
|
|
});
|
|
|
|
return textLayerStylePromise;
|
2011-08-17 04:17:46 +09:00
|
|
|
}
|
|
|
|
|
2016-08-18 02:56:43 +09:00
|
|
|
function rasterizeTextLayer(ctx, viewport, textContent,
|
|
|
|
enhanceTextSelection) {
|
2018-01-25 09:06:25 +09:00
|
|
|
return new Promise(function (resolve, reject) {
|
2015-11-20 02:03:52 +09:00
|
|
|
// Building SVG with size of the viewport.
|
|
|
|
var svg = document.createElementNS(SVG_NS, 'svg:svg');
|
|
|
|
svg.setAttribute('width', viewport.width + 'px');
|
|
|
|
svg.setAttribute('height', viewport.height + 'px');
|
|
|
|
// items are transformed to have 1px font size
|
|
|
|
svg.setAttribute('font-size', 1);
|
|
|
|
|
|
|
|
// Adding element to host our HTML (style + text layer div).
|
|
|
|
var foreignObject = document.createElementNS(SVG_NS, 'svg:foreignObject');
|
|
|
|
foreignObject.setAttribute('x', '0');
|
|
|
|
foreignObject.setAttribute('y', '0');
|
|
|
|
foreignObject.setAttribute('width', viewport.width + 'px');
|
|
|
|
foreignObject.setAttribute('height', viewport.height + 'px');
|
|
|
|
var style = document.createElement('style');
|
|
|
|
var stylePromise = getTextLayerStyle();
|
|
|
|
foreignObject.appendChild(style);
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.className = 'textLayer';
|
|
|
|
foreignObject.appendChild(div);
|
|
|
|
|
|
|
|
// Rendering text layer as HTML.
|
2018-03-16 05:49:28 +09:00
|
|
|
var task = pdfjsLib.renderTextLayer({
|
2017-04-28 20:40:47 +09:00
|
|
|
textContent,
|
2015-11-20 02:03:52 +09:00
|
|
|
container: div,
|
2017-04-28 20:40:47 +09:00
|
|
|
viewport,
|
|
|
|
enhanceTextSelection,
|
2015-11-20 02:03:52 +09:00
|
|
|
});
|
|
|
|
Promise.all([stylePromise, task.promise]).then(function (results) {
|
2016-08-17 08:06:35 +09:00
|
|
|
task.expandTextDivs(true);
|
2015-11-20 02:03:52 +09:00
|
|
|
style.textContent = results[0];
|
|
|
|
svg.appendChild(foreignObject);
|
|
|
|
|
|
|
|
// We need to have UTF-8 encoded XML.
|
|
|
|
var svg_xml = unescape(encodeURIComponent(
|
|
|
|
(new XMLSerializer()).serializeToString(svg)));
|
|
|
|
var img = new Image();
|
|
|
|
img.src = 'data:image/svg+xml;base64,' + btoa(svg_xml);
|
|
|
|
img.onload = function () {
|
|
|
|
ctx.drawImage(img, 0, 0);
|
|
|
|
resolve();
|
|
|
|
};
|
2018-01-25 09:06:25 +09:00
|
|
|
img.onerror = function(e) {
|
|
|
|
reject(new Error('Error rasterizing text layer ' + e));
|
|
|
|
};
|
2015-11-20 02:03:52 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2011-08-17 04:17:46 +09:00
|
|
|
|
2015-11-20 02:03:52 +09:00
|
|
|
return rasterizeTextLayer;
|
2015-05-15 22:29:43 +09:00
|
|
|
})();
|
2013-02-07 08:19:29 +09:00
|
|
|
|
2015-12-19 06:29:22 +09:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
|
|
|
var rasterizeAnnotationLayer = (function rasterizeAnnotationLayerClosure() {
|
2017-09-11 01:10:43 +09:00
|
|
|
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* them with a set of overrides to make all elements visible.
|
|
|
|
*
|
|
|
|
* Note that we cannot simply use `@import` to import the common styles in
|
|
|
|
* the overrides file because the browser does not resolve that when the
|
|
|
|
* styles are inserted via XHR. Therefore, we load and combine them here.
|
|
|
|
*/
|
|
|
|
let styles = {
|
|
|
|
common: {
|
|
|
|
file: '../web/annotation_layer_builder.css',
|
|
|
|
promise: null,
|
|
|
|
},
|
|
|
|
overrides: {
|
|
|
|
file: './annotation_layer_builder_overrides.css',
|
|
|
|
promise: null,
|
|
|
|
},
|
|
|
|
};
|
2015-12-19 06:29:22 +09:00
|
|
|
|
|
|
|
function getAnnotationLayerStyle() {
|
2017-09-11 01:10:43 +09:00
|
|
|
// Use the cached promises if they are available.
|
|
|
|
if (styles.common.promise && styles.overrides.promise) {
|
|
|
|
return Promise.all([styles.common.promise, styles.overrides.promise]);
|
2015-12-19 06:29:22 +09:00
|
|
|
}
|
2017-09-11 01:10:43 +09:00
|
|
|
|
|
|
|
// Load the style files and cache the results.
|
|
|
|
for (let key in styles) {
|
2018-01-25 09:06:25 +09:00
|
|
|
styles[key].promise = new Promise(function(resolve, reject) {
|
2017-09-11 01:10:43 +09:00
|
|
|
let xhr = new XMLHttpRequest();
|
|
|
|
xhr.open('GET', styles[key].file);
|
|
|
|
xhr.onload = function() {
|
|
|
|
resolve(xhr.responseText);
|
|
|
|
};
|
2018-01-25 09:06:25 +09:00
|
|
|
xhr.onerror = function(e) {
|
|
|
|
reject(new Error('Error fetching annotation style ' + e));
|
|
|
|
};
|
2017-09-11 01:10:43 +09:00
|
|
|
xhr.send(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.all([styles.common.promise, styles.overrides.promise]);
|
2015-12-19 06:29:22 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
function inlineAnnotationImages(images) {
|
|
|
|
var imagePromises = [];
|
|
|
|
for (var i = 0, ii = images.length; i < ii; i++) {
|
2018-01-25 09:06:25 +09:00
|
|
|
var imagePromise = new Promise(function(resolve, reject) {
|
2015-12-19 06:29:22 +09:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
xhr.responseType = 'blob';
|
|
|
|
xhr.onload = function() {
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onloadend = function() {
|
|
|
|
resolve(reader.result);
|
|
|
|
};
|
|
|
|
reader.readAsDataURL(xhr.response);
|
|
|
|
};
|
2018-01-25 09:06:25 +09:00
|
|
|
xhr.onerror = function(e) {
|
|
|
|
reject(new Error('Error fetching inline annotation image ' + e));
|
2015-12-19 06:29:22 +09:00
|
|
|
};
|
|
|
|
xhr.open('GET', images[i].src);
|
|
|
|
xhr.send();
|
|
|
|
});
|
|
|
|
imagePromises.push(imagePromise);
|
|
|
|
}
|
|
|
|
return imagePromises;
|
|
|
|
}
|
|
|
|
|
2016-09-07 23:06:18 +09:00
|
|
|
function rasterizeAnnotationLayer(ctx, viewport, annotations, page,
|
2018-02-13 21:17:11 +09:00
|
|
|
imageResourcesPath,
|
2016-09-07 23:06:18 +09:00
|
|
|
renderInteractiveForms) {
|
2018-01-25 09:06:25 +09:00
|
|
|
return new Promise(function (resolve, reject) {
|
2015-12-19 06:29:22 +09:00
|
|
|
// Building SVG with size of the viewport.
|
|
|
|
var svg = document.createElementNS(SVG_NS, 'svg:svg');
|
|
|
|
svg.setAttribute('width', viewport.width + 'px');
|
|
|
|
svg.setAttribute('height', viewport.height + 'px');
|
|
|
|
|
|
|
|
// Adding element to host our HTML (style + annotation layer div).
|
|
|
|
var foreignObject = document.createElementNS(SVG_NS, 'svg:foreignObject');
|
|
|
|
foreignObject.setAttribute('x', '0');
|
|
|
|
foreignObject.setAttribute('y', '0');
|
|
|
|
foreignObject.setAttribute('width', viewport.width + 'px');
|
|
|
|
foreignObject.setAttribute('height', viewport.height + 'px');
|
|
|
|
var style = document.createElement('style');
|
|
|
|
var stylePromise = getAnnotationLayerStyle();
|
|
|
|
foreignObject.appendChild(style);
|
|
|
|
var div = document.createElement('div');
|
|
|
|
div.className = 'annotationLayer';
|
|
|
|
|
|
|
|
// Rendering annotation layer as HTML.
|
2017-09-11 01:10:43 +09:00
|
|
|
stylePromise.then(function (common, overrides) {
|
|
|
|
style.textContent = common + overrides;
|
2015-12-19 06:29:22 +09:00
|
|
|
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var annotation_viewport = viewport.clone({ dontFlip: true, });
|
2015-12-19 06:29:22 +09:00
|
|
|
var parameters = {
|
|
|
|
viewport: annotation_viewport,
|
2017-04-28 20:40:47 +09:00
|
|
|
div,
|
|
|
|
annotations,
|
|
|
|
page,
|
2018-03-16 05:49:28 +09:00
|
|
|
linkService: new pdfjsViewer.SimpleLinkService(),
|
2018-02-13 21:17:11 +09:00
|
|
|
imageResourcesPath,
|
2017-04-28 20:40:47 +09:00
|
|
|
renderInteractiveForms,
|
2015-12-19 06:29:22 +09:00
|
|
|
};
|
2018-03-16 05:49:28 +09:00
|
|
|
pdfjsLib.AnnotationLayer.render(parameters);
|
2015-12-19 06:29:22 +09:00
|
|
|
|
|
|
|
// Inline SVG images from text annotations.
|
|
|
|
var images = div.getElementsByTagName('img');
|
|
|
|
var imagePromises = inlineAnnotationImages(images);
|
|
|
|
var converted = Promise.all(imagePromises).then(function(data) {
|
2018-01-25 09:06:25 +09:00
|
|
|
var loadedPromises = [];
|
2015-12-19 06:29:22 +09:00
|
|
|
for (var i = 0, ii = data.length; i < ii; i++) {
|
|
|
|
images[i].src = data[i];
|
2018-01-25 09:06:25 +09:00
|
|
|
loadedPromises.push(new Promise(function (resolve, reject) {
|
|
|
|
images[i].onload = resolve;
|
|
|
|
images[i].onerror = function(e) {
|
|
|
|
reject(new Error('Error loading image ' + e));
|
|
|
|
};
|
|
|
|
}));
|
2015-12-19 06:29:22 +09:00
|
|
|
}
|
2018-01-25 09:06:25 +09:00
|
|
|
return loadedPromises;
|
2015-12-19 06:29:22 +09:00
|
|
|
});
|
|
|
|
|
|
|
|
foreignObject.appendChild(div);
|
|
|
|
svg.appendChild(foreignObject);
|
|
|
|
|
|
|
|
// We need to have UTF-8 encoded XML.
|
|
|
|
converted.then(function() {
|
|
|
|
var svg_xml = unescape(encodeURIComponent(
|
|
|
|
(new XMLSerializer()).serializeToString(svg)));
|
|
|
|
var img = new Image();
|
|
|
|
img.src = 'data:image/svg+xml;base64,' + btoa(svg_xml);
|
|
|
|
img.onload = function () {
|
|
|
|
ctx.drawImage(img, 0, 0);
|
|
|
|
resolve();
|
|
|
|
};
|
2018-01-25 09:06:25 +09:00
|
|
|
img.onerror = function(e) {
|
|
|
|
reject(new Error('Error rasterizing annotation layer ' + e));
|
|
|
|
};
|
2015-12-19 06:29:22 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return rasterizeAnnotationLayer;
|
|
|
|
})();
|
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
/**
|
|
|
|
* @typedef {Object} DriverOptions
|
|
|
|
* @property {HTMLSpanElement} inflight - Field displaying the number of
|
|
|
|
* inflight requests.
|
2015-05-16 02:58:34 +09:00
|
|
|
* @property {HTMLInputElement} disableScrolling - Checkbox to disable
|
|
|
|
* automatic scrolling of the output container.
|
|
|
|
* @property {HTMLPreElement} output - Container for all output messages.
|
2015-05-15 22:29:43 +09:00
|
|
|
* @property {HTMLDivElement} end - Container for a completion message.
|
|
|
|
*/
|
2011-07-05 06:17:23 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
/**
|
|
|
|
* @class
|
|
|
|
*/
|
2017-02-05 21:23:42 +09:00
|
|
|
var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
2015-05-15 22:29:43 +09:00
|
|
|
/**
|
|
|
|
* @constructs Driver
|
|
|
|
* @param {DriverOptions} options
|
|
|
|
*/
|
|
|
|
function Driver(options) {
|
2018-02-14 22:49:24 +09:00
|
|
|
// Configure the global worker options.
|
2018-03-16 05:49:28 +09:00
|
|
|
pdfjsLib.GlobalWorkerOptions.workerSrc = WORKER_SRC;
|
2018-02-14 22:49:24 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
// Set the passed options
|
|
|
|
this.inflight = options.inflight;
|
2015-05-16 02:58:34 +09:00
|
|
|
this.disableScrolling = options.disableScrolling;
|
|
|
|
this.output = options.output;
|
2015-05-15 22:29:43 +09:00
|
|
|
this.end = options.end;
|
|
|
|
|
|
|
|
// Set parameters from the query string
|
|
|
|
var parameters = this._getQueryStringParameters();
|
|
|
|
this.browser = parameters.browser;
|
|
|
|
this.manifestFile = parameters.manifestFile;
|
|
|
|
this.appPath = parameters.path;
|
|
|
|
this.delay = (parameters.delay | 0) || 0;
|
|
|
|
this.inFlightRequests = 0;
|
2015-07-11 18:26:53 +09:00
|
|
|
this.testFilter = parameters.testFilter ?
|
|
|
|
JSON.parse(parameters.testFilter) : [];
|
2015-05-15 22:29:43 +09:00
|
|
|
|
|
|
|
// Create a working canvas
|
|
|
|
this.canvas = document.createElement('canvas');
|
2013-01-31 04:31:08 +09:00
|
|
|
}
|
2014-04-10 08:44:07 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
Driver.prototype = {
|
|
|
|
_getQueryStringParameters: function Driver_getQueryStringParameters() {
|
2015-05-15 22:54:48 +09:00
|
|
|
var queryString = window.location.search.substring(1);
|
|
|
|
var values = queryString.split('&');
|
|
|
|
var parameters = {};
|
|
|
|
for (var i = 0, ii = values.length; i < ii; i++) {
|
|
|
|
var value = values[i].split('=');
|
|
|
|
parameters[unescape(value[0])] = unescape(value[1]);
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
2015-05-15 22:54:48 +09:00
|
|
|
return parameters;
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
run: function Driver_run() {
|
2015-05-15 22:54:48 +09:00
|
|
|
var self = this;
|
2016-03-23 07:49:32 +09:00
|
|
|
window.onerror = function(message, source, line, column, error) {
|
|
|
|
self._info('Error: ' + message + ' Script: ' + source + ' Line: ' +
|
2016-12-10 22:28:27 +09:00
|
|
|
line + ' Column: ' + column + ' StackTrace: ' + error);
|
2016-03-23 07:49:32 +09:00
|
|
|
};
|
2015-05-15 22:54:48 +09:00
|
|
|
this._info('User agent: ' + navigator.userAgent);
|
2015-05-15 22:29:43 +09:00
|
|
|
this._log('Harness thinks this browser is "' + this.browser +
|
|
|
|
'" with path "' + this.appPath + '"\n');
|
|
|
|
this._log('Fetching manifest "' + this.manifestFile + '"... ');
|
|
|
|
|
|
|
|
var r = new XMLHttpRequest();
|
|
|
|
r.open('GET', this.manifestFile, false);
|
2015-05-15 22:54:48 +09:00
|
|
|
r.onreadystatechange = function() {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (r.readyState === 4) {
|
|
|
|
self._log('done\n');
|
|
|
|
self.manifest = JSON.parse(r.responseText);
|
2015-07-11 18:26:53 +09:00
|
|
|
if (self.testFilter && self.testFilter.length) {
|
|
|
|
self.manifest = self.manifest.filter(function(item) {
|
2018-02-11 01:06:03 +09:00
|
|
|
return self.testFilter.includes(item.id);
|
2015-07-11 18:26:53 +09:00
|
|
|
});
|
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
self.currentTask = 0;
|
|
|
|
self._nextTask();
|
|
|
|
}
|
|
|
|
};
|
2015-05-15 22:54:48 +09:00
|
|
|
if (this.delay > 0) {
|
|
|
|
this._log('\nDelaying for ' + this.delay + ' ms...\n');
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
|
|
|
// When gathering the stats the numbers seem to be more reliable
|
2015-05-15 22:54:48 +09:00
|
|
|
// if the browser is given more time to start.
|
2015-05-15 22:29:43 +09:00
|
|
|
setTimeout(function() {
|
|
|
|
r.send(null);
|
|
|
|
}, this.delay);
|
|
|
|
},
|
|
|
|
|
2017-05-11 19:54:48 +09:00
|
|
|
_nextTask() {
|
|
|
|
let failure = '';
|
2015-05-15 22:29:43 +09:00
|
|
|
|
2017-05-11 19:54:48 +09:00
|
|
|
this._cleanup().then(() => {
|
|
|
|
if (this.currentTask === this.manifest.length) {
|
|
|
|
this._done();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
let task = this.manifest[this.currentTask];
|
|
|
|
task.round = 0;
|
|
|
|
task.pageNum = task.firstPage || 1;
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
task.stats = { times: [], };
|
2017-05-11 19:54:48 +09:00
|
|
|
|
|
|
|
this._log('Loading file "' + task.file + '"\n');
|
|
|
|
|
|
|
|
let absoluteUrl = new URL(task.file, window.location).href;
|
|
|
|
try {
|
2018-11-08 21:40:06 +09:00
|
|
|
const loadingTask = pdfjsLib.getDocument({
|
2017-05-11 19:54:48 +09:00
|
|
|
url: absoluteUrl,
|
|
|
|
password: task.password,
|
2017-07-11 23:21:50 +09:00
|
|
|
nativeImageDecoderSupport: task.nativeImageDecoderSupport,
|
2018-02-18 00:57:24 +09:00
|
|
|
cMapUrl: CMAP_URL,
|
|
|
|
cMapPacked: CMAP_PACKED,
|
2018-02-18 06:22:10 +09:00
|
|
|
disableRange: task.disableRange,
|
2018-02-18 06:08:45 +09:00
|
|
|
disableAutoFetch: !task.enableAutoFetch,
|
2018-02-18 07:13:49 +09:00
|
|
|
pdfBug: true,
|
2018-11-08 21:40:06 +09:00
|
|
|
});
|
|
|
|
loadingTask.promise.then((doc) => {
|
2017-05-11 19:54:48 +09:00
|
|
|
task.pdfDoc = doc;
|
|
|
|
this._nextPage(task, failure);
|
|
|
|
}, (err) => {
|
|
|
|
failure = 'Loading PDF document: ' + err;
|
|
|
|
this._nextPage(task, failure);
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
} catch (e) {
|
|
|
|
failure = 'Loading PDF document: ' + this._exceptionToString(e);
|
|
|
|
}
|
|
|
|
this._nextPage(task, failure);
|
|
|
|
});
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
2017-05-11 19:54:48 +09:00
|
|
|
_cleanup() {
|
2015-05-15 22:29:43 +09:00
|
|
|
// Clear out all the stylesheets since a new one is created for each font.
|
|
|
|
while (document.styleSheets.length > 0) {
|
2017-05-11 19:54:48 +09:00
|
|
|
let styleSheet = document.styleSheets[0];
|
2015-05-15 22:29:43 +09:00
|
|
|
while (styleSheet.cssRules.length > 0) {
|
|
|
|
styleSheet.deleteRule(0);
|
|
|
|
}
|
2018-02-11 00:19:45 +09:00
|
|
|
styleSheet.ownerNode.remove();
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
2017-05-11 19:54:48 +09:00
|
|
|
let body = document.body;
|
2015-05-15 22:29:43 +09:00
|
|
|
while (body.lastChild !== this.end) {
|
|
|
|
body.removeChild(body.lastChild);
|
|
|
|
}
|
2011-07-05 06:17:23 +09:00
|
|
|
|
2017-05-11 19:54:48 +09:00
|
|
|
let destroyedPromises = [];
|
2015-05-15 22:29:43 +09:00
|
|
|
// Wipe out the link to the pdfdoc so it can be GC'ed.
|
2017-05-11 19:54:48 +09:00
|
|
|
for (let i = 0; i < this.manifest.length; i++) {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (this.manifest[i].pdfDoc) {
|
2017-05-11 19:54:48 +09:00
|
|
|
destroyedPromises.push(this.manifest[i].pdfDoc.destroy());
|
2015-05-15 22:29:43 +09:00
|
|
|
delete this.manifest[i].pdfDoc;
|
|
|
|
}
|
|
|
|
}
|
2017-05-11 19:54:48 +09:00
|
|
|
return Promise.all(destroyedPromises);
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
2011-12-08 13:07:34 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
_exceptionToString: function Driver_exceptionToString(e) {
|
|
|
|
if (typeof e !== 'object') {
|
|
|
|
return String(e);
|
|
|
|
}
|
|
|
|
if (!('message' in e)) {
|
|
|
|
return JSON.stringify(e);
|
|
|
|
}
|
|
|
|
return e.message + ('stack' in e ? ' at ' + e.stack.split('\n')[0] : '');
|
|
|
|
},
|
2011-09-24 23:44:50 +09:00
|
|
|
|
2015-05-15 22:54:48 +09:00
|
|
|
_getLastPageNumber: function Driver_getLastPageNumber(task) {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (!task.pdfDoc) {
|
|
|
|
return task.firstPage || 1;
|
|
|
|
}
|
2015-05-15 22:54:48 +09:00
|
|
|
var lastPageNumber = task.lastPage || 0;
|
|
|
|
if (!lastPageNumber || lastPageNumber > task.pdfDoc.numPages) {
|
|
|
|
lastPageNumber = task.pdfDoc.numPages;
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
2015-05-15 22:54:48 +09:00
|
|
|
return lastPageNumber;
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
_nextPage: function Driver_nextPage(task, loadError) {
|
|
|
|
var self = this;
|
2015-05-15 22:54:48 +09:00
|
|
|
var failure = loadError || '';
|
2015-11-17 01:50:02 +09:00
|
|
|
var ctx;
|
2015-05-15 22:29:43 +09:00
|
|
|
|
|
|
|
if (!task.pdfDoc) {
|
|
|
|
var dataUrl = this.canvas.toDataURL('image/png');
|
|
|
|
this._sendResult(dataUrl, task, failure, function () {
|
|
|
|
self._log('done' + (failure ? ' (failed !: ' + failure + ')' : '') +
|
|
|
|
'\n');
|
|
|
|
self.currentTask++;
|
|
|
|
self._nextTask();
|
2014-01-04 09:17:05 +09:00
|
|
|
});
|
2015-05-15 22:29:43 +09:00
|
|
|
return;
|
|
|
|
}
|
2012-09-16 23:46:29 +09:00
|
|
|
|
2015-05-15 22:54:48 +09:00
|
|
|
if (task.pageNum > this._getLastPageNumber(task)) {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (++task.round < task.rounds) {
|
|
|
|
this._log(' Round ' + (1 + task.round) + '\n');
|
|
|
|
task.pageNum = task.firstPage || 1;
|
2012-09-12 08:04:01 +09:00
|
|
|
} else {
|
2015-05-15 22:29:43 +09:00
|
|
|
this.currentTask++;
|
|
|
|
this._nextTask();
|
|
|
|
return;
|
2012-09-12 08:04:01 +09:00
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
|
|
|
|
2018-02-11 01:06:03 +09:00
|
|
|
if (task.skipPages && task.skipPages.includes(task.pageNum)) {
|
2015-05-15 22:54:48 +09:00
|
|
|
this._log(' Skipping page ' + task.pageNum + '/' +
|
2017-04-06 20:17:52 +09:00
|
|
|
task.pdfDoc.numPages + '...\n');
|
|
|
|
task.pageNum++;
|
|
|
|
this._nextPage(task);
|
2015-05-15 22:29:43 +09:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!failure) {
|
|
|
|
try {
|
2015-05-15 22:54:48 +09:00
|
|
|
this._log(' Loading page ' + task.pageNum + '/' +
|
2015-05-15 22:29:43 +09:00
|
|
|
task.pdfDoc.numPages + '... ');
|
2015-11-17 01:50:02 +09:00
|
|
|
this.canvas.mozOpaque = true;
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
ctx = this.canvas.getContext('2d', { alpha: false, });
|
2015-05-15 22:29:43 +09:00
|
|
|
task.pdfDoc.getPage(task.pageNum).then(function(page) {
|
2018-12-21 19:47:37 +09:00
|
|
|
var viewport = page.getViewport({ scale: PDF_TO_CSS_UNITS, });
|
2015-05-15 22:29:43 +09:00
|
|
|
self.canvas.width = viewport.width;
|
|
|
|
self.canvas.height = viewport.height;
|
2015-05-15 22:54:48 +09:00
|
|
|
self._clearCanvas();
|
2015-05-15 22:29:43 +09:00
|
|
|
|
2016-09-19 05:36:40 +09:00
|
|
|
// Initialize various `eq` test subtypes, see comment below.
|
|
|
|
var renderAnnotations = false, renderForms = false;
|
|
|
|
|
2015-12-19 06:29:22 +09:00
|
|
|
var textLayerCanvas, annotationLayerCanvas;
|
2015-11-20 02:03:52 +09:00
|
|
|
var initPromise;
|
2015-05-15 22:29:43 +09:00
|
|
|
if (task.type === 'text') {
|
|
|
|
// Using a dummy canvas for PDF context drawing operations
|
2015-11-20 02:03:52 +09:00
|
|
|
textLayerCanvas = self.textLayerCanvas;
|
|
|
|
if (!textLayerCanvas) {
|
|
|
|
textLayerCanvas = document.createElement('canvas');
|
|
|
|
self.textLayerCanvas = textLayerCanvas;
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
2015-11-20 02:03:52 +09:00
|
|
|
textLayerCanvas.width = viewport.width;
|
|
|
|
textLayerCanvas.height = viewport.height;
|
|
|
|
var textLayerContext = textLayerCanvas.getContext('2d');
|
|
|
|
textLayerContext.clearRect(0, 0,
|
|
|
|
textLayerCanvas.width, textLayerCanvas.height);
|
2016-08-18 02:56:43 +09:00
|
|
|
var enhanceText = !!task.enhance;
|
2015-05-15 22:29:43 +09:00
|
|
|
// The text builder will draw its content on the test canvas
|
2016-07-04 01:29:47 +09:00
|
|
|
initPromise = page.getTextContent({
|
|
|
|
normalizeWhitespace: true,
|
|
|
|
}).then(function(textContent) {
|
|
|
|
return rasterizeTextLayer(textLayerContext, viewport,
|
2016-08-18 02:56:43 +09:00
|
|
|
textContent, enhanceText);
|
2016-07-04 01:29:47 +09:00
|
|
|
});
|
2015-05-15 22:29:43 +09:00
|
|
|
} else {
|
2015-11-20 02:03:52 +09:00
|
|
|
textLayerCanvas = null;
|
2016-09-19 05:36:40 +09:00
|
|
|
// We fetch the `eq` specific test subtypes here, to avoid
|
|
|
|
// accidentally changing the behaviour for other types of tests.
|
|
|
|
renderAnnotations = !!task.annotations;
|
|
|
|
renderForms = !!task.forms;
|
2015-12-19 06:29:22 +09:00
|
|
|
|
|
|
|
// Render the annotation layer if necessary.
|
2016-09-19 05:36:40 +09:00
|
|
|
if (renderAnnotations || renderForms) {
|
2015-12-19 06:29:22 +09:00
|
|
|
// Create a dummy canvas for the drawing operations.
|
|
|
|
annotationLayerCanvas = self.annotationLayerCanvas;
|
|
|
|
if (!annotationLayerCanvas) {
|
|
|
|
annotationLayerCanvas = document.createElement('canvas');
|
|
|
|
self.annotationLayerCanvas = annotationLayerCanvas;
|
|
|
|
}
|
|
|
|
annotationLayerCanvas.width = viewport.width;
|
|
|
|
annotationLayerCanvas.height = viewport.height;
|
|
|
|
var annotationLayerContext =
|
|
|
|
annotationLayerCanvas.getContext('2d');
|
|
|
|
annotationLayerContext.clearRect(0, 0,
|
|
|
|
annotationLayerCanvas.width, annotationLayerCanvas.height);
|
|
|
|
|
|
|
|
// The annotation builder will draw its content on the canvas.
|
|
|
|
initPromise =
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
page.getAnnotations({ intent: 'display', }).then(
|
2015-12-19 06:29:22 +09:00
|
|
|
function(annotations) {
|
|
|
|
return rasterizeAnnotationLayer(annotationLayerContext,
|
|
|
|
viewport, annotations,
|
2018-02-13 21:17:11 +09:00
|
|
|
page,
|
|
|
|
IMAGE_RESOURCES_PATH,
|
|
|
|
renderForms);
|
2015-12-19 06:29:22 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
annotationLayerCanvas = null;
|
|
|
|
initPromise = Promise.resolve();
|
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
2015-12-19 06:29:22 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
var renderContext = {
|
2015-11-20 02:03:52 +09:00
|
|
|
canvasContext: ctx,
|
2017-04-28 20:40:47 +09:00
|
|
|
viewport,
|
2016-09-19 05:36:40 +09:00
|
|
|
renderInteractiveForms: renderForms,
|
2015-05-15 22:29:43 +09:00
|
|
|
};
|
|
|
|
var completeRender = (function(error) {
|
2015-11-20 02:03:52 +09:00
|
|
|
// if text layer is present, compose it on top of the page
|
|
|
|
if (textLayerCanvas) {
|
|
|
|
ctx.save();
|
|
|
|
ctx.globalCompositeOperation = 'screen';
|
|
|
|
ctx.fillStyle = 'rgb(128, 255, 128)'; // making it green
|
|
|
|
ctx.fillRect(0, 0, viewport.width, viewport.height);
|
|
|
|
ctx.restore();
|
|
|
|
ctx.drawImage(textLayerCanvas, 0, 0);
|
|
|
|
}
|
2015-12-19 06:29:22 +09:00
|
|
|
// If we have annotation layer, compose it on top of the page.
|
|
|
|
if (annotationLayerCanvas) {
|
|
|
|
ctx.drawImage(annotationLayerCanvas, 0, 0);
|
|
|
|
}
|
[api-major] Only create a `StatTimer` for pages when `enableStats == true` (issue 5215)
Unless the debugging tools (i.e. `PDFBug`) are enabled, or the `browsertest` is running, the `PDFPageProxy.stats` aren't actually used for anything.
Rather than initializing unnecessary `StatTimer` instances, we can simply re-use *one* dummy class (with static methods) for every page. Note that by using a dummy `StatTimer` in this way, rather than letting `PDFPageProxy.stats` be undefined, we don't need to guard *every* single stats collection callsite.
Since it wouldn't make much sense to attempt to use `PDFPageProxy.stats` when stat collection is disabled, it was instead changed to a "private" property (i.e. `PDFPageProxy._stats`) and a getter was added for accessing `PDFPageProxy.stats`. This getter will now return `null` when stat collection is disabled, making that case easy to handle.
For benchmarking purposes, the test-suite used to re-create the `StatTimer` after loading/rendering each page. However, modifying properties on various API code from the outside in this way seems very error-prone, and is an anti-pattern that we really should avoid at all cost. Hence the `PDFPageProxy.cleanup` method was modified to accept an optional parameter, which will take care of resetting `this.stats` when necessary, and `test/driver.js` was updated accordingly.
Finally, a tiny bit more validation was added on the viewer side, to ensure that all the code we're attempting to access is defined when handling `PDFPageProxy` stats.
2017-12-07 00:30:04 +09:00
|
|
|
if (page.stats) { // Get the page stats *before* running cleanup.
|
|
|
|
task.stats = page.stats;
|
|
|
|
}
|
|
|
|
page.cleanup(/* resetStats = */ true);
|
2015-05-15 22:29:43 +09:00
|
|
|
self._snapshot(task, error);
|
|
|
|
});
|
|
|
|
initPromise.then(function () {
|
2018-01-25 09:06:25 +09:00
|
|
|
return page.render(renderContext).promise.then(function() {
|
2015-05-15 22:29:43 +09:00
|
|
|
completeRender(false);
|
|
|
|
});
|
2018-01-25 09:06:25 +09:00
|
|
|
}).catch(function (error) {
|
|
|
|
completeRender('render : ' + error);
|
2015-05-15 22:29:43 +09:00
|
|
|
});
|
2013-06-06 04:28:31 +09:00
|
|
|
},
|
|
|
|
function(error) {
|
2015-05-15 22:29:43 +09:00
|
|
|
self._snapshot(task, 'render : ' + error);
|
2013-06-06 04:28:31 +09:00
|
|
|
});
|
2015-05-15 22:29:43 +09:00
|
|
|
} catch (e) {
|
|
|
|
failure = 'page setup : ' + this._exceptionToString(e);
|
|
|
|
this._snapshot(task, failure);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_clearCanvas: function Driver_clearCanvas() {
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
var ctx = this.canvas.getContext('2d', { alpha: false, });
|
2015-05-15 22:29:43 +09:00
|
|
|
ctx.beginPath();
|
|
|
|
ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
|
|
},
|
|
|
|
|
|
|
|
_snapshot: function Driver_snapshot(task, failure) {
|
|
|
|
var self = this;
|
2015-05-15 22:54:48 +09:00
|
|
|
this._log('Snapshotting... ');
|
2015-05-15 22:29:43 +09:00
|
|
|
|
|
|
|
var dataUrl = this.canvas.toDataURL('image/png');
|
|
|
|
this._sendResult(dataUrl, task, failure, function () {
|
|
|
|
self._log('done' + (failure ? ' (failed !: ' + failure + ')' : '') +
|
|
|
|
'\n');
|
|
|
|
task.pageNum++;
|
|
|
|
self._nextPage(task);
|
2012-04-12 10:05:43 +09:00
|
|
|
});
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
_quit: function Driver_quit() {
|
|
|
|
this._log('Done !');
|
2015-05-15 22:54:48 +09:00
|
|
|
this.end.textContent = 'Tests finished. Close this window!';
|
2015-05-15 22:29:43 +09:00
|
|
|
|
2015-05-15 22:54:48 +09:00
|
|
|
// Send the quit request
|
2015-05-15 22:29:43 +09:00
|
|
|
var r = new XMLHttpRequest();
|
|
|
|
r.open('POST', '/tellMeToQuit?path=' + escape(this.appPath), false);
|
2015-05-15 22:54:48 +09:00
|
|
|
r.onreadystatechange = function(e) {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (r.readyState === 4) {
|
2015-05-15 22:54:48 +09:00
|
|
|
window.close();
|
2015-05-15 22:29:43 +09:00
|
|
|
}
|
|
|
|
};
|
|
|
|
r.send(null);
|
|
|
|
},
|
|
|
|
|
|
|
|
_info: function Driver_info(message) {
|
|
|
|
this._send('/info', JSON.stringify({
|
|
|
|
browser: this.browser,
|
2017-04-28 20:40:47 +09:00
|
|
|
message,
|
2015-05-15 22:29:43 +09:00
|
|
|
}));
|
|
|
|
},
|
|
|
|
|
2015-05-15 22:54:48 +09:00
|
|
|
_log: function Driver_log(message) {
|
|
|
|
// Using insertAdjacentHTML yields a large performance gain and
|
|
|
|
// reduces runtime significantly.
|
|
|
|
if (this.output.insertAdjacentHTML) {
|
|
|
|
this.output.insertAdjacentHTML('BeforeEnd', message);
|
2015-05-15 22:29:43 +09:00
|
|
|
} else {
|
2015-05-15 22:54:48 +09:00
|
|
|
this.output.textContent += message;
|
2014-04-12 03:02:03 +09:00
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
|
2015-05-16 02:58:34 +09:00
|
|
|
if (message.lastIndexOf('\n') >= 0 && !this.disableScrolling.checked) {
|
2015-05-15 22:29:43 +09:00
|
|
|
// Scroll to the bottom of the page
|
2015-05-16 02:58:34 +09:00
|
|
|
this.output.scrollTop = this.output.scrollHeight;
|
2012-12-05 03:28:25 +09:00
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
_done: function Driver_done() {
|
|
|
|
if (this.inFlightRequests > 0) {
|
2015-05-15 22:54:48 +09:00
|
|
|
this.inflight.textContent = this.inFlightRequests;
|
2015-07-11 18:26:53 +09:00
|
|
|
setTimeout(this._done.bind(this), WAITING_TIME);
|
2015-05-15 22:29:43 +09:00
|
|
|
} else {
|
2015-07-11 18:26:53 +09:00
|
|
|
setTimeout(this._quit.bind(this), WAITING_TIME);
|
2014-03-25 21:29:53 +09:00
|
|
|
}
|
2015-05-15 22:29:43 +09:00
|
|
|
},
|
|
|
|
|
|
|
|
_sendResult: function Driver_sendResult(snapshot, task, failure,
|
|
|
|
callback) {
|
|
|
|
var result = JSON.stringify({
|
|
|
|
browser: this.browser,
|
|
|
|
id: task.id,
|
|
|
|
numPages: task.pdfDoc ?
|
|
|
|
(task.lastPage || task.pdfDoc.numPages) : 0,
|
2015-05-15 22:54:48 +09:00
|
|
|
lastPageNum: this._getLastPageNumber(task),
|
2017-04-28 20:40:47 +09:00
|
|
|
failure,
|
2015-05-15 22:29:43 +09:00
|
|
|
file: task.file,
|
|
|
|
round: task.round,
|
|
|
|
page: task.pageNum,
|
2017-04-28 20:40:47 +09:00
|
|
|
snapshot,
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
stats: task.stats.times,
|
2015-05-15 22:29:43 +09:00
|
|
|
});
|
|
|
|
this._send('/submit_task_results', result, callback);
|
|
|
|
},
|
|
|
|
|
|
|
|
_send: function Driver_send(url, message, callback) {
|
|
|
|
var self = this;
|
|
|
|
var r = new XMLHttpRequest();
|
|
|
|
r.open('POST', url, true);
|
|
|
|
r.setRequestHeader('Content-Type', 'application/json');
|
2015-05-15 22:54:48 +09:00
|
|
|
r.onreadystatechange = function(e) {
|
2015-05-15 22:29:43 +09:00
|
|
|
if (r.readyState === 4) {
|
|
|
|
self.inFlightRequests--;
|
|
|
|
|
|
|
|
// Retry until successful
|
|
|
|
if (r.status !== 200) {
|
|
|
|
setTimeout(function() {
|
|
|
|
self._send(url, message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-05-15 22:54:48 +09:00
|
|
|
this.inflight.textContent = this.inFlightRequests++;
|
2015-05-15 22:29:43 +09:00
|
|
|
r.send(message);
|
Fix inconsistent spacing and trailing commas in objects in `test/` files, so we can enable the `comma-dangle` and `object-curly-spacing` ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing
Given that we currently have quite inconsistent object formatting, fixing this in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.
Please note: This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.
```diff
diff --git a/test/chromium/test-telemetry.js b/test/chromium/test-telemetry.js
index cc412a31..2e5bdfa1 100755
--- a/test/chromium/test-telemetry.js
+++ b/test/chromium/test-telemetry.js
@@ -324,7 +324,7 @@ var tests = [
var window = createExtensionGlobal();
telemetryScript.runInNewContext(window);
window.chrome.runtime.getManifest = function() {
- return { version: '1.0.1', };
+ return { version: '1.0.1', };
};
window.Date.test_now_value += 12 * 36E5;
telemetryScript.runInNewContext(window);
diff --git a/test/unit/api_spec.js b/test/unit/api_spec.js
index 1f00747a..f22988e7 100644
--- a/test/unit/api_spec.js
+++ b/test/unit/api_spec.js
@@ -503,8 +503,9 @@ describe('api', function() {
it('gets destinations, from /Dests dictionary', function(done) {
var promise = doc.getDestinations();
promise.then(function(data) {
- expect(data).toEqual({ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', },
- 0, 841.89, null], });
+ expect(data).toEqual({
+ chapter1: [{ gen: 0, num: 17, }, { name: 'XYZ', }, 0, 841.89, null],
+ });
done();
}).catch(function (reason) {
done.fail(reason);
diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js
index 66441212..62127eb9 100644
--- a/test/unit/function_spec.js
+++ b/test/unit/function_spec.js
@@ -492,9 +492,11 @@ describe('function', function() {
it('check compiled mul', function() {
check([0.25, 0.5, 'mul'], [], [0, 1], [{ input: [], output: [0.125], }]);
check([0, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
- check([0.5, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.125], }]);
+ check([0.5, 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0.125], }]);
check([1, 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0.25], }]);
- check([0, 'exch', 'mul'], [0, 1], [0, 1], [{ input: [0.25], output: [0], }]);
+ check([0, 'exch', 'mul'], [0, 1], [0, 1],
+ [{ input: [0.25], output: [0], }]);
check([0.5, 'exch', 'mul'], [0, 1], [0, 1],
[{ input: [0.25], output: [0.125], }]);
check([1, 'exch', 'mul'], [0, 1], [0, 1],
```
2017-06-02 19:55:01 +09:00
|
|
|
},
|
2011-09-16 05:32:44 +09:00
|
|
|
};
|
2013-05-31 08:33:05 +09:00
|
|
|
|
2015-05-15 22:29:43 +09:00
|
|
|
return Driver;
|
|
|
|
})();
|