tests/touch-events-v1/approved/multi-touch-interfaces.html
author Art Barstow <art.barstow@nokia.com>
Sat, 08 Dec 2012 17:02:45 -0500
changeset 165 5a5df40e3cbf
child 167 418583839ba5
permissions -rw-r--r--
Approved test files copied to approved directory
165
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     1
<!DOCTYPE HTML>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     2
<html>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     3
<!-- 
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     4
     Test cases for Touch Events v1 Candiate Recommendation
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     5
     http://www.w3.org/TR/2011/CR-touch-events-20111215/
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     6
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     7
     These tests are based on Mozilla-Nokia-Google's single-touch tests and to some extent Olli Pettay's multi-touch tests. 
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     8
	 http://w3c-test.org/webevents/tests/touch-events-v1/submissions/Moz-Nok-Goog/single-touch.html
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
     9
     http://w3c-test.org/webevents/tests/touch-events-v1/submissions/Mozilla/multi-touch.html
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    10
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    11
	 The primary purpose of the tests in this document is checking that the various interfaces of the Touch Events APIs are correctly implemented.
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    12
	 Other interactions are covered in other test files.
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    13
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    14
     This document references Test Assertions (abbrev TA below) written by Cathy Chan
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    15
     http://www.w3.org/2010/webevents/wiki/TestAssertions
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    16
-->
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    17
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    18
<head>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    19
<title>Touch Events Multi-Touch Interface Tests</title>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    20
<meta name="viewport" content="width=device-width">
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    21
<script src="../../../testharness.js"></script>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    22
<script>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    23
    setup({explicit_done: true});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    24
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    25
    var hasIdentifiedTouch = true;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    26
    
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    27
    // Check a Touch object's atttributes for existence and correct type
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    28
    // TA: 1.1.2, 1.1.3
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    29
    function check_Touch_object (t) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    30
        test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    31
           assert_equals(Object.prototype.toString.call(t), "[object Touch]", "touch is of type Touch");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    32
        }, "touch point is a Touch object");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    33
        [
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    34
          ["long", "identifier"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    35
          ["EventTarget", "target"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    36
          ["long", "screenX"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    37
          ["long", "screenY"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    38
          ["long", "clientX"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    39
          ["long", "clientY"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    40
          ["long", "pageX"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    41
          ["long", "pageY"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    42
        ].forEach(function(attr) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    43
            var type = attr[0];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    44
            var name = attr[1];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    45
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    46
            // existence check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    47
            test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    48
                assert_true(name in t, name + " attribute in Touch object");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    49
            }, "Touch." + name + " attribute exists");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    50
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    51
            // type check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    52
            switch(type) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    53
            case "long":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    54
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    55
                    assert_equals(typeof t[name], "number", name + " attribute of type long");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    56
                }, "Touch." + name + " attribute is of type number (long)");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    57
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    58
            case "EventTarget":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    59
                // An event target is some type of Element
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    60
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    61
                    assert_true(t[name] instanceof Element, "EventTarget must be an Element.");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    62
                }, "Touch." + name + " attribute is of type Element");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    63
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    64
            default:
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    65
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    66
            }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    67
       }); 
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    68
    }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    69
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    70
    // Check a TouchList object's attributes and methods for existence and proper type
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    71
    // Also make sure all of the members of the list are Touch objects
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    72
    // TA: 1.2.1, 1.2.2, 1.2.5, 1.2.6
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    73
    function check_TouchList_object (tl) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    74
        test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    75
           assert_equals(Object.prototype.toString.call(tl), "[object TouchList]", "touch list is of type TouchList");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    76
        }, "touch list is a TouchList object");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    77
		if(hasIdentifiedTouch) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    78
			test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    79
				// A common failure mode (eg. WebKit bug 96294), don't report multiple errors for it
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    80
				hasIdentifiedTouch = 'identifiedTouch' in tl;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    81
				assert_true(hasIdentifiedTouch);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    82
			}, "TouchList contains an identifiedTouch property");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    83
		}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    84
        [
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    85
          ["unsigned long", "length"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    86
          ["function", "item"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    87
          ["function", "identifiedTouch"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    88
        ].forEach(function(attr) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    89
            var type = attr[0];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    90
            var name = attr[1];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    91
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    92
            if (name == "identifiedTouch" && !hasIdentifiedTouch)
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    93
              return;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    94
              
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    95
            // existence check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    96
            test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    97
                assert_true(name in tl, name + " attribute in TouchList");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    98
            }, "TouchList." + name + " attribute exists");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
    99
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   100
            // type check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   101
            switch(type) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   102
            case "unsigned long":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   103
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   104
                    assert_equals(typeof tl[name], "number", name + " attribute of type long");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   105
                }, "TouchList." + name + " attribute is of type number (unsigned long)");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   106
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   107
            case "function":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   108
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   109
                    assert_equals(typeof tl[name], "function", name + " attribute of type long");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   110
                }, "TouchList." + name + " attribute is of type function");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   111
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   112
            default:
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   113
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   114
            }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   115
       }); 
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   116
       // Each member of tl should be a proper Touch object
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   117
       for (var i=0; i < tl.length; i++) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   118
           check_Touch_object(tl.item(i));
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   119
       }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   120
       // identifiedTouch should return the member Touch object with the specified identifier
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   121
	   test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   122
		   if (hasIdentifiedTouch) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   123
			  for (var i=0; i < tl.length; i++) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   124
				  assert_equals(tl.item(i), tl.identifiedTouch(tl.item(i).identifier), "TouchList.identifiedTouch returns the correct item");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   125
			   }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   126
		   }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   127
		}, "TouchList.identifiedTouch returns the correct item");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   128
    }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   129
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   130
    // Check a TouchEvent event's attributes for existence and proper type
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   131
    // Also check that each of the event's TouchList objects are valid
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   132
    // TA: 1.{3,4,5}.1.1, 1.{3,4,5}.1.2
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   133
    function check_TouchEvent(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   134
        test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   135
           assert_true(ev instanceof TouchEvent, "event is a TouchEvent event");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   136
        }, ev.type + " event is a TouchEvent event");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   137
        [
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   138
          ["TouchList", "touches"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   139
          ["TouchList", "targetTouches"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   140
          ["TouchList", "changedTouches"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   141
          ["boolean", "altKey"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   142
          ["boolean", "metaKey"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   143
          ["boolean", "ctrlKey"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   144
          ["boolean", "shiftKey"],
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   145
        ].forEach(function(attr) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   146
            var type = attr[0];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   147
            var name = attr[1];
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   148
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   149
            // existence check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   150
            test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   151
                assert_true(name in ev, name + " attribute in " + ev.type + " event");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   152
            }, ev.type + "." + name + " attribute exists");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   153
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   154
            // type check
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   155
            switch(type) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   156
            case "boolean":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   157
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   158
                    assert_equals(typeof ev[name], "boolean", name + " attribute of type boolean");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   159
                }, ev.type + "." + name + " attribute is of type boolean");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   160
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   161
            case "TouchList":
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   162
                test(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   163
                    assert_equals(Object.prototype.toString.call(ev[name]), "[object TouchList]", name + " attribute of type TouchList");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   164
                }, ev.type + "." + name + " attribute is of type TouchList");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   165
                // Now check the validity of the TouchList
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   166
                check_TouchList_object(ev[name]);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   167
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   168
            default:
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   169
                break;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   170
            }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   171
       }); 
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   172
    }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   173
    
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   174
    function is_touch_over_element(touch, element) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   175
      var bounds = element.getBoundingClientRect();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   176
      return touch.pageX >= bounds.left && touch.pageX <= bounds.right &&
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   177
          touch.pageY >= bounds.top && touch.pageY <= bounds.bottom;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   178
    }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   179
    
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   180
    function check_touch_clientXY(touch) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   181
      assert_equals(touch.clientX, touch.pageX - window.pageXOffset, "touch.clientX is touch.pageX - window.pageXOffset.");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   182
      assert_equals(touch.clientY, touch.pageY - window.pageYOffset, "touch.clientY is touch.pageY - window.pageYOffset.");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   183
    }
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   184
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   185
    function run() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   186
		var target0 = document.getElementById("target0");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   187
		var target1 = document.getElementById("target1");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   188
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   189
		var test_touchstart = async_test("touchstart event received");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   190
		var test_touchmove = async_test("touchmove event received");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   191
		var test_touchend = async_test("touchend event received");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   192
		var test_mousedown = async_test("Interaction with mouse events");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   193
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   194
		var touchstart_received = 0;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   195
		var touchmove_received = false;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   196
		var touchend_received = false;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   197
		var invalid_touchmove_received = false;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   198
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   199
		on_event(target0, "touchstart", function onTouchStart(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   200
			ev.preventDefault();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   201
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   202
			if(!touchstart_received) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   203
				// Check event ordering TA: 1.6.2
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   204
				test_touchstart.step(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   205
					assert_false(touchmove_received, "touchstart precedes touchmove");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   206
					assert_false(touchend_received, "touchstart precedes touchend");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   207
				});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   208
				test_touchstart.done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   209
				test_mousedown.done(); // If we got here, then the mouse event test is not needed.
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   210
			}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   211
			
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   212
			if(++touchstart_received <= 2)
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   213
				check_TouchEvent(ev);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   214
		});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   215
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   216
		on_event(target0, "touchmove", function onTouchMove(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   217
			ev.preventDefault();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   218
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   219
			if (touchmove_received)
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   220
			  return;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   221
			touchmove_received = true;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   222
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   223
			test_touchmove.step(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   224
				assert_true(touchstart_received>0, "touchmove follows touchstart");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   225
				assert_false(touchend_received, "touchmove precedes touchend");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   226
			});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   227
			test_touchmove.done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   228
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   229
			check_TouchEvent(ev);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   230
		});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   231
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   232
		on_event(target1, "touchmove", function onTouchMove(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   233
			invalid_touchmove_received = true;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   234
		});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   235
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   236
		on_event(window, "touchend", function onTouchEnd(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   237
			touchend_received = true;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   238
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   239
			test_touchend.step(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   240
				assert_true(touchstart_received>0, "touchend follows touchstart");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   241
				assert_true(touchmove_received, "touchend follows touchmove");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   242
				assert_false(invalid_touchmove_received, "touchmove dispatched to correct target");
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   243
			});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   244
			test_touchend.done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   245
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   246
			check_TouchEvent(ev);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   247
			done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   248
		});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   249
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   250
		on_event(target0, "mousedown", function onMouseDown(ev) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   251
			test_mousedown.step(function() {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   252
				assert_true(touchstart_received,
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   253
					"The touchstart event must be dispatched before any mouse " +
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   254
					"events. (If this fails, it might mean that the user agent does " +
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   255
					"not implement W3C touch events at all.)"
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   256
				);
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   257
			});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   258
			test_mousedown.done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   259
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   260
			if (!touchstart_received) {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   261
				// Abort the tests.  If touch events are not supported, then most of
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   262
				// the other event handlers will never be called, and the test will
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   263
				// time out with misleading results.
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   264
				done();
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   265
			}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   266
		});
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   267
	}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   268
</script>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   269
<style>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   270
	div {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   271
		margin: 0em;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   272
		padding: 2em;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   273
	}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   274
	#target0 {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   275
		background: yellow;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   276
		border: 1px solid orange;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   277
	}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   278
	#target1 {
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   279
		background: lightblue;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   280
		border: 1px solid blue;
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   281
	}
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   282
</style>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   283
</head>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   284
<body onload="run()">
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   285
	<h1>Touch Events: multi-touch interface tests</h1>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   286
	<div id="target0">
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   287
		Touch this box with one finger, then another one...
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   288
	</div>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   289
	<div id="target1">
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   290
		...then drag to this box and lift your fingers.
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   291
	</div>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   292
	<div id="log"></div>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   293
</body>
5a5df40e3cbf Approved test files copied to approved directory
Art Barstow <art.barstow@nokia.com>
parents:
diff changeset
   294
</html>