1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-24 09:08:07 +02:00

Merge upstream.

This commit is contained in:
Rob Sayre 2011-06-23 09:57:36 -07:00
commit a420cc8733
4 changed files with 141 additions and 56 deletions

View file

@ -11,6 +11,7 @@ DOC_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__),".."))
ANAL = True
DEFAULT_MANIFEST_FILE = 'test_manifest.json'
DEFAULT_BROWSER_MANIFEST_FILE = 'browser_manifest.json'
EQLOG_FILE = 'eq.log'
REFDIR = 'ref'
TMPDIR = 'tmp'
VERBOSE = False
@ -42,7 +43,7 @@ def prompt(question):
MIMEs = {
'.css': 'text/css',
'.html': 'text/html',
'.js': 'application/json',
'.js': 'application/javascript',
'.json': 'application/json',
'.pdf': 'application/pdf',
'.xhtml': 'application/xhtml+xml',
@ -61,6 +62,7 @@ class State:
numEqNoSnapshot = 0
numFBFFailures = 0
numLoadFailures = 0
eqLog = None
class Result:
def __init__(self, snapshot, failure):
@ -191,7 +193,7 @@ def setUp(options):
taskResults.append([ ])
State.taskResults[b.name][id] = taskResults
State.remaining = len(manifestList)
State.remaining = len(testBrowsers) * len(manifestList)
for b in testBrowsers:
print 'Launching', b.name
@ -231,6 +233,7 @@ def check(task, results, browser):
def checkEq(task, results, browser):
pfx = os.path.join(REFDIR, sys.platform, browser, task['id'])
results = results[0]
taskId = task['id']
passed = True
for page in xrange(len(results)):
@ -249,7 +252,21 @@ def checkEq(task, results, browser):
eq = (ref == snapshot)
if not eq:
print 'TEST-UNEXPECTED-FAIL | eq', task['id'], '| in', browser, '| rendering of page', page + 1, '!= reference rendering'
print 'TEST-UNEXPECTED-FAIL | eq', taskId, '| in', browser, '| rendering of page', page + 1, '!= reference rendering'
# XXX need to dump this always, somehow, when we have
# the reference repository
if State.masterMode:
if not State.eqLog:
State.eqLog = open(EQLOG_FILE, 'w')
eqLog = State.eqLog
# NB: this follows the format of Mozilla reftest
# output so that we can reuse its reftest-analyzer
# script
print >>eqLog, 'REFTEST TEST-UNEXPECTED-FAIL |', browser +'-'+ taskId +'-page'+ str(page + 1), '| image comparison (==)'
print >>eqLog, 'REFTEST IMAGE 1 (TEST):', snapshot
print >>eqLog, 'REFTEST IMAGE 2 (REFERENCE):', ref
passed = False
State.numEqFailures += 1

View file

@ -1,6 +1,7 @@
<html>
<head>
<title>pdf.js test slave</title>
<style type="text/css"></style>
<script type="text/javascript" src="/pdf.js"></script>
<script type="text/javascript" src="/fonts.js"></script>
<script type="text/javascript" src="/glyphlist.js"></script>
@ -31,7 +32,7 @@ function load() {
stdout = document.getElementById("stdout");
log("Harness thinks this browser is '"+ browser +"'\n");
log("Fetching manifest ...");
log("Fetching manifest "+ manifestFile +"...");
var r = new XMLHttpRequest();
r.open("GET", manifestFile, false);
@ -81,38 +82,69 @@ function nextPage() {
}
failure = '';
log(" drawing page "+ currentTask.pageNum +"...");
log(" loading page "+ currentTask.pageNum +"... ");
var ctx = canvas.getContext("2d");
clear(ctx);
var fonts = [];
var fontsReady = true;
var gfx = new CanvasGraphics(ctx);
try {
currentPage = pdfDoc.getPage(currentTask.pageNum);
currentPage.compile(gfx, fonts);
// Inspect fonts and translate the missing ones
var count = fonts.length;
for (var i = 0; i < count; ++i) {
var font = fonts[i];
if (Fonts[font.name]) {
fontsReady = fontsReady && !Fonts[font.name].loading;
continue;
}
new Font(font.name, font.file, font.properties);
fontsReady = false;
}
} catch(e) {
failure = 'compile: '+ e.toString();
}
// TODO load fonts
setTimeout(function() {
if (!failure) {
try {
currentPage.display(gfx);
} catch(e) {
failure = 'render: '+ e.toString();
}
var checkFontsLoadedIntervalTimer = null;
function checkFontsLoaded() {
for (var i = 0; i < count; i++) {
if (Fonts[font.name].loading) {
return;
}
currentTask.taskDone = (currentTask.pageNum == pdfDoc.numPages
&& (1 + currentTask.round) == currentTask.rounds);
sendTaskResult(canvas.toDataURL("image/png"));
log("done"+ (failure ? " (failed!)" : "") +"\n");
}
window.clearInterval(checkFontsLoadedIntervalTimer);
++currentTask.pageNum, nextPage();
},
0
);
snapshotCurrentPage(gfx);
}
if (failure || fontsReady) {
snapshotCurrentPage(gfx);
} else {
checkFontsLoadedIntervalTimer = setInterval(checkFontsLoaded, 10);
}
}
function snapshotCurrentPage(gfx) {
log("done, snapshotting... ");
if (!failure) {
try {
currentPage.display(gfx);
} catch(e) {
failure = 'render: '+ e.toString();
}
}
currentTask.taskDone = (currentTask.pageNum == pdfDoc.numPages
&& (1 + currentTask.round) == currentTask.rounds);
sendTaskResult(canvas.toDataURL("image/png"));
log("done"+ (failure ? " (failed!)" : "") +"\n");
++currentTask.pageNum, nextPage();
}
function done() {