summaryrefslogtreecommitdiffstats
path: root/dom/events/test/pointerevents/test_trigger_popup_by_pointer_events.html
blob: cda279e265ee41bacae2d247c8b097f97f941170 (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
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Test for triggering popup by pointer events</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"/>
</head>
<body>
<div id="target" style="width: 50px; height: 50px; background: green"></div>
<script>

SimpleTest.waitForExplicitFinish();

function sendMouseEvent(element, eventName, listenEventName, handler) {
  element.addEventListener(listenEventName, handler, {once: true});
  synthesizeMouseAtCenter(element, {type: eventName});
}

function checkAllowOpenPopup(e) {
  let w = window.open("about:blank");
  ok(w, "Should allow popup in the " + e.type + " listener");
  if (w) {
    w.close();
  }
}

function checkBlockOpenPopup(e) {
  let w = window.open("about:blank");
  ok(!w, "Should block popup in the " + e.type + " listener");
  if (w) {
    w.close();
  }
}

function startTest() {
  let target = document.getElementById("target");
  // By default, only allow opening popup in the pointerup listener.
  sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
  sendMouseEvent(target, "mousedown", "pointerdown", checkBlockOpenPopup);
  sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
  sendMouseEvent(target, "mouseup", "pointerup", checkAllowOpenPopup);
  SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events",
                                      "pointerdown pointerup"]]}, () => {
    // Adding pointerdown to preference should work
    sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
    sendMouseEvent(target, "mousedown", "pointerdown", checkAllowOpenPopup);
    sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
    sendMouseEvent(target, "mouseup", "pointerup", checkAllowOpenPopup);
    SpecialPowers.pushPrefEnv({"set": [["dom.popup_allowed_events",
                                        "pointerdown pointerup pointermove"]]}, () => {
      // Adding pointermove to preference should be no effect.
      sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
      sendMouseEvent(target, "mousedown", "pointerdown", checkAllowOpenPopup);
      sendMouseEvent(target, "mousemove", "pointermove", checkBlockOpenPopup);
      sendMouseEvent(target, "mouseup", "pointerup", checkAllowOpenPopup);
      SimpleTest.finish();
    });
  });
}

const DENY_ACTION = SpecialPowers.Ci.nsIPermissionManager.DENY_ACTION;

SimpleTest.waitForFocus(() => {
  SpecialPowers.pushPermissions([{'type': 'popup', 'allow': DENY_ACTION,
                                  'context': document}], () => {
    SpecialPowers.pushPrefEnv({
      "set": [["dom.w3c_pointer_events.enabled", true]]
    }, startTest);
  });
});

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