summaryrefslogtreecommitdiffstats
path: root/dom/tests/browser/browser_bug1316330.js
blob: a4ffa224f03365ae65ef9ba4a048952eb5e99495 (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
const URL =
  "data:text/html,<script>" +
  "window.focus();" +
  "var down = 0; var press = 0;" +
  "onkeydown = function(e) {" +
  "  var startTime = Date.now();" +
  "  document.body.setAttribute('data-down', ++down);" +
  "  if (e.keyCode == KeyboardEvent.DOM_VK_D) while (Date.now() - startTime < 500) {}" +
  "};" +
  "onkeypress = function(e) {" +
  "  var startTime = Date.now();" +
  "  document.body.setAttribute('data-press', ++press);" +
  "  if (e.charCode == 'p'.charCodeAt(0)) while (Date.now() - startTime < 500) {}" +
  "};" +
  "</script>";

add_task(async function() {
  let tab = await BrowserTestUtils.openNewForegroundTab(gBrowser, URL);
  let browser = tab.linkedBrowser;

  await EventUtils.synthesizeAndWaitKey("d", { repeat: 3 });

  await SpecialPowers.spawn(browser, [], async function() {
    is(
      content.document.body.getAttribute("data-down"),
      "2",
      "Correct number of events"
    );
    is(
      content.document.body.getAttribute("data-press"),
      "2",
      "Correct number of events"
    );
  });

  await EventUtils.synthesizeAndWaitKey("p", { repeat: 3 });

  await SpecialPowers.spawn(browser, [], async function() {
    is(
      content.document.body.getAttribute("data-down"),
      "4",
      "Correct number of events"
    );
    is(
      content.document.body.getAttribute("data-press"),
      "4",
      "Correct number of events"
    );
  });

  gBrowser.removeCurrentTab();
});