test_waterfall-utils-collapse-01.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests if the waterfall collapsing logic works properly.
  6. */
  7. function run_test() {
  8. run_next_test();
  9. }
  10. add_task(function test() {
  11. const WaterfallUtils = require("devtools/client/performance/modules/logic/waterfall-utils");
  12. let rootMarkerNode = WaterfallUtils.createParentNode({ name: "(root)" });
  13. WaterfallUtils.collapseMarkersIntoNode({
  14. rootNode: rootMarkerNode,
  15. markersList: gTestMarkers
  16. });
  17. function compare(marker, expected) {
  18. for (let prop in expected) {
  19. if (prop === "submarkers") {
  20. for (let i = 0; i < expected.submarkers.length; i++) {
  21. compare(marker.submarkers[i], expected.submarkers[i]);
  22. }
  23. } else if (prop !== "uid") {
  24. equal(marker[prop], expected[prop], `${expected.name} matches ${prop}`);
  25. }
  26. }
  27. }
  28. compare(rootMarkerNode, gExpectedOutput);
  29. });
  30. const gTestMarkers = [
  31. { start: 1, end: 18, name: "DOMEvent" },
  32. // Test that JS markers can fold in DOM events and have marker children
  33. { start: 2, end: 16, name: "Javascript" },
  34. // Test all these markers can be children
  35. { start: 3, end: 4, name: "Paint" },
  36. { start: 5, end: 6, name: "Reflow" },
  37. { start: 7, end: 8, name: "Styles" },
  38. { start: 9, end: 9, name: "TimeStamp" },
  39. { start: 10, end: 11, name: "Parse HTML" },
  40. { start: 12, end: 13, name: "Parse XML" },
  41. { start: 14, end: 15, name: "GarbageCollection" },
  42. // Test that JS markers can be parents without being a child of DOM events
  43. { start: 25, end: 30, name: "Javascript" },
  44. { start: 26, end: 27, name: "Paint" },
  45. ];
  46. const gExpectedOutput = {
  47. name: "(root)", submarkers: [
  48. { start: 1, end: 18, name: "DOMEvent", submarkers: [
  49. { start: 2, end: 16, name: "Javascript", submarkers: [
  50. { start: 3, end: 4, name: "Paint" },
  51. { start: 5, end: 6, name: "Reflow" },
  52. { start: 7, end: 8, name: "Styles" },
  53. { start: 9, end: 9, name: "TimeStamp" },
  54. { start: 10, end: 11, name: "Parse HTML" },
  55. { start: 12, end: 13, name: "Parse XML" },
  56. { start: 14, end: 15, name: "GarbageCollection" },
  57. ]}
  58. ]},
  59. { start: 25, end: 30, name: "Javascript", submarkers: [
  60. { start: 26, end: 27, name: "Paint" },
  61. ]}
  62. ]};