test/touchevents/single-touch.html
author Matt Brubeck <mbrubeck@mozilla.com>
Thu, 11 Aug 2011 15:27:48 -0700
branchv1
changeset 101 2d830a098494
parent 91 b2c4ba0eb943
permissions -rw-r--r--
Initial checkin for Touch Events version 1

This version is limited to those parts of the specification that already have
interoperable implementations. The following events and attributes will not
be included in v1, but will appear in Touch Events v2:

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