test/touchevents/single-touch.html
author Matt Brubeck <mbrubeck@mozilla.com>
Sun, 24 Apr 2011 21:58:39 -0700
changeset 44 ad7715ddbcda
parent 43 fc6abcf8b74c
child 46 e761aa494278
permissions -rw-r--r--
Add more conformance 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>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
     4
  <title>Touch Events: Touch area tests</title>
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() {
44
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    42
          assert_equals(t.identifier, ct.identifier, "touches and changedTouches match.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    43
          assert_equals(t.identifier, tt.identifier, "touches and targetTouches match.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    44
        }, "TouchLists contain the same TouchPoint.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    45
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    46
        test(function() {
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    47
          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
    48
          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
    49
42
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    50
          assert_true(t.radiusX > 0, "radiusX is positive.");
49296bde5e04 radiusX and radiusY must be positive.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 41
diff changeset
    51
          assert_true(t.radiusY > 0, "radiusY is positive.");
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
          assert_true(t.force >= 0, "force >= 0.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    54
          assert_true(t.force <= 1, "force <= 1.");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    55
        }, "TouchPoint attribute values are valid");
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    56
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    57
        test(function() {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    58
          var attrs = ["screenX", "screenY", "clientX", "clientY",
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    59
                       "pageX", "pageY"];
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    60
          for (var i = 0; i < attrs.length; i++) {
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    61
            assert_true(attrs[i] in t);
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    62
          }
ad7715ddbcda Add more conformance tests.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 43
diff changeset
    63
        }, "TouchPoint location attributes are present.");
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    64
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    65
        done();
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    66
      });
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    67
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    68
      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
    69
        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
    70
          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
    71
            "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
    72
            "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
    73
            "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
    74
          );
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    75
        });
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.done();
41
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    77
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    78
        if (!touchstart_received) {
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    79
          // 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
    80
          // 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
    81
          // 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
    82
          done();
d4970c8cc39c Expand the touch-area test into a general single-touch test.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 40
diff changeset
    83
        }
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    84
      });
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    85
    }
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    86
  </script>
40
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    87
  <style>
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    88
    #target {
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    89
      background: yellow;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    90
      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
    91
      padding: 2em;
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    92
    }
8b932f6d4ec8 Abort the test if a click is received without any touchstart event.
Matt Brubeck <mbrubeck@mozilla.com>
parents: 33
diff changeset
    93
  </style>
26
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    94
</head>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    95
<body onload="run()">
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
    96
  <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
    97
  <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
    98
    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
    99
  </p>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   100
  <div id="log"></div>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   101
</body>
9b69cee6dfb8 Add a test harness and a simple conformance test.
Matt Brubeck <mbrubeck@mozilla.com>
parents:
diff changeset
   102
</html>