Commit d8803405 authored by Neil Deakin's avatar Neil Deakin
Browse files

Bug 1737696, skip spam check for downloads that were saved; this allows the...

Bug 1737696, skip spam check for downloads that were saved; this allows the save link context menu item to work properly, r=mtigley

Differential Revision: https://phabricator.services.mozilla.com/D130999
parent 51a05715
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1738,7 +1738,7 @@ NS_IMETHODIMP nsExternalAppHandler::OnStartRequest(nsIRequest* request) {
    aChannel->GetURI(getter_AddRefs(mSourceUrl));
  }

  if (StaticPrefs::browser_download_enable_spam_prevention() &&
  if (!mForceSave && StaticPrefs::browser_download_enable_spam_prevention() &&
      IsDownloadSpam(aChannel)) {
    RecordDownloadTelemetry(aChannel, "spam");
    return NS_OK;
+29 −0
Original line number Diff line number Diff line
@@ -17,6 +17,10 @@ const TEST_PATH = getRootDirectory(gTestPath).replace(

const AUTOMATIC_DOWNLOAD_TOPIC = "blocked-automatic-download";

var MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
registerCleanupFunction(() => MockFilePicker.cleanup());

add_task(async function setup() {
  // Create temp directory
  let time = new Date().getTime();
@@ -124,4 +128,29 @@ add_task(async function check_download_spam_permissions() {
  for (let event of events) {
    is(event[4], "spam", "download is blocked");
  }

  await savelink();
});

// Check to ensure that a link saved manually is not blocked.
async function savelink() {
  let menu = document.getElementById("contentAreaContextMenu");
  let popupShown = BrowserTestUtils.waitForEvent(menu, "popupshown");
  BrowserTestUtils.synthesizeMouse(
    "#image",
    5,
    5,
    { type: "contextmenu", button: 2 },
    gBrowser.selectedBrowser
  );
  await popupShown;

  await new Promise(resolve => {
    MockFilePicker.showCallback = function(fp) {
      setTimeout(resolve, 0);
      return Ci.nsIFilePicker.returnCancel;
    };
    let menuitem = menu.querySelector("#context-savelink");
    menu.activateItem(menuitem);
  });
}
+1 −0
Original line number Diff line number Diff line
@@ -22,5 +22,6 @@ window.onload = window.onclick = function() {
  }
}
</script>
<a id="image" href="${TEST_ROOT}/file_with@@funny_name.png">Image</a>
</body>
</html>