Index: third_party/WebKit/LayoutTests/fast/events/constructors/touch-touchevent-constructor.html |
diff --git a/third_party/WebKit/LayoutTests/fast/events/constructors/touch-touchevent-constructor.html b/third_party/WebKit/LayoutTests/fast/events/constructors/touch-touchevent-constructor.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3b60760d9cd8105f7a2570032aca4eaa631d0b79 |
--- /dev/null |
+++ b/third_party/WebKit/LayoutTests/fast/events/constructors/touch-touchevent-constructor.html |
@@ -0,0 +1,155 @@ |
+<!-- |
+ TODO(chongz): Remove this file and import from w3c tests after approved. |
+ crbug.com/552530 |
+--> |
+<!DOCTYPE HTML> |
+<html> |
+<!-- |
+ Test cases for Touch Events v2 Recommendation |
+ https://w3c.github.io/touch-events/ |
+ |
+ These tests are based on Mozilla-Nokia-Google's single-touch tests. |
+ |
+ The primary purpose of the tests in this document is checking that the createTouch and |
+ createTouchList interfaces of the Touch Events APIs are correctly implemented. |
+ Other interactions are covered in other test files. |
+ |
+ This document references Test Assertions (abbrev TA below) written by Cathy Chan |
+ http://www.w3.org/2010/webevents/wiki/TestAssertions |
+--> |
+ |
+<head> |
+<title>Touch Events Touch and TouchEvent Constructor Tests</title> |
+<meta name="viewport" content="width=device-width"> |
+<script src="../../../resources/testharness.js"></script> |
+<script src="../../../resources/testharnessreport.js"></script> |
+<script src="touch-support.js"></script> |
+<script> |
+setup({ |
+ explicit_done: true |
+}); |
+ |
+function run() { |
+ var target0 = document.getElementById("target0"); |
+ var touch1, touch2; |
+ var touchEvent1; |
+ |
+ var testPageX = 15; |
+ var testPageY = 20.2; |
+ var testScreenX = 35.34; |
+ var testScreenY = 40.56; |
+ var testClientX = 10.175; |
+ var testClientY = 5; |
+ var approxEpsilon = 0.00001; |
+ |
+ test(function() { |
+ touch1 = new Touch({ |
+ identifier: 42, |
+ target: target0, |
+ pageX: testPageX, |
+ pageY: testPageY, |
+ screenX: testScreenX, |
+ screenY: testScreenY, |
+ clientX: testClientX, |
+ clientY: testClientY, |
+ }); |
+ check_Touch_object(touch1); |
+ assert_equals(touch1.target, target0, "touch.target is target0"); |
+ assert_equals(touch1.identifier, 42, "touch.identifier is requested value"); |
+ assert_approx_equals(touch1.pageX, testPageX, approxEpsilon, "touch.pageX is requested value"); |
+ assert_approx_equals(touch1.pageY, testPageY, approxEpsilon, "touch.pageY is requested value"); |
+ assert_approx_equals(touch1.screenX, testScreenX, approxEpsilon, "touch.screenX is requested value"); |
+ assert_approx_equals(touch1.screenY, testScreenY, approxEpsilon, "touch.screenY is requested value"); |
+ // Constructor does not calculate clientX/Y in v2 |
+ assert_approx_equals(touch1.clientX, testClientX, approxEpsilon, "touch.clientX is requested value."); |
+ assert_approx_equals(touch1.clientY, testClientY, approxEpsilon, "touch.clientY is requested value."); |
+ }, "Touch constructor exists and creates a Touch object with requested properties"); |
+ |
+ test(function() { |
+ assert_throws(new TypeError(), function() {touch1 = new Touch();}, "Touch constructor requires initialize dictionary"); |
+ assert_throws(new TypeError(), function() {touch1 = new Touch({});}, "Touch constructor requires identifier and target"); |
+ }, "Create a Touch object with insufficient properties"); |
+ |
+ test(function() { |
+ touch2 = new Touch({ |
+ identifier: 74, |
+ target: target0, |
+ }); |
+ check_Touch_object(touch2); |
+ assert_equals(touch2.target, target0, "touch.target is target0"); |
+ assert_equals(touch2.identifier, 74, "touch.identifier is requested value"); |
+ assert_approx_equals(touch2.pageX, 0, approxEpsilon, "touch.pageX is default value"); |
+ assert_approx_equals(touch2.pageY, 0, approxEpsilon, "touch.pageY is default value"); |
+ assert_approx_equals(touch2.screenX, 0, approxEpsilon, "touch.screenX is default value"); |
+ assert_approx_equals(touch2.screenY, 0, approxEpsilon, "touch.screenY is default value"); |
+ assert_approx_equals(touch2.clientX, 0, approxEpsilon, "touch.clientX is default value."); |
+ assert_approx_equals(touch2.clientY, 0, approxEpsilon, "touch.clientY is default value."); |
+ }, "Touch constructor exists and creates a Touch object with minimum properties"); |
+ |
+ test(function() { |
+ touch1 = new Touch({ |
+ identifier: 45, |
+ target: target0, |
+ pageX: 45, |
+ pageY: 50, |
+ screenX: 65, |
+ screenY: 60, |
+ clientX: 70, |
+ clientY: 75, |
+ }); |
+ touch2 = new Touch({ |
+ identifier: 52, |
+ target: target0, |
+ pageX: 15, |
+ pageY: 20, |
+ screenX: 15, |
+ screenY: 20, |
+ clientX: 15, |
+ clientY: 20, |
+ }); |
+ |
+ touchEvent1 = new TouchEvent("ontouchstart", { |
+ touches: [touch1, touch2], |
+ targetTouches: [touch1], |
+ altKey: true, |
+ metaKey: false, |
+ }); |
+ |
+ check_TouchEvent(touchEvent1); |
+ assert_equals(touchEvent1.type, "ontouchstart", "touchEvent.type is requested value"); |
+ assert_equals(touchEvent1.touches.length, 2, "touchEvent.touches.length is requested value"); |
+ assert_equals(touchEvent1.touches[0], touch1, "touchEvent.touches[0] is requested value"); |
+ assert_equals(touchEvent1.touches[1], touch2, "touchEvent.touches[1] is requested value"); |
+ assert_equals(touchEvent1.targetTouches.length, 1, "touchEvent.targetTouches.length is requested value"); |
+ assert_equals(touchEvent1.targetTouches[0], touch1, "touchEvent.targetTouches[0] is requested value"); |
+ assert_equals(touchEvent1.changedTouches.length, 0, "touchEvent.changedTouches.length is requested value"); |
+ assert_equals(touchEvent1.altKey, true, "touchEvent.altKey is requested value"); |
+ assert_equals(touchEvent1.metaKey, false, "touchEvent.metaKey is requested value"); |
+ assert_equals(touchEvent1.ctrlKey, false, "touchEvent.ctrlKey is requested value"); |
+ assert_equals(touchEvent1.shiftKey, false, "touchEvent.shiftKey is requested value."); |
+ }, "TouchEvent constructor exists and creates a TouchEvent object with requested properties"); |
+ |
+ target0.innerHTML = "Test complete." |
+ done(); |
+} |
+</script> |
+<style> |
+div { |
+ margin: 0em; |
+ padding: 2em; |
+} |
+ |
+#target0 { |
+ background: yellow; |
+ border: 1px solid orange; |
+} |
+</style> |
+</head> |
+ |
+<body onload="run()"> |
+ <h1>Touch Events: Touch and TouchEvent constructor tests</h1> |
+ <div id="target0">Please wait for test to complete...</div> |
+ <div id="log"></div> |
+</body> |
+ |
+</html> |