summaryrefslogtreecommitdiffstats
path: root/devtools/client/sourceeditor/test/browser_editor_autocomplete_js.js
blob: 4c34fc55c65aa8d79fb6aa2e343086f6a9d34c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

// Test to make sure that JS autocompletion is opening popups.
function test() {
  waitForExplicitFinish();
  setup((ed, win) => {
    let edWin = ed.container.contentWindow.wrappedJSObject;
    testJS(ed, edWin).then(() => {
      teardown(ed, win);
    });
  });
}

function testJS(ed, win) {
  ok(!ed.getOption("autocomplete"), "Autocompletion is not set");
  ok(!win.tern, "Tern is not defined on the window");

  ed.setMode(Editor.modes.js);
  ed.setOption("autocomplete", true);

  ok(ed.getOption("autocomplete"), "Autocompletion is set");
  ok(win.tern, "Tern is defined on the window");

  ed.focus();
  ed.setText("document.");
  ed.setCursor({line: 0, ch: 9});

  let waitForSuggestion = promise.defer();

  ed.on("before-suggest", () => {
    info("before-suggest has been triggered");
    EventUtils.synthesizeKey("VK_ESCAPE", { }, win);
    waitForSuggestion.resolve();
  });

  let autocompleteKey =
    Editor.keyFor("autocompletion", { noaccel: true }).toUpperCase();
  EventUtils.synthesizeKey("VK_" + autocompleteKey, { ctrlKey: true }, win);

  return waitForSuggestion.promise;
}