tests/touch-events-v1/approved/multi-touch-interfaces.html
changeset 177 19c6f3d0eb8a
parent 167 418583839ba5
equal deleted inserted replaced
167:418583839ba5 177:19c6f3d0eb8a
    20 <meta name="viewport" content="width=device-width">
    20 <meta name="viewport" content="width=device-width">
    21 <script src="/resources/testharness.js"></script>
    21 <script src="/resources/testharness.js"></script>
    22 <script>
    22 <script>
    23     setup({explicit_done: true});
    23     setup({explicit_done: true});
    24 
    24 
    25     var hasIdentifiedTouch = true;
       
    26     
       
    27     // Check a Touch object's atttributes for existence and correct type
    25     // Check a Touch object's atttributes for existence and correct type
    28     // TA: 1.1.2, 1.1.3
    26     // TA: 1.1.2, 1.1.3
    29     function check_Touch_object (t) {
    27     function check_Touch_object (t) {
    30         test(function() {
    28         test(function() {
    31            assert_equals(Object.prototype.toString.call(t), "[object Touch]", "touch is of type Touch");
    29            assert_equals(Object.prototype.toString.call(t), "[object Touch]", "touch is of type Touch");
    72     // TA: 1.2.1, 1.2.2, 1.2.5, 1.2.6
    70     // TA: 1.2.1, 1.2.2, 1.2.5, 1.2.6
    73     function check_TouchList_object (tl) {
    71     function check_TouchList_object (tl) {
    74         test(function() {
    72         test(function() {
    75            assert_equals(Object.prototype.toString.call(tl), "[object TouchList]", "touch list is of type TouchList");
    73            assert_equals(Object.prototype.toString.call(tl), "[object TouchList]", "touch list is of type TouchList");
    76         }, "touch list is a TouchList object");
    74         }, "touch list is a TouchList object");
    77 		if(hasIdentifiedTouch) {
       
    78 			test(function() {
       
    79 				// A common failure mode (eg. WebKit bug 96294), don't report multiple errors for it
       
    80 				hasIdentifiedTouch = 'identifiedTouch' in tl;
       
    81 				assert_true(hasIdentifiedTouch);
       
    82 			}, "TouchList contains an identifiedTouch property");
       
    83 		}
       
    84         [
    75         [
    85           ["unsigned long", "length"],
    76           ["unsigned long", "length"],
    86           ["function", "item"],
    77           ["function", "item"],
    87           ["function", "identifiedTouch"],
       
    88         ].forEach(function(attr) {
    78         ].forEach(function(attr) {
    89             var type = attr[0];
    79             var type = attr[0];
    90             var name = attr[1];
    80             var name = attr[1];
    91 
    81 
    92             if (name == "identifiedTouch" && !hasIdentifiedTouch)
       
    93               return;
       
    94               
       
    95             // existence check
    82             // existence check
    96             test(function() {
    83             test(function() {
    97                 assert_true(name in tl, name + " attribute in TouchList");
    84                 assert_true(name in tl, name + " attribute in TouchList");
    98             }, "TouchList." + name + " attribute exists");
    85             }, "TouchList." + name + " attribute exists");
    99 
    86 
   104                     assert_equals(typeof tl[name], "number", name + " attribute of type long");
    91                     assert_equals(typeof tl[name], "number", name + " attribute of type long");
   105                 }, "TouchList." + name + " attribute is of type number (unsigned long)");
    92                 }, "TouchList." + name + " attribute is of type number (unsigned long)");
   106                 break;
    93                 break;
   107             case "function":
    94             case "function":
   108                 test(function() {
    95                 test(function() {
   109                     assert_equals(typeof tl[name], "function", name + " attribute of type long");
    96                     assert_equals(typeof tl[name], "function", name + " attribute of type function");
   110                 }, "TouchList." + name + " attribute is of type function");
    97                 }, "TouchList." + name + " attribute is of type function");
   111                 break;
    98                 break;
   112             default:
    99             default:
   113                 break;
   100                 break;
   114             }
   101             }
   115        }); 
   102        }); 
   116        // Each member of tl should be a proper Touch object
   103        // Each member of tl should be a proper Touch object
   117        for (var i=0; i < tl.length; i++) {
   104        for (var i=0; i < tl.length; i++) {
   118            check_Touch_object(tl.item(i));
   105            check_Touch_object(tl.item(i));
   119        }
   106        }
   120        // identifiedTouch should return the member Touch object with the specified identifier
       
   121 	   test(function() {
       
   122 		   if (hasIdentifiedTouch) {
       
   123 			  for (var i=0; i < tl.length; i++) {
       
   124 				  assert_equals(tl.item(i), tl.identifiedTouch(tl.item(i).identifier), "TouchList.identifiedTouch returns the correct item");
       
   125 			   }
       
   126 		   }
       
   127 		}, "TouchList.identifiedTouch returns the correct item");
       
   128     }
   107     }
   129 
   108 
   130     // Check a TouchEvent event's attributes for existence and proper type
   109     // Check a TouchEvent event's attributes for existence and proper type
   131     // Also check that each of the event's TouchList objects are valid
   110     // Also check that each of the event's TouchList objects are valid
   132     // TA: 1.{3,4,5}.1.1, 1.{3,4,5}.1.2
   111     // TA: 1.{3,4,5}.1.1, 1.{3,4,5}.1.2