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