test_bug1290965.xul 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?xml version="1.0"?>
  2. <?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
  3. <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml" xmlns:h="http://www.w3.org/1999/xhtml">
  4. <script type="application/javascript"
  5. src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
  6. <toolbarbutton oncommand="++countera;" id="a">A</toolbarbutton>
  7. <toolbarbutton oncommand="++counterb;" id="b">B</toolbarbutton>
  8. <script type="text/javascript">
  9. <![CDATA[
  10. let aEl = document.getElementById('a');
  11. let bEl = document.getElementById('b');
  12. let countera = 0;
  13. let counterb = 0;
  14. aEl.addEventListener('click', function (aEvent) {
  15. aEvent.preventDefault();
  16. let cmdEvent = document.createEvent("xulcommandevent");
  17. cmdEvent.initCommandEvent("command", true, true, window, 0,
  18. aEvent.ctrlKey, aEvent.altKey, aEvent.shiftKey,
  19. aEvent.metaKey, null);
  20. aEvent.currentTarget.dispatchEvent(cmdEvent);
  21. });
  22. bEl.addEventListener('click', function (aEvent) {
  23. let cmdEvent = document.createEvent("xulcommandevent");
  24. cmdEvent.initCommandEvent("command", true, true, window, 0,
  25. aEvent.ctrlKey, aEvent.altKey, aEvent.shiftKey,
  26. aEvent.metaKey, null);
  27. aEvent.currentTarget.dispatchEvent(cmdEvent);
  28. });
  29. bEl.click();
  30. aEl.click();
  31. is(countera, 1, "Counter should be one as event fires once");
  32. is(counterb, 2, "Counter should be two as event fires twice");
  33. ]]>
  34. </script>
  35. </window>