summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/unit/test_tree-model-07.js
blob: 2ea08c5cae3470438ce6b079354a86517ac41203 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

/**
 * Tests that when displaying only content nodes, platform nodes are generalized.
 */

var { CATEGORY_MASK } = require("devtools/client/performance/modules/categories");

function run_test() {
  run_next_test();
}

add_task(function test() {
  let { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  let url = (n) => `http://content/${n}`;

  // Create a root node from a given samples array.

  let root = getFrameNodePath(new ThreadNode(gThread, { startTime: 5, endTime: 30,
                                                        contentOnly: true }), "(root)");

  /*
   * should have a tree like:
   * root
   *   - (JS)
   *   - A
   *     - (GC)
   *     - B
   *       - C
   *       - D
   *     - E
   *       - F
   *         - (JS)
   */

  // Test the root node.

  equal(root.calls.length, 2, "root has 2 children");
  ok(getFrameNodePath(root, url("A")), "root has content child");
  ok(getFrameNodePath(root, "64"), "root has platform generalized child");
  equal(getFrameNodePath(root, "64").calls.length, 0,
        "platform generalized child is a leaf.");

  ok(getFrameNodePath(root, `${url("A")} > 128`),
     "A has platform generalized child of another type");
  equal(getFrameNodePath(root, `${url("A")} > 128`).calls.length, 0,
        "second generalized type is a leaf.");

  ok(getFrameNodePath(root, `${url("A")} > ${url("E")} > ${url("F")} > 64`),
     "a second leaf of the first generalized type exists deep in the tree.");
  ok(getFrameNodePath(root, `${url("A")} > 128`),
     "A has platform generalized child of another type");

  equal(getFrameNodePath(root, "64").category,
     getFrameNodePath(root, `${url("A")} > ${url("E")} > ${url("F")} > 64`).category,
     "generalized frames of same type are duplicated in top-down view");
});

var gThread = synthesizeProfileForTest([{
  time: 5,
  frames: [
    { location: "(root)" },
    { location: "http://content/A" },
    { location: "http://content/B" },
    { location: "http://content/C" }
  ]
}, {
  time: 5 + 6,
  frames: [
    { location: "(root)" },
    { location: "http://content/A" },
    { location: "http://content/B" },
    { location: "contentY", category: CATEGORY_MASK("css") },
    { location: "http://content/D" }
  ]
}, {
  time: 5 + 6 + 7,
  frames: [
    { location: "(root)" },
    { location: "http://content/A" },
    { location: "contentY", category: CATEGORY_MASK("css") },
    { location: "http://content/E" },
    { location: "http://content/F" },
    { location: "contentY", category: CATEGORY_MASK("js") },
  ]
}, {
  time: 5 + 20,
  frames: [
    { location: "(root)" },
    { location: "contentX", category: CATEGORY_MASK("js") },
  ]
}, {
  time: 5 + 25,
  frames: [
    { location: "(root)" },
    { location: "http://content/A" },
    { location: "contentZ", category: CATEGORY_MASK("gc", 1) },
  ]
}]);