summaryrefslogtreecommitdiffstats
path: root/devtools/shared/heapsnapshot/tests/unit/test_HeapSnapshot_computeShortestPaths_02.js
blob: 04fe58733b2209d5d56bbb6f7c6fe452fa970bda (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test computing shortest paths with invalid arguments.

function run_test() {
  const path = ChromeUtils.saveHeapSnapshot({ runtime: true });
  const snapshot = ChromeUtils.readHeapSnapshot(path);

  const dominatorTree = snapshot.computeDominatorTree();
  const target = dominatorTree.getImmediatelyDominated(dominatorTree.root).pop();
  ok(target);

  let threw = false;
  try {
    snapshot.computeShortestPaths(0, [target], 2);
  } catch (_) {
    threw = true;
  }
  ok(threw, "invalid start node should throw");

  threw = false;
  try {
    snapshot.computeShortestPaths(dominatorTree.root, [0], 2);
  } catch (_) {
    threw = true;
  }
  ok(threw, "invalid target nodes should throw");

  threw = false;
  try {
    snapshot.computeShortestPaths(dominatorTree.root, [], 2);
  } catch (_) {
    threw = true;
  }
  ok(threw, "empty target nodes should throw");

  threw = false;
  try {
    snapshot.computeShortestPaths(dominatorTree.root, [target], 0);
  } catch (_) {
    threw = true;
  }
  ok(threw, "0 max paths should throw");

  do_test_finished();
}