tests/touch-events-v1/single-touch.html
author Art Barstow <art.barstow@nokia.com>
Tue, 17 Jan 2012 09:54:25 -0500
changeset 149 068cf38fa150
parent 148 tests/touchevents/single-touch.html@22c2e3d43b31
permissions -rw-r--r--
rename touchevents directory to touch-events-vi
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.");
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    38
          assert_equals(ev.relatedTarget, null, "relatedTarget must be null for touchstart event.");
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
    39
        }, "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
    40
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    41
        test(function() {
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    42
          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    43
          for (var i = 0; i < attrs.length; i++) {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    44
            assert_true(attrs[i] in ev);
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    45
          }
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
    46
        }, "touchstart TouchEvent modifier key attributes are present.");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    47
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    48
        test(function() {
41
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.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
    50
          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
    51
          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
    52
        }, "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
    53
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    54
        var t = ev.touches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    55
        var ct = ev.changedTouches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    56
        var tt = ev.targetTouches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    57
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    58
        test(function() {
50
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    59
          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
    60
          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
    61
          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
    62
        }, "Interface names are correct.");
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    63
91
b2c4ba0eb943 ISSUE-15: identifier attribute should be an opaque token
Matt Brubeck <mbrubeck@mozilla.com>
parents: 88
diff changeset
    64
        touchstart_identifier = t.identifier;
50
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    65
        test(function() {
91
b2c4ba0eb943 ISSUE-15: identifier attribute should be an opaque token
Matt Brubeck <mbrubeck@mozilla.com>
parents: 88
diff changeset
    66
          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
    67
          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
    68
        }, "Touch identifiers are consistent.");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    69
56
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
    70
        test(function() {
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
    71
          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
    72
        }, "identifiedTouch");
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
    73
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    74
        test(function() {
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    75
          assert_true(t.rotationAngle >= 0, "rotationAngle must be >= 0.");
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    76
          assert_true(t.rotationAngle < 90, "rotationAngle must be > 90.");
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    77
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    78
          assert_true(t.radiusX > 0, "radiusX is positive.");
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    79
          assert_true(t.radiusY > 0, "radiusY is positive.");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    80
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    81
          assert_true(t.force >= 0, "force >= 0.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    82
          assert_true(t.force <= 1, "force <= 1.");
46
e761aa494278 ISSUE-11: Rename TouchPoint to Touch
Matt Brubeck <mbrubeck@mozilla.com>
parents: 44
diff changeset
    83
        }, "Touch attribute values are valid");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    84
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    85
        test(function() {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    86
          var attrs = ["screenX", "screenY", "clientX", "clientY",
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    87
                       "pageX", "pageY"];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    88
          for (var i = 0; i < attrs.length; i++) {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    89
            assert_true(attrs[i] in t);
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    90
          }
46
e761aa494278 ISSUE-11: Rename TouchPoint to Touch
Matt Brubeck <mbrubeck@mozilla.com>
parents: 44
diff changeset
    91
        }, "Touch location attributes are present.");
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    92
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
    93
      });
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
    94
55
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
    95
      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
    96
        ev.preventDefault();
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
    97
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
    98
        if (touchmove_received)
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
    99
          return;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   100
        touchmove_received = true;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   101
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   102
        test_touchmove.step(function() {
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   103
          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
   104
          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
   105
        });
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   106
        test_touchmove.done();
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
        test(function() {
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   109
          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
   110
          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
   111
          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
   112
        }, "touchmove TouchList lengths are correct.");
56
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
   113
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
   114
        test(function() {
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
   115
          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
   116
          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
   117
          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
   118
        }, "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
   119
      });
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   120
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   121
      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
   122
        invalid_touchmove_received = true;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   123
      });
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   124
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   125
      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
   126
        touchend_received = true;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   127
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   128
        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
   129
          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
   130
          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
   131
          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
   132
          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
   133
        });
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   134
        test_touchend.done();
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   135
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   136
        test(function() {
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   137
          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   138
          for (var i = 0; i < attrs.length; i++) {
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   139
            assert_true(attrs[i] in ev);
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   140
          }
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   141
        }, "touchend TouchEvent modifier key attributes are present.");
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
          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
   145
          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
   146
          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
   147
        }, "touchend TouchList lengths are correct.");
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
        var t = ev.changedTouches[0];
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   150
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   151
        test(function() {
56
6343517cbbee Add more tests for identifier and identifiedTouch.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 55
diff changeset
   152
          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
   153
        }, "touchend identifier matches.");
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   154
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   155
        test(function() {
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   156
          assert_true(t.rotationAngle >= 0, "rotationAngle must be >= 0.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   157
          assert_true(t.rotationAngle < 90, "rotationAngle must be > 90.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   158
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   159
          assert_true(t.radiusX > 0, "radiusX is positive.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   160
          assert_true(t.radiusY > 0, "radiusY is positive.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   161
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   162
          assert_true(t.force >= 0, "force >= 0.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   163
          assert_true(t.force <= 1, "force <= 1.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   164
        }, "Touch attribute values are valid");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   165
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   166
        test(function() {
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   167
          var attrs = ["screenX", "screenY", "clientX", "clientY",
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   168
                       "pageX", "pageY"];
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   169
          for (var i = 0; i < attrs.length; i++) {
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   170
            assert_true(attrs[i] in t);
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   171
          }
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   172
        }, "Touch location attributes are present.");
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   173
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   174
        done();
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   175
      });
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   176
52
a3bdd103c7d9 Add tests for the touchend event
Matt Brubeck <mbrubeck@mozilla.com>
parents: 50
diff changeset
   177
55
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   178
      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
   179
        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
   180
          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
   181
            "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
   182
            "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
   183
            "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
   184
          );
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   185
        });
55
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   186
        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
   187
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
   188
        if (!touchstart_received) {
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
   189
          // 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
   190
          // 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
   191
          // 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
   192
          done();
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
   193
        }
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   194
      });
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   195
    }
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   196
  </script>
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   197
  <style>
55
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   198
    div {
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   199
      margin: 0em;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   200
      padding: 2em;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   201
    }
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   202
    #target0 {
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   203
      background: yellow;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   204
      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
   205
    }
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   206
    #target1 {
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   207
      background: lightblue;
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   208
      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
   209
    }
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   210
  </style>
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   211
</head>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   212
<body onload="run()">
88
dcdef856c426 Update heading in test file.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 56
diff changeset
   213
  <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
   214
  <div id="target0">
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   215
    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
   216
  </div>
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   217
  <div id="target1">
7df98116715b Clarify targeting of touchmove and touchend events, and add tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 52
diff changeset
   218
    ...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
   219
  </div>
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   220
  <div id="log"></div>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   221
</body>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   222
</html>