test_bug742376.html 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <!DOCTYPE HTML>
  2. <html>
  3. <!--
  4. https://bugzilla.mozilla.org/show_bug.cgi?id=402089
  5. -->
  6. <head>
  7. <title>Test for Bug 742376</title>
  8. <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  9. <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
  10. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  11. </head>
  12. <body>
  13. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=742376">Mozilla Bug 742376</a>
  14. <script class="testbody" type="text/javascript">
  15. /** Test for Bug 742376 **/
  16. function hasListeners() {
  17. var Cc = SpecialPowers.Cc;
  18. var Ci = SpecialPowers.Ci;
  19. var dss = Cc["@mozilla.org/devicesensors;1"].getService(Ci.nsIDeviceSensors);
  20. return dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ORIENTATION, window) ||
  21. dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ROTATION_VECTOR, window) ||
  22. dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_GAME_ROTATION_VECTOR, window);
  23. }
  24. is(hasListeners(), false, "Must not have listeners before tests start");
  25. function dumbListener(event) {}
  26. function dumbListener2(event) {}
  27. function dumbListener3(event) {}
  28. window.addEventListener("deviceorientation", dumbListener, false);
  29. window.addEventListener("random_event_name", function() {}, false);
  30. window.addEventListener("deviceorientation", dumbListener2, false);
  31. is(hasListeners(), true, "Listeners should have been added");
  32. window.setTimeout(function() {
  33. window.removeEventListener("deviceorientation", dumbListener, false);
  34. is(hasListeners(), true, "Only some listeners should have been removed");
  35. window.setTimeout(function() {
  36. window.removeEventListener("deviceorientation", dumbListener2, false);
  37. window.setTimeout(function() {
  38. is(hasListeners(), false, "Listeners should have been removed");
  39. testEventHandler();
  40. }, 0);
  41. }, 0);
  42. }, 0);
  43. function testEventHandler() {
  44. window.ondeviceorientation = function() {}
  45. window.setTimeout(function() {
  46. is(hasListeners(), true, "Handler should have been added");
  47. window.ondeviceorientation = null;
  48. window.setTimeout(function() {
  49. is(hasListeners(), false, "Handler should have been removed");
  50. SimpleTest.finish();
  51. }, 0);
  52. }, 0)
  53. }
  54. SimpleTest.waitForExplicitFinish();
  55. </script>
  56. </pre>
  57. </body>
  58. </html>