mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-11-12 22:28:59 +02:00
MozReview-Commit-ID: GuWeax0ubv3 --HG-- rename : toolkit/components/jsdownloads/src/DownloadCore.jsm => toolkit/components/downloads/DownloadCore.jsm rename : toolkit/components/jsdownloads/src/DownloadHistory.jsm => toolkit/components/downloads/DownloadHistory.jsm rename : toolkit/components/jsdownloads/src/DownloadIntegration.jsm => toolkit/components/downloads/DownloadIntegration.jsm rename : toolkit/components/jsdownloads/src/DownloadLegacy.js => toolkit/components/downloads/DownloadLegacy.js rename : toolkit/components/jsdownloads/src/DownloadList.jsm => toolkit/components/downloads/DownloadList.jsm rename : toolkit/components/jsdownloads/src/DownloadPaths.jsm => toolkit/components/downloads/DownloadPaths.jsm rename : toolkit/components/jsdownloads/src/DownloadPlatform.cpp => toolkit/components/downloads/DownloadPlatform.cpp rename : toolkit/components/jsdownloads/src/DownloadPlatform.h => toolkit/components/downloads/DownloadPlatform.h rename : toolkit/components/jsdownloads/src/DownloadStore.jsm => toolkit/components/downloads/DownloadStore.jsm rename : toolkit/components/jsdownloads/src/DownloadUIHelper.jsm => toolkit/components/downloads/DownloadUIHelper.jsm rename : toolkit/components/jsdownloads/src/Downloads.jsm => toolkit/components/downloads/Downloads.jsm rename : toolkit/components/jsdownloads/src/Downloads.manifest => toolkit/components/downloads/Downloads.manifest rename : toolkit/components/jsdownloads/src/moz.build => toolkit/components/downloads/moz.build rename : toolkit/components/jsdownloads/public/mozIDownloadPlatform.idl => toolkit/components/downloads/mozIDownloadPlatform.idl rename : toolkit/components/jsdownloads/test/browser/.eslintrc.js => toolkit/components/downloads/test/browser/.eslintrc.js rename : toolkit/components/jsdownloads/test/browser/browser.ini => toolkit/components/downloads/test/browser/browser.ini rename : toolkit/components/jsdownloads/test/browser/browser_DownloadPDFSaver.js => toolkit/components/downloads/test/browser/browser_DownloadPDFSaver.js rename : toolkit/components/jsdownloads/test/browser/head.js => toolkit/components/downloads/test/browser/head.js rename : toolkit/components/jsdownloads/test/browser/testFile.html => toolkit/components/downloads/test/browser/testFile.html rename : toolkit/components/jsdownloads/test/data/.eslintrc.js => toolkit/components/downloads/test/data/.eslintrc.js rename : toolkit/components/jsdownloads/test/data/empty.txt => toolkit/components/downloads/test/data/empty.txt rename : toolkit/components/jsdownloads/test/data/source.txt => toolkit/components/downloads/test/data/source.txt rename : toolkit/components/jsdownloads/test/unit/.eslintrc.js => toolkit/components/downloads/test/unit/.eslintrc.js rename : toolkit/components/jsdownloads/test/unit/common_test_Download.js => toolkit/components/downloads/test/unit/common_test_Download.js rename : toolkit/components/jsdownloads/test/unit/head.js => toolkit/components/downloads/test/unit/head.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadCore.js => toolkit/components/downloads/test/unit/test_DownloadCore.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadHistory.js => toolkit/components/downloads/test/unit/test_DownloadHistory.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadIntegration.js => toolkit/components/downloads/test/unit/test_DownloadIntegration.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadLegacy.js => toolkit/components/downloads/test/unit/test_DownloadLegacy.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadList.js => toolkit/components/downloads/test/unit/test_DownloadList.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadPaths.js => toolkit/components/downloads/test/unit/test_DownloadPaths.js rename : toolkit/components/jsdownloads/test/unit/test_DownloadStore.js => toolkit/components/downloads/test/unit/test_DownloadStore.js rename : toolkit/components/jsdownloads/test/unit/test_Downloads.js => toolkit/components/downloads/test/unit/test_Downloads.js rename : toolkit/components/jsdownloads/test/unit/test_PrivateTemp.js => toolkit/components/downloads/test/unit/test_PrivateTemp.js rename : toolkit/components/jsdownloads/test/unit/xpcshell.ini => toolkit/components/downloads/test/unit/xpcshell.ini extra : rebase_source : 7062bc9278460abf0da3f1ae2ba02daa3c4f6abc
84 lines
2.6 KiB
JavaScript
84 lines
2.6 KiB
JavaScript
/* -*- 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 integration with legacy interfaces for downloads.
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
// Execution of common tests
|
|
|
|
var gUseLegacySaver = true;
|
|
|
|
var scriptFile = do_get_file("common_test_Download.js");
|
|
Services.scriptloader.loadSubScript(NetUtil.newURI(scriptFile).spec);
|
|
|
|
/**
|
|
* Checks the referrer for restart downloads.
|
|
* If the legacy download is stopped and restarted, the saving method
|
|
* is changed from DownloadLegacySaver to the DownloadCopySaver.
|
|
* The referrer header should be passed correctly.
|
|
*/
|
|
add_task(async function test_referrer_restart() {
|
|
let sourcePath = "/test_referrer_restart.txt";
|
|
let sourceUrl = httpUrl("test_referrer_restart.txt");
|
|
|
|
function cleanup() {
|
|
gHttpServer.registerPathHandler(sourcePath, null);
|
|
}
|
|
registerCleanupFunction(cleanup);
|
|
|
|
registerInterruptibleHandler(sourcePath,
|
|
function firstPart(aRequest, aResponse) {
|
|
aResponse.setHeader("Content-Type", "text/plain", false);
|
|
Assert.ok(aRequest.hasHeader("Referer"));
|
|
Assert.equal(aRequest.getHeader("Referer"), TEST_REFERRER_URL);
|
|
|
|
aResponse.setHeader("Content-Length", "" + (TEST_DATA_SHORT.length * 2),
|
|
false);
|
|
aResponse.write(TEST_DATA_SHORT);
|
|
}, function secondPart(aRequest, aResponse) {
|
|
Assert.ok(aRequest.hasHeader("Referer"));
|
|
Assert.equal(aRequest.getHeader("Referer"), TEST_REFERRER_URL);
|
|
|
|
aResponse.write(TEST_DATA_SHORT);
|
|
});
|
|
|
|
async function restart_and_check_referrer(download) {
|
|
let promiseSucceeded = download.whenSucceeded();
|
|
|
|
// Cancel the first download attempt.
|
|
await promiseDownloadMidway(download);
|
|
await download.cancel();
|
|
|
|
// The second request is allowed to complete.
|
|
continueResponses();
|
|
download.start().catch(() => {});
|
|
|
|
// Wait for the download to finish by waiting on the whenSucceeded promise.
|
|
await promiseSucceeded;
|
|
|
|
Assert.ok(download.stopped);
|
|
Assert.ok(download.succeeded);
|
|
Assert.ok(!download.canceled);
|
|
|
|
Assert.equal(download.source.referrer, TEST_REFERRER_URL);
|
|
}
|
|
|
|
mustInterruptResponses();
|
|
let download = await promiseStartLegacyDownload(
|
|
sourceUrl, { referrer: TEST_REFERRER_URL });
|
|
await restart_and_check_referrer(download);
|
|
|
|
mustInterruptResponses();
|
|
download = await promiseStartLegacyDownload(
|
|
sourceUrl, { referrer: TEST_REFERRER_URL,
|
|
isPrivate: true});
|
|
await restart_and_check_referrer(download);
|
|
|
|
cleanup();
|
|
});
|
|
|