Bug 906134 - Fix downloads' startTime serialization. r=paolo
☠☠ backed out by 7f28b6fac8bd ☠ ☠
authorFelipe Gomes <felipc@gmail.com>
Wed, 11 Sep 2013 16:14:49 -0300
changeset 159594 c6d7c7739056a826f6638db521fc72c879cd0b88
parent 159593 6b98e5ee513b4e158f35070775435d8e932d7f5a
child 159595 270d7ca88c31b07840dcb1d3f99348aa28740104
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs906134
milestone26.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 906134 - Fix downloads' startTime serialization. r=paolo
toolkit/components/jsdownloads/src/DownloadCore.jsm
toolkit/components/jsdownloads/src/DownloadImport.jsm
toolkit/components/jsdownloads/test/unit/common_test_Download.js
--- a/toolkit/components/jsdownloads/src/DownloadCore.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadCore.jsm
@@ -811,16 +811,20 @@ Download.prototype = {
     if (saver !== "copy") {
       serializable.saver = saver;
     }
 
     if (this.error && ("message" in this.error)) {
       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]) {
         serializable[property] = this[property];
       }
     }
 
     return serializable;
@@ -848,17 +852,16 @@ Download.prototype = {
 
 /**
  * Defines which properties of the Download object are serializable.
  */
 const kSerializableDownloadProperties = [
   "succeeded",
   "canceled",
   "error",
-  "startTime",
   "totalBytes",
   "hasPartialData",
   "tryToKeepPartialData",
   "launcherPath",
   "launchWhenSucceeded",
   "contentType",
 ];
 
@@ -896,16 +899,23 @@ Download.fromSerializable = function (aS
   }
   if ("saver" in aSerializable) {
     download.saver = DownloadSaver.fromSerializable(aSerializable.saver);
   } else {
     download.saver = DownloadSaver.fromSerializable("copy");
   }
   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];
     }
   }
 
   return download;
 };
--- a/toolkit/components/jsdownloads/src/DownloadImport.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadImport.jsm
@@ -148,17 +148,17 @@ this.DownloadImport.prototype = {
               target: {
                 path: targetPath,
                 partFilePath: tempPath,
               },
               saver: {
                 type: "copy",
                 entityID: entityID
               },
-              startTime: startTime,
+              startTime: new Date(startTime / 1000),
               totalBytes: maxBytes,
               hasPartialData: !!tempPath,
               tryToKeepPartialData: true,
               launchWhenSucceeded: launchWhenSucceeded,
               contentType: mimeType,
               launcherPath: preferredApplication
             };
 
--- a/toolkit/components/jsdownloads/test/unit/common_test_Download.js
+++ b/toolkit/components/jsdownloads/test/unit/common_test_Download.js
@@ -1620,16 +1620,35 @@ add_task(function test_launchWhenSucceed
 add_task(function test_contentType() {
   let download = yield promiseStartDownload(httpUrl("source.txt"));
   yield promiseDownloadStopped(download);
 
   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
  * specific behaviours, this at least ensures that there is no error or crash.
  */
 add_task(function test_platform_integration()
 {
   let downloadFiles = [];
   function cleanup() {