Bug 941099 - Default application handler is not correctly used when an alternate app handler exists. r=paolo a=lsblakk
authorFelipe Gomes <felipc@gmail.com>
Thu, 28 Nov 2013 20:45:44 -0200
changeset 167588 566926400786f819c658db05831eb6871fe74b68
parent 167587 3cadac0a4a787146ebcc75a070c2f540e397e603
child 167589 0a5e44e5476411a0d47f5d5d58543922ba49b2d5
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo, lsblakk
bugs941099
milestone27.0a2
Bug 941099 - Default application handler is not correctly used when an alternate app handler exists. r=paolo a=lsblakk
toolkit/components/jsdownloads/src/DownloadLegacy.js
toolkit/components/jsdownloads/test/unit/common_test_Download.js
toolkit/components/jsdownloads/test/unit/head.js
--- a/toolkit/components/jsdownloads/src/DownloadLegacy.js
+++ b/toolkit/components/jsdownloads/src/DownloadLegacy.js
@@ -190,17 +190,18 @@ DownloadLegacyTransfer.prototype = {
     let launchWhenSucceeded = false, contentType = null, launcherPath = null;
 
     if (aMIMEInfo instanceof Ci.nsIMIMEInfo) {
       launchWhenSucceeded =
                 aMIMEInfo.preferredAction != Ci.nsIMIMEInfo.saveToDisk;
       contentType = aMIMEInfo.type;
 
       let appHandler = aMIMEInfo.preferredApplicationHandler;
-      if (appHandler instanceof Ci.nsILocalHandlerApp) {
+      if (aMIMEInfo.preferredAction == Ci.nsIMIMEInfo.useHelperApp &&
+          appHandler instanceof Ci.nsILocalHandlerApp) {
         launcherPath = appHandler.executable.path;
       }
     }
 
     // Create a new Download object associated to a DownloadLegacySaver, and
     // wait for it to be available.  This operation may cause the entire
     // download system to initialize before the object is created.
     Downloads.createDownload({
--- a/toolkit/components/jsdownloads/test/unit/common_test_Download.js
+++ b/toolkit/components/jsdownloads/test/unit/common_test_Download.js
@@ -1461,37 +1461,39 @@ add_task(function test_launch() {
     let download;
     if (!gUseLegacySaver) {
       // When testing DownloadCopySaver, we have control over the download, thus
       // we can test that file is not launched if download.succeeded is not set.
       download = yield Downloads.createDownload({
         source: httpUrl("source.txt"),
         target: getTempFile(TEST_TARGET_FILE_NAME).path,
         launcherPath: launcherPath,
+        launchWhenSucceeded: true
       });
 
       try {
         yield download.launch();
         do_throw("Can't launch download file as it has not completed yet");
       } catch (ex) {
         do_check_eq(ex.message,
                     "launch can only be called if the download succeeded");
       }
 
       yield download.start();
     } else {
       // When testing DownloadLegacySaver, the download is already started when
       // it is created, thus we don't test calling "launch" before starting.
       download = yield promiseStartLegacyDownload(
                                          httpUrl("source.txt"),
-                                         { launcherPath: launcherPath });
+                                         { launcherPath: launcherPath,
+                                           launchWhenSucceeded: true });
       yield promiseDownloadStopped(download);
     }
 
-    do_check_false(download.launchWhenSucceeded);
+    do_check_true(download.launchWhenSucceeded);
 
     DownloadIntegration._deferTestOpenFile = Promise.defer();
     download.launch();
     let result = yield DownloadIntegration._deferTestOpenFile.promise;
 
     // Verify that the results match the test case.
     if (!launcherPath) {
       // This indicates that the default handler has been chosen.
--- a/toolkit/components/jsdownloads/test/unit/head.js
+++ b/toolkit/components/jsdownloads/test/unit/head.js
@@ -336,16 +336,17 @@ function promiseStartLegacyDownload(aSou
   if (aOptions && aOptions.launcherPath) {
     do_check_true(mimeInfo != null);
 
     let localHandlerApp = Cc["@mozilla.org/uriloader/local-handler-app;1"]
                             .createInstance(Ci.nsILocalHandlerApp);
     localHandlerApp.executable = new FileUtils.File(aOptions.launcherPath);
 
     mimeInfo.preferredApplicationHandler = localHandlerApp;
+    mimeInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp;
   }
 
   if (aOptions && aOptions.launchWhenSucceeded) {
     do_check_true(mimeInfo != null);
 
     mimeInfo.preferredAction = Ci.nsIMIMEInfo.useHelperApp;
   }