summaryrefslogtreecommitdiffstats
path: root/devtools/client/performance/test/helpers/input-utils.js
blob: 180091d076aa3f42160c31c2374b14ef723841c5 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";

exports.HORIZONTAL_AXIS = 1;
exports.VERTICAL_AXIS = 2;

/**
 * Simulates a command event on an element.
 */
exports.command = (node) => {
  let ev = node.ownerDocument.createEvent("XULCommandEvent");
  ev.initCommandEvent("command", true, true, node.ownerDocument.defaultView, 0, false,
                      false, false, false, null);
  node.dispatchEvent(ev);
};

/**
 * Simulates a click event on a devtools canvas graph.
 */
exports.clickCanvasGraph = (graph, { x, y }) => {
  x = x || 0;
  y = y || 0;
  x /= graph._window.devicePixelRatio;
  y /= graph._window.devicePixelRatio;
  graph._onMouseMove({ testX: x, testY: y });
  graph._onMouseDown({ testX: x, testY: y });
  graph._onMouseUp({ testX: x, testY: y });
};

/**
 * Simulates a drag start event on a devtools canvas graph.
 */
exports.dragStartCanvasGraph = (graph, { x, y }) => {
  x = x || 0;
  y = y || 0;
  x /= graph._window.devicePixelRatio;
  y /= graph._window.devicePixelRatio;
  graph._onMouseMove({ testX: x, testY: y });
  graph._onMouseDown({ testX: x, testY: y });
};

/**
 * Simulates a drag stop event on a devtools canvas graph.
 */
exports.dragStopCanvasGraph = (graph, { x, y }) => {
  x = x || 0;
  y = y || 0;
  x /= graph._window.devicePixelRatio;
  y /= graph._window.devicePixelRatio;
  graph._onMouseMove({ testX: x, testY: y });
  graph._onMouseUp({ testX: x, testY: y });
};

/**
 * Simulates a scroll event on a devtools canvas graph.
 */
exports.scrollCanvasGraph = (graph, { axis, wheel, x, y }) => {
  x = x || 1;
  y = y || 1;
  x /= graph._window.devicePixelRatio;
  y /= graph._window.devicePixelRatio;
  graph._onMouseMove({
    testX: x,
    testY: y
  });
  graph._onMouseWheel({
    testX: x,
    testY: y,
    axis: axis,
    detail: wheel,
    HORIZONTAL_AXIS: exports.HORIZONTAL_AXIS,
    VERTICAL_AXIS: exports.VERTICAL_AXIS
  });
};