browser_perf-tree-abstract-03.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. * is keyboard accessible.
  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, myDataSrc } = synthesizeCustomTreeClass();
  12. let container = document.createElement("vbox");
  13. yield appendAndWaitForPaint(gBrowser.selectedBrowser.parentNode, container);
  14. // Populate the tree by pressing RIGHT...
  15. let treeRoot = new MyCustomTreeItem(myDataSrc, { parent: null });
  16. treeRoot.attachTo(container);
  17. treeRoot.focus();
  18. key("VK_RIGHT");
  19. ok(treeRoot.expanded,
  20. "The root node is now expanded.");
  21. is(document.commandDispatcher.focusedElement, treeRoot.target,
  22. "The root node is still focused.");
  23. let fooItem = treeRoot.getChild(0);
  24. let barItem = treeRoot.getChild(1);
  25. key("VK_RIGHT");
  26. ok(!fooItem.expanded,
  27. "The 'foo' node is not expanded yet.");
  28. is(document.commandDispatcher.focusedElement, fooItem.target,
  29. "The 'foo' node is now focused.");
  30. key("VK_RIGHT");
  31. ok(fooItem.expanded,
  32. "The 'foo' node is now expanded.");
  33. is(document.commandDispatcher.focusedElement, fooItem.target,
  34. "The 'foo' node is still focused.");
  35. key("VK_RIGHT");
  36. ok(!barItem.expanded,
  37. "The 'bar' node is not expanded yet.");
  38. is(document.commandDispatcher.focusedElement, barItem.target,
  39. "The 'bar' node is now focused.");
  40. key("VK_RIGHT");
  41. ok(barItem.expanded,
  42. "The 'bar' node is now expanded.");
  43. is(document.commandDispatcher.focusedElement, barItem.target,
  44. "The 'bar' node is still focused.");
  45. let bazItem = barItem.getChild(0);
  46. key("VK_RIGHT");
  47. ok(!bazItem.expanded,
  48. "The 'baz' node is not expanded yet.");
  49. is(document.commandDispatcher.focusedElement, bazItem.target,
  50. "The 'baz' node is now focused.");
  51. key("VK_RIGHT");
  52. ok(bazItem.expanded,
  53. "The 'baz' node is now expanded.");
  54. is(document.commandDispatcher.focusedElement, bazItem.target,
  55. "The 'baz' node is still focused.");
  56. // Test RIGHT on a leaf node.
  57. key("VK_RIGHT");
  58. is(document.commandDispatcher.focusedElement, bazItem.target,
  59. "The 'baz' node is still focused.");
  60. // Test DOWN on a leaf node.
  61. key("VK_DOWN");
  62. is(document.commandDispatcher.focusedElement, bazItem.target,
  63. "The 'baz' node is now refocused.");
  64. // Test UP.
  65. key("VK_UP");
  66. is(document.commandDispatcher.focusedElement, barItem.target,
  67. "The 'bar' node is now refocused.");
  68. key("VK_UP");
  69. is(document.commandDispatcher.focusedElement, fooItem.target,
  70. "The 'foo' node is now refocused.");
  71. key("VK_UP");
  72. is(document.commandDispatcher.focusedElement, treeRoot.target,
  73. "The root node is now refocused.");
  74. // Test DOWN.
  75. key("VK_DOWN");
  76. is(document.commandDispatcher.focusedElement, fooItem.target,
  77. "The 'foo' node is now refocused.");
  78. key("VK_DOWN");
  79. is(document.commandDispatcher.focusedElement, barItem.target,
  80. "The 'bar' node is now refocused.");
  81. key("VK_DOWN");
  82. is(document.commandDispatcher.focusedElement, bazItem.target,
  83. "The 'baz' node is now refocused.");
  84. // Test LEFT.
  85. key("VK_LEFT");
  86. ok(barItem.expanded,
  87. "The 'bar' node is still expanded.");
  88. is(document.commandDispatcher.focusedElement, barItem.target,
  89. "The 'bar' node is now refocused.");
  90. key("VK_LEFT");
  91. ok(!barItem.expanded,
  92. "The 'bar' node is not expanded anymore.");
  93. is(document.commandDispatcher.focusedElement, barItem.target,
  94. "The 'bar' node is still focused.");
  95. key("VK_LEFT");
  96. ok(treeRoot.expanded,
  97. "The root node is still expanded.");
  98. is(document.commandDispatcher.focusedElement, treeRoot.target,
  99. "The root node is now refocused.");
  100. key("VK_LEFT");
  101. ok(!treeRoot.expanded,
  102. "The root node is not expanded anymore.");
  103. is(document.commandDispatcher.focusedElement, treeRoot.target,
  104. "The root node is still focused.");
  105. // Test LEFT on the root node.
  106. key("VK_LEFT");
  107. is(document.commandDispatcher.focusedElement, treeRoot.target,
  108. "The root node is still focused.");
  109. // Test UP on the root node.
  110. key("VK_UP");
  111. is(document.commandDispatcher.focusedElement, treeRoot.target,
  112. "The root node is still focused.");
  113. container.remove();
  114. });