browser_perf-tree-abstract-05.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * supports PageUp/PageDown/Home/End keys.
  7. */
  8. const { appendAndWaitForPaint } = require("devtools/client/performance/test/helpers/dom-utils");
  9. const { synthesizeCustomTreeClass } = require("devtools/client/performance/test/helpers/synth-utils");
  10. add_task(function* () {
  11. let { MyCustomTreeItem } = synthesizeCustomTreeClass();
  12. let container = document.createElement("vbox");
  13. container.style.height = "100%";
  14. container.style.overflow = "scroll";
  15. yield appendAndWaitForPaint(gBrowser.selectedBrowser.parentNode, container);
  16. let myDataSrc = {
  17. label: "root",
  18. children: []
  19. };
  20. for (let i = 0; i < 1000; i++) {
  21. myDataSrc.children.push({
  22. label: "child-" + i,
  23. children: []
  24. });
  25. }
  26. let treeRoot = new MyCustomTreeItem(myDataSrc, { parent: null });
  27. treeRoot.attachTo(container);
  28. treeRoot.focus();
  29. treeRoot.expand();
  30. is(document.commandDispatcher.focusedElement, treeRoot.target,
  31. "The root node is focused.");
  32. // Test HOME and END
  33. key("VK_END");
  34. is(document.commandDispatcher.focusedElement,
  35. treeRoot.getChild(myDataSrc.children.length - 1).target,
  36. "The last node is focused.");
  37. key("VK_HOME");
  38. is(document.commandDispatcher.focusedElement, treeRoot.target,
  39. "The first (root) node is focused.");
  40. // Test PageUp and PageDown
  41. let nodesPerPageSize = treeRoot._getNodesPerPageSize();
  42. key("VK_PAGE_DOWN");
  43. is(document.commandDispatcher.focusedElement,
  44. treeRoot.getChild(nodesPerPageSize - 1).target,
  45. "The first node in the second page is focused.");
  46. key("VK_PAGE_DOWN");
  47. is(document.commandDispatcher.focusedElement,
  48. treeRoot.getChild(nodesPerPageSize * 2 - 1).target,
  49. "The first node in the third page is focused.");
  50. key("VK_PAGE_UP");
  51. is(document.commandDispatcher.focusedElement,
  52. treeRoot.getChild(nodesPerPageSize - 1).target,
  53. "The first node in the second page is focused.");
  54. key("VK_PAGE_UP");
  55. is(document.commandDispatcher.focusedElement, treeRoot.target,
  56. "The first (root) node is focused.");
  57. // Test PageUp in the middle of the first page
  58. let middleIndex = Math.floor(nodesPerPageSize / 2);
  59. treeRoot.getChild(middleIndex).target.focus();
  60. is(document.commandDispatcher.focusedElement,
  61. treeRoot.getChild(middleIndex).target,
  62. "The middle node in the first page is focused.");
  63. key("VK_PAGE_UP");
  64. is(document.commandDispatcher.focusedElement, treeRoot.target,
  65. "The first (root) node is focused.");
  66. // Test PageDown in the middle of the last page
  67. middleIndex = Math.ceil(myDataSrc.children.length - middleIndex);
  68. treeRoot.getChild(middleIndex).target.focus();
  69. is(document.commandDispatcher.focusedElement,
  70. treeRoot.getChild(middleIndex).target,
  71. "The middle node in the last page is focused.");
  72. key("VK_PAGE_DOWN");
  73. is(document.commandDispatcher.focusedElement,
  74. treeRoot.getChild(myDataSrc.children.length - 1).target,
  75. "The last node is focused.");
  76. container.remove();
  77. });