Bug 1146907 - Dismissing the unblock related dialog window unblocks the download. r=paolo, a=sledru
authorJared Wein <jwein@mozilla.com>
Wed, 25 Mar 2015 13:39:01 -0400
changeset 248536 154f30b91df382a4deca636c9ff3dbee34e88fe4
parent 248535 8333cdfb08e80d69fdd70f2da5931473e07a4262
child 248537 36249d8296a49d39e488fd288d0561b9aef87b50
push id7856
push userryanvm@gmail.com
push dateMon, 30 Mar 2015 13:25:20 +0000
treeherdermozilla-aurora@7049015f9ce3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo, sledru
bugs1146907
milestone38.0a2
Bug 1146907 - Dismissing the unblock related dialog window unblocks the download. r=paolo, a=sledru
browser/components/downloads/DownloadsCommon.jsm
browser/components/downloads/test/browser/browser_confirm_unblock_download.js
--- a/browser/components/downloads/DownloadsCommon.jsm
+++ b/browser/components/downloads/DownloadsCommon.jsm
@@ -546,17 +546,18 @@ this.DownloadsCommon = {
    *
    * @return True to unblock the file, false to keep the user safe and
    *         cancel the operation.
    */
   confirmUnblockDownload: Task.async(function* (aType, aOwnerWindow) {
     let s = DownloadsCommon.strings;
     let title = s.unblockHeader;
     let buttonFlags = (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
-                      (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1);
+                      (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
+                      Ci.nsIPrompt.BUTTON_POS_1_DEFAULT;
     let type = "";
     let message = s.unblockTip;
     let okButton = s.unblockButtonContinue;
     let cancelButton = s.unblockButtonCancel;
 
     switch (aType) {
       case this.BLOCK_VERDICT_MALWARE:
         type = s.unblockTypeMalware;
@@ -587,19 +588,21 @@ this.DownloadsCommon = {
               // Change the dialog to use a warning icon.
               dialog.classList.add("alert-dialog");
             }
           }
         });
       }
     });
 
+    // The ordering of the ok/cancel buttons is used this way to allow "cancel"
+    // to have the same result as hitting the ESC or Close button (see bug 345067).
     let rv = Services.prompt.confirmEx(aOwnerWindow, title, message, buttonFlags,
-                                       cancelButton, okButton, null, null, {});
-    return (rv == 1);
+                                       okButton, cancelButton, null, null, {});
+    return (rv == 0);
   }),
 };
 
 /**
  * Returns true if we are executing on Windows Vista or a later version.
  */
 XPCOMUtils.defineLazyGetter(DownloadsCommon, "isWinVistaOrHigher", function () {
   let os = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
--- a/browser/components/downloads/test/browser/browser_confirm_unblock_download.js
+++ b/browser/components/downloads/test/browser/browser_confirm_unblock_download.js
@@ -27,20 +27,20 @@ function addDialogOpenObserver(buttonAct
           doc.getButton(buttonAction).click();
         }
       });
     }
   });
 }
 
 add_task(function* test_confirm_unblock_dialog_unblock() {
-  addDialogOpenObserver("cancel");
+  addDialogOpenObserver("accept");
   let result = yield DownloadsCommon.confirmUnblockDownload(DownloadsCommon.BLOCK_VERDICT_MALWARE,
                                                             window);
   ok(result, "Should return true when the user clicks on `Unblock` button.");
 });
 
 add_task(function* test_confirm_unblock_dialog_keep_safe() {
-  addDialogOpenObserver("accept");
+  addDialogOpenObserver("cancel");
   let result = yield DownloadsCommon.confirmUnblockDownload(DownloadsCommon.BLOCK_VERDICT_MALWARE,
                                                             window);
   ok(!result, "Should return false when the user clicks on `Keep me safe` button.");
 });