Use local HTTP server for Zotero.BrowserDownload test
This commit is contained in:
parent
dab423e857
commit
639b4b5623
1 changed files with 20 additions and 2 deletions
|
@ -25,13 +25,31 @@
|
||||||
|
|
||||||
describe("Zotero.BrowserDownload", function () {
|
describe("Zotero.BrowserDownload", function () {
|
||||||
describe("#downloadPDF()", function () {
|
describe("#downloadPDF()", function () {
|
||||||
|
var http, port, baseURL;
|
||||||
var tmpFile = Zotero.getTempDirectory();
|
var tmpFile = Zotero.getTempDirectory();
|
||||||
tmpFile.append('browserDownloadTest.pdf');
|
tmpFile.append('browserDownloadTest.pdf');
|
||||||
|
|
||||||
it("#downloadPDF() should download a PDF from a JS redirect page", async function () {
|
before(async function () {
|
||||||
this.timeout(65e3);
|
({ httpd, port } = await startHTTPServer());
|
||||||
|
baseURL = `http://localhost:${port}/`;
|
||||||
|
});
|
||||||
|
|
||||||
await Zotero.BrowserDownload.downloadPDF('https://zotero-static.s3.amazonaws.com/test-pdf-redirect.html', tmpFile.path);
|
after(async function () {
|
||||||
|
await new Promise(resolve => httpd.stop(resolve));
|
||||||
|
});
|
||||||
|
|
||||||
|
it("#downloadPDF() should download a PDF from a JS redirect page", async function () {
|
||||||
|
var dir = getTestDataDirectory().path;
|
||||||
|
httpd.registerFile(
|
||||||
|
'/test-pdf-redirect.html',
|
||||||
|
Zotero.File.pathToFile(PathUtils.join(dir, 'test-pdf-redirect.html'))
|
||||||
|
);
|
||||||
|
httpd.registerFile(
|
||||||
|
'/test.pdf',
|
||||||
|
Zotero.File.pathToFile(PathUtils.join(dir, 'test.pdf'))
|
||||||
|
);
|
||||||
|
|
||||||
|
await Zotero.BrowserDownload.downloadPDF(`${baseURL}test-pdf-redirect.html`, tmpFile.path);
|
||||||
|
|
||||||
var sample = await Zotero.File.getContentsAsync(tmpFile, null, 1000);
|
var sample = await Zotero.File.getContentsAsync(tmpFile, null, 1000);
|
||||||
assert.equal(Zotero.MIME.sniffForMIMEType(sample), 'application/pdf');
|
assert.equal(Zotero.MIME.sniffForMIMEType(sample), 'application/pdf');
|
||||||
|
|
Loading…
Add table
Reference in a new issue