test/touchevents/single-touch.html
author Matt Brubeck <mbrubeck@mozilla.com>
Tue, 26 Apr 2011 10:09:28 -0700
changeset 50 c030af565635
parent 48 a217ab1b3f14
child 52 a3bdd103c7d9
permissions -rw-r--r--
Add a test for interface names.
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});
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
     9
    var test_click = async_test("Interaction with mouse events");
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    10
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    11
    function run() {
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    12
      var target = document.getElementById("target");
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    13
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    14
      var touchstart_received = false;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    15
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    16
      on_event(target, "touchstart", function onTouchStart(ev) {
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    17
        touchstart_received = true;
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    18
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    19
        test(function() {
43
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    20
          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
    21
          assert_equals(ev.relatedTarget, null, "relatedTarget must be null for touchstart event.");
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    22
        }, "TouchEvent target attributes are correct.");
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    23
fc6abcf8b74c ISSUE-10: Add a relatedTarget attribute to the TouchEvent interface.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 42
diff changeset
    24
        test(function() {
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    25
          var attrs = ["altKey", "metaKey", "ctrlKey", "shiftKey"];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    26
          for (var i = 0; i < attrs.length; i++) {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    27
            assert_true(attrs[i] in ev);
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    28
          }
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    29
        }, "TouchEvent modifier key attributes are present.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    30
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    31
        test(function() {
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    32
          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
    33
          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
    34
          assert_equals(ev.targetTouches.length, 1, "One target touch point.");
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    35
        }, "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
    36
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    37
        var t = ev.touches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    38
        var ct = ev.changedTouches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    39
        var tt = ev.targetTouches[0];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    40
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    41
        test(function() {
50
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    42
          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
    43
          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
    44
          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
    45
        }, "Interface names are correct.");
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    46
c030af565635 Add a test for interface names.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 48
diff changeset
    47
        test(function() {
48
a217ab1b3f14 Use a stricter test for the "identifier" attribute.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 46
diff changeset
    48
          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
    49
          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
    50
          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
    51
        }, "Touch identifiers are correct.");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    52
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    53
        test(function() {
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    54
          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
    55
          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
    56
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    57
          assert_true(t.radiusX > 0, "radiusX is positive.");
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    58
          assert_true(t.radiusY > 0, "radiusY is positive.");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    59
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    60
          assert_true(t.force >= 0, "force >= 0.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    61
          assert_true(t.force <= 1, "force <= 1.");
46
e761aa494278 ISSUE-11: Rename TouchPoint to Touch
Matt Brubeck <mbrubeck@mozilla.com>
parents: 44
diff changeset
    62
        }, "Touch attribute values are valid");
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    63
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    64
        test(function() {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    65
          var attrs = ["screenX", "screenY", "clientX", "clientY",
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    66
                       "pageX", "pageY"];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    67
          for (var i = 0; i < attrs.length; i++) {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    68
            assert_true(attrs[i] in t);
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    69
          }
46
e761aa494278 ISSUE-11: Rename TouchPoint to Touch
Matt Brubeck <mbrubeck@mozilla.com>
parents: 44
diff changeset
    70
        }, "Touch location attributes are present.");
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    71
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    72
        done();
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    73
      });
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    74
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    75
      on_event(target, "click", function onClick(ev) {
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    76
        test_click.step(function() {
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    77
          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
    78
            "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
    79
            "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
    80
            "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
    81
          );
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    82
        });
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    83
        test_click.done();
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    84
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    85
        if (!touchstart_received) {
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    86
          // 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
    87
          // 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
    88
          // 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
    89
          done();
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    90
        }
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    91
      });
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    92
    }
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    93
  </script>
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    94
  <style>
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    95
    #target {
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    96
      background: yellow;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    97
      border: 1px solid orange;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    98
      padding: 2em;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    99
    }
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   100
  </style>
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   101
</head>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   102
<body onload="run()">
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   103
  <h1>Touch area tests</h1>
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   104
  <p id="target">
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
   105
    Tap this element with one finger (or other pointing device).
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   106
  </p>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   107
  <div id="log"></div>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   108
</body>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   109
</html>