summaryrefslogtreecommitdiffstats
path: root/toolkit/components/commandlines/test/unit/test_createCommandLine.js
blob: 08c02981d97674497a9adf609dcf2b5102da2e87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

add_task(async function test_createCommandLine() {
  const EXISTING_FILE = do_get_file("xpcshell.toml");

  // Test `arguments`.
  let cmdLine = Cu.createCommandLine(
    [],
    null,
    Ci.nsICommandLine.STATE_REMOTE_EXPLICIT
  );
  Assert.equal(cmdLine.length, 0);
  Assert.throws(() => cmdLine.workingDirectory, /NS_ERROR_NOT_INITIALIZED/);
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_EXPLICIT);

  cmdLine = Cu.createCommandLine(
    ["test"],
    null,
    Ci.nsICommandLine.STATE_REMOTE_EXPLICIT
  );
  Assert.equal(cmdLine.length, 1);
  Assert.equal(cmdLine.getArgument(0), "test");
  Assert.throws(() => cmdLine.getArgument(1), /NS_ERROR_ILLEGAL_VALUE/);
  Assert.throws(() => cmdLine.workingDirectory, /NS_ERROR_NOT_INITIALIZED/);
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_EXPLICIT);

  cmdLine = Cu.createCommandLine(
    ["test1", "test2"],
    null,
    Ci.nsICommandLine.STATE_REMOTE_EXPLICIT
  );
  Assert.equal(cmdLine.length, 2);
  Assert.equal(cmdLine.getArgument(0), "test1");
  Assert.equal(cmdLine.getArgument(1), "test2");
  Assert.throws(() => cmdLine.getArgument(2), /NS_ERROR_ILLEGAL_VALUE/);
  Assert.throws(() => cmdLine.workingDirectory, /NS_ERROR_NOT_INITIALIZED/);
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_EXPLICIT);

  // Test `workingDirectory`.
  cmdLine = Cu.createCommandLine(
    [],
    EXISTING_FILE.parent,
    Ci.nsICommandLine.STATE_REMOTE_AUTO
  );
  Assert.equal(cmdLine.length, 0);
  Assert.equal(cmdLine.workingDirectory.path, EXISTING_FILE.parent.path);
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_AUTO);

  // Test `state`.
  cmdLine = Cu.createCommandLine([], null, Ci.nsICommandLine.STATE_REMOTE_AUTO);
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_AUTO);

  cmdLine = Cu.createCommandLine(
    [],
    EXISTING_FILE.parent,
    Ci.nsICommandLine.STATE_REMOTE_EXPLICIT
  );
  Assert.equal(cmdLine.state, Ci.nsICommandLine.STATE_REMOTE_EXPLICIT);
});