Add tests for the touchend event
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 26 Apr 2011 17:12:37 -0700
changeset 52 a3bdd103c7d9
parent 51 fdd08cbcf438
child 53 fec574167f19
Add tests for the touchend event
test/touchevents/single-touch.html
--- a/test/touchevents/single-touch.html	Tue Apr 26 10:43:26 2011 -0700
+++ b/test/touchevents/single-touch.html	Tue Apr 26 17:12:37 2011 -0700
@@ -6,33 +6,37 @@
   <script src="../testharness.js"></script>
   <script>
     setup({explicit_done: true});
-    var test_click = async_test("Interaction with mouse events");
 
     function run() {
       var target = document.getElementById("target");
 
+      var test_click = async_test("Interaction with mouse events");
+      var test_touchstart = async_test("touchstart event received");
+      var test_touchend = async_test("touchend event received");
+
       var touchstart_received = false;
 
       on_event(target, "touchstart", function onTouchStart(ev) {
         touchstart_received = true;
+        test_touchstart.done();
 
         test(function() {
           assert_true(ev.target instanceof Element, "target must be an Element.");
           assert_equals(ev.relatedTarget, null, "relatedTarget must be null for touchstart event.");
-        }, "TouchEvent target attributes are correct.");
+        }, "touchstart TouchEvent target attributes are correct.");
 
         test(function() {
           var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
           for (var i = 0; i < attrs.length; i++) {
             assert_true(attrs[i] in ev);
           }
-        }, "TouchEvent modifier key attributes are present.");
+        }, "touchstart TouchEvent modifier key attributes are present.");
 
         test(function() {
           assert_equals(ev.touches.length, 1, "One touch point.");
           assert_equals(ev.changedTouches.length, 1, "One changed touch point.");
           assert_equals(ev.targetTouches.length, 1, "One target touch point.");
-        }, "TouchList lengths are correct.");
+        }, "touchstart TouchList lengths are correct.");
 
         var t = ev.touches[0];
         var ct = ev.changedTouches[0];
@@ -69,9 +73,56 @@
           }
         }, "Touch location attributes are present.");
 
+      });
+
+      on_event(target, "touchend", function onTouchStart(ev) {
+        test_touchend.step(function() {
+          assert_true(touchstart_received, "touchend follows touchstart");
+        });
+        test_touchend.done();
+
+        test(function() {
+          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
+          for (var i = 0; i < attrs.length; i++) {
+            assert_true(attrs[i] in ev);
+          }
+        }, "touchend TouchEvent modifier key attributes are present.");
+
+        test(function() {
+          assert_equals(ev.touches.length, 0, "Zero touch points.");
+          assert_equals(ev.changedTouches.length, 1, "One changed touch point.");
+          assert_equals(ev.targetTouches.length, 0, "Zero target touch points.");
+        }, "touchend TouchList lengths are correct.");
+
+        var t = ev.changedTouches[0];
+
+        test(function() {
+          assert_equals(t.identifier, 0, "changedTouches identifier is 0.");
+        }, "Touch identifier is correct.");
+
+        test(function() {
+          assert_true(t.rotationAngle >= 0, "rotationAngle must be >= 0.");
+          assert_true(t.rotationAngle < 90, "rotationAngle must be > 90.");
+
+          assert_true(t.radiusX > 0, "radiusX is positive.");
+          assert_true(t.radiusY > 0, "radiusY is positive.");
+
+          assert_true(t.force >= 0, "force >= 0.");
+          assert_true(t.force <= 1, "force <= 1.");
+        }, "Touch attribute values are valid");
+
+        test(function() {
+          var attrs = ["screenX", "screenY", "clientX", "clientY",
+                       "pageX", "pageY"];
+          for (var i = 0; i < attrs.length; i++) {
+            assert_true(attrs[i] in t);
+          }
+        }, "Touch location attributes are present.");
+
         done();
       });
 
+
       on_event(target, "click", function onClick(ev) {
         test_click.step(function() {
           assert_true(touchstart_received,