browser_scratchpad_autocomplete.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Any copyright is dedicated to the Public Domain.
  2. http://creativecommons.org/publicdomain/zero/1.0/ */
  3. /* Bug 968896 */
  4. // Test the completions using numbers.
  5. const source = "0x1.";
  6. const completions = ["toExponential", "toFixed", "toString"];
  7. const { Task } = require("devtools/shared/task");
  8. function test() {
  9. const options = { tabContent: "test scratchpad autocomplete" };
  10. openTabAndScratchpad(options)
  11. .then(Task.async(runTests))
  12. .then(finish, console.error);
  13. }
  14. function* runTests([win, sp]) {
  15. const {editor} = sp;
  16. const editorWin = editor.container.contentWindow;
  17. // Show the completions popup.
  18. sp.setText(source);
  19. sp.editor.setCursor({ line: 0, ch: source.length });
  20. yield keyOnce("suggestion-entered", " ", { ctrlKey: true });
  21. // Get the hints popup container.
  22. const hints = editorWin.document.querySelector(".CodeMirror-hints");
  23. ok(hints,
  24. "The hint container should exist.");
  25. is(hints.childNodes.length, 3,
  26. "The hint container should have the completions.");
  27. let i = 0;
  28. for (let completion of completions) {
  29. let active = hints.querySelector(".CodeMirror-hint-active");
  30. is(active.textContent, completion,
  31. "Check that completion " + i++ + " is what is expected.");
  32. yield keyOnce("suggestion-entered", "VK_DOWN");
  33. }
  34. // We should have looped around to the first suggestion again. Accept it.
  35. yield keyOnce("after-suggest", "VK_RETURN");
  36. is(sp.getText(), source + completions[0],
  37. "Autocompletion should work and select the right element.");
  38. // Check that the information tooltips work.
  39. sp.setText("5");
  40. yield keyOnce("show-information", " ", { ctrlKey: true, shiftKey: true });
  41. // Get the information container.
  42. const info = editorWin.document.querySelector(".CodeMirror-Tern-information");
  43. ok(info,
  44. "Info tooltip should appear.");
  45. is(info.textContent.slice(0, 6), "number",
  46. "Info tooltip should have expected contents.");
  47. function keyOnce(event, key, opts = {}) {
  48. const p = editor.once(event);
  49. EventUtils.synthesizeKey(key, opts, editorWin);
  50. return p;
  51. }
  52. }