dom/events/test/test_bug547996-1.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/test/test_bug547996-1.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=547996
     1.8 +-->
     1.9 +<head>
    1.10 +  <title>Test for Bug 547996</title>
    1.11 +  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.12 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.13 +</head>
    1.14 +<body>
    1.15 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=547996">Mozilla Bug 547996</a>
    1.16 +<p id="display"></p>
    1.17 +<div id="content" style="display: none">
    1.18 +  
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script type="application/javascript">
    1.22 +
    1.23 +/** Test for Bug 547996 **/
    1.24 +/* mouseEvent.mozInputSource attribute */
    1.25 +
    1.26 +function prepareListener(eventName, expectedValue) {
    1.27 +  return function(event) {
    1.28 +    is(event.mozInputSource, expectedValue, "Correct .mozInputSource value in " + eventName);
    1.29 +  };
    1.30 +}
    1.31 +
    1.32 +const INPUT_SOURCE_UNKNOWN = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_UNKNOWN;
    1.33 +const INPUT_SOURCE_KEYBOARD = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD;
    1.34 +
    1.35 +function doTest() {
    1.36 +  var eventNames = [
    1.37 +    "mousedown",
    1.38 +    "mouseup",
    1.39 +    "click",
    1.40 +    "dblclick",
    1.41 +    "contextmenu",
    1.42 +    "DOMMouseScroll",
    1.43 +    "dragdrop",
    1.44 +    "dragstart",
    1.45 +    "dragend",
    1.46 +    "dragenter",
    1.47 +    "dragleave",
    1.48 +    "dragover"
    1.49 +  ];
    1.50 +
    1.51 +   var target = document.getElementById("testTarget");
    1.52 +
    1.53 +  for (var i in eventNames) {
    1.54 +    for(var value = INPUT_SOURCE_UNKNOWN; value <= INPUT_SOURCE_KEYBOARD; value++) {
    1.55 +      var eventName = eventNames[i];
    1.56 +      var listener = prepareListener(eventName, value);
    1.57 +
    1.58 +      target.addEventListener(eventName, listener, false);
    1.59 +
    1.60 +      var newEvent = document.createEvent("MouseEvent");
    1.61 +      newEvent.initNSMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0,
    1.62 +                                false, false, false, false, 0, null, 0, value);
    1.63 +      target.dispatchEvent(newEvent);
    1.64 +      target.removeEventListener(eventName, listener, false);
    1.65 +    }
    1.66 +
    1.67 +    // Events created by script that do not initialize the mozInputSource
    1.68 +    // value should have the value MOZ_SOURCE_UNKNOWN
    1.69 +    var listener = prepareListener(eventName, INPUT_SOURCE_UNKNOWN);
    1.70 +    target.addEventListener(eventName, listener, false);
    1.71 +
    1.72 +    var newEvent = document.createEvent("MouseEvent");
    1.73 +    newEvent.initMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0,
    1.74 +                              false, false, false, false, 0, null);
    1.75 +    target.dispatchEvent(newEvent);
    1.76 +    target.removeEventListener(eventName, listener, false);
    1.77 +
    1.78 +  }
    1.79 +
    1.80 +  SimpleTest.finish();
    1.81 +}
    1.82 +
    1.83 +SimpleTest.waitForExplicitFinish();
    1.84 +addLoadEvent(doTest);
    1.85 +
    1.86 +</script>
    1.87 +</pre>
    1.88 +<span id="testTarget" style="border: 1px solid black;">testTarget</span>
    1.89 +</body>
    1.90 +</html>

mercurial