diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index 6b34a5ded..48d0a26f4 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -4123,8 +4123,7 @@ var ZoteroPane = new function() } else { if (!item.isImportedAttachment() - || (!Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID) - || !Zotero.Sync.Storage.Local.downloadAsNeeded(item.libraryID))) { + || !Zotero.Sync.Storage.Local.getEnabledForLibrary(item.libraryID)) { this.showAttachmentNotFoundDialog(itemID, noLocateOnMissing); return; } diff --git a/test/tests/zoteroPaneTest.js b/test/tests/zoteroPaneTest.js index 073b223a1..114a4e25a 100644 --- a/test/tests/zoteroPaneTest.js +++ b/test/tests/zoteroPaneTest.js @@ -177,56 +177,59 @@ describe("ZoteroPane", function() { }) it("should download an attachment on-demand", function* () { - yield setup(); - Zotero.Sync.Storage.Local.downloadAsNeeded(Zotero.Libraries.userLibraryID, true); - - var item = new Zotero.Item("attachment"); - item.attachmentLinkMode = 'imported_file'; - item.attachmentPath = 'storage:test.txt'; - // TODO: Test binary data - var text = Zotero.Utilities.randomString(); - item.attachmentSyncState = "to_download"; - yield item.saveTx(); - - var mtime = "1441252524000"; - var md5 = Zotero.Utilities.Internal.md5(text) - - var s3Path = `pretend-s3/${item.key}`; - this.httpd.registerPathHandler( - `/users/1/items/${item.key}/file`, - { - handle: function (request, response) { - response.setStatusLine(null, 302, "Found"); - response.setHeader("Zotero-File-Modification-Time", mtime, false); - response.setHeader("Zotero-File-MD5", md5, false); - response.setHeader("Zotero-File-Compressed", "No", false); - response.setHeader("Location", baseURL + s3Path, false); + for (let fn of ['downloadAsNeeded', 'downloadOnSync']) { + yield setup(); + + Zotero.Sync.Storage.Local[fn](Zotero.Libraries.userLibraryID, true); + + var item = new Zotero.Item("attachment"); + item.attachmentLinkMode = 'imported_file'; + item.attachmentPath = 'storage:test.txt'; + // TODO: Test binary data + var text = Zotero.Utilities.randomString(); + item.attachmentSyncState = "to_download"; + yield item.saveTx(); + + var mtime = "1441252524000"; + var md5 = Zotero.Utilities.Internal.md5(text) + + var s3Path = `pretend-s3/${item.key}`; + this.httpd.registerPathHandler( + `/users/1/items/${item.key}/file`, + { + handle: function (request, response) { + response.setStatusLine(null, 302, "Found"); + response.setHeader("Zotero-File-Modification-Time", mtime, false); + response.setHeader("Zotero-File-MD5", md5, false); + response.setHeader("Zotero-File-Compressed", "No", false); + response.setHeader("Location", baseURL + s3Path, false); + } } - } - ); - this.httpd.registerPathHandler( - "/" + s3Path, - { - handle: function (request, response) { - response.setStatusLine(null, 200, "OK"); - response.write(text); + ); + this.httpd.registerPathHandler( + "/" + s3Path, + { + handle: function (request, response) { + response.setStatusLine(null, 200, "OK"); + response.write(text); + } } - } - ); - - // Disable loadURI() so viewAttachment() doesn't trigger translator loading - var stub = sinon.stub(zp, "loadURI"); - - yield zp.viewAttachment(item.id); - - assert.ok(stub.calledOnce); - assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath()))); - stub.restore(); - - assert.equal((yield item.attachmentHash), md5); - assert.equal((yield item.attachmentModificationTime), mtime); - var path = yield item.getFilePathAsync(); - assert.equal((yield Zotero.File.getContentsAsync(path)), text); + ); + + // Disable loadURI() so viewAttachment() doesn't trigger translator loading + var stub = sinon.stub(zp, "loadURI"); + + yield zp.viewAttachment(item.id); + + assert.ok(stub.calledOnce); + assert.ok(stub.calledWith(OS.Path.toFileURI(item.getFilePath()))); + stub.restore(); + + assert.equal((yield item.attachmentHash), md5); + assert.equal((yield item.attachmentModificationTime), mtime); + var path = yield item.getFilePathAsync(); + assert.equal((yield Zotero.File.getContentsAsync(path)), text); + } }) })