зеркало из https://github.com/mozilla/gecko-dev.git
Bug 983197 - Test that downloads fail with an HTTP/1.1 response shorter than the Content-Length. r=enn
This commit is contained in:
Родитель
60e30ab6d5
Коммит
8158d3f672
|
@ -1066,6 +1066,48 @@ add_task(function test_error_source()
|
|||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Ensures a download error is reported when receiving less bytes than what was
|
||||
* specified in the Content-Length header.
|
||||
*/
|
||||
add_task(function test_error_source_partial()
|
||||
{
|
||||
let sourceUrl = httpUrl("shorter-than-content-length-http-1-1.txt");
|
||||
|
||||
let download;
|
||||
try {
|
||||
if (!gUseLegacySaver) {
|
||||
// When testing DownloadCopySaver, we want to check that the promise
|
||||
// returned by the "start" method is rejected.
|
||||
download = yield promiseNewDownload(sourceUrl);
|
||||
|
||||
do_check_true(download.error === null);
|
||||
|
||||
yield download.start();
|
||||
} else {
|
||||
// When testing DownloadLegacySaver, we cannot be sure whether we are
|
||||
// testing the promise returned by the "start" method or we are testing
|
||||
// the "error" property checked by promiseDownloadStopped. This happens
|
||||
// because we don't have control over when the download is started.
|
||||
download = yield promiseStartLegacyDownload(sourceUrl);
|
||||
yield promiseDownloadStopped(download);
|
||||
}
|
||||
do_throw("The download should have failed.");
|
||||
} catch (ex if ex instanceof Downloads.Error && ex.becauseSourceFailed) {
|
||||
// A specific error object is thrown when reading from the source fails.
|
||||
}
|
||||
|
||||
// Check the properties now that the download stopped.
|
||||
do_check_true(download.stopped);
|
||||
do_check_false(download.canceled);
|
||||
do_check_true(download.error !== null);
|
||||
do_check_true(download.error.becauseSourceFailed);
|
||||
do_check_false(download.error.becauseTargetFailed);
|
||||
do_check_eq(download.error.result, Cr.NS_ERROR_NET_PARTIAL_TRANSFER);
|
||||
|
||||
do_check_false(yield OS.File.exists(download.target.path));
|
||||
});
|
||||
|
||||
/**
|
||||
* Ensures download error details are reported on local writing failures.
|
||||
*/
|
||||
|
|
|
@ -783,6 +783,17 @@ add_task(function test_common_initialize()
|
|||
TEST_DATA_SHORT_GZIP_ENCODED_SECOND.length);
|
||||
});
|
||||
|
||||
gHttpServer.registerPathHandler("/shorter-than-content-length-http-1-1.txt",
|
||||
function (aRequest, aResponse) {
|
||||
aResponse.processAsync();
|
||||
aResponse.setStatusLine("1.1", 200, "OK");
|
||||
aResponse.setHeader("Content-Type", "text/plain", false);
|
||||
aResponse.setHeader("Content-Length", "" + (TEST_DATA_SHORT.length * 2),
|
||||
false);
|
||||
aResponse.write(TEST_DATA_SHORT);
|
||||
aResponse.finish();
|
||||
});
|
||||
|
||||
// This URL will emulate being blocked by Windows Parental controls
|
||||
gHttpServer.registerPathHandler("/parentalblocked.zip",
|
||||
function (aRequest, aResponse) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче