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