Commit 4b7b29cf authored by Victor Porof's avatar Victor Porof
Browse files

Bug 1561435 - Format toolkit/xre/, a=automatic-formatting

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D36059

--HG--
extra : source : 04a147cbaa99c0195126412724b82b8be60503ee
parent 463c2994
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -3,10 +3,14 @@

// Tests that the dll blocklist initializes correctly during test runs.
add_task(async function test() {
  await BrowserTestUtils.withNewTab({gBrowser, url: "about:blank" }, function(browser) {
    ok(Services.appinfo.windowsDLLBlocklistStatus,
  await BrowserTestUtils.withNewTab({ gBrowser, url: "about:blank" }, function(
    browser
  ) {
    ok(
      Services.appinfo.windowsDLLBlocklistStatus,
      "Windows dll blocklist status should be true, indicating it is " +
        "running properly. A failure in this test is considered a " +
       "release blocker.");
        "release blocker."
    );
  });
});
+3 −1
Original line number Diff line number Diff line
const xre = Cc["@mozilla.org/xre/directory-provider;1"].getService(Ci.nsIXREDirProvider);
const xre = Cc["@mozilla.org/xre/directory-provider;1"].getService(
  Ci.nsIXREDirProvider
);
dump(`${xre.getInstallHash(false)}\n`);
+37 −9
Original line number Diff line number Diff line
@@ -7,9 +7,13 @@
 */

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { Subprocess } = ChromeUtils.import("resource://gre/modules/Subprocess.jsm");
const { Subprocess } = ChromeUtils.import(
  "resource://gre/modules/Subprocess.jsm"
);

const XRE = Cc["@mozilla.org/xre/directory-provider;1"].getService(Ci.nsIXREDirProvider);
const XRE = Cc["@mozilla.org/xre/directory-provider;1"].getService(
  Ci.nsIXREDirProvider
);
const HASH = XRE.getInstallHash(false);
const EXE = Services.dirsvc.get("XREExeF", Ci.nsIFile);
const SCRIPT = do_get_file("show_hash.js", false);
@@ -66,7 +70,11 @@ function countParts(path) {
add_task(async function testSameBinary() {
  // Running with the same binary path should definitely work and give the same
  // hash.
  Assert.equal(await getHash(EXE), HASH, "Should have the same hash when running the same binary.");
  Assert.equal(
    await getHash(EXE),
    HASH,
    "Should have the same hash when running the same binary."
  );
});

add_task(async function testUpperCase() {
@@ -75,7 +83,11 @@ add_task(async function testUpperCase() {

  // We may not get a hash if any part of the filesystem is case sensitive.
  if (hash) {
    Assert.equal(hash, HASH, `Should have seen the same hash from ${upper.path}.`);
    Assert.equal(
      hash,
      HASH,
      `Should have seen the same hash from ${upper.path}.`
    );
  }
});

@@ -85,7 +97,11 @@ add_task(async function testLowerCase() {

  // We may not get a hash if any part of the filesystem is case sensitive.
  if (hash) {
    Assert.equal(hash, HASH, `Should have seen the same hash from ${lower.path}.`);
    Assert.equal(
      hash,
      HASH,
      `Should have seen the same hash from ${lower.path}.`
    );
  }
});

@@ -95,17 +111,29 @@ add_task(async function testEachPart() {

  let count = countParts(EXE);
  for (let i = 0; i < count; i++) {
    let upper = mutatePath(EXE, (p, index) => index == i ? p.toLocaleUpperCase() : p);
    let lower = mutatePath(EXE, (p, index) => index == i ? p.toLocaleLowerCase() : p);
    let upper = mutatePath(EXE, (p, index) =>
      index == i ? p.toLocaleUpperCase() : p
    );
    let lower = mutatePath(EXE, (p, index) =>
      index == i ? p.toLocaleLowerCase() : p
    );

    let upperHash = await getHash(upper);
    if (upperHash) {
      Assert.equal(upperHash, HASH, `Should have seen the same hash from ${upper.path}.`);
      Assert.equal(
        upperHash,
        HASH,
        `Should have seen the same hash from ${upper.path}.`
      );
    }

    let lowerHash = await getHash(lower);
    if (lowerHash) {
      Assert.equal(lowerHash, HASH, `Should have seen the same hash from ${lower.path}.`);
      Assert.equal(
        lowerHash,
        HASH,
        `Should have seen the same hash from ${lower.path}.`
      );
    }
  }
});
+57 −31
Original line number Diff line number Diff line
@@ -10,18 +10,20 @@
const Cm = Components.manager;

ChromeUtils.import("resource://gre/modules/Services.jsm", this);
const {AppConstants} = ChromeUtils.import("resource://gre/modules/AppConstants.jsm");

const { AppConstants } = ChromeUtils.import(
  "resource://gre/modules/AppConstants.jsm"
);

const APP_TIMER_TIMEOUT_MS = 1000 * 15;
const TRY_COUNT = 50;


// Sets a group of environment variables, returning the old values.
// newVals AND return value is an array of { key: "", value: "" }
function setEnvironmentVariables(newVals) {
  let oldVals = [];
  let env = Cc["@mozilla.org/process/environment;1"].getService(Ci.nsIEnvironment);
  let env = Cc["@mozilla.org/process/environment;1"].getService(
    Ci.nsIEnvironment
  );
  for (let i = 0; i < newVals.length; ++i) {
    let key = newVals[i].key;
    let value = newVals[i].value;
@@ -38,7 +40,6 @@ function setEnvironmentVariables(newVals) {
  return oldVals;
}


function getFirefoxExecutableFilename() {
  if (AppConstants.platform === "win") {
    return AppConstants.MOZ_APP_NAME + ".exe";
@@ -46,7 +47,6 @@ function getFirefoxExecutableFilename() {
  return AppConstants.MOZ_APP_NAME;
}


// Returns a nsIFile to the firefox.exe executable file
function getFirefoxExecutableFile() {
  let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
@@ -56,7 +56,6 @@ function getFirefoxExecutableFile() {
  return file;
}


// Takes an executable and arguments, and wraps it in a call to the system shell.
// Technique adapted from \toolkit\mozapps\update\tests\unit_service_updater\xpcshellUtilsAUS.js
// to avoid child process console output polluting the xpcshell log.
@@ -75,12 +74,14 @@ function wrapLaunchInShell(file, args) {
    ret.args = [file.path].concat(args).concat(["> /dev/null"]);
  }

  Assert.ok(ret.file.exists(), "Executable file should exist: " + ret.file.path);
  Assert.ok(
    ret.file.exists(),
    "Executable file should exist: " + ret.file.path
  );

  return ret;
}


// Needed because process.kill() kills the console, not its child process, firefox.
function terminateFirefox(completion) {
  let executableName = getFirefoxExecutableFilename();
@@ -108,11 +109,16 @@ function terminateFirefox(completion) {
    observe: function PO_observe(aSubject, aTopic, aData) {
      info("topic: " + aTopic + ", process exitValue: " + process.exitValue);

      Assert.equal(process.exitValue, 0,
                   "Terminate firefox process exit value should be 0");
      Assert.equal(aTopic, "process-finished",
                   "Terminate firefox observer topic should be " +
                   "process-finished");
      Assert.equal(
        process.exitValue,
        0,
        "Terminate firefox process exit value should be 0"
      );
      Assert.equal(
        aTopic,
        "process-finished",
        "Terminate firefox observer topic should be " + "process-finished"
      );

      if (completion) {
        completion();
@@ -126,7 +132,6 @@ function terminateFirefox(completion) {
  info("             with pid: " + process.pid);
}


// Launches file with args asynchronously, failing if the process did not
// exit within timeoutMS milliseconds. If a timeout occurs, handler()
// is called.
@@ -143,7 +148,9 @@ function launchProcess(file, args, env, timeoutMS, handler, attemptCount) {
        return;
      }

      info("topic: " + aTopic + ", process exitValue: " + state.process.exitValue);
      info(
        "topic: " + aTopic + ", process exitValue: " + state.process.exitValue
      );

      info("Restoring environment variables");
      setEnvironmentVariables(state.oldEnv);
@@ -151,11 +158,16 @@ function launchProcess(file, args, env, timeoutMS, handler, attemptCount) {
      state.appTimer.cancel();
      state.appTimer = null;

      Assert.equal(state.process.exitValue, 0,
                   "the application process exit value should be 0");
      Assert.equal(aTopic, "process-finished",
                   "the application process observer topic should be " +
                   "process-finished");
      Assert.equal(
        state.process.exitValue,
        0,
        "the application process exit value should be 0"
      );
      Assert.equal(
        aTopic,
        "process-finished",
        "the application process observer topic should be " + "process-finished"
      );

      handler(true);
    },
@@ -189,11 +201,17 @@ function launchProcess(file, args, env, timeoutMS, handler, attemptCount) {
    info("             " + env[i].key + "=" + env[i].value);
  }

  state.process = Cc["@mozilla.org/process/util;1"].createInstance(Ci.nsIProcess);
  state.process = Cc["@mozilla.org/process/util;1"].createInstance(
    Ci.nsIProcess
  );
  state.process.init(file);

  state.appTimer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
  state.appTimer.initWithCallback(state.appTimerCallback, timeoutMS, Ci.nsITimer.TYPE_ONE_SHOT);
  state.appTimer.initWithCallback(
    state.appTimerCallback,
    timeoutMS,
    Ci.nsITimer.TYPE_ONE_SHOT
  );

  state.oldEnv = setEnvironmentVariables(env);

@@ -202,7 +220,6 @@ function launchProcess(file, args, env, timeoutMS, handler, attemptCount) {
  info("             with pid: " + state.process.pid);
}


function run_test() {
  do_test_pending();

@@ -218,7 +235,7 @@ function run_test() {

  let handler = function launchFirefoxHandler(okToContinue) {
    triesStarted++;
    if ((triesStarted <= TRY_COUNT) && okToContinue) {
    if (triesStarted <= TRY_COUNT && okToContinue) {
      testTry();
    } else {
      do_test_finished();
@@ -226,11 +243,20 @@ function run_test() {
  };

  let testTry = function testTry() {
    let shell = wrapLaunchInShell(getFirefoxExecutableFile(), ["-no-remote", "-test-launch-without-hang"]);
    let shell = wrapLaunchInShell(getFirefoxExecutableFile(), [
      "-no-remote",
      "-test-launch-without-hang",
    ]);
    info("Try attempt #" + triesStarted);
    launchProcess(shell.file, shell.args, env, APP_TIMER_TIMEOUT_MS, handler, triesStarted);
    launchProcess(
      shell.file,
      shell.args,
      env,
      APP_TIMER_TIMEOUT_MS,
      handler,
      triesStarted
    );
  };

  testTry();
}