summaryrefslogtreecommitdiffstats
path: root/dom/heapsnapshot/tests/unit/test_census_filtering_04.js
blob: c9871436b864fd634307fe6b25b35db39328dd20 (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
102
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

// Test the filtered nodes' counts and bytes are the same as they were when
// unfiltered.

function run_test() {
  const COUNT = { by: "count", count: true, bytes: true };
  const INTERNAL_TYPE = { by: "internalType", then: COUNT };

  const BREAKDOWN = {
    by: "coarseType",
    objects: { by: "objectClass", then: COUNT, other: COUNT },
    strings: COUNT,
    scripts: {
      by: "filename",
      then: INTERNAL_TYPE,
      noFilename: INTERNAL_TYPE
    },
    other: INTERNAL_TYPE,
  };

  const REPORT = {
    objects: {
      Function: {
        count: 7,
        bytes: 70
      },
      Array: {
        count: 6,
        bytes: 60
      }
    },
    scripts: {
      "http://mozilla.github.io/pdf.js/build/pdf.js": {
        "js::LazyScript": {
          count: 4,
          bytes: 40
        },
      }
    },
    strings: {
      count: 2,
      bytes: 20
    },
    other: {
      "js::Shape": {
        count: 1,
        bytes: 10
      }
    }
  };

  const EXPECTED = {
    name: null,
    bytes: 0,
    totalBytes: 200,
    count: 0,
    totalCount: 20,
    parent: undefined,
    children: [
      {
        name: "objects",
        bytes: 0,
        totalBytes: 130,
        count: 0,
        totalCount: 13,
        children: [
          {
            name: "Function",
            bytes: 70,
            totalBytes: 70,
            count: 7,
            totalCount: 7,
            id: 13,
            parent: 12,
            children: undefined,
            reportLeafIndex: 2,
          },
          {
            name: "Array",
            bytes: 60,
            totalBytes: 60,
            count: 6,
            totalCount: 6,
            id: 14,
            parent: 12,
            children: undefined,
            reportLeafIndex: 3,
          },
        ],
        id: 12,
        parent: 11,
        reportLeafIndex: undefined,
      }
    ],
    id: 11,
    reportLeafIndex: undefined,
  };

  compareCensusViewData(BREAKDOWN, REPORT, EXPECTED, { filter: "objects" });
}