tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_stub_installer.js (1980B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 const { Subprocess } = ChromeUtils.importESModule(
      8  "resource://gre/modules/Subprocess.sys.mjs"
      9 );
     10 
     11 function _getBinaryUtil(binaryUtilName) {
     12  let utilBin = Services.dirsvc.get("GreD", Ci.nsIFile);
     13  // On macOS, GreD is .../Contents/Resources, and most binary utilities
     14  // are located there, but certutil is in GreBinD (or .../Contents/MacOS),
     15  // so we have to change the path accordingly.
     16  if (binaryUtilName === "certutil") {
     17    utilBin = Services.dirsvc.get("GreBinD", Ci.nsIFile);
     18  }
     19  utilBin.append(binaryUtilName + mozinfo.bin_suffix);
     20  // If we're testing locally, the above works. If not, the server executable
     21  // is in another location.
     22  if (!utilBin.exists()) {
     23    utilBin = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
     24    while (utilBin.path.includes("xpcshell")) {
     25      utilBin = utilBin.parent;
     26    }
     27    utilBin.append("bin");
     28    utilBin.append(binaryUtilName + mozinfo.bin_suffix);
     29  }
     30  // But maybe we're on Android, where binaries are in /data/local/xpcb.
     31  if (!utilBin.exists()) {
     32    utilBin.initWithPath("/data/local/xpcb/");
     33    utilBin.append(binaryUtilName);
     34  }
     35  Assert.ok(utilBin.exists(), `Binary util ${binaryUtilName} should exist`);
     36  return utilBin;
     37 }
     38 
     39 add_task(async function test_openFile() {
     40  // "GreD" is the "Gecko runtime environment directory", which the build system knows as $(topobjdir)/dist/bin
     41  const executableFile = _getBinaryUtil("test_stub_installer");
     42  const command = executableFile.path;
     43 
     44  const proc = await Subprocess.call({
     45    command,
     46  });
     47 
     48  let { exitCode } = await proc.wait();
     49  Assert.equal(0, exitCode);
     50  let stdout = await proc.stdout.readString();
     51  // Verify that the contents of the output file look OK.
     52  Assert.equal("All stub installer tests passed", stdout);
     53 });