summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/test-console-output-events.html
blob: 908a86fabde1808e70858ab4ef073609d9adf2cf (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
<!DOCTYPE HTML>
<html dir="ltr" lang="en-US">
<head>
  <meta charset="utf-8">
  <title>Test the web console output for DOM events</title>
  <!--
  - Any copyright is dedicated to the Public Domain.
  - http://creativecommons.org/publicdomain/zero/1.0/
  -->
</head>
<body>
  <p>hello world!</p>

  <script type="text/javascript">
function testDOMEvents() {
  function eventLogger(ev) {
    console.log("eventLogger", ev);
  }
  document.addEventListener("mousemove", eventLogger);
  document.addEventListener("keypress", eventLogger);

  synthesizeMouseMove();
  synthesizeKeyPress("a", {shiftKey: true});
}

function synthesizeMouseMove(element) {
  var mouseEvent = document.createEvent("MouseEvent");
  mouseEvent.initMouseEvent("mousemove", true, true, window, 0, 0, 0, 0, 0,
                            false, false, false, false, 0, null);

  document.dispatchEvent(mouseEvent);
}

function synthesizeKeyPress(key, options) {
  var keyboardEvent = document.createEvent("KeyboardEvent");
  keyboardEvent.initKeyEvent("keypress", true, true, window, false, false,
                             options.shiftKey, false, key.charCodeAt(0), 0);
  document.dispatchEvent(keyboardEvent);
}
  </script>
</body>
</html>