test_windows_cmdline_file.js 1001 B

12345678910111213141516171819202122
  1. let { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
  2. Cu.import("resource://gre/modules/Services.jsm");
  3. let executableFile = Services.dirsvc.get("CurProcD", Ci.nsIFile);
  4. executableFile.append("xpcshell.exe");
  5. function run_test() {
  6. let quote = '"'; // Windows' cmd processor doesn't actually use single quotes.
  7. for (let suffix of ["", " -osint", ` --blah "%PROGRAMFILES%"`]) {
  8. let cmdline = quote + executableFile.path + quote + suffix;
  9. do_print(`Testing with ${cmdline}`);
  10. let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFileWin);
  11. f.initWithCommandLine(cmdline);
  12. Assert.equal(f.path, executableFile.path, "Should be able to recover executable path");
  13. }
  14. let f = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFileWin);
  15. f.initWithCommandLine("%ComSpec% -c echo 'hi'");
  16. let cmd = Services.dirsvc.get("SysD", Ci.nsIFile);
  17. cmd.append("cmd.exe");
  18. Assert.equal(f.path, cmd.path, "Should be able to replace env vars.");
  19. }