Commit 6c1d6be6 authored by Sebastian Hengst's avatar Sebastian Hengst
Browse files

Backed out 3 changesets (bug 1398229) for failing own browser-chrome...

Backed out 3 changesets (bug 1398229) for failing own browser-chrome browser/components/contextualidentity/test/browser/browser_saveLink.js. r=backout on a CLOSED TREE

Backed out changeset 5b3b0a38b2d1 (bug 1398229)
Backed out changeset a726fc7506ca (bug 1398229)
Backed out changeset 53dae7764e58 (bug 1398229)
parent 63600494
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -1153,11 +1153,14 @@ nsContextMenu.prototype = {
    };

    // setting up a new channel for 'right click - save link as ...'
    // ideally we should use:
    // * doc            - as the loadingNode, and/or
    // * this.principal - as the loadingPrincipal
    // for now lets use systemPrincipal to bypass mixedContentBlocker
    // checks after redirects, see bug: 1136055
    var channel = NetUtil.newChannel({
                    uri: makeURI(linkURL),
                    loadingPrincipal: this.principal,
                    contentPolicyType: Ci.nsIContentPolicy.TYPE_SAVEAS_DOWNLOAD,
                    securityFlags: Ci.nsILoadInfo.SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS,
                    loadUsingSystemPrincipal: true
                  });

    if (linkDownload)
+0 −4
Original line number Diff line number Diff line
@@ -30,7 +30,3 @@ tags = openwindow
[browser_imageCache.js]
[browser_count_and_remove.js]
[browser_relatedTab.js]
[browser_saveLink.js]
support-files =
  saveLink.sjs
  !/toolkit/content/tests/browser/common/mockTransfer.js
+0 −148
Original line number Diff line number Diff line
"use strict";

const BASE_ORIGIN = "https://example.com";
const URI = BASE_ORIGIN +
  "/browser/browser/components/contextualidentity/test/browser/saveLink.sjs";

const { Downloads } = Cu.import("resource://gre/modules/Downloads.jsm", {});

let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);

add_task(async function setup() {
  // make sure userContext is enabled.
  await SpecialPowers.pushPrefEnv({"set": [
    ["privacy.userContext.enabled", true]
  ]});
});

add_task(async function test() {
  info("Let's create a temporary dir");
  let tempDir = createTemporarySaveDirectory();

  let downloadList = await Downloads.getList(Downloads.ALL);
  let all = await downloadList.getAll();
  is(all.length, 0, "No pending downloads!");

  info("Let's open a new window");
  let win = await BrowserTestUtils.openNewBrowserWindow();

  info("Opening tab with UCI: 1");
  let tab = BrowserTestUtils.addTab(win.gBrowser, URI + "?UCI=1", {userContextId: 1});

  // select tab and make sure its browser is focused
  win.gBrowser.selectedTab = tab;
  tab.ownerGlobal.focus();

  info("Waiting to load content");
  let browser = gBrowser.getBrowserForTab(tab);
  await BrowserTestUtils.browserLoaded(browser);

  let path = await new Promise(resolve => {
    info("Register to handle popupshown");
    win.document.addEventListener("popupshown", event => {
      info("Context menu opened");

      let destFile = tempDir.clone();

      MockFilePicker.displayDirectory = tempDir;
      MockFilePicker.showCallback = fp => {
        info("MockFilePicker showCallback");
        let fileName = fp.defaultString;
        info("fileName: " + fileName);
        destFile.append(fileName);
        MockFilePicker.setFiles([destFile]);
        MockFilePicker.filterIndex = 1; // kSaveAsType_URL
        info("MockFilePicker showCallback done");
      };

      MockFilePicker.afterOpenCallback = () => {
        info("MockFilePicker afterOpenCallback");

        function resolveOrWait() {
          downloadList.getAll().then(downloads => {
            if (downloads.length) {
              is(downloads.length, 1, "We were expecting 1 download only.");
              ok(downloads[0].source.url.indexOf("saveLink.sjs") != -1, "The path is correct");

              downloads[0].whenSucceeded().then(() => {
                win.close();
                resolve(destFile.leafName);
              });
              return;
            }

            let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
            timer.initWithCallback(() => resolveOrWait, 500, Ci.nsITimer.TYPE_ONE_SHOT);
          });
        }

        resolveOrWait();
      };

      // Select "Save Link As" option from context menu
      let saveLinkCommand = win.document.getElementById("context-savelink");
      info("saveLinkCommand: " + saveLinkCommand);
      saveLinkCommand.doCommand();

      event.target.hidePopup();
      info("popup hidden");
    }, {once: true});

    BrowserTestUtils.synthesizeMouseAtCenter("#fff", {type: "contextmenu", button: 2},
                                             win.gBrowser.selectedBrowser);
    info("Right clicked!");
  });

  ok(path, "File downloaded correctly: " + path);

  let savedFile = tempDir.clone();
  savedFile.append(path);
  ok(savedFile.exists(), "We have the file");

  let content = readFile(savedFile);
  is(content, "cookie-present-UCI=1", "Correct file content: -" + content + "-");

  info("Removing the temporary directory");
  tempDir.remove(true);

  info("Closing the window");
  await BrowserTestUtils.closeWindow(win);
});

