browser_perf-tree-abstract-01.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 abstract tree base class for the profiler's tree view
  6. * works as advertised.
  7. */
  8. const { appendAndWaitForPaint } = require("devtools/client/performance/test/helpers/dom-utils");
  9. const { synthesizeCustomTreeClass } = require("devtools/client/performance/test/helpers/synth-utils");
  10. const { once } = require("devtools/client/performance/test/helpers/event-utils");
  11. add_task(function* () {
  12. let { MyCustomTreeItem, myDataSrc } = synthesizeCustomTreeClass();
  13. let container = document.createElement("vbox");
  14. yield appendAndWaitForPaint(gBrowser.selectedBrowser.parentNode, container);
  15. // Populate the tree and test the root item...
  16. let treeRoot = new MyCustomTreeItem(myDataSrc, { parent: null });
  17. treeRoot.attachTo(container);
  18. ok(!treeRoot.expanded,
  19. "The root node should not be expanded yet.");
  20. ok(!treeRoot.populated,
  21. "The root node should not be populated yet.");
  22. is(container.childNodes.length, 1,
  23. "The container node should have one child available.");
  24. is(container.childNodes[0], treeRoot.target,
  25. "The root node's target is a child of the container node.");
  26. is(treeRoot.root, treeRoot,
  27. "The root node has the correct root.");
  28. is(treeRoot.parent, null,
  29. "The root node has the correct parent.");
  30. is(treeRoot.level, 0,
  31. "The root node has the correct level.");
  32. is(treeRoot.target.style.marginInlineStart, "0px",
  33. "The root node's indentation is correct.");
  34. is(treeRoot.target.textContent, "root",
  35. "The root node's text contents are correct.");
  36. is(treeRoot.container, container,
  37. "The root node's container is correct.");
  38. // Expand the root and test the child items...
  39. let receivedExpandEvent = once(treeRoot, "expand", { spreadArgs: true });
  40. let receivedFocusEvent = once(treeRoot, "focus");
  41. mousedown(treeRoot.target.querySelector(".arrow"));
  42. let [, eventItem] = yield receivedExpandEvent;
  43. is(eventItem, treeRoot,
  44. "The 'expand' event target is correct (1).");
  45. yield receivedFocusEvent;
  46. is(document.commandDispatcher.focusedElement, treeRoot.target,
  47. "The root node is now focused.");
  48. let fooItem = treeRoot.getChild(0);
  49. let barItem = treeRoot.getChild(1);
  50. is(container.childNodes.length, 3,
  51. "The container node should now have three children available.");
  52. is(container.childNodes[0], treeRoot.target,
  53. "The root node's target is a child of the container node.");
  54. is(container.childNodes[1], fooItem.target,
  55. "The 'foo' node's target is a child of the container node.");
  56. is(container.childNodes[2], barItem.target,
  57. "The 'bar' node's target is a child of the container node.");
  58. is(fooItem.root, treeRoot,
  59. "The 'foo' node has the correct root.");
  60. is(fooItem.parent, treeRoot,
  61. "The 'foo' node has the correct parent.");
  62. is(fooItem.level, 1,
  63. "The 'foo' node has the correct level.");
  64. is(fooItem.target.style.marginInlineStart, "10px",
  65. "The 'foo' node's indentation is correct.");
  66. is(fooItem.target.textContent, "foo",
  67. "The 'foo' node's text contents are correct.");
  68. is(fooItem.container, container,
  69. "The 'foo' node's container is correct.");
  70. is(barItem.root, treeRoot,
  71. "The 'bar' node has the correct root.");
  72. is(barItem.parent, treeRoot,
  73. "The 'bar' node has the correct parent.");
  74. is(barItem.level, 1,
  75. "The 'bar' node has the correct level.");
  76. is(barItem.target.style.marginInlineStart, "10px",
  77. "The 'bar' node's indentation is correct.");
  78. is(barItem.target.textContent, "bar",
  79. "The 'bar' node's text contents are correct.");
  80. is(barItem.container, container,
  81. "The 'bar' node's container is correct.");
  82. // Test clicking on the `foo` node...
  83. receivedFocusEvent = once(treeRoot, "focus", { spreadArgs: true });
  84. mousedown(fooItem.target);
  85. [, eventItem] = yield receivedFocusEvent;
  86. is(eventItem, fooItem,
  87. "The 'focus' event target is correct (2).");
  88. is(document.commandDispatcher.focusedElement, fooItem.target,
  89. "The 'foo' node is now focused.");
  90. // Test double clicking on the `bar` node...
  91. receivedExpandEvent = once(treeRoot, "expand", { spreadArgs: true });
  92. receivedFocusEvent = once(treeRoot, "focus");
  93. dblclick(barItem.target);
  94. [, eventItem] = yield receivedExpandEvent;
  95. is(eventItem, barItem,
  96. "The 'expand' event target is correct (3).");
  97. yield receivedFocusEvent;
  98. is(document.commandDispatcher.focusedElement, barItem.target,
  99. "The 'foo' node is now focused.");
  100. // A child item got expanded, test the descendants...
  101. let bazItem = barItem.getChild(0);
  102. is(container.childNodes.length, 4,
  103. "The container node should now have four children available.");
  104. is(container.childNodes[0], treeRoot.target,
  105. "The root node's target is a child of the container node.");
  106. is(container.childNodes[1], fooItem.target,
  107. "The 'foo' node's target is a child of the container node.");
  108. is(container.childNodes[2], barItem.target,
  109. "The 'bar' node's target is a child of the container node.");
  110. is(container.childNodes[3], bazItem.target,
  111. "The 'baz' node's target is a child of the container node.");
  112. is(bazItem.root, treeRoot,
  113. "The 'baz' node has the correct root.");
  114. is(bazItem.parent, barItem,
  115. "The 'baz' node has the correct parent.");
  116. is(bazItem.level, 2,
  117. "The 'baz' node has the correct level.");
  118. is(bazItem.target.style.marginInlineStart, "20px",
  119. "The 'baz' node's indentation is correct.");
  120. is(bazItem.target.textContent, "baz",
  121. "The 'baz' node's text contents are correct.");
  122. is(bazItem.container, container,
  123. "The 'baz' node's container is correct.");
  124. container.remove();
  125. });