diff --git a/src/worker.js b/src/worker.js index 9bc43be433367..a312643a283d0 100644 --- a/src/worker.js +++ b/src/worker.js @@ -161,12 +161,20 @@ var WorkerMessageHandler = { var source = data.source; var disableRange = data.disableRange; if (source.data) { - pdfManager = new LocalPdfManager(source.data, source.password); - pdfManagerPromise.resolve(); + try { + pdfManager = new LocalPdfManager(source.data, source.password); + pdfManagerPromise.resolve(); + } catch (ex) { + pdfManagerPromise.reject(ex); + } return pdfManagerPromise; } else if (source.chunkedViewerLoading) { - pdfManager = new NetworkPdfManager(source, handler); - pdfManagerPromise.resolve(); + try { + pdfManager = new NetworkPdfManager(source, handler); + pdfManagerPromise.resolve(); + } catch (ex) { + pdfManagerPromise.reject(ex); + } return pdfManagerPromise; } @@ -203,14 +211,22 @@ var WorkerMessageHandler = { networkManager.abortRequest(fullRequestXhrId); source.length = length; - pdfManager = new NetworkPdfManager(source, handler); - pdfManagerPromise.resolve(pdfManager); + try { + pdfManager = new NetworkPdfManager(source, handler); + pdfManagerPromise.resolve(pdfManager); + } catch (ex) { + pdfManagerPromise.reject(ex); + } }, onDone: function onDone(args) { // the data is array, instantiating directly from it - pdfManager = new LocalPdfManager(args.chunk, source.password); - pdfManagerPromise.resolve(); + try { + pdfManager = new LocalPdfManager(args.chunk, source.password); + pdfManagerPromise.resolve(); + } catch (ex) { + pdfManagerPromise.reject(ex); + } }, onError: function onError(status) { @@ -310,8 +326,8 @@ var WorkerMessageHandler = { pdfManager.onLoadedStream().then(function() { loadDocument(true).then(onSuccess, onFailure); }); - }); - }); + }, onFailure); + }, onFailure); }); handler.on('GetPageRequest', function wphSetupGetPage(data) { diff --git a/test/driver.js b/test/driver.js index 4483f86be5025..d275dd1162bba 100644 --- a/test/driver.js +++ b/test/driver.js @@ -152,6 +152,9 @@ function nextTask() { } function getLastPageNum(task) { + if (!task.pdfDoc) { + return task.firstPage || 1; + } var lastPageNum = task.lastPage || 0; if (!lastPageNum || lastPageNum > task.pdfDoc.numPages) { lastPageNum = task.pdfDoc.numPages; diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 0dd45793f5b71..b8a5231776b97 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -1,4 +1,5 @@ *.pdf +*.error !tracemonkey.pdf !issue2391-1.pdf diff --git a/test/test.py b/test/test.py index 25558b4077dd1..c04abe1992f6f 100644 --- a/test/test.py +++ b/test/test.py @@ -14,6 +14,7 @@ import json, platform, os, shutil, sys, subprocess, tempfile, threading import time, urllib, urllib2, hashlib, re, base64, uuid, socket, errno +import traceback from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer from SocketServer import ThreadingMixIn from optparse import OptionParser @@ -64,8 +65,6 @@ def __init__(self, **kwargs): help="Run the font tests.", default=False) self.add_option("--noDownload", action="store_true", dest="noDownload", help="Skips test PDFs downloading.", default=False) - self.add_option("--ignoreDownloadErrors", action="store_true", dest="ignoreDownloadErrors", - help="Ignores errors during test PDFs downloading.", default=False) self.add_option("--statsFile", action="store", dest="statsFile", type="string", help="The file where to store stats.", default=None) self.add_option("--statsDelay", action="store", dest="statsDelay", type="int", @@ -551,24 +550,29 @@ def downloadLinkedPDF(f): print 'done' -def downloadLinkedPDFs(manifestList, ignoreDownloadErrors): +def downloadLinkedPDFs(manifestList): for item in manifestList: f, isLink = item['file'], item.get('link', False) if isLink and not os.access(f, os.R_OK): try: downloadLinkedPDF(f) except: + exc_type, exc_value, exc_traceback = sys.exc_info() print 'ERROR: Unable to download file "' + f + '".' - if ignoreDownloadErrors: - open(f, 'wb').close() - else: - raise + open(f, 'wb').close() + with open(f + '.error', 'w') as out: + out.write('\n'.join(traceback.format_exception(exc_type, + exc_value, + exc_traceback))) def verifyPDFs(manifestList): error = False for item in manifestList: f = item['file'] - if os.access(f, os.R_OK): + if os.path.isfile(f + '.error'): + print 'WARNING: File was not downloaded. See "' + f + '.error" file.' + error = True + elif os.access(f, os.R_OK): fileMd5 = hashlib.md5(open(f, 'rb').read()).hexdigest() if 'md5' not in item: print 'WARNING: Missing md5 for file "' + f + '".', @@ -615,7 +619,7 @@ def setUp(options): manifestList = json.load(mf) if not options.noDownload: - downloadLinkedPDFs(manifestList, options.ignoreDownloadErrors) + downloadLinkedPDFs(manifestList) if not verifyPDFs(manifestList): print 'Unable to verify the checksum for the files that are used for testing.' @@ -679,8 +683,11 @@ def check(task, results, browser, masterMode): failure = pageResult.failure if failure: failed = True - State.numErrors += 1 - print 'TEST-UNEXPECTED-FAIL | test failed', task['id'], '| in', browser, '| page', p + 1, 'round', r, '|', failure + if os.path.isfile(task['file'] + '.error'): + print 'TEST-SKIPPED | PDF was not downloaded', task['id'], '| in', browser, '| page', p + 1, 'round', r, '|', failure + else: + State.numErrors += 1 + print 'TEST-UNEXPECTED-FAIL | test failed', task['id'], '| in', browser, '| page', p + 1, 'round', r, '|', failure if failed: return