michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Public request gets times=0 cookie, completes michael@0: // Private request gets times=1 cookie, canceled michael@0: // Private resumed request sends times=1 cookie, completes michael@0: michael@0: function run_test() { michael@0: if (oldDownloadManagerDisabled()) { michael@0: return; michael@0: } michael@0: michael@0: // Allow all cookies. michael@0: Services.prefs.setIntPref("network.cookie.cookieBehavior", 0); michael@0: michael@0: do_test_pending(); michael@0: let httpserv = new HttpServer(); michael@0: michael@0: let times = 0; michael@0: httpserv.registerPathHandler("/head_download_manager.js", function (meta, response) { michael@0: response.setHeader("Content-Type", "text/plain", false); michael@0: response.setStatusLine("1.1", !meta.hasHeader('range') ? 200 : 206); michael@0: michael@0: // Set a cookie if none is sent with the request. Public and private requests michael@0: // should therefore receive different cookies, so we can tell if the resumed michael@0: // request is actually treated as private or not. michael@0: if (!meta.hasHeader('Cookie')) { michael@0: do_check_true(times == 0 || times == 1); michael@0: response.setHeader('Set-Cookie', 'times=' + times++); michael@0: } else { michael@0: do_check_eq(times, 2); michael@0: do_check_eq(meta.getHeader('Cookie'), 'times=1'); michael@0: } michael@0: let full = ""; michael@0: let body = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; //60 michael@0: for (var i = 0; i < 1000; i++) { michael@0: full += body; michael@0: } michael@0: response.write(full); michael@0: }); michael@0: httpserv.start(-1); michael@0: michael@0: let state = 0; michael@0: michael@0: let listener = { michael@0: onDownloadStateChange: function(aState, aDownload) { michael@0: switch (aDownload.state) { michael@0: case downloadUtils.downloadManager.DOWNLOAD_DOWNLOADING: michael@0: // We only care about the private download michael@0: if (state != 1) michael@0: break; michael@0: michael@0: state++; michael@0: do_check_true(aDownload.resumable); michael@0: michael@0: aDownload.pause(); michael@0: do_check_eq(aDownload.state, downloadUtils.downloadManager.DOWNLOAD_PAUSED); michael@0: michael@0: do_execute_soon(function() { michael@0: aDownload.resume(); michael@0: }); michael@0: break; michael@0: michael@0: case downloadUtils.downloadManager.DOWNLOAD_FINISHED: michael@0: if (state == 0) { michael@0: do_execute_soon(function() { michael@0: // Perform an identical request but in private mode. michael@0: // It should receive a different cookie than the michael@0: // public request. michael@0: michael@0: state++; michael@0: michael@0: addDownload(httpserv, { michael@0: isPrivate: true, michael@0: sourceURI: downloadCSource, michael@0: downloadName: downloadCName + "!!!", michael@0: runBeforeStart: function (aDownload) { michael@0: // Check that dl is retrievable michael@0: do_check_eq(downloadUtils.downloadManager.activePrivateDownloadCount, 1); michael@0: } michael@0: }); michael@0: }); michael@0: } else if (state == 2) { michael@0: // We're done here. michael@0: do_execute_soon(function() { michael@0: httpserv.stop(do_test_finished); michael@0: }); michael@0: } michael@0: break; michael@0: michael@0: default: michael@0: break; michael@0: } michael@0: }, michael@0: onStateChange: function(a, b, c, d, e) { }, michael@0: onProgressChange: function(a, b, c, d, e, f, g) { }, michael@0: onSecurityChange: function(a, b, c, d) { } michael@0: }; michael@0: michael@0: downloadUtils.downloadManager.addPrivacyAwareListener(listener); michael@0: michael@0: const downloadCSource = "http://localhost:" + michael@0: httpserv.identity.primaryPort + michael@0: "/head_download_manager.js"; michael@0: const downloadCName = "download-C"; michael@0: michael@0: // First a public download that completes without interruption. michael@0: let dl = addDownload(httpserv, { michael@0: isPrivate: false, michael@0: sourceURI: downloadCSource, michael@0: downloadName: downloadCName, michael@0: runBeforeStart: function (aDownload) { michael@0: // Check that dl is retrievable michael@0: do_check_eq(downloadUtils.downloadManager.activeDownloadCount, 1); michael@0: } michael@0: }); michael@0: }