browser_webconsole_autocomplete_accessibility.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
  2. /* Any copyright is dedicated to the Public Domain.
  3. * http://creativecommons.org/publicdomain/zero/1.0/ */
  4. // Tests that the autocomplete input is being blurred and focused when selecting a value.
  5. // This will help screen-readers notify users of the value that was set in the input.
  6. "use strict";
  7. const TEST_URI = "data:text/html;charset=utf8,<p>test code completion";
  8. add_task(function* () {
  9. yield loadTab(TEST_URI);
  10. let hud = yield openConsole();
  11. let jsterm = hud.jsterm;
  12. let input = jsterm.inputNode;
  13. info("Type 'd' to open the autocomplete popup");
  14. yield autocomplete(jsterm, "d");
  15. // Add listeners for focus and blur events.
  16. let wasBlurred = false;
  17. input.addEventListener("blur", () => {
  18. wasBlurred = true;
  19. }, {
  20. once: true
  21. });
  22. let wasFocused = false;
  23. input.addEventListener("blur", () => {
  24. ok(wasBlurred, "jsterm input received a blur event before received back the focus");
  25. wasFocused = true;
  26. }, {
  27. once: true
  28. });
  29. info("Close the autocomplete popup by simulating a TAB key event");
  30. let onPopupClosed = jsterm.autocompletePopup.once("popup-closed");
  31. EventUtils.synthesizeKey("VK_TAB", {});
  32. info("Wait for the autocomplete popup to be closed");
  33. yield onPopupClosed;
  34. ok(wasFocused, "jsterm input received a focus event");
  35. });
  36. function* autocomplete(jsterm, value) {
  37. let popup = jsterm.autocompletePopup;
  38. yield new Promise(resolve => {
  39. jsterm.setInputValue(value);
  40. jsterm.complete(jsterm.COMPLETE_HINT_ONLY, resolve);
  41. });
  42. ok(popup.isOpen && popup.itemCount > 0,
  43. "Autocomplete popup is open and contains suggestions");
  44. }