From 58150885866c1afba9e3c5519306228f945b543b Mon Sep 17 00:00:00 2001 From: Martynas Bagdonas Date: Thu, 18 Jan 2018 12:23:27 +0200 Subject: [PATCH] Fix PDF tools usage in tests --- chrome/content/zotero/xpcom/fulltext.js | 42 ++++++++++++++++--------- test/content/runtests.js | 28 +++++++++++++++++ test/runtests.sh | 9 ++++++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index 45efcc6db4..9c7e656881 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -26,8 +26,6 @@ Zotero.Fulltext = Zotero.FullText = new function(){ this.isCachedMIMEType = isCachedMIMEType; - this.__defineGetter__("pdfConverterName", function() { return 'pdftotext'; }); - this.__defineGetter__("pdfInfoName", function() { return 'pdfinfo'; }); this.__defineGetter__("pdfConverterCacheFile", function () { return '.zotero-ft-cache'; }); this.__defineGetter__("pdfInfoCacheFile", function () { return '.zotero-ft-info'; }); @@ -54,11 +52,9 @@ Zotero.Fulltext = Zotero.FullText = new function(){ const kWbClassHWKatakanaLetter = 6; const kWbClassThaiLetter = 7; - var _pdfConverterFileName = null; var _pdfConverter = null; // nsIFile to executable - var _pdfInfoFileName = null; var _pdfInfo = null; // nsIFile to executable - var _popplerDatadir = null; + var _pdfData = null; var _idleObserverIsRegistered = false; var _idleObserverDelay = 30; @@ -74,19 +70,19 @@ Zotero.Fulltext = Zotero.FullText = new function(){ this.decoder = Components.classes["@mozilla.org/intl/utf8converterservice;1"]. getService(Components.interfaces.nsIUTF8ConverterService); - _pdfConverterFileName = this.pdfConverterName; - _pdfInfoFileName = this.pdfInfoName; + let pdfConverterFileName = "pdftotext"; + let pdfInfoFileName = "pdfinfo"; if (Zotero.isWin) { - _pdfConverterFileName += '.exe'; - _pdfInfoFileName += '.exe'; + pdfConverterFileName += '.exe'; + pdfInfoFileName += '.exe'; } let dir = FileUtils.getFile('AChrom', []).parent; - _popplerDatadir = dir.clone(); - _popplerDatadir.append('poppler-data'); - _popplerDatadir = _popplerDatadir.path; + _pdfData = dir.clone(); + _pdfData.append('poppler-data'); + _pdfData = _pdfData.path; _pdfConverter = dir.clone(); _pdfInfo = dir.clone(); @@ -99,8 +95,8 @@ Zotero.Fulltext = Zotero.FullText = new function(){ _pdfInfo.append('MacOS'); } - _pdfConverter.append(_pdfConverterFileName); - _pdfInfo.append(_pdfInfoFileName); + _pdfConverter.append(pdfConverterFileName); + _pdfInfo.append(pdfInfoFileName); Zotero.uiReadyPromise.delay(30000).then(() => { this.registerContentProcessor(); @@ -135,6 +131,22 @@ Zotero.Fulltext = Zotero.FullText = new function(){ }); + this.setPDFConverterPath = function(path) { + _pdfConverter = Zotero.File.pathToFile(path); + }; + + + this.setPDFInfoPath = function(path) { + _pdfInfo = Zotero.File.pathToFile(path); + + }; + + + this.setPDFDataPath = function(path) { + _pdfData = path; + }; + + this.getLibraryVersion = function (libraryID) { if (!libraryID) throw new Error("libraryID not provided"); return Zotero.DB.valueQueryAsync( @@ -201,7 +213,7 @@ Zotero.Fulltext = Zotero.FullText = new function(){ this.getPDFConverterExecAndArgs = function () { return { exec: _pdfConverter, - args: ['-datadir', _popplerDatadir] + args: ['-datadir', _pdfData] } }; diff --git a/test/content/runtests.js b/test/content/runtests.js index 82aa700b67..712dc6910f 100644 --- a/test/content/runtests.js +++ b/test/content/runtests.js @@ -293,6 +293,34 @@ if(run) { window.onload = function() { Zotero.spawn(function* () { yield Zotero.Schema.schemaUpdatePromise; + + // Init paths for PDF tools and data + let pdfConvertedFileName = 'pdftotext'; + let pdfInfoFileName = 'pdfinfo'; + + if (Zotero.isWin) { + pdfConvertedFileName += '-win.exe'; + pdfInfoFileName += '-win.exe'; + } + else if (Zotero.isMac) { + pdfConvertedFileName += '-mac'; + pdfInfoFileName += '-mac'; + } + else { + let cpu = Zotero.platform.split(' ')[1]; + pdfConvertedFileName += '-linux-' + cpu; + pdfInfoFileName += '-linux-' + cpu; + } + + let pdfToolsPath = OS.Path.join(Zotero.Profile.dir, 'pdftools'); + let pdfConverterPath = OS.Path.join(pdfToolsPath, pdfConvertedFileName); + let pdfInfoPath = OS.Path.join(pdfToolsPath, pdfInfoFileName); + let pdfDataPath = OS.Path.join(pdfToolsPath, 'poppler-data'); + + Zotero.FullText.setPDFConverterPath(pdfConverterPath); + Zotero.FullText.setPDFInfoPath(pdfInfoPath); + Zotero.FullText.setPDFDataPath(pdfDataPath); + return mocha.run(); }) }; diff --git a/test/runtests.sh b/test/runtests.sh index 99a1478066..5914f91152 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -125,6 +125,15 @@ echo "$ZOTERO_UNIT_PATH" > "$PROFILE/extensions/zotero-unit@zotero.org" # Create data directory mkdir "$TEMPDIR/Zotero" +# Download PDF tools +PDF_TOOLS_VERSION="0.0.1" +PDF_TOOLS_URL="https://zotero-download.s3.amazonaws.com/pdftools/pdftools-$PDF_TOOLS_VERSION.tar.gz" + +PDF_TOOLS_DIR="$PROFILE/pdftools" +mkdir $PDF_TOOLS_DIR +curl -o "$PDF_TOOLS_DIR/pdftools.tar.gz" $PDF_TOOLS_URL +tar -zxf "$PDF_TOOLS_DIR/pdftools.tar.gz" -C $PDF_TOOLS_DIR + cat < "$PROFILE/prefs.js" user_pref("app.update.enabled", false); user_pref("extensions.autoDisableScopes", 0);