summaryrefslogtreecommitdiffstats
path: root/layout/base/tests/bug977003_inner_4.html
blob: ab2cb06a238a1544aa89ad4f125e0167a1c58c22 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=977003
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 977003</title>
  <meta name="author" content="Maksim Lebedev" />
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script src="/tests/SimpleTest/EventUtils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  <style>
    #target, #mediator, #listener { background: yellow; }
  </style>
  <script type="application/javascript">
    var target = undefined;
    var mediator = undefined;
    var listener = undefined;
    var test_down_got = false;
    var test_mediator_got = false;
    var test_mediator_lost = false;
    var test_listener_got = false;
    var test_listener_lost = false;

    function TargetDownHandler(event) {
      logger("Target receive event: " + event.type);
      logger("Send pointerCapture to Mediator");
      mediator.setPointerCapture(event.pointerId);
      logger("setPointerCapture was executed");
      test_down_got = true;
    }
    function MediatorGotPCHandler(event) {
      logger("Mediator receive event: " + event.type);
      logger("Try send setPointerCapture on listener");
      listener.setPointerCapture(event.pointerId);
      logger("Try send releasePointerCapture from Mediator");
      mediator.releasePointerCapture(event.pointerId);
      test_mediator_got = true;
    }
    function MediatorLostPCHandler(event) {
      logger("Mediator receive event: " + event.type);
      test_mediator_lost = true;
    }
    function ListenerGotHandler(event) {
      test_listener_got = true;
    }
    function ListenerLostHandler(event) {
      test_listener_lost = true;
    }
    function logger(message) {
      console.log(message);
      var log = document.getElementById('log');
      log.innerHTML = message + "<br>" + log.innerHTML;
    }

    function prepareTest() {
      parent.turnOnPointerEvents(executeTest);
    }
    function executeTest()
    {
      logger("executeTest");
      target = document.getElementById("target");
      mediator = document.getElementById("mediator");
      listener = document.getElementById("listener");
      target.addEventListener("pointerdown",          TargetDownHandler);
      mediator.addEventListener("gotpointercapture",  MediatorGotPCHandler);
      mediator.addEventListener("lostpointercapture", MediatorLostPCHandler);
      listener.addEventListener("gotpointercapture",  ListenerGotHandler);
      listener.addEventListener("lostpointercapture", ListenerLostHandler);
      var rect = target.getBoundingClientRect();
      synthesizeMouse(target, rect.width/2, rect.height/2, {type: "mousedown"});
      synthesizeMouse(target, rect.width/3, rect.height/3, {type: "mousemove"});
      synthesizeMouse(target, rect.width/4, rect.height/4, {type: "mousemove"});
      synthesizeMouse(target, rect.width/4, rect.height/4, {type: "mouseup"});
      finishTest();
    }
    function finishTest() {
      parent.is(test_down_got,      true,  "Part 4: pointerdown event should be received");
      parent.is(test_mediator_got,  true,  "Part 4: gotpointercapture event should be received by Mediator");
      parent.is(test_mediator_lost, true,  "Part 4: lostpointercapture event should be received by Mediator");
      parent.is(test_listener_got,  true,  "Part 4: gotpointercapture event should be received by listener");
      parent.is(test_listener_lost, true,  "Part 4: lostpointercapture event should be received by listener");
      logger("finishTest");
      parent.finishTest();
    }
  </script>
</head>
<body onload="prepareTest()">
  <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=977003">Mozilla Bug 977003 Test 4</a>
  <p id="display"></p>
  <div id="content" style="display: none">
  </div>
  <div id="listener">div id=listener</div>
  <div id="mediator">div id=mediator</div>
  <div id="target">div id=target</div>
  <pre id="log">
  </pre>
</body>
</html>