summaryrefslogtreecommitdiffstats
path: root/dom/html/test/test_bug1089326.html
blob: 06f3a7c44d412429c5bb84ccd93defd2a9b90258 (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
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1089326
-->
<head>
  <meta charset="utf-8">
  <title>Test for Bug 1089326</title>
  <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"/>
  <script type="application/javascript">

  /** Test for Bug 1089326 **/
  function test() {
    var b = document.getElementById("button");
    var b_rect = b.getBoundingClientRect();
    var a = document.getElementById("anchor");
    var a_rect = a.getBoundingClientRect();

    is(document.elementFromPoint(b_rect.x + 1, b_rect.y + 1), b,
       "Should find button when doing hit test on top of it.");
    is(document.elementFromPoint(a_rect.x + 1, a_rect.y + 1), a,
       "Should find anchor when doing hit test on top of it.");

    var expectedTarget;
    var clickCount = 0;
    var container = document.getElementById("interactiveContentContainer");
    container.addEventListener("click", function(event) {
        is(event.target, expectedTarget, "Got expected click event target.");
        ++clickCount;
      }, true);
    var i1 = document.getElementById("interactiveContent1");
    var s11 = document.getElementById("s11");
    var s12 = document.getElementById("s12");

    var i2 = document.getElementById("interactiveContent2");
    var s21 = document.getElementById("s21");

    expectedTarget = i1;
    synthesizeMouseAtCenter(s11, { type: "mousedown" });
    synthesizeMouseAtCenter(s12, { type: "mouseup" });
    is(clickCount, 1, "Should have got a click event.");

    expectedTarget = null;
    synthesizeMouseAtCenter(s11, { type: "mousedown" });
    synthesizeMouseAtCenter(s21, { type: "mouseup" });
    is(clickCount, 1, "Should not have got a click event.");

    expectedTarget = null;
    synthesizeMouseAtCenter(s21, { type: "mousedown" });
    synthesizeMouseAtCenter(s11, { type: "mouseup" });
    is(clickCount, 1, "Should not have got a click event.");

    var span1 = document.getElementById("span1");
    var span2 = document.getElementById("span2");
    expectedTarget = container;
    synthesizeMouseAtCenter(span1, { type: "mousedown" });
    synthesizeMouseAtCenter(span2, { type: "mouseup" });
    is(clickCount, 2, "Should not have got a click event.");

    button.addEventListener("click", function(event) {
        is(event.target, expectedTarget, "Got expected click event target.");
        ++clickCount;
      }, true);

    expectedTarget = a;
    synthesizeMouseAtCenter(a, { type: "mousedown" });
    synthesizeMouseAtCenter(a, { type: "mouseup" });
    is(clickCount, 3, "Should have got a click event.");

    expectedTarget = a;
    synthesizeMouseAtCenter(b, { type: "mousedown" });
    synthesizeMouseAtCenter(b, { type: "mouseup" });
    is(clickCount, 4, "Should have got a click event.");

    SimpleTest.finish();
  }

  SimpleTest.waitForExplicitFinish();
  SimpleTest.waitForFocus(test);

  </script>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1089326">Mozilla Bug 1089326</a>
<p id="display"></p>
<button id="button">button <a id="anchor" href="#">anchor</a>button</button>

<div id="interactiveContentContainer">
  <a id="interactiveContent1" href="#">foo <span id="s11">s11</span><span id="s12">s12</span> bar</a>
  <a id="interactiveContent2" href="#">foo <span id="s21">s21</span><span id="s22">s22</span> bar</a>

  <div>
    <span>
      <span id="span1">span1</span>
    </span>
  </div>

  <div>
    <span>
      <span id="span2">span2</span>
    </span>
  </div>
</div>

</body>
</html>