/* import-globals-from ../../../../../toolkit/content/tests/browser/common/mockTransfer.js */
Services.scriptloader.loadSubScript("chrome://mochitests/content/browser/toolkit/content/tests/browser/common/mockTransfer.js", this);

function readFile(file) {
  let inputStream = Cc["@mozilla.org/network/file-input-stream;1"]
                      .createInstance(Ci.nsIFileInputStream);
  inputStream.init(file, -1, 0, 0);
  try {
    let scrInputStream = Cc["@mozilla.org/scriptableinputstream;1"]
                           .createInstance(Ci.nsIScriptableInputStream);
    scrInputStream.init(inputStream);
    try {
      // Assume that the file is much shorter than 1 MiB.
      return scrInputStream.read(1048576);
    } finally {
      // Close the scriptable stream after reading, even if the operation
      // failed.
      scrInputStream.close();
    }
  } finally {
    // Close the stream after reading, if it is still open, even if the read
    // operation failed.
    inputStream.close();
  }
}

function createTemporarySaveDirectory() {
  let saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
  saveDir.append("testsavedir");
  if (!saveDir.exists()) {
    info("create testsavedir!");
    saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
  }
  info("return from createTempSaveDir: " + saveDir.path);
  return saveDir;
}
+0 −37
Original line number Diff line number Diff line
const HTTP_ORIGIN = "http://example.com";
const HTTPS_ORIGIN = "https://example.com";
const URI_PATH = "/browser/browser/components/contextualidentity/test/browser/saveLink.sjs";

Components.utils.importGlobalProperties(["URLSearchParams"]);

function handleRequest(aRequest, aResponse) {
  var params = new URLSearchParams(aRequest.queryString);

  // This is the first request, where we set the cookie.
  if (params.has("UCI")) {
    aResponse.setStatusLine(aRequest.httpVersion, 200);
    aResponse.setHeader("Set-Cookie", "UCI=" + params.get("UCI"));
    aResponse.write("<html><body><a href='" + HTTPS_ORIGIN + URI_PATH + "?redirect=1' id='fff'>this is a link</a></body></html>");
    return;
  }

  // Second request. This is the save-as content, but we make a redirect to see
  // if we are able to follow it.
  if (params.has("redirect")) {
    aResponse.setStatusLine(aRequest.httpVersion, 302, "Found");
    aResponse.setHeader("Location", HTTP_ORIGIN + URI_PATH, false);
    aResponse.write("Redirect!");
    return;
  }

  // This is the 3rd request where we offer the content to be saved.
  if (aRequest.hasHeader("Cookie")) {
    aResponse.setStatusLine(aRequest.httpVersion, 200);
    aResponse.write("cookie-present-" + aRequest.getHeader("Cookie"));
    return;
  }

  // We should not be here!
  aResponse.setStatusLine(aRequest.httpVersion, 500);
  aResponse.write("ERROR!!!");
}
+0 −1
Original line number Diff line number Diff line
@@ -114,7 +114,6 @@ NS_CP_ContentTypeName(uint32_t contentType)
    CASE_RETURN( TYPE_FETCH                       );
    CASE_RETURN( TYPE_IMAGESET                    );
    CASE_RETURN( TYPE_WEB_MANIFEST                );
    CASE_RETURN( TYPE_SAVEAS_DOWNLOAD             );
    CASE_RETURN( TYPE_INTERNAL_SCRIPT             );
    CASE_RETURN( TYPE_INTERNAL_WORKER             );
    CASE_RETURN( TYPE_INTERNAL_SHARED_WORKER      );
Loading