test_bug617528.xul 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
  3. <?xml-stylesheet type="text/css"
  4. href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
  5. <!--
  6. https://bugzilla.mozilla.org/show_bug.cgi?id=617528
  7. -->
  8. <window title="Mozilla Bug 617528"
  9. xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  10. <script type="application/javascript"
  11. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
  12. <body xmlns="http://www.w3.org/1999/xhtml">
  13. <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=617528"
  14. target="_blank">Mozilla Bug 617528</a>
  15. </body>
  16. <script type="application/javascript"><![CDATA[
  17. var _window;
  18. var browser;
  19. function start() {
  20. _window = window.open("window_bug617528.xul", "_new", "chrome");
  21. _window.addEventListener("load", onLoad, false);
  22. }
  23. function onLoad() {
  24. _window.removeEventListener("load", onLoad, false);
  25. browser = _window.document.getElementById("browser");
  26. browser.addEventListener("pageshow", onPageShow, false);
  27. var uri='data:text/html,\
  28. <html>\
  29. <body>\
  30. <div oncontextmenu="event.preventDefault()">\
  31. <input id="node" type="text" value="Click here"></input>\
  32. </div>\
  33. </body>\
  34. </html>';
  35. browser.loadURI(uri);
  36. }
  37. function onPageShow() {
  38. browser.removeEventListener("pageshow", onPageShow, true);
  39. SimpleTest.executeSoon(doTest);
  40. }
  41. function onContextMenu1(event) {
  42. is(event.defaultPrevented, true,
  43. "expected event.defaultPrevented to be true (1)");
  44. is(event.target.localName, "input",
  45. "expected event.target.localName to be 'input' (1)");
  46. is(event.originalTarget.localName, "div",
  47. "expected event.originalTarget.localName to be 'div' (1)");
  48. }
  49. function onContextMenu2(event) {
  50. is(event.defaultPrevented, false,
  51. "expected event.defaultPrevented to be false (2)");
  52. is(event.target.localName, "input",
  53. "expected event.target.localName to be 'input' (2)");
  54. is(event.originalTarget.localName, "div",
  55. "expected event.originalTarget.localName to be 'div' (2)");
  56. }
  57. function doTest() {
  58. var win = browser.contentWindow;
  59. win.focus();
  60. var node = win.document.getElementById("node");
  61. var rect = node.getBoundingClientRect();
  62. var left = rect.left + rect.width / 2;
  63. var top = rect.top + rect.height / 2;
  64. var wu = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
  65. .getInterface(Components.interfaces.nsIDOMWindowUtils);
  66. browser.addEventListener("contextmenu", onContextMenu1, false);
  67. wu.sendMouseEvent("contextmenu", left, top, 2, 1, 0);
  68. browser.removeEventListener("contextmenu", onContextMenu1, false);
  69. browser.addEventListener("contextmenu", onContextMenu2, false);
  70. var shiftMask = Components.interfaces.nsIDOMEvent.SHIFT_MASK;
  71. wu.sendMouseEvent("contextmenu", left, top, 2, 1, shiftMask);
  72. browser.removeEventListener("contextmenu", onContextMenu2, false);
  73. _window.close();
  74. SimpleTest.finish();
  75. }
  76. addLoadEvent(start);
  77. SimpleTest.waitForExplicitFinish();
  78. ]]></script>
  79. </window>