summaryrefslogtreecommitdiffstats
path: root/editor/libeditor/tests/browser_bug527935.js
blob: 6c05d17abdf081625caa953c6899a0a1e8f09a53 (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
add_task(async function() {
  await new Promise(resolve => waitForFocus(resolve, window));

  const kPageURL =
    "http://example.org/browser/editor/libeditor/tests/bug527935.html";
  await BrowserTestUtils.withNewTab(
    {
      gBrowser,
      url: kPageURL,
    },
    async function(aBrowser) {
      var popupShown = false;
      function listener() {
        popupShown = true;
      }
      SpecialPowers.addAutoCompletePopupEventListener(
        window,
        "popupshowing",
        listener
      );

      await SpecialPowers.spawn(aBrowser, [], async function() {
        var window = content.window.wrappedJSObject;
        var document = window.document;
        var formTarget = document.getElementById("formTarget");
        var initValue = document.getElementById("initValue");

        window.loadPromise = new Promise(resolve => {
          formTarget.onload = resolve;
        });

        initValue.focus();
        initValue.value = "foo";
      });

      EventUtils.synthesizeKey("KEY_Enter");

      await SpecialPowers.spawn(aBrowser, [], async function() {
        var window = content.window.wrappedJSObject;
        var document = window.document;

        await window.loadPromise;

        var newInput = document.createElement("input");
        newInput.setAttribute("name", "test");
        document.body.appendChild(newInput);

        var event = new window.KeyboardEvent("keypress", {
          bubbles: true,
          cancelable: true,
          view: null,
          keyCode: 0,
          charCode: "f".charCodeAt(0),
        });
        newInput.value = "";
        newInput.focus();
        newInput.dispatchEvent(event);
      });

      await new Promise(resolve => hitEventLoop(resolve, 100));

      ok(!popupShown, "Popup must not be opened");
      SpecialPowers.removeAutoCompletePopupEventListener(
        window,
        "popupshowing",
        listener
      );
    }
  );
});

function hitEventLoop(func, times) {
  if (times > 0) {
    setTimeout(hitEventLoop, 0, func, times - 1);
  } else {
    setTimeout(func, 0);
  }
}