summaryrefslogtreecommitdiffstats
path: root/dom/base/test/test_domwindowutils.html
blob: 21ad43ae81e522fd7933a81e11f53a1324150877 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Test for DOMWindowUtils</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript">
SimpleTest.waitForExplicitFinish();

var utils = SpecialPowers.getDOMWindowUtils(window);
function test_sendMouseEventDefaults() {
  var x = 1, y = 2, button = 1, clickCount = 2,
      modifiers = SpecialPowers.Ci.nsIDOMWindowUtils.MODIFIER_SHIFT;

  window.addEventListener("mousedown", function(evt) {
    // Mandatory args
    // coordinates may change slightly due to rounding
    ok((evt.clientX <= x+2) && (evt.clientX >= x-2), "check x");
    ok((evt.clientY <= y+2) && (evt.clientY >= y-2), "check y");
    is(evt.button, button, "check button");
    is(evt.detail, clickCount, "check click count");
    is(evt.getModifierState("Shift"), true, "check modifiers");

    // Default value for optionals
    is(evt.mozPressure, 0, "check pressure");
    is(evt.mozInputSource, MouseEvent.MOZ_SOURCE_MOUSE, "check input source");
    is(evt.isSynthesized, undefined, "check isSynthesized is undefined in content");
    is(SpecialPowers.wrap(evt).isSynthesized, true, "check isSynthesized is true from chrome");
    SimpleTest.executeSoon(next);
  }, {once: true});

  // Only pass mandatory arguments and check default values
  utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
}

function test_sendMouseEventOptionals() {
  var x = 1, y = 2, button = 1, clickCount = 3,
      modifiers = SpecialPowers.Ci.nsIDOMWindowUtils.MODIFIER_SHIFT,
      pressure = 0.5,
      source = MouseEvent.MOZ_SOURCE_KEYBOARD;

  window.addEventListener("mouseup", function(evt) {
    is(evt.mozInputSource, source, "explicit input source is valid");
    is(SpecialPowers.wrap(evt).isSynthesized, false, "we can dispatch event that don't look synthesized");
    SimpleTest.executeSoon(next);
  }, {once: true});

  // Check explicit value for optional args
  utils.sendMouseEvent("mouseup", x, y, button, clickCount, modifiers,
                       false, pressure, source, false);
}

function test_sendMouseEvent4thButton() {
  const x = 1, y = 2, button = 3, clickCount = 1, modifiers = 0;

  window.addEventListener("mousedown", evt => {
    is(evt.buttons, 2 ** button, "check button");
    SimpleTest.executeSoon(next);
  }, { once: true });

  utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
}

function test_sendMouseEvent5thButton() {
  const x = 1, y = 2, button = 4, clickCount = 1, modifiers = 0;

  window.addEventListener("mousedown", evt => {
    is(evt.buttons, 2 ** button, "check button");
    SimpleTest.executeSoon(next);
  }, { once: true });

  utils.sendMouseEvent("mousedown", x, y, button, clickCount, modifiers);
}

function test_getUnanimatedComputedStyle() {
  SpecialPowers.pushPrefEnv(
    {
      set: [
        ["dom.animations-api.timelines.enabled", true],
        ["layout.css.properties-and-values.enabled", true],
      ],
    },
    () => {
      window.open("file_domwindowutils_animation.html");
    }
  );
}

function test_setDynamicToolbarMaxHeight() {
  window.open("file_domwindowutils_dynamic_toolbar.html");
}

var tests = [
  test_sendMouseEventDefaults,
  test_sendMouseEventOptionals,
  test_sendMouseEvent4thButton,
  test_sendMouseEvent5thButton,
  test_getUnanimatedComputedStyle,
  test_setDynamicToolbarMaxHeight
];

function next() {
  if (!tests.length) {
    SimpleTest.finish();
    return;
  }

  var test = tests.shift();
  test();
}

function start() {
  SimpleTest.waitForExplicitFinish();
  SimpleTest.executeSoon(next);
}

window.addEventListener("load", start);

</script>
</pre>
</body>
</html>