Bug 915968 - Fix downloads' startTime serialization. r=paolo

This commit is contained in:
Felipe Gomes 2013-09-12 23:32:01 -03:00
parent 7a6d5abf2d
commit 1777823f24
3 changed files with 31 additions and 2 deletions

View File

@ -832,6 +832,10 @@ Download.prototype = {
serializable.error = { message: this.error.message };
}
if (this.startTime) {
serializable.startTime = this.startTime.toJSON();
}
// These are serialized unless they are false, null, or empty strings.
for (let property of kSerializableDownloadProperties) {
if (property != "error" && this[property]) {
@ -869,7 +873,6 @@ const kSerializableDownloadProperties = [
"succeeded",
"canceled",
"error",
"startTime",
"totalBytes",
"hasPartialData",
"tryToKeepPartialData",
@ -917,6 +920,13 @@ Download.fromSerializable = function (aSerializable) {
}
download.saver.download = download;
if ("startTime" in aSerializable) {
let time = aSerializable.startTime.getTime
? aSerializable.startTime.getTime()
: aSerializable.startTime;
download.startTime = new Date(time);
}
for (let property of kSerializableDownloadProperties) {
if (property in aSerializable) {
download[property] = aSerializable[property];

View File

@ -153,7 +153,7 @@ this.DownloadImport.prototype = {
type: "copy",
entityID: entityID
},
startTime: startTime,
startTime: new Date(startTime / 1000),
totalBytes: maxBytes,
hasPartialData: !!tempPath,
tryToKeepPartialData: true,

View File

@ -1624,6 +1624,25 @@ add_task(function test_contentType() {
do_check_eq("text/plain", download.contentType);
});
/**
* Tests that the serialization/deserialization of the startTime Date
* object works correctly.
*/
add_task(function test_toSerializable_startTime()
{
let download1 = yield promiseStartDownload(httpUrl("source.txt"));
yield promiseDownloadStopped(download1);
let serializable = download1.toSerializable();
let reserialized = JSON.parse(JSON.stringify(serializable));
let download2 = yield Downloads.createDownload(reserialized);
do_check_eq(download1.startTime.constructor.name, "Date");
do_check_eq(download2.startTime.constructor.name, "Date");
do_check_eq(download1.startTime.toJSON(), download2.startTime.toJSON());
});
/**
* This test will call the platform specific operations within
* DownloadPlatform::DownloadDone. While there is no test to verify the