зеркало из https://github.com/mozilla/gecko-dev.git
Bug 852478 - Store the date and time of downloads. r=paolo
This commit is contained in:
Родитель
0d48310a84
Коммит
a8d07a4b9a
|
@ -128,6 +128,13 @@ Download.prototype = {
|
|||
*/
|
||||
error: null,
|
||||
|
||||
/**
|
||||
* Indicates the start time of the download. When the download starts,
|
||||
* this property is set to a valid Date object. The default value is null
|
||||
* before the download starts.
|
||||
*/
|
||||
startTime: null,
|
||||
|
||||
/**
|
||||
* Indicates whether this download's "progress" property is able to report
|
||||
* partial progress while the download proceeds, and whether the value in
|
||||
|
@ -237,6 +244,7 @@ Download.prototype = {
|
|||
this.progress = 0;
|
||||
this.totalBytes = 0;
|
||||
this.currentBytes = 0;
|
||||
this.startTime = new Date();
|
||||
|
||||
// Create a new deferred object and an associated promise before starting
|
||||
// the actual download. We store it on the download as the current attempt.
|
||||
|
|
|
@ -127,6 +127,20 @@ function promiseExecuteSoon()
|
|||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Waits for a pending events to be processed after a timeout.
|
||||
*
|
||||
* @return {Promise}
|
||||
* @resolves When pending events have been processed.
|
||||
* @rejects Never.
|
||||
*/
|
||||
function promiseTimeout(aTime)
|
||||
{
|
||||
let deferred = Promise.defer();
|
||||
do_timeout(aTime, deferred.resolve);
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Download object, setting a temporary file as the target.
|
||||
*
|
||||
|
@ -296,6 +310,16 @@ function registerInterruptibleHandler(aPath, aFirstPartFn, aSecondPartFn)
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the given date object is valid.
|
||||
*
|
||||
* @param aDate
|
||||
* The date object to be checked. This value can be null.
|
||||
*/
|
||||
function isValidDate(aDate) {
|
||||
return aDate && aDate.getTime && !isNaN(aDate.getTime());
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//// Initialization functions common to all tests
|
||||
|
||||
|
|
|
@ -47,6 +47,7 @@ add_task(function test_download_initial_final_state()
|
|||
do_check_false(download.canceled);
|
||||
do_check_true(download.error === null);
|
||||
do_check_eq(download.progress, 0);
|
||||
do_check_true(download.startTime === null);
|
||||
|
||||
// Starts the download and waits for completion.
|
||||
yield download.start();
|
||||
|
@ -56,6 +57,7 @@ add_task(function test_download_initial_final_state()
|
|||
do_check_false(download.canceled);
|
||||
do_check_true(download.error === null);
|
||||
do_check_eq(download.progress, 100);
|
||||
do_check_true(isValidDate(download.startTime));
|
||||
});
|
||||
|
||||
/**
|
||||
|
@ -674,3 +676,25 @@ add_task(function test_download_error_restart()
|
|||
|
||||
yield promiseVerifyContents(download.target.file, TEST_DATA_SHORT);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Checks the startTime gets updated even after a restart.
|
||||
*/
|
||||
add_task(function test_download_cancel_immediately_restart_and_check_startTime()
|
||||
{
|
||||
let download = yield promiseSimpleDownload();
|
||||
|
||||
download.start();
|
||||
let startTime = download.startTime;
|
||||
do_check_true(isValidDate(download.startTime));
|
||||
|
||||
yield download.cancel();
|
||||
do_check_eq(download.startTime.getTime(), startTime.getTime());
|
||||
|
||||
// Wait for a timeout.
|
||||
yield promiseTimeout(10);
|
||||
|
||||
yield download.start();
|
||||
do_check_true(download.startTime.getTime() > startTime.getTime());
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче