Update PDF tool handling in tests

The test runner now downloads and caches the PDF tools for the current
platform within the test data directory and only redownloads them when
out of date, and it updates the download URL so that the full-text code
pulls from the cache directory via a file:// URL.

The installPDFTools() support function now installs the files directly
instead of going through the prefs, and a new uninstallPDFTools()
function removes the tools. Since the presence of the PDF tools can
affect other tests, tests that need the tools should install them in a
before() and uninstall them in an after(), leaving most tests to run
without PDF indexing.

This also adds a callback to the waitForWindow() support function. If a
modal dialog is opened, it blocks the next promise handler from running,
so a callback has to be used to interact with and close the dialog
immediately.
This commit is contained in:
Dan Stillman 2015-05-31 23:07:24 -04:00
parent 55d27273fb
commit 5ba344516e
7 changed files with 158 additions and 69 deletions

View file

@ -140,8 +140,56 @@ if(ZoteroUnit.tests) {
if(run) {
window.onload = function() {
Zotero.Schema.schemaUpdatePromise.then(function() {
mocha.run();
});
Zotero.spawn(function* () {
yield Zotero.Schema.schemaUpdatePromise;
// Download and cache PDF tools for this platform
//
// To reset, delete test/tests/data/pdf/ directory
var cachePDFTools = Zotero.Promise.coroutine(function* () {
Components.utils.import("resource://zotero/config.js");
var baseURL = ZOTERO_CONFIG.PDF_TOOLS_URL;
var path = OS.Path.join(getTestDataDirectory().path, 'pdf');
yield OS.File.makeDir(path, { ignoreExisting: true });
// Get latest tools version for the current platform
var latestPath = OS.Path.join(path, "latest.json");
var xmlhttp = yield Zotero.HTTP.request("GET", baseURL + "latest.json");
var json = xmlhttp.responseText;
yield Zotero.File.putContentsAsync(latestPath, json);
json = JSON.parse(json);
var platform = Zotero.platform.replace(/\s/g, '-');
var version = json[platform] || json['default'];
// Create version directory (e.g., data/pdf/3.04) and download tools to it if
// they don't exist
yield OS.File.makeDir(OS.Path.join(path, version), { ignoreExisting: true });
var fileName = "pdfinfo-" + platform + (Zotero.isWin ? ".exe" : "");
var execPath = OS.Path.join(path, version, fileName);
if (!(yield OS.File.exists(execPath))) {
yield Zotero.File.download(baseURL + version + "/" + fileName, execPath);
}
fileName = "pdftotext-" + platform;
execPath = OS.Path.join(path, version, fileName);
if (!(yield OS.File.exists(execPath))) {
yield Zotero.File.download(baseURL + version + "/" + fileName, execPath);
}
// Point full-text code to the cache directory, so downloads come from there
Zotero.Fulltext.pdfToolsDownloadBaseURL = OS.Path.toFileURI(path) + "/";
});
try {
yield cachePDFTools();
}
catch (e) {
Zotero.logError(e);
}
return mocha.run();
})
};
}