test_tree-model-07.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests that when displaying only content nodes, platform nodes are generalized.
  6. */
  7. var { CATEGORY_MASK } = require("devtools/client/performance/modules/categories");
  8. function run_test() {
  9. run_next_test();
  10. }
  11. add_task(function test() {
  12. let { ThreadNode } = require("devtools/client/performance/modules/logic/tree-model");
  13. let url = (n) => `http://content/${n}`;
  14. // Create a root node from a given samples array.
  15. let root = getFrameNodePath(new ThreadNode(gThread, { startTime: 5, endTime: 30,
  16. contentOnly: true }), "(root)");
  17. /*
  18. * should have a tree like:
  19. * root
  20. * - (JS)
  21. * - A
  22. * - (GC)
  23. * - B
  24. * - C
  25. * - D
  26. * - E
  27. * - F
  28. * - (JS)
  29. */
  30. // Test the root node.
  31. equal(root.calls.length, 2, "root has 2 children");
  32. ok(getFrameNodePath(root, url("A")), "root has content child");
  33. ok(getFrameNodePath(root, "64"), "root has platform generalized child");
  34. equal(getFrameNodePath(root, "64").calls.length, 0,
  35. "platform generalized child is a leaf.");
  36. ok(getFrameNodePath(root, `${url("A")} > 128`),
  37. "A has platform generalized child of another type");
  38. equal(getFrameNodePath(root, `${url("A")} > 128`).calls.length, 0,
  39. "second generalized type is a leaf.");
  40. ok(getFrameNodePath(root, `${url("A")} > ${url("E")} > ${url("F")} > 64`),
  41. "a second leaf of the first generalized type exists deep in the tree.");
  42. ok(getFrameNodePath(root, `${url("A")} > 128`),
  43. "A has platform generalized child of another type");
  44. equal(getFrameNodePath(root, "64").category,
  45. getFrameNodePath(root, `${url("A")} > ${url("E")} > ${url("F")} > 64`).category,
  46. "generalized frames of same type are duplicated in top-down view");
  47. });
  48. var gThread = synthesizeProfileForTest([{
  49. time: 5,
  50. frames: [
  51. { location: "(root)" },
  52. { location: "http://content/A" },
  53. { location: "http://content/B" },
  54. { location: "http://content/C" }
  55. ]
  56. }, {
  57. time: 5 + 6,
  58. frames: [
  59. { location: "(root)" },
  60. { location: "http://content/A" },
  61. { location: "http://content/B" },
  62. { location: "contentY", category: CATEGORY_MASK("css") },
  63. { location: "http://content/D" }
  64. ]
  65. }, {
  66. time: 5 + 6 + 7,
  67. frames: [
  68. { location: "(root)" },
  69. { location: "http://content/A" },
  70. { location: "contentY", category: CATEGORY_MASK("css") },
  71. { location: "http://content/E" },
  72. { location: "http://content/F" },
  73. { location: "contentY", category: CATEGORY_MASK("js") },
  74. ]
  75. }, {
  76. time: 5 + 20,
  77. frames: [
  78. { location: "(root)" },
  79. { location: "contentX", category: CATEGORY_MASK("js") },
  80. ]
  81. }, {
  82. time: 5 + 25,
  83. frames: [
  84. { location: "(root)" },
  85. { location: "http://content/A" },
  86. { location: "contentZ", category: CATEGORY_MASK("gc", 1) },
  87. ]
  88. }]);