Bug 899571, DownloadIntegration testMode doesn't reset cached directory, r=paolo
authorNeil Deakin <neil@mozilla.com>
Fri, 02 Aug 2013 11:42:50 -0400
changeset 141154 91dd80f73cfb6f58f648228fbb4282c3e3a11064
parent 141153 4ff7455f6720867482f499ecc839e33ac49dc5f2
child 141155 a49ebc80a97fc5e1870d2864d3a958a8f9e07389
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewerspaolo
bugs899571
milestone25.0a1
Bug 899571, DownloadIntegration testMode doesn't reset cached directory, r=paolo
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
toolkit/components/jsdownloads/test/unit/test_DownloadIntegration.js
--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -68,32 +68,41 @@ XPCOMUtils.defineLazyGetter(this, "gStri
 //// DownloadIntegration
 
 /**
  * Provides functions to integrate with the host application, handling for
  * example the global prompts on shutdown.
  */
 this.DownloadIntegration = {
   // For testing only
-  testMode: false,
+  _testMode: false,
   dontLoad: false,
   dontCheckParentalControls: false,
   shouldBlockInTest: false,
   dontOpenFileAndFolder: false,
   _deferTestOpenFile: null,
   _deferTestShowDir: null,
 
   /**
    * Main DownloadStore object for loading and saving the list of persistent
    * downloads, or null if the download list was never requested and thus it
    * doesn't need to be persisted.
    */
   _store: null,
 
   /**
+   * Gets and sets test mode
+   */
+  get testMode() this._testMode,
+  set testMode(mode) {
+    this._downloadsDirectory = null;
+    return (this._testMode = mode);
+  },
+
+  /**
    * Performs initialization of the list of persistent downloads, before its
    * first use by the host application.  This function may be called only once
    * during the entire lifetime of the application.
    *
    * @param aList
    *        DownloadList object to be populated with the download objects
    *        serialized from the previous session.  This list will be persisted
    *        to disk during the session lifetime or when the session terminates.
--- a/toolkit/components/jsdownloads/test/unit/test_DownloadIntegration.js
+++ b/toolkit/components/jsdownloads/test/unit/test_DownloadIntegration.js
@@ -16,17 +16,17 @@ XPCOMUtils.defineLazyGetter(this, "gStri
 });
 
 /**
  * Tests that the getSystemDownloadsDirectory returns a valid nsFile
  * download directory object.
  */
 add_task(function test_getSystemDownloadsDirectory()
 {
-  // Enable test mode for the getSystemDownloadsDirectoy method to return
+  // Enable test mode for the getSystemDownloadsDirectory method to return
   // temp directory instead so we can check whether the desired directory
   // is created or not.
   DownloadIntegration.testMode = true;
   function cleanup() {
     DownloadIntegration.testMode = false;
   }
   do_register_cleanup(cleanup);
 
@@ -54,17 +54,21 @@ add_task(function test_getSystemDownload
     downloadDir = yield DownloadIntegration.getSystemDownloadsDirectory();
     do_check_eq(downloadDir.path, targetPath);
     do_check_true(yield OS.File.exists(downloadDir.path));
 
     let info = yield OS.File.stat(downloadDir.path);
     do_check_true(info.isDir);
     yield OS.File.removeEmptyDir(targetPath);
   }
+
+  let downloadDirBefore = yield DownloadIntegration.getSystemDownloadsDirectory();
   cleanup();
+  let downloadDirAfter = yield DownloadIntegration.getSystemDownloadsDirectory();
+  do_check_false(downloadDirBefore.equals(downloadDirAfter));
 });
 
 /**
  * Tests that the getUserDownloadsDirectory returns a valid nsFile
  * download directory object.
  */
 add_task(function test_getUserDownloadsDirectory()
 {