summaryrefslogtreecommitdiffstats
path: root/devtools/shared/heapsnapshot/tests/xpcshell/test_HeapSnapshot_computeShortestPaths_02.js
blob: 714986c6012612732d4218b07e19436e603fc155 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// 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();
}