Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 4 | * http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 5 | |
michael@0 | 6 | /** |
michael@0 | 7 | * Tests the functions located directly in the "Downloads" object. |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | "use strict"; |
michael@0 | 11 | |
michael@0 | 12 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 13 | //// Tests |
michael@0 | 14 | |
michael@0 | 15 | /** |
michael@0 | 16 | * Tests that the createDownload function exists and can be called. More |
michael@0 | 17 | * detailed tests are implemented separately for the DownloadCore module. |
michael@0 | 18 | */ |
michael@0 | 19 | add_task(function test_createDownload() |
michael@0 | 20 | { |
michael@0 | 21 | // Creates a simple Download object without starting the download. |
michael@0 | 22 | yield Downloads.createDownload({ |
michael@0 | 23 | source: { url: "about:blank" }, |
michael@0 | 24 | target: { path: getTempFile(TEST_TARGET_FILE_NAME).path }, |
michael@0 | 25 | saver: { type: "copy" }, |
michael@0 | 26 | }); |
michael@0 | 27 | }); |
michael@0 | 28 | |
michael@0 | 29 | /** |
michael@0 | 30 | * Tests createDownload for private download. |
michael@0 | 31 | */ |
michael@0 | 32 | add_task(function test_createDownload_private() |
michael@0 | 33 | { |
michael@0 | 34 | let download = yield Downloads.createDownload({ |
michael@0 | 35 | source: { url: "about:blank", isPrivate: true }, |
michael@0 | 36 | target: { path: getTempFile(TEST_TARGET_FILE_NAME).path }, |
michael@0 | 37 | saver: { type: "copy" } |
michael@0 | 38 | }); |
michael@0 | 39 | do_check_true(download.source.isPrivate); |
michael@0 | 40 | }); |
michael@0 | 41 | |
michael@0 | 42 | /** |
michael@0 | 43 | * Tests createDownload for normal (public) download. |
michael@0 | 44 | */ |
michael@0 | 45 | add_task(function test_createDownload_public() |
michael@0 | 46 | { |
michael@0 | 47 | let tempPath = getTempFile(TEST_TARGET_FILE_NAME).path; |
michael@0 | 48 | let download = yield Downloads.createDownload({ |
michael@0 | 49 | source: { url: "about:blank", isPrivate: false }, |
michael@0 | 50 | target: { path: tempPath }, |
michael@0 | 51 | saver: { type: "copy" } |
michael@0 | 52 | }); |
michael@0 | 53 | do_check_false(download.source.isPrivate); |
michael@0 | 54 | |
michael@0 | 55 | download = yield Downloads.createDownload({ |
michael@0 | 56 | source: { url: "about:blank" }, |
michael@0 | 57 | target: { path: tempPath }, |
michael@0 | 58 | saver: { type: "copy" } |
michael@0 | 59 | }); |
michael@0 | 60 | do_check_false(download.source.isPrivate); |
michael@0 | 61 | }); |
michael@0 | 62 | |
michael@0 | 63 | /** |
michael@0 | 64 | * Tests "fetch" with nsIURI and nsIFile as arguments. |
michael@0 | 65 | */ |
michael@0 | 66 | add_task(function test_fetch_uri_file_arguments() |
michael@0 | 67 | { |
michael@0 | 68 | let targetFile = getTempFile(TEST_TARGET_FILE_NAME); |
michael@0 | 69 | yield Downloads.fetch(NetUtil.newURI(httpUrl("source.txt")), targetFile); |
michael@0 | 70 | yield promiseVerifyContents(targetFile.path, TEST_DATA_SHORT); |
michael@0 | 71 | }); |
michael@0 | 72 | |
michael@0 | 73 | /** |
michael@0 | 74 | * Tests "fetch" with DownloadSource and DownloadTarget as arguments. |
michael@0 | 75 | */ |
michael@0 | 76 | add_task(function test_fetch_object_arguments() |
michael@0 | 77 | { |
michael@0 | 78 | let targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; |
michael@0 | 79 | yield Downloads.fetch({ url: httpUrl("source.txt") }, { path: targetPath }); |
michael@0 | 80 | yield promiseVerifyContents(targetPath, TEST_DATA_SHORT); |
michael@0 | 81 | }); |
michael@0 | 82 | |
michael@0 | 83 | /** |
michael@0 | 84 | * Tests "fetch" with string arguments. |
michael@0 | 85 | */ |
michael@0 | 86 | add_task(function test_fetch_string_arguments() |
michael@0 | 87 | { |
michael@0 | 88 | let targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; |
michael@0 | 89 | yield Downloads.fetch(httpUrl("source.txt"), targetPath); |
michael@0 | 90 | yield promiseVerifyContents(targetPath, TEST_DATA_SHORT); |
michael@0 | 91 | |
michael@0 | 92 | targetPath = getTempFile(TEST_TARGET_FILE_NAME).path; |
michael@0 | 93 | yield Downloads.fetch(new String(httpUrl("source.txt")), |
michael@0 | 94 | new String(targetPath)); |
michael@0 | 95 | yield promiseVerifyContents(targetPath, TEST_DATA_SHORT); |
michael@0 | 96 | }); |
michael@0 | 97 | |
michael@0 | 98 | /** |
michael@0 | 99 | * Tests that the getList function returns the same list when called multiple |
michael@0 | 100 | * times with the same argument, but returns different lists when called with |
michael@0 | 101 | * different arguments. More detailed tests are implemented separately for the |
michael@0 | 102 | * DownloadList module. |
michael@0 | 103 | */ |
michael@0 | 104 | add_task(function test_getList() |
michael@0 | 105 | { |
michael@0 | 106 | let publicListOne = yield Downloads.getList(Downloads.PUBLIC); |
michael@0 | 107 | let privateListOne = yield Downloads.getList(Downloads.PRIVATE); |
michael@0 | 108 | |
michael@0 | 109 | let publicListTwo = yield Downloads.getList(Downloads.PUBLIC); |
michael@0 | 110 | let privateListTwo = yield Downloads.getList(Downloads.PRIVATE); |
michael@0 | 111 | |
michael@0 | 112 | do_check_eq(publicListOne, publicListTwo); |
michael@0 | 113 | do_check_eq(privateListOne, privateListTwo); |
michael@0 | 114 | |
michael@0 | 115 | do_check_neq(publicListOne, privateListOne); |
michael@0 | 116 | }); |
michael@0 | 117 | |
michael@0 | 118 | /** |
michael@0 | 119 | * Tests that the getSummary function returns the same summary when called |
michael@0 | 120 | * multiple times with the same argument, but returns different summaries when |
michael@0 | 121 | * called with different arguments. More detailed tests are implemented |
michael@0 | 122 | * separately for the DownloadSummary object in the DownloadList module. |
michael@0 | 123 | */ |
michael@0 | 124 | add_task(function test_getSummary() |
michael@0 | 125 | { |
michael@0 | 126 | let publicSummaryOne = yield Downloads.getSummary(Downloads.PUBLIC); |
michael@0 | 127 | let privateSummaryOne = yield Downloads.getSummary(Downloads.PRIVATE); |
michael@0 | 128 | |
michael@0 | 129 | let publicSummaryTwo = yield Downloads.getSummary(Downloads.PUBLIC); |
michael@0 | 130 | let privateSummaryTwo = yield Downloads.getSummary(Downloads.PRIVATE); |
michael@0 | 131 | |
michael@0 | 132 | do_check_eq(publicSummaryOne, publicSummaryTwo); |
michael@0 | 133 | do_check_eq(privateSummaryOne, privateSummaryTwo); |
michael@0 | 134 | |
michael@0 | 135 | do_check_neq(publicSummaryOne, privateSummaryOne); |
michael@0 | 136 | }); |
michael@0 | 137 | |
michael@0 | 138 | /** |
michael@0 | 139 | * Tests that the getSystemDownloadsDirectory returns a non-empty download |
michael@0 | 140 | * directory string. |
michael@0 | 141 | */ |
michael@0 | 142 | add_task(function test_getSystemDownloadsDirectory() |
michael@0 | 143 | { |
michael@0 | 144 | let downloadDir = yield Downloads.getSystemDownloadsDirectory(); |
michael@0 | 145 | do_check_neq(downloadDir, ""); |
michael@0 | 146 | }); |
michael@0 | 147 | |
michael@0 | 148 | /** |
michael@0 | 149 | * Tests that the getPreferredDownloadsDirectory returns a non-empty download |
michael@0 | 150 | * directory string. |
michael@0 | 151 | */ |
michael@0 | 152 | add_task(function test_getPreferredDownloadsDirectory() |
michael@0 | 153 | { |
michael@0 | 154 | let downloadDir = yield Downloads.getPreferredDownloadsDirectory(); |
michael@0 | 155 | do_check_neq(downloadDir, ""); |
michael@0 | 156 | }); |
michael@0 | 157 | |
michael@0 | 158 | /** |
michael@0 | 159 | * Tests that the getTemporaryDownloadsDirectory returns a non-empty download |
michael@0 | 160 | * directory string. |
michael@0 | 161 | */ |
michael@0 | 162 | add_task(function test_getTemporaryDownloadsDirectory() |
michael@0 | 163 | { |
michael@0 | 164 | let downloadDir = yield Downloads.getTemporaryDownloadsDirectory(); |
michael@0 | 165 | do_check_neq(downloadDir, ""); |
michael@0 | 166 | }); |
michael@0 | 167 | |
michael@0 | 168 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 169 | //// Termination |
michael@0 | 170 | |
michael@0 | 171 | let tailFile = do_get_file("tail.js"); |
michael@0 | 172 | Services.scriptloader.loadSubScript(NetUtil.newURI(tailFile).spec); |