summaryrefslogtreecommitdiffstats
path: root/dom/events/test/test_bug617528.xul
blob: 83038b36be875d0afab38a2790c78a5fd0003dab (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
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css"
                 href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=617528
-->
<window title="Mozilla Bug 617528"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <script type="application/javascript"
          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <body xmlns="http://www.w3.org/1999/xhtml">
    <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=617528"
       target="_blank">Mozilla Bug 617528</a>
  </body>

  <script type="application/javascript"><![CDATA[
    var _window;
    var browser;

    function start() {
      _window = window.open("window_bug617528.xul", "_new", "chrome");
      _window.addEventListener("load", onLoad, false);
    }

    function onLoad() {
      _window.removeEventListener("load", onLoad, false);

      browser = _window.document.getElementById("browser");
      browser.addEventListener("pageshow", onPageShow, false);

      var uri='data:text/html,\
<html>\
  <body>\
    <div oncontextmenu="event.preventDefault()">\
      <input id="node" type="text" value="Click here"></input>\
    </div>\
  </body>\
</html>';
      browser.loadURI(uri);
    }

    function onPageShow() {
      browser.removeEventListener("pageshow", onPageShow, true);
      SimpleTest.executeSoon(doTest);
    }

    function onContextMenu1(event) {
      is(event.defaultPrevented, true,
        "expected event.defaultPrevented to be true (1)");
      is(event.target.localName, "input",
        "expected event.target.localName to be 'input' (1)");
      is(event.originalTarget.localName, "div",
        "expected event.originalTarget.localName to be 'div' (1)");
    }

    function onContextMenu2(event) {
      is(event.defaultPrevented, false,
        "expected event.defaultPrevented to be false (2)");
      is(event.target.localName, "input",
        "expected event.target.localName to be 'input' (2)");
      is(event.originalTarget.localName, "div",
        "expected event.originalTarget.localName to be 'div' (2)");
    }

    function doTest() {
      var win = browser.contentWindow;
      win.focus();
      var node = win.document.getElementById("node");
      var rect = node.getBoundingClientRect();
      var left = rect.left + rect.width / 2;
      var top = rect.top + rect.height / 2;

      var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
        .getInterface(Components.interfaces.nsIDOMWindowUtils);

      browser.addEventListener("contextmenu", onContextMenu1, false);
      wu.sendMouseEvent("contextmenu", left, top, 2, 1, 0);
      browser.removeEventListener("contextmenu", onContextMenu1, false);

      browser.addEventListener("contextmenu", onContextMenu2, false);
      var shiftMask = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
      wu.sendMouseEvent("contextmenu", left, top, 2, 1, shiftMask);
      browser.removeEventListener("contextmenu", onContextMenu2, false);

      _window.close();
      SimpleTest.finish();
    }

    addLoadEvent(start);
    SimpleTest.waitForExplicitFinish();
  ]]></script>
</window>