test_tree-model-04.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. "use strict";
  4. /**
  5. * Tests if a call tree model can be correctly computed from a samples array,
  6. * while at the same time filtering by duration and content-only frames.
  7. */
  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. // Create a root node from a given samples array, filtering by time.
  14. let startTime = 5;
  15. let endTime = 18;
  16. let thread = new ThreadNode(gThread, { startTime, endTime, contentOnly: true });
  17. let root = getFrameNodePath(thread, "(root)");
  18. // Test the ThreadNode, only node which should have duration
  19. equal(thread.duration, endTime - startTime,
  20. "The correct duration was calculated for the root ThreadNode.");
  21. equal(root.calls.length, 2,
  22. "The correct number of child calls were calculated for the root node.");
  23. ok(getFrameNodePath(root, "http://D"),
  24. "The root has a 'http://D' child call.");
  25. ok(getFrameNodePath(root, "http://A"),
  26. "The root has a 'http://A' child call.");
  27. // Test all the descendant nodes.
  28. equal(getFrameNodePath(root, "http://A").calls.length, 1,
  29. "The correct number of child calls were calculated for the 'http://A' node.");
  30. ok(getFrameNodePath(root, "http://A > https://E"),
  31. "The 'http://A' node's only child call is correct.");
  32. equal(getFrameNodePath(root, "http://A > https://E").calls.length, 1,
  33. "The correct number of child calls were calculated for the 'http://A > http://E' node.");
  34. ok(getFrameNodePath(root, "http://A > https://E > file://F"),
  35. "The 'http://A > https://E' node's only child call is correct.");
  36. equal(getFrameNodePath(root, "http://A > https://E > file://F").calls.length, 1,
  37. "The correct number of child calls were calculated for the 'http://A > https://E >> file://F' node.");
  38. ok(getFrameNodePath(root, "http://A > https://E > file://F > app://H"),
  39. "The 'http://A > https://E >> file://F' node's only child call is correct.");
  40. equal(getFrameNodePath(root, "http://D").calls.length, 0,
  41. "The correct number of child calls were calculated for the 'http://D' node.");
  42. });
  43. var gThread = synthesizeProfileForTest([{
  44. time: 5,
  45. frames: [
  46. { location: "(root)" },
  47. { location: "http://A" },
  48. { location: "http://B" },
  49. { location: "http://C" }
  50. ]
  51. }, {
  52. time: 5 + 6,
  53. frames: [
  54. { location: "(root)" },
  55. { location: "chrome://A" },
  56. { location: "resource://B" },
  57. { location: "jar:file://G" },
  58. { location: "http://D" }
  59. ]
  60. }, {
  61. time: 5 + 6 + 7,
  62. frames: [
  63. { location: "(root)" },
  64. { location: "http://A" },
  65. { location: "https://E" },
  66. { location: "file://F" },
  67. { location: "app://H" },
  68. ]
  69. }, {
  70. time: 5 + 6 + 7 + 8,
  71. frames: [
  72. { location: "(root)" },
  73. { location: "http://A" },
  74. { location: "http://B" },
  75. { location: "http://C" },
  76. { location: "http://D" }
  77. ]
  78. }]);