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