test_bug648573.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <!-- This Source Code Form is subject to the terms of the Mozilla Public
  2. - License, v. 2.0. If a copy of the MPL was not distributed with this
  3. - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
  4. <!DOCTYPE html>
  5. <html>
  6. <!--
  7. https://bugzilla.mozilla.org/show_bug.cgi?id=648573
  8. -->
  9. <head>
  10. <title>Test for Bug 648573</title>
  11. <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  12. <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
  13. </head>
  14. <body>
  15. <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=648573">Mozilla Bug 648573</a>
  16. <p id="display"></p>
  17. <div id="content" style="display: none">
  18. </div>
  19. <pre id="test">
  20. <script type="application/javascript">
  21. /** Test for Bug 648573 **/
  22. SimpleTest.waitForExplicitFinish();
  23. var utils = SpecialPowers.getDOMWindowUtils(window);
  24. ok("createTouch" in document, "Should have createTouch function");
  25. ok("createTouchList" in document, "Should have createTouchList function");
  26. ok(document.createEvent("touchevent"), "Should be able to create TouchEvent objects");
  27. var t1 = document.createTouch(window, document, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
  28. is(t1.target, document, "Wrong target");
  29. is(t1.identifier, 1, "Wrong identifier");
  30. is(t1.pageX, 2, "Wrong pageX");
  31. is(t1.pageY, 3, "Wrong pageY");
  32. is(t1.screenX, 4, "Wrong screenX");
  33. is(t1.screenY, 5, "Wrong screenY");
  34. is(t1.clientX, 6, "Wrong clientX");
  35. is(t1.clientY, 7, "Wrong clientY");
  36. is(t1.radiusX, 8, "Wrong radiusX");
  37. is(t1.radiusY, 9, "Wrong radiusY");
  38. is(t1.rotationAngle, 10, "Wrong rotationAngle");
  39. is(t1.force, 11, "Wrong force");
  40. var t2 = document.createTouch();
  41. var l1 = document.createTouchList(t1);
  42. is(l1.length, 1, "Wrong length");
  43. is(l1.item(0), t1, "Wront item (1)");
  44. is(l1[0], t1, "Wront item (2)");
  45. var l2 = document.createTouchList([t1, t2]);
  46. is(l2.length, 2, "Wrong length");
  47. is(l2.item(0), t1, "Wront item (3)");
  48. is(l2.item(1), t2, "Wront item (4)");
  49. is(l2[0], t1, "Wront item (5)");
  50. is(l2[1], t2, "Wront item (6)");
  51. var l3 = document.createTouchList();
  52. var e = document.createEvent("touchevent");
  53. e.initTouchEvent("touchmove", true, true, window, 0, true, true, true, true,
  54. l1, l2, l3);
  55. is(e.touches, l1, "Wrong list (1)");
  56. is(e.targetTouches, l2, "Wrong list (2)");
  57. is(e.changedTouches, l3, "Wrong list (3)");
  58. ok(e.altKey, "Alt should be true");
  59. ok(e.metaKey, "Meta should be true");
  60. ok(e.ctrlKey, "Ctrl should be true");
  61. ok(e.shiftKey, "Shift should be true");
  62. var events =
  63. ["touchstart",
  64. "touchend",
  65. "touchmove",
  66. "touchcancel"];
  67. function runEventTest(type) {
  68. var e = document.createEvent("touchevent");
  69. e.initTouchEvent(type, true, true, window, 0, true, true, true, true,
  70. l1, l2, l3);
  71. var t = document.createElement("div");
  72. // Testing target.onFoo;
  73. var didCall = false;
  74. t["on" + type] = function (evt) {
  75. is(evt, e, "Wrong event");
  76. evt.target.didCall = true;
  77. }
  78. t.dispatchEvent(e);
  79. ok(t.didCall, "Should have called the listener(1)");
  80. // Testing <element onFoo="">
  81. t = document.createElement("div");
  82. t.setAttribute("on" + type, "this.didCall = true;");
  83. t.dispatchEvent(e);
  84. ok(t.didCall, "Should have called the listener(2)");
  85. }
  86. for (var i = 0; i < events.length; ++i) {
  87. runEventTest(events[i]);
  88. }
  89. SimpleTest.finish();
  90. </script>
  91. </pre>
  92. </body>
  93. </html>