tests/touch-events-v2/submissions/Mozilla/single-touch.html
author Art Barstow <art.barstow@nokia.com>
Mon, 10 Sep 2012 12:56:18 -0400
changeset 160 e0e3783147f0
permissions -rw-r--r--
single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
160
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     1
<!DOCTYPE HTML>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     2
<html>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     3
<head>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     4
  <title>Touch Events: Single-touch tests</title>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     5
  <meta name="viewport" content="width=device-width">
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     6
  <script src="../../../testharness.js"></script>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     7
  <script>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     8
    setup({explicit_done: true});
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     9
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    10
    function run() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    11
      var target0 = document.getElementById("target0");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    12
      var target1 = document.getElementById("target1");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    13
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    14
      var test_touchstart = async_test("touchstart event received");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    15
      var test_touchmove = async_test("touchmove event received");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    16
      var test_touchend = async_test("touchend event received");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    17
      var test_mousedown = async_test("Interaction with mouse events");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    18
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    19
      var touchstart_received = false;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    20
      var touchmove_received = false;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    21
      var touchend_received = false;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    22
      var invalid_touchmove_received = false;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    23
      var touchstart_identifier;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    24
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    25
      on_event(target0, "touchstart", function onTouchStart(ev) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    26
        ev.preventDefault();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    27
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    28
        touchstart_received = true;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    29
        test_touchstart.step(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    30
          assert_false(touchmove_received, "touchstart precedes touchmove");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    31
          assert_false(touchend_received, "touchstart precedes touchend");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    32
        });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    33
        test_touchstart.done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    34
        test_mousedown.done(); // If we got here, then the mouse event test is not needed.
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    35
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    36
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    37
          assert_true(ev.target instanceof Element, "target must be an Element.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    38
          assert_equals(ev.relatedTarget, null, "relatedTarget must be null for touchstart event.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    39
        }, "touchstart TouchEvent target attributes are correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    40
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    41
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    42
          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    43
          for (var i = 0; i < attrs.length; i++) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    44
            assert_true(attrs[i] in ev);
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    45
          }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    46
        }, "touchstart TouchEvent modifier key attributes are present.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    47
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    48
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    49
          assert_equals(ev.touches.length, 1, "One touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    50
          assert_equals(ev.changedTouches.length, 1, "One changed touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    51
          assert_equals(ev.targetTouches.length, 1, "One target touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    52
        }, "touchstart TouchList lengths are correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    53
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    54
        var t = ev.touches[0];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    55
        var ct = ev.changedTouches[0];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    56
        var tt = ev.targetTouches[0];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    57
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    58
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    59
          assert_true(ev instanceof TouchEvent, "Event is a TouchEvent.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    60
          assert_true(ev.touches instanceof TouchList, "touches is a TouchList");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    61
          assert_true(t instanceof Touch, "touches[0] is a Touch");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    62
        }, "Interface names are correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    63
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    64
        touchstart_identifier = t.identifier;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    65
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    66
          assert_equals(ct.identifier, touchstart_identifier, "changedTouches identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    67
          assert_equals(tt.identifier, touchstart_identifier, "targetTouches identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    68
        }, "Touch identifiers are consistent.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    69
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    70
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    71
          assert_equals(ev.touches.identifiedTouch(touchstart_identifier), t, "touches.identifiedTouch is correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    72
        }, "identifiedTouch");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    73
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    74
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    75
          assert_true(t.rotationAngle >= 0, "rotationAngle must be >= 0.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    76
          assert_true(t.rotationAngle < 90, "rotationAngle must be > 90.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    77
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    78
          assert_true(t.radiusX > 0, "radiusX is positive.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    79
          assert_true(t.radiusY > 0, "radiusY is positive.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    80
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    81
          assert_true(t.force >= 0, "force >= 0.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    82
          assert_true(t.force <= 1, "force <= 1.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    83
        }, "Touch attribute values are valid");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    84
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    85
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    86
          var attrs = ["screenX", "screenY", "clientX", "clientY",
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    87
                       "pageX", "pageY"];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    88
          for (var i = 0; i < attrs.length; i++) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    89
            assert_true(attrs[i] in t);
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    90
          }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    91
        }, "Touch location attributes are present.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    92
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    93
      });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    94
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    95
      on_event(target0, "touchmove", function onTouchMove(ev) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    96
        ev.preventDefault();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    97
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    98
        if (touchmove_received)
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    99
          return;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   100
        touchmove_received = true;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   101
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   102
        test_touchmove.step(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   103
          assert_true(touchstart_received, "touchend follows touchstart");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   104
          assert_false(touchend_received, "touchmove precedes touchend");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   105
        });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   106
        test_touchmove.done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   107
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   108
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   109
          assert_equals(ev.touches.length, 1, "One touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   110
          assert_equals(ev.changedTouches.length, 1, "One changed touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   111
          assert_equals(ev.targetTouches.length, 1, "One target touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   112
        }, "touchmove TouchList lengths are correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   113
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   114
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   115
          assert_equals(ev.touches[0].identifier, touchstart_identifier, "Touch identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   116
          assert_equals(ev.changedTouches[0].identifier, touchstart_identifier, "Changed touch identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   117
          assert_equals(ev.targetTouches[0].identifier, touchstart_identifier, "Target touch identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   118
        }, "touchmove identifier matches touchstart identifier.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   119
      });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   120
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   121
      on_event(target1, "touchmove", function onTouchMove(ev) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   122
        invalid_touchmove_received = true;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   123
      });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   124
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   125
      on_event(window, "touchend", function onTouchStart(ev) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   126
        touchend_received = true;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   127
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   128
        test_touchend.step(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   129
          assert_equals(ev.target, target0, "touchend is dispatched to the original target");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   130
          assert_true(touchstart_received, "touchend follows touchstart");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   131
          assert_true(touchmove_received, "touchend follows touchmove");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   132
          assert_false(invalid_touchmove_received, "touchmove dispatched to correct target");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   133
        });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   134
        test_touchend.done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   135
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   136
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   137
          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   138
          for (var i = 0; i < attrs.length; i++) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   139
            assert_true(attrs[i] in ev);
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   140
          }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   141
        }, "touchend TouchEvent modifier key attributes are present.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   142
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   143
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   144
          assert_equals(ev.touches.length, 0, "Zero touch points.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   145
          assert_equals(ev.changedTouches.length, 1, "One changed touch point.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   146
          assert_equals(ev.targetTouches.length, 0, "Zero target touch points.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   147
        }, "touchend TouchList lengths are correct.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   148
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   149
        var t = ev.changedTouches[0];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   150
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   151
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   152
          assert_equals(t.identifier, touchstart_identifier, "changedTouches identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   153
        }, "touchend identifier matches.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   154
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   155
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   156
          assert_true(t.rotationAngle >= 0, "rotationAngle must be >= 0.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   157
          assert_true(t.rotationAngle < 90, "rotationAngle must be > 90.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   158
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   159
          assert_true(t.radiusX > 0, "radiusX is positive.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   160
          assert_true(t.radiusY > 0, "radiusY is positive.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   161
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   162
          assert_true(t.force >= 0, "force >= 0.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   163
          assert_true(t.force <= 1, "force <= 1.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   164
        }, "Touch attribute values are valid");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   165
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   166
        test(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   167
          var attrs = ["screenX", "screenY", "clientX", "clientY",
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   168
                       "pageX", "pageY"];
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   169
          for (var i = 0; i < attrs.length; i++) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   170
            assert_true(attrs[i] in t);
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   171
          }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   172
        }, "Touch location attributes are present.");
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   173
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   174
        done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   175
      });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   176
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   177
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   178
      on_event(target0, "mousedown", function onMouseDown(ev) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   179
        test_mousedown.step(function() {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   180
          assert_true(touchstart_received,
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   181
            "The touchstart event must be dispatched before any mouse " +
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   182
            "events. (If this fails, it might mean that the user agent does " +
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   183
            "not implement W3C touch events at all.)"
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   184
          );
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   185
        });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   186
        test_mousedown.done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   187
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   188
        if (!touchstart_received) {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   189
          // Abort the tests.  If touch events are not supported, then most of
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   190
          // the other event handlers will never be called, and the test will
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   191
          // time out with misleading results.
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   192
          done();
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   193
        }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   194
      });
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   195
    }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   196
  </script>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   197
  <style>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   198
    div {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   199
      margin: 0em;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   200
      padding: 2em;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   201
    }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   202
    #target0 {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   203
      background: yellow;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   204
      border: 1px solid orange;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   205
    }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   206
    #target1 {
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   207
      background: lightblue;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   208
      border: 1px solid blue;
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   209
    }
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   210
  </style>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   211
</head>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   212
<body onload="run()">
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   213
  <h1>Touch Events: single-touch tests</h1>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   214
  <div id="target0">
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   215
    Touch this box with one finger (or other pointing device)...
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   216
  </div>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   217
  <div id="target1">
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   218
    ...then drag to this box and lift your finger.
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   219
  </div>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   220
  <div id="log"></div>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   221
</body>
e0e3783147f0 single-touch tests for Touch Events v2 spec; based on a copy of the v1 tests
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   222
</html>