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

@ -1,18 +1,9 @@
describe("Zotero.Fulltext", function () {
describe("#downloadPDFTool()", function () {
var originalBaseURL;
before(function* () {
originalBaseURL = Zotero.Fulltext.pdfToolsDownloadBaseURL;
})
after(function () {
Zotero.Fulltext.pdfToolsDownloadBaseURL = originalBaseURL;
})
it("should install the PDF tools", function* () {
var version = "3.04";
var dataDir = Zotero.getZoteroDirectory().path;
var execFileName = Zotero.Fulltext.pdfInfoFileName;
var execContents = new Array(50001).join('a');
var execPath = OS.Path.join(dataDir, execFileName);
var versionFileName = execFileName + '.version';
var versionPath = OS.Path.join(dataDir, versionFileName);
@ -21,6 +12,9 @@ describe("Zotero.Fulltext", function () {
var scriptContents = yield Zotero.File.getContentsFromURLAsync(
'resource://zotero/redirect.' + scriptExt
);
var cacheExecPath = OS.Path.join(
getTestDataDirectory().path, "pdf", version, execFileName
);
// Delete existing files
try {
@ -36,23 +30,12 @@ describe("Zotero.Fulltext", function () {
}
catch (e) {}
var tmpDir = Zotero.getTempDirectory();
// Create temp version directory
var tmpVersionDir = OS.Path.join(tmpDir.path, version);
yield OS.File.makeDir(tmpVersionDir);
// Create dummy executable file to download
var tmpExecPath = OS.Path.join(tmpVersionDir, execFileName);
yield Zotero.File.putContentsAsync(tmpExecPath, execContents);
// Override the download URL with a file URL for the temp directory
Zotero.Fulltext.pdfToolsDownloadBaseURL = OS.Path.toFileURI(tmpDir.path) + "/";
yield Zotero.Fulltext.downloadPDFTool('info', version);
assert.ok(Zotero.Fulltext.pdfInfoIsRegistered());
assert.equal(
(yield Zotero.File.getContentsAsync(execPath)),
execContents
(yield Zotero.File.getBinaryContentsAsync(cacheExecPath)),
(yield Zotero.File.getBinaryContentsAsync(execPath))
);
assert.equal((yield OS.File.stat(execPath)).unixMode, 0o755);
assert.equal(
@ -65,7 +48,8 @@ describe("Zotero.Fulltext", function () {
);
assert.equal((yield OS.File.stat(scriptPath)).unixMode, 0o755);
yield OS.File.removeDir(tmpVersionDir);
yield Zotero.Fulltext.uninstallPDFTools();
assert.isFalse(Zotero.Fulltext.pdfInfoIsRegistered());
})
})
})