test_bug547996-1.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=547996
  5. -->
  6. <head>
  7. <title>Test for Bug 547996</title>
  8. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  10. </head>
  11. <body>
  12. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=547996">Mozilla Bug 547996</a>
  13. <p id="display"></p>
  14. <div id="content" style="display: none">
  15. </div>
  16. <pre id="test">
  17. <script type="application/javascript">
  18. /** Test for Bug 547996 **/
  19. /* mouseEvent.mozInputSource attribute */
  20. function prepareListener(eventName, expectedValue) {
  21. return function(event) {
  22. is(event.mozInputSource, expectedValue, "Correct .mozInputSource value in " + eventName);
  23. };
  24. }
  25. const INPUT_SOURCE_UNKNOWN = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_UNKNOWN;
  26. const INPUT_SOURCE_KEYBOARD = SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_KEYBOARD;
  27. function doTest() {
  28. var eventNames = [
  29. "mousedown",
  30. "mouseup",
  31. "click",
  32. "dblclick",
  33. "contextmenu",
  34. "DOMMouseScroll",
  35. "dragdrop",
  36. "dragstart",
  37. "dragend",
  38. "dragenter",
  39. "dragleave",
  40. "dragover"
  41. ];
  42. var target = document.getElementById("testTarget");
  43. for (var i in eventNames) {
  44. for(var value = INPUT_SOURCE_UNKNOWN; value <= INPUT_SOURCE_KEYBOARD; value++) {
  45. var eventName = eventNames[i];
  46. var listener = prepareListener(eventName, value);
  47. target.addEventListener(eventName, listener, false);
  48. var newEvent = document.createEvent("MouseEvent");
  49. newEvent.initNSMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0,
  50. false, false, false, false, 0, null, 0, value);
  51. target.dispatchEvent(newEvent);
  52. target.removeEventListener(eventName, listener, false);
  53. }
  54. // Events created by script that do not initialize the mozInputSource
  55. // value should have the value MOZ_SOURCE_UNKNOWN
  56. var listener = prepareListener(eventName, INPUT_SOURCE_UNKNOWN);
  57. target.addEventListener(eventName, listener, false);
  58. var newEvent = document.createEvent("MouseEvent");
  59. newEvent.initMouseEvent(eventName, true, true, window, 0, 0, 0, 0, 0,
  60. false, false, false, false, 0, null);
  61. target.dispatchEvent(newEvent);
  62. target.removeEventListener(eventName, listener, false);
  63. }
  64. SimpleTest.finish();
  65. }
  66. SimpleTest.waitForExplicitFinish();
  67. addLoadEvent(doTest);
  68. </script>
  69. </pre>
  70. <span id="testTarget" style="border: 1px solid black;">testTarget</span>
  71. </body>
  72. </html>