]> git.parisson.com Git - pdf.js.git/commitdiff
actually wait for fonts to be loaded, and write out a log of failed eq comparisons
authorChris Jones <jones.chris.g@gmail.com>
Thu, 23 Jun 2011 01:37:58 +0000 (18:37 -0700)
committerChris Jones <jones.chris.g@gmail.com>
Thu, 23 Jun 2011 01:37:58 +0000 (18:37 -0700)
test.py
test_slave.html

diff --git a/test.py b/test.py
index 0c326ec094c14dd8c8f0447244c1582215d7be93..26a86b6ddf55aae1402c215ac4fce3a2da61f54e 100644 (file)
--- a/test.py
+++ b/test.py
@@ -9,6 +9,7 @@ def prompt(question):
 
 ANAL = True
 DEFAULT_MANIFEST_FILE = 'test_manifest.json'
+EQLOG_FILE = 'eq.log'
 REFDIR = 'ref'
 TMPDIR = 'tmp'
 VERBOSE = False
@@ -35,6 +36,7 @@ class State:
     numEqNoSnapshot = 0
     numFBFFailures = 0
     numLoadFailures = 0
+    eqLog = None
 
 class Result:
     def __init__(self, snapshot, failure):
@@ -190,6 +192,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)):
@@ -208,7 +211,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
 
@@ -292,6 +309,12 @@ def main(args):
         masterMode = (args[0] == '-m')
         manifestFile = args[0] if not masterMode else manifestFile
 
+
+
+    masterMode = True
+
+
+
     setUp(manifestFile, masterMode)
 
     server = HTTPServer(('127.0.0.1', 8080), PDFTestHandler)
index 06b911810d1d9d26e78fed3bc673daa63f10635f..718e887e03915a3d6bc5b43f61c29be7438b6ae4 100644 (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() {