summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/pointerlock/file_suppressSomeMouseEvents.html
blob: bc1e1e64a5b0059180ee103cf55361e35ad04810 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=633602
-->
<head>
  <title>Bug 633602 - file_cursorPosEvents.html</title>
  <script src="/tests/SimpleTest/SimpleTest.js">
  </script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <script type="application/javascript" src="pointerlock_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style type="text/css">
    #child {
      width: 100px;
      height: 100px;
      background-color:Green;
    }
  </style>
</head>
<body>
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=633602">
  Mozilla Bug 633602</a>

  <div id="parent">
    <div id="child"></div>
  </div>

  <script type="application/javascript">
      /*
       * Test for Bug 633602
       * Test will check to make sure that the following mouse events are no
       * longer executed in pointer lock.
       *  - mouseover, mouseout, mouseenter, mouseleave
       */

      SimpleTest.waitForExplicitFinish();

      function PointerEventStats() {
        this.mouseEnter = false;
        this.mouseLeave = false;
        this.mouseOver = false;
        this.mouseOut = false;
      }

      var parent
        , child
        , parentStats = new PointerEventStats()
        , childStats = new PointerEventStats()
        , isPointerLocked = false;

      function runTests () {
        ok(isPointerLocked, "expected mouse to be locked, but wasn't.");

        is(childStats.mouseEnter, false,
           "child's mouseenter should not be firing in Full Screen and Pointer Lock.");
        is(childStats.mouseOver, false,
           "child's mouseover should not be firing in Full Screen and Pointer Lock.");
        is(childStats.mouseLeave, false,
           "child's mouseleave should not be firing in Full Screen and Pointer Lock.");
        is(childStats.mouseOut, false,
           "child's mouseout should not be firing in Full Screen and Pointer Lock.");

        is(parentStats.mouseEnter, false,
           "parent's mouseenter should not be firing in Full Screen and Pointer Lock.");
        is(parentStats.mouseOver, false,
           "parent's mouseover should not be firing in Full Screen and Pointer Lock.");
        is(parentStats.mouseLeave, false,
           "parent's mouseleave should not be firing in Full Screen and Pointer Lock.");
        is(parentStats.mouseOut, false,
           "parent's mouseout should not be firing in Full Screen and Pointer Lock.");
      }

      var parentMoveListener = function () {
        isPointerLocked = !!document.pointerLockElement;
        removeEventListeners();
        document.exitPointerLock();
      };

      var parentOutListener = function (e) {
          parentStats.mouseOut = true;
      };
      var parentLeaveListener = function (e) {
          parentStats.mouseLeave = true;
      };
      var parentOverListener = function (e) {
          parentStats.mouseOver = true;
      };
      var parentEnterListener = function (e) {
          parentStats.mouseEnter = true;
      };

      var childOutListener = function (e) {
          childStats.mouseOut = true;
      };
      var childLeaveListener = function (e) {
          childStats.mouseLeave = true;
      };
      var childOverListener = function (e) {
          childStats.mouseOver = true;
      };
      var childEnterListener = function (e) {
          childStats.mouseEnter = true;
      };

      function addEventListeners() {
        parent.addEventListener("mousemove", parentMoveListener);

        parent.addEventListener("mouseout", parentOutListener);
        parent.addEventListener("mouseleave", parentLeaveListener);
        parent.addEventListener("mouseover", parentOverListener);
        parent.addEventListener("mouseenter", parentEnterListener);

        child.addEventListener("mouseout", childOutListener);
        child.addEventListener("mouseleave", childLeaveListener);
        child.addEventListener("mouseover", childOverListener);
        child.addEventListener("mouseenter", childEnterListener);
      }

      function removeEventListeners() {
        parent.removeEventListener("mousemove", parentMoveListener);

        parent.removeEventListener("mouseout", parentOutListener);
        parent.removeEventListener("mouseleave", parentLeaveListener);
        parent.removeEventListener("mouseover", parentOverListener);
        parent.removeEventListener("mouseenter", parentEnterListener);

        child.removeEventListener("mouseout", childOutListener);
        child.removeEventListener("mouseleave", childLeaveListener);
        child.removeEventListener("mouseover"  , childOverListener);
        child.removeEventListener("mouseenter", childEnterListener);
      }

      document.addEventListener("pointerlockchange", function (e) {
        if (document.pointerLockElement === parent) {
          addEventListeners();
          synthesizeMouseAtCenter(child, { type: "mousemove" }, window);
        }
        else {
          addFullscreenChangeContinuation("exit", function() {
            runTests();
            SimpleTest.finish();
          });
          document.exitFullscreen();
        }
      });

      function start() {
        parent = document.getElementById("parent");
        child = document.getElementById("child");
        addFullscreenChangeContinuation("enter", function() {
          parent.requestPointerLock();
        });
        parent.requestFullscreen();
      }
  </script>
</body>
</html>