Bug 847863 - Part 1 of 8 - Selectively disable old Download Manager xpcshell tests. r=enn
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 19 Aug 2013 17:23:59 +0200
changeset 143068 5b2e0df01a1fe8de2529e322a36993163520587b
parent 143067 5f42d98b068ba28cc517dece7424631e73ae4ff7
child 143069 257a3ee7fe725df22335ac7ba2c7d3eca8f056eb
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersenn
bugs847863
milestone26.0a1
Bug 847863 - Part 1 of 8 - Selectively disable old Download Manager xpcshell tests. r=enn
toolkit/components/downloads/test/unit/head_download_manager.js
toolkit/components/downloads/test/unit/test_bug_382825.js
toolkit/components/downloads/test/unit/test_bug_395092.js
toolkit/components/downloads/test/unit/test_bug_401430.js
toolkit/components/downloads/test/unit/test_bug_401582.js
toolkit/components/downloads/test/unit/test_bug_406857.js
toolkit/components/downloads/test/unit/test_bug_409179.js
toolkit/components/downloads/test/unit/test_bug_420230.js
toolkit/components/downloads/test/unit/test_cancel_download_files_removed.js
toolkit/components/downloads/test/unit/test_download_manager.js
toolkit/components/downloads/test/unit/test_download_samename.js
toolkit/components/downloads/test/unit/test_guid.js
toolkit/components/downloads/test/unit/test_history_expiration.js
toolkit/components/downloads/test/unit/test_offline_support.js
toolkit/components/downloads/test/unit/test_old_download_files_removed.js
toolkit/components/downloads/test/unit/test_private_resume.js
toolkit/components/downloads/test/unit/test_privatebrowsing.js
toolkit/components/downloads/test/unit/test_privatebrowsing_cancel.js
toolkit/components/downloads/test/unit/test_removeDownloadsByTimeframe.js
toolkit/components/downloads/test/unit/test_resume.js
toolkit/components/downloads/test/unit/test_sleep_wake.js
--- a/toolkit/components/downloads/test/unit/head_download_manager.js
+++ b/toolkit/components/downloads/test/unit/head_download_manager.js
@@ -235,8 +235,17 @@ XPCOMUtils.defineLazyGetter(this, "Servi
 });
 
 // Disable alert service notifications
 Services.prefs.setBoolPref("browser.download.manager.showAlertOnComplete", false);
 
 do_register_cleanup(function() {
   Services.obs.notifyObservers(null, "quit-application", null);
 });
+
+function oldDownloadManagerDisabled() {
+  try {
+    if (Services.prefs.getBoolPref("browser.download.useJSTransfer")) {
+      return true;
+    }
+  } catch (ex) { }
+  return false;
+}
\ No newline at end of file
--- a/toolkit/components/downloads/test/unit/test_bug_382825.js
+++ b/toolkit/components/downloads/test/unit/test_bug_382825.js
@@ -34,16 +34,20 @@ function test_retry_bad()
   }
 }
 
 var tests = [test_retry_canceled, test_retry_bad];
 
 var httpserv = null;
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   httpserv = new HttpServer();
   httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(-1);
 
   dm.addListener(getDownloadListener());
 
   for (var i = 0; i < tests.length; i++)
     tests[i]();
--- a/toolkit/components/downloads/test/unit/test_bug_395092.js
+++ b/toolkit/components/downloads/test/unit/test_bug_395092.js
@@ -25,16 +25,20 @@ var observer = {
     }
   }
 };
 
 var httpserv = null;
 var timer = null;
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   httpserv = new HttpServer();
   httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(-1);
 
   // our download listener
   var listener = {
     onDownloadStateChange: function(aOldState, aDownload)
     {
--- a/toolkit/components/downloads/test/unit/test_bug_401430.js
+++ b/toolkit/components/downloads/test/unit/test_bug_401430.js
@@ -71,16 +71,20 @@ function checkRecentDocsFor(aFileName) {
       return true;
   }
   return false;
 }
 
 var httpserv = null;
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // This test functionality only implemented on Windows.
   // Is there a better way of doing this?
   var httpPH = Cc["@mozilla.org/network/protocol;1?name=http"].
                getService(Ci.nsIHttpProtocolHandler);
   if (httpPH.platform != "Windows")
     return;
 
   // Don't finish until the download is finished
--- a/toolkit/components/downloads/test/unit/test_bug_401582.js
+++ b/toolkit/components/downloads/test/unit/test_bug_401582.js
@@ -22,11 +22,15 @@ function test_noScanningDownloads()
   stmt.reset();
   stmt.finalize();
 }
 
 var tests = [test_noScanningDownloads];
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   for (var i = 0; i < tests.length; i++)
     tests[i]();
 }
--- a/toolkit/components/downloads/test/unit/test_bug_406857.js
+++ b/toolkit/components/downloads/test/unit/test_bug_406857.js
@@ -4,16 +4,20 @@
 
 /**
  * Test bug 406857 to make sure a download's referrer doesn't disappear when
  * retrying the download.
  */
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   let dm = Cc["@mozilla.org/download-manager;1"].
            getService(Ci.nsIDownloadManager);
   let db = dm.DBConnection;
   var httpserv = new HttpServer();
   httpserv.start(-1);
 
   let stmt = db.createStatement(
     "INSERT INTO moz_downloads (source, target, state, referrer) " +
--- a/toolkit/components/downloads/test/unit/test_bug_409179.js
+++ b/toolkit/components/downloads/test/unit/test_bug_409179.js
@@ -4,16 +4,20 @@
 
 // This file ensures that the download manager service can be instantiated with
 // a certain downloads.sqlite file that had incorrect data.
 
 importDownloadsFile("bug_409179_downloads.sqlite");
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   var caughtException = false;
   try {
     var dm = Cc["@mozilla.org/download-manager;1"].
              getService(Ci.nsIDownloadManager);
   } catch (e) {
     caughtException = true;
   }
   do_check_false(caughtException);
--- a/toolkit/components/downloads/test/unit/test_bug_420230.js
+++ b/toolkit/components/downloads/test/unit/test_bug_420230.js
@@ -5,16 +5,20 @@
 // This tests data uri downloading of the DM in relation to the new security policy
 // checks put in place on windows. (bug 416683)
 
 const nsIDownloadManager = Ci.nsIDownloadManager;
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDownloadManager);
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // Don't finish until the download is finished
   do_test_pending();
 
   function addDownload() {
     const nsIWBP = Ci.nsIWebBrowserPersist;
     var persist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
                   .createInstance(Ci.nsIWebBrowserPersist);
     persist.persistFlags = nsIWBP.PERSIST_FLAGS_REPLACE_EXISTING_FILES |
--- a/toolkit/components/downloads/test/unit/test_cancel_download_files_removed.js
+++ b/toolkit/components/downloads/test/unit/test_cancel_download_files_removed.js
@@ -118,16 +118,20 @@ function getResponse(aSet) {
 //   3.) after they have been resumed
 let tests = [
   { serverPath: "/test1.html", data: "Test data 1" },
   { serverPath: "/test2.html", data: "Test data 2", doPause: true },
   { serverPath: "/test3.html", data: "Test data 3", doPause: true, doResume: true},
 ];
 
 function run_test() {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // setup a download listener to run tests during and after the download
   DownloadListener.init();
   Services.prefs.setBoolPref("browser.download.manager.showWhenStarting", false);
 
   httpserver = new HttpServer();
   httpserver.start(-1);
   do_test_pending();
 
--- a/toolkit/components/downloads/test/unit/test_download_manager.js
+++ b/toolkit/components/downloads/test/unit/test_download_manager.js
@@ -91,16 +91,20 @@ function test_dm_getDownload(aDl)
 var tests = [test_get_download_empty_queue, test_connection,
              test_count_empty_queue, test_canCleanUp_empty_queue,
              test_pauseDownload_empty_queue, test_resumeDownload_empty_queue,
              test_addDownload_normal, test_addDownload_cancel];
 
 var httpserv = null;
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   httpserv = new HttpServer();
   httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(-1);
 
   // our download listener
   var listener = {
     // this listener checks to ensure activeDownloadCount is correct.
     onDownloadStateChange: function(aState, aDownload)
--- a/toolkit/components/downloads/test/unit/test_download_samename.js
+++ b/toolkit/components/downloads/test/unit/test_download_samename.js
@@ -140,16 +140,20 @@ function getResponse(aSet) {
 // itself
 let tests = [
   { serverURL: "/test1.html", data: "Test data 1", doPause: false },
   { serverURL: "/test2.html", data: "Test data 2", doPause: false },
   { serverURL: "/test3.html", data: "Test data 3", doPause: true }
 ];
 
 function run_test() {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // setup a download listener to run tests after each download finished
   DownloadListener.init();
   Services.prefs.setBoolPref("browser.download.manager.showWhenStarting", false);
 
   httpserver = new HttpServer();
   httpserver.start(-1);
   do_test_pending();
 
--- a/toolkit/components/downloads/test/unit/test_guid.js
+++ b/toolkit/components/downloads/test/unit/test_guid.js
@@ -1,16 +1,20 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 const dm = Cc["@mozilla.org/download-manager;1"].getService(Ci.nsIDownloadManager);
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   let server = new HttpServer();
   server.start(-1);
   let dl = addDownload(server);
   do_test_pending();
 
   do_print(dl.guid);
   do_check_true(/^[a-zA-Z0-9\-_]{12}$/.test(dl.guid));
 
--- a/toolkit/components/downloads/test/unit/test_history_expiration.js
+++ b/toolkit/components/downloads/test/unit/test_history_expiration.js
@@ -21,16 +21,20 @@ function getExpirablePRTime() {
   dateObj.setSeconds(0);
   dateObj.setMilliseconds(0);
   dateObj = new Date(dateObj.getTime() - 8 * 86400000);
   return dateObj.getTime() * 1000;
 }
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   run_next_test();
 }
 
 add_task(function test_execute()
 {
   // Like the code, we check to see if nav-history-service exists
   // (i.e MOZ_PLACES is enabled), so that we don't run this test if it doesn't.
   if (!("@mozilla.org/browser/nav-history-service;1" in Cc))
--- a/toolkit/components/downloads/test/unit/test_offline_support.js
+++ b/toolkit/components/downloads/test/unit/test_offline_support.js
@@ -13,17 +13,19 @@
  */
 let doNotError = false;
 
 const nsIF = Ci.nsIFile;
 const nsIDM = Ci.nsIDownloadManager;
 const nsIWBP = Ci.nsIWebBrowserPersist;
 const nsIWPL = Ci.nsIWebProgressListener;
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
-dm.cleanUp();
+if (!oldDownloadManagerDisabled()) {
+  dm.cleanUp();
+}
 
 function setOnlineState(aOnline)
 {
   // We do not actually set the offline state because that introduces some neat
   // conditions when being called within a listener.  We do dispatch the right
   // observer topics though, so this tests just the download manager.
   let topic = aOnline ?
     "network:offline-status-changed" :
@@ -31,16 +33,20 @@ function setOnlineState(aOnline)
   let state = aOnline ? "online" : "offline";
   Cc["@mozilla.org/observer-service;1"].
   getService(Ci.nsIObserverService).
   notifyObservers(null, topic, state);
 }
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   /**
    * 1. Create data for http server to send
    */
   // data starts at 10 bytes
   let data = "1234567890";
   // data * 10^4 = 100,000 bytes (actually 101,111 bytes with newline)
   for (let i = 0; i < 4; i++)
     data = [data,data,data,data,data,data,data,data,data,data,"\n"].join("");
--- a/toolkit/components/downloads/test/unit/test_old_download_files_removed.js
+++ b/toolkit/components/downloads/test/unit/test_old_download_files_removed.js
@@ -2,16 +2,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Make sure we remove old, now-unused downloads.rdf (pre-Firefox 3 storage)
 // when starting the download manager.
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // Create the downloads.rdf file
   importDownloadsFile("empty_downloads.rdf");
 
   // Make sure it got created
   let rdfFile = dirSvc.get("DLoads", Ci.nsIFile);
   do_check_true(rdfFile.exists());
 
   // Initialize the download manager, which will delete downloads.rdf
--- a/toolkit/components/downloads/test/unit/test_private_resume.js
+++ b/toolkit/components/downloads/test/unit/test_private_resume.js
@@ -2,16 +2,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Public request gets times=0 cookie, completes
 // Private request gets times=1 cookie, canceled
 // Private resumed request sends times=1 cookie, completes
 
 function run_test() {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   // Allow all cookies.
   Services.prefs.setIntPref("network.cookie.cookieBehavior", 0);
 
   do_test_pending();
   let httpserv = new HttpServer();
 
   let times = 0;
   httpserv.registerPathHandler("/head_download_manager.js", function (meta, response) {
--- a/toolkit/components/downloads/test/unit/test_privatebrowsing.js
+++ b/toolkit/components/downloads/test/unit/test_privatebrowsing.js
@@ -74,16 +74,20 @@ function is_download_available(aGUID, aS
       do_check_eq(download.displayName, aName);
       do_check_eq(download.isPrivate, aPrivate);
     }
     do_test_finished();
   });
 }
 
 function run_test() {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   let prefBranch = Cc["@mozilla.org/preferences-service;1"].
                    getService(Ci.nsIPrefBranch);
 
   do_test_pending();
   let httpserv = new HttpServer();
   httpserv.registerDirectory("/", do_get_cwd());
   httpserv.start(-1);
 
--- a/toolkit/components/downloads/test/unit/test_privatebrowsing_cancel.js
+++ b/toolkit/components/downloads/test/unit/test_privatebrowsing_cancel.js
@@ -72,16 +72,20 @@ function trigger_pb_cleanup(expected)
   cancel.data = false;
   obs.notifyObservers(cancel, "last-pb-context-exiting", null);
   do_check_eq(expected, cancel.data);
   if (!expected)
     obs.notifyObservers(cancel, "last-pb-context-exited", null);
 }
 
 function run_test() {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   function finishTest() {
     // Cancel Download-G
     dlG.cancel();
     dlG.remove();
     dm.cleanUp();
     dm.cleanUpPrivate();
     do_check_eq(dm.activeDownloadCount, 0);
     do_check_eq(dm.activePrivateDownloadCount, 0);
--- a/toolkit/components/downloads/test/unit/test_removeDownloadsByTimeframe.js
+++ b/toolkit/components/downloads/test/unit/test_removeDownloadsByTimeframe.js
@@ -150,13 +150,17 @@ let tests = [
   test_multiple_downloads_in_range,
   test_no_downloads_in_range,
   test_active_download_in_range,
   test_observer_dispatched,
 ];
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   for (let i = 0; i < tests.length; i++) {
     dm.cleanUp();
     tests[i]();
   }
 }
--- a/toolkit/components/downloads/test/unit/test_resume.js
+++ b/toolkit/components/downloads/test/unit/test_resume.js
@@ -12,16 +12,20 @@
 const nsIF = Ci.nsIFile;
 const nsIDM = Ci.nsIDownloadManager;
 const nsIWBP = Ci.nsIWebBrowserPersist;
 const nsIWPL = Ci.nsIWebProgressListener;
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   /**
    * 1. Create data for http server to send
    */
   // data starts at 10 bytes
   var data = "1234567890";
   // data * 10^4 = 100,000 bytes (actually 101,111 bytes with newline)
   for (var i = 0; i < 4; i++) {
     data = [data,data,data,data,data,data,data,data,data,data,"\n"].join("");
--- a/toolkit/components/downloads/test/unit/test_sleep_wake.js
+++ b/toolkit/components/downloads/test/unit/test_sleep_wake.js
@@ -13,27 +13,33 @@
  */
 let doNotError = false;
 
 const nsIF = Ci.nsIFile;
 const nsIDM = Ci.nsIDownloadManager;
 const nsIWBP = Ci.nsIWebBrowserPersist;
 const nsIWPL = Ci.nsIWebProgressListener;
 const dm = Cc["@mozilla.org/download-manager;1"].getService(nsIDM);
-dm.cleanUp();
+if (!oldDownloadManagerDisabled()) {
+  dm.cleanUp();
+}
 
 function notify(aTopic)
 {
   Cc["@mozilla.org/observer-service;1"].
   getService(Ci.nsIObserverService).
   notifyObservers(null, aTopic, null);
 }
 
 function run_test()
 {
+  if (oldDownloadManagerDisabled()) {
+    return;
+  }
+
   /**
    * 0. Speed up the resume on wake delay from 10 seconds
    */
   Cc["@mozilla.org/preferences-service;1"].
   getService(Ci.nsIPrefBranch).
   setIntPref("browser.download.manager.resumeOnWakeDelay", 1000);
 
   /**