browser_flame-graph-utils-03.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. // Tests if platform frames are removed from the flame graph data.
  5. const {FlameGraphUtils} = require("devtools/client/shared/widgets/FlameGraph");
  6. const {PALLETTE_SIZE} = require("devtools/client/shared/widgets/FlameGraph");
  7. add_task(function* () {
  8. yield addTab("about:blank");
  9. yield performTest();
  10. gBrowser.removeCurrentTab();
  11. });
  12. function* performTest() {
  13. let out = FlameGraphUtils.createFlameGraphDataFromThread(TEST_DATA, {
  14. contentOnly: true
  15. });
  16. ok(out, "Some data was outputted properly");
  17. is(out.length, PALLETTE_SIZE, "The outputted length is correct.");
  18. info("Got flame graph data:\n" + out.toSource() + "\n");
  19. for (let i = 0; i < out.length; i++) {
  20. let found = out[i];
  21. let expected = EXPECTED_OUTPUT[i];
  22. is(found.blocks.length, expected.blocks.length,
  23. "The correct number of blocks were found in this bucket.");
  24. for (let j = 0; j < found.blocks.length; j++) {
  25. is(found.blocks[j].x, expected.blocks[j].x,
  26. "The expected block X position is correct for this frame.");
  27. is(found.blocks[j].y, expected.blocks[j].y,
  28. "The expected block Y position is correct for this frame.");
  29. is(found.blocks[j].width, expected.blocks[j].width,
  30. "The expected block width is correct for this frame.");
  31. is(found.blocks[j].height, expected.blocks[j].height,
  32. "The expected block height is correct for this frame.");
  33. is(found.blocks[j].text, expected.blocks[j].text,
  34. "The expected block text is correct for this frame.");
  35. }
  36. }
  37. }
  38. var TEST_DATA = synthesizeProfileForTest([{
  39. frames: [{
  40. location: "http://A"
  41. }, {
  42. location: "https://B"
  43. }, {
  44. location: "file://C",
  45. }, {
  46. location: "chrome://D"
  47. }, {
  48. location: "resource://E"
  49. }],
  50. time: 50,
  51. }]);
  52. var EXPECTED_OUTPUT = [{
  53. blocks: []
  54. }, {
  55. blocks: []
  56. }, {
  57. blocks: [{
  58. startTime: 0,
  59. frameKey: "http://A",
  60. x: 0,
  61. y: 0,
  62. width: 50,
  63. height: 15,
  64. text: "http://A"
  65. }]
  66. }, {
  67. blocks: []
  68. }, {
  69. blocks: []
  70. }, {
  71. blocks: []
  72. }, {
  73. blocks: [{
  74. startTime: 0,
  75. frameKey: "Gecko",
  76. x: 0,
  77. y: 45,
  78. width: 50,
  79. height: 15,
  80. text: "Gecko"
  81. }]
  82. }, {
  83. blocks: []
  84. }, {
  85. blocks: [{
  86. startTime: 0,
  87. frameKey: "https://B",
  88. x: 0,
  89. y: 15,
  90. width: 50,
  91. height: 15,
  92. text: "https://B"
  93. }]
  94. }, {
  95. blocks: []
  96. }, {
  97. blocks: []
  98. }, {
  99. blocks: []
  100. }, {
  101. blocks: [{
  102. startTime: 0,
  103. frameKey: "file://C",
  104. x: 0,
  105. y: 30,
  106. width: 50,
  107. height: 15,
  108. text: "file://C"
  109. }]
  110. }, {
  111. blocks: []
  112. }, {
  113. blocks: []
  114. }, {
  115. blocks: []
  116. }, {
  117. blocks: []
  118. }, {
  119. blocks: []
  120. }, {
  121. blocks: []
  122. }, {
  123. blocks: []
  124. }];