summaryrefslogtreecommitdiff
path: root/layout/base/tests/bug1162990_inner_2.html
blob: e418927bd69fe95c28b7211a6ccffcdbbfe373a5 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1162990
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1162990</title>
  <meta name="author" content="Maksim Lebedev" />
  <script type="application/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>
    div#basket {
      background: red;
      padding: 10px;
      margin: 10px;
    }
    div#target {
      background: lightgreen;
      padding: 10px;
      margin: 10px;
    }
    div#child {
      background: lightblue;
      padding: 10px;
      margin: 10px;
    }
    div#listener {
      background: yellow;
      padding: 10px;
      margin: 10px;
    }
  </style>
  <script type="application/javascript">
    var basket;
    var target;
    var child;
    var listener;

    var test_basketLeave = 0;
    var test_targetDown = 0;
    var test_targetGotCapture = 0;
    var test_targetLostCapture = 0;
    var test_targetLeave = 0;
    var test_childLeave = 0;
    var test_listenerLeave = 0;

    function basketLeaveHandler(event) {
      logger("basket: " + event.type);
      test_basketLeave++;
    }
    function targetDownHandler(event) {
      logger("target: " + event.type);
      target.setPointerCapture(event.pointerId);
      test_targetDown++;
    }
    function targetGotHandler(event) {
      logger("target: " + event.type);
      test_targetGotCapture++;
    }
    function targetLostHandler(event) {
      logger("target: " + event.type);
      test_targetLostCapture++;
    }
    function targetLeaveHandler(event) {
      logger("target: " + event.type);
      test_targetLeave++;
    }
    function childLeaveHandler(event) {
      logger("child: " + event.type);
      test_childLeave++;
    }
    function listenerLeaveHandler(event) {
      logger("listener: " + event.type);
      test_listenerLeave++;
    }

    function prepareTest() {
      parent.turnOnPointerEvents(executeTest);
    }

    function setEventHandlers() {
      basket = document.getElementById("basket");
      target = document.getElementById("target");
      child = document.getElementById("child");
      listener = document.getElementById("listener");

      basket.addEventListener("pointerleave",       basketLeaveHandler,   false);
      target.addEventListener("pointerdown",        targetDownHandler,    false);
      target.addEventListener("gotpointercapture",  targetGotHandler,     false);
      target.addEventListener("lostpointercapture", targetLostHandler,    false);
      target.addEventListener("pointerleave",       targetLeaveHandler,   false);
      child.addEventListener("pointerleave",        childLeaveHandler,    false);
      listener.addEventListener("pointerleave",     listenerLeaveHandler, false);
    }

    function executeTest()
    {
      logger("executeTest");
      setEventHandlers();
      var rectTg = target.getBoundingClientRect();
      var rectCd = child.getBoundingClientRect();
      var rectLr = listener.getBoundingClientRect();
      synthesizePointer(target,   rectTg.width/3, rectTg.height/7,  {type: "pointerdown"});
      synthesizePointer(child,    rectCd.width/3, rectCd.height/2,  {type: "pointermove"});
      synthesizePointer(listener, rectLr.width/3, rectLr.height/2,  {type: "pointermove"});
      synthesizePointer(child,    rectCd.width/3, rectCd.height/2,  {type: "pointermove"});
      synthesizePointer(target,   rectTg.width/3, rectTg.height/7,  {type: "pointermove"});
      synthesizePointer(target,   rectTg.width/3, rectTg.height/7,  {type: "pointerup"});
      synthesizePointer(target,   rectTg.width/3, rectTg.height/9,  {type: "pointermove"});
      finishTest();
    }

    function finishTest() {
      parent.is(test_basketLeave,       0, "Part2: basket should not receive pointerleave event after pointer capturing");
      parent.is(test_targetDown,        1, "Part2: target should receive pointerdown event");
      parent.is(test_targetGotCapture,  1, "Part2: target should receive gotpointercapture event");
      parent.is(test_targetLostCapture, 1, "Part2: target should receive lostpointercapture event");
      parent.is(test_targetLeave,       0, "Part2: target should not receive pointerleave event");
      parent.is(test_childLeave,        0, "Part2: child should not receive pointerleave event after pointer capturing");
      parent.is(test_listenerLeave,     0, "Part2: listener should not receive pointerleave event after pointer capturing");
      logger("finishTest");
      parent.finishTest();
    }

    function logger(message) {
      var log = document.getElementById('log');
      log.innerHTML = message + "<br>" + log.innerHTML;
    }
  </script>
</head>
<body onload="prepareTest()">
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1162990">Mozilla Bug 1162990 Test 2</a>
  <p id="display"></p>
  <div id="content" style="display: none">
  </div>
  <div id="basket">div id=basket
    <div id="target">div id=target
      <div id="child">div id=child</div>
    </div>
  </div>
  <div id="listener">div id=listener</div>
  <pre id="log">
  </pre>
</body>
</html>