summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/unit/test_tree-model-05.js
blob: 3b94707988fb2046e7fc6d4c4bc0f631e522b1c8 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Tests if an inverted call tree model can be correctly computed from a samples
 * array.
 */

var time = 1;

var gThread = synthesizeProfileForTest([{
  time: time++,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
    { location: "C" }
  ]
}, {
  time: time++,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "D" },
    { location: "C" }
  ]
}, {
  time: time++,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "E" },
    { location: "C" }
  ],
}, {
  time: time++,
  frames: [
    { location: "(root)" },
    { location: "A" },
    { location: "B" },
    { location: "F" }
  ]
}]);

function run_test() {
  run_next_test();
}

add_task(function test() {
  let { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");

  let root = new ThreadNode(gThread, { invertTree: true, startTime: 0, endTime: 4 });

  equal(root.calls.length, 2,
     "Should get the 2 youngest frames, not the 1 oldest frame");

  let C = getFrameNodePath(root, "C");
  ok(C, "Should have C as a child of the root.");

  equal(C.calls.length, 3,
     "Should have 3 frames that called C.");
  ok(getFrameNodePath(C, "B"), "B called C.");
  ok(getFrameNodePath(C, "D"), "D called C.");
  ok(getFrameNodePath(C, "E"), "E called C.");

  equal(getFrameNodePath(C, "B").calls.length, 1);
  ok(getFrameNodePath(C, "B > A"), "A called B called C");
  equal(getFrameNodePath(C, "D").calls.length, 1);
  ok(getFrameNodePath(C, "D > A"), "A called D called C");
  equal(getFrameNodePath(C, "E").calls.length, 1);
  ok(getFrameNodePath(C, "E > A"), "A called E called C");

  let F = getFrameNodePath(root, "F");
  ok(F, "Should have F as a child of the root.");

  equal(F.calls.length, 1);
  ok(getFrameNodePath(F, "B"), "B called F");

  equal(getFrameNodePath(F, "B").calls.length, 1);
  ok(getFrameNodePath(F, "B > A"), "A called B called F");
});