summaryrefslogtreecommitdiffstats
path: root/devtools/shared/heapsnapshot/tests/xpcshell/test_deduplicatePaths_01.js
blob: fc2864f5f4fafcc3d6e32b2994b6a8b14b9659fd (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

// Test the behavior of the deduplicatePaths utility function.

function edge(from, to, name) {
  return { from, to, name };
}

function run_test() {
  const a = 1;
  const b = 2;
  const c = 3;
  const d = 4;
  const e = 5;
  const f = 6;
  const g = 7;

  dumpn("Single long path");
  assertDeduplicatedPaths({
    target: g,
    paths: [
      [
        pathEntry(a, "e1"),
        pathEntry(b, "e2"),
        pathEntry(c, "e3"),
        pathEntry(d, "e4"),
        pathEntry(e, "e5"),
        pathEntry(f, "e6"),
      ],
    ],
    expectedNodes: [a, b, c, d, e, f, g],
    expectedEdges: [
      edge(a, b, "e1"),
      edge(b, c, "e2"),
      edge(c, d, "e3"),
      edge(d, e, "e4"),
      edge(e, f, "e5"),
      edge(f, g, "e6"),
    ],
  });

  dumpn("Multiple edges from and to the same nodes");
  assertDeduplicatedPaths({
    target: a,
    paths: [[pathEntry(b, "x")], [pathEntry(b, "y")], [pathEntry(b, "z")]],
    expectedNodes: [a, b],
    expectedEdges: [edge(b, a, "x"), edge(b, a, "y"), edge(b, a, "z")],
  });

  dumpn("Multiple paths sharing some nodes and edges");
  assertDeduplicatedPaths({
    target: g,
    paths: [
      [pathEntry(a, "a->b"), pathEntry(b, "b->c"), pathEntry(c, "foo")],
      [pathEntry(a, "a->b"), pathEntry(b, "b->d"), pathEntry(d, "bar")],
      [pathEntry(a, "a->b"), pathEntry(b, "b->e"), pathEntry(e, "baz")],
    ],
    expectedNodes: [a, b, c, d, e, g],
    expectedEdges: [
      edge(a, b, "a->b"),
      edge(b, c, "b->c"),
      edge(b, d, "b->d"),
      edge(b, e, "b->e"),
      edge(c, g, "foo"),
      edge(d, g, "bar"),
      edge(e, g, "baz"),
    ],
  });

  dumpn("Second shortest path contains target itself");
  assertDeduplicatedPaths({
    target: g,
    paths: [
      [pathEntry(a, "a->b"), pathEntry(b, "b->g")],
      [
        pathEntry(a, "a->b"),
        pathEntry(b, "b->g"),
        pathEntry(g, "g->f"),
        pathEntry(f, "f->g"),
      ],
    ],
    expectedNodes: [a, b, g],
    expectedEdges: [edge(a, b, "a->b"), edge(b, g, "b->g")],
  });
}