diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/components/downloads/test/unit/test_Downloads.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/downloads/test/unit/test_Downloads.js')
-rw-r--r-- | toolkit/components/downloads/test/unit/test_Downloads.js | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/toolkit/components/downloads/test/unit/test_Downloads.js b/toolkit/components/downloads/test/unit/test_Downloads.js new file mode 100644 index 0000000000..b99f823008 --- /dev/null +++ b/toolkit/components/downloads/test/unit/test_Downloads.js @@ -0,0 +1,153 @@ +/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set ts=2 et sw=2 tw=80: */ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +/** + * Tests the functions located directly in the "Downloads" object. + */ + +"use strict"; + +// Tests + +/** + * Tests that the createDownload function exists and can be called. More + * detailed tests are implemented separately for the DownloadCore module. + */ +add_task(async function test_createDownload() { + // Creates a simple Download object without starting the download. + await Downloads.createDownload({ + source: { url: "about:blank" }, + target: { path: getTempFile(TEST_TARGET_FILE_NAME).path }, + saver: { type: "copy" }, + }); +}); + +/** + * Tests createDownload for private download. + */ +add_task(async function test_createDownload_private() { + let download = await Downloads.createDownload({ + source: { url: "about:blank", isPrivate: true }, + target: { path: getTempFile(TEST_TARGET_FILE_NAME).path }, + saver: { type: "copy" }, + }); + Assert.ok(download.source.isPrivate); +}); + +/** + * Tests createDownload for normal (public) download. + */ +add_task(async function test_createDownload_public() { + let tempPath = getTempFile(TEST_TARGET_FILE_NAME).path; + let download = await Downloads.createDownload({ + source: { url: "about:blank", isPrivate: false }, + target: { path: tempPath }, + saver: { type: "copy" }, + }); + Assert.ok(!download.source.isPrivate); + + download = await Downloads.createDownload({ + source: { url: "about:blank" }, + target: { path: tempPath }, + saver: { type: "copy" }, + }); + Assert.ok(!download.source.isPrivate); +}); + +/** + * Tests "fetch" with nsIURI and nsIFile as arguments. + */ +add_task(async function test_fetch_uri_file_arguments() { + let targetFile = getTempFile(TEST_TARGET_FILE_NAME); + await Downloads.fetch(NetUtil.newURI(httpUrl("source.txt")), targetFile); + await promiseVerifyContents(targetFile.path, TEST_DATA_SHORT); +}); + +/** + * Tests "fetch" with DownloadSource and DownloadTarget as arguments. + */ +add_task(async function test_fetch_object_arguments() { + let targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; + await Downloads.fetch({ url: httpUrl("source.txt") }, { path: targetPath }); + await promiseVerifyContents(targetPath, TEST_DATA_SHORT); +}); + +/** + * Tests "fetch" with string arguments. + */ +add_task(async function test_fetch_string_arguments() { + let targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; + await Downloads.fetch(httpUrl("source.txt"), targetPath); + await promiseVerifyContents(targetPath, TEST_DATA_SHORT); + + targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; + await Downloads.fetch(httpUrl("source.txt"), targetPath); + await promiseVerifyContents(targetPath, TEST_DATA_SHORT); +}); + +/** + * Tests that the getList function returns the same list when called multiple + * times with the same argument, but returns different lists when called with + * different arguments. More detailed tests are implemented separately for the + * DownloadList module. + */ +add_task(async function test_getList() { + let publicListOne = await Downloads.getList(Downloads.PUBLIC); + let privateListOne = await Downloads.getList(Downloads.PRIVATE); + + let publicListTwo = await Downloads.getList(Downloads.PUBLIC); + let privateListTwo = await Downloads.getList(Downloads.PRIVATE); + + Assert.equal(publicListOne, publicListTwo); + Assert.equal(privateListOne, privateListTwo); + + Assert.notEqual(publicListOne, privateListOne); +}); + +/** + * Tests that the getSummary function returns the same summary when called + * multiple times with the same argument, but returns different summaries when + * called with different arguments. More detailed tests are implemented + * separately for the DownloadSummary object in the DownloadList module. + */ +add_task(async function test_getSummary() { + let publicSummaryOne = await Downloads.getSummary(Downloads.PUBLIC); + let privateSummaryOne = await Downloads.getSummary(Downloads.PRIVATE); + + let publicSummaryTwo = await Downloads.getSummary(Downloads.PUBLIC); + let privateSummaryTwo = await Downloads.getSummary(Downloads.PRIVATE); + + Assert.equal(publicSummaryOne, publicSummaryTwo); + Assert.equal(privateSummaryOne, privateSummaryTwo); + + Assert.notEqual(publicSummaryOne, privateSummaryOne); +}); + +/** + * Tests that the getSystemDownloadsDirectory returns a non-empty download + * directory string. + */ +add_task(async function test_getSystemDownloadsDirectory() { + let downloadDir = await Downloads.getSystemDownloadsDirectory(); + Assert.notEqual(downloadDir, ""); +}); + +/** + * Tests that the getPreferredDownloadsDirectory returns a non-empty download + * directory string. + */ +add_task(async function test_getPreferredDownloadsDirectory() { + let downloadDir = await Downloads.getPreferredDownloadsDirectory(); + Assert.notEqual(downloadDir, ""); +}); + +/** + * Tests that the getTemporaryDownloadsDirectory returns a non-empty download + * directory string. + */ +add_task(async function test_getTemporaryDownloadsDirectory() { + let downloadDir = await Downloads.getTemporaryDownloadsDirectory(); + Assert.notEqual(downloadDir, ""); +}); |