Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pointer Events: Ported jQuery submission from mercurial. #107

Merged
merged 2 commits into from Jun 28, 2013
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Pointer Events: Ported jQuery submission from mercurial.

  • Loading branch information...
scottgonzalez committed May 7, 2013
commit bbe2f503235719d56d48d4b3e747553cd2c35de8
@@ -0,0 +1,188 @@
<!doctype html>
<html>
<!--
Test cases for Pointer Events v1 spec
This document references Test Assertions (abbrev TA below) written by Cathy Chan
http://www.w3.org/wiki/PointerEvents/TestAssertions
-->
<head>
<title>Pointer Events pointerdown Tests</title>
<meta name="viewport" content="width=device-width">
<script src="http://w3c-test.org/resources/testharness.js"></script>
<script>
setup({ explicit_done: true });
var detected_pointertypes = {};
add_completion_callback(showPointerTypes);
// Check for conformance to PointerEvent interface
// TA: 1.1, 1.2, 1.6, 1.7, 1.8, 1.9, 1.10, 1.11, 1.12, 1.13
function check_PointerEvent(event) {
test(function() {
assert_true(event instanceof PointerEvent,
"event is a PointerEvent event");
}, event.type + " event is a PointerEvent event");
// Check attributes for conformance to WebIDL:
// * attribute exists
// * has proper type
// * if the attribute is "readonly", it cannot be changed
// TA: 1.1, 1.2
[
["readonly", "long", "pointerId"],
["readonly", "long", "width"],
["readonly", "long", "height"],
["readonly", "float", "pressure"],
["readonly", "long", "tiltX"],
["readonly", "long", "tiltY"],
["readonly", "DOMString", "pointerType"],
["readonly", "boolean", "isPrimary"]
].forEach(function(attr) {
var readonly = attr[0];
var type = attr[1];
var name = attr[2];
// existence check
test(function() {
assert_true(name in event,
name + " attribute in " + event.type + " event");
}, event.type + "." + name + " attribute exists");
// readonly check
if (readonly === "readonly") {
test(function() {
assert_readonly(event.type, name,
event.type + "." + name + " cannot be changed");
}, event.type + "." + name + " is readonly");
}
// type check
if ( type === "float" || type === "long" ) {
test(function() {
assert_equals(typeof event[name], "number",
name + " attribute of type " + type);
}, event.type + "." + name + " attribute is of type number (" + type + ")");
} else {
test(function() {
assert_equals(typeof event[name], type,
name + " attribute of type " + type);
}, event.type + "." + name + " attribute is of type " + type);
}
});
// Check the pressure value
// TA: 1.6, 1.7, 1.8
test(function() {
// TA: 1.6
assert_greater_than_equal(event.pressure, 0,
"pressure is greater than or equal to 0");
assert_less_than_equal(event.pressure, 1,
"pressure is less than or equal to 1");
// TA: 1.7, 1.8
if ( event.pointerType === "mouse" ) {
if ( event.buttons === 0 ) {
assert_equals( event.pressure, 0,
"pressure is 0 for mouse with no buttons pressed");
} else {
assert_equals( event.pressure, 0.5,
"pressure is 0.5 for mouse with a button pressed");
}
}
}, event.type + ".pressure value is valid" );
// Check mouse-specific properties
if ( event.pointerType === "mouse" ) {
// TA: 1.9, 1.10, 1.11, 1.13
test(function() {
assert_equals(event.tiltX, 0,
event.type + ".tiltX is 0 for mouse");
assert_equals(event.tiltY, 0,
event.type + ".tiltY is 0 for mouse");
assert_equals(event.pointerId, 1,
event.type + ".pointerId is 1 for mouse");
assert_true(event.isPrimary,
event.type + ".isPrimary is true for mouse");
}, event.type + " properties for pointerType=mouse");
// Check properties for pointers other than mouse
} else {
// TA: 1.12
test(function() {
assert_true(event.pointerId !== 1,
event.type + ".pointerId is not 1 for " + event.pointerType);
}, event.type + " properties for pointerType=" + event.pointerType);
}
}
function run() {
var target0 = document.getElementById("target0");
var test_pointerdown = async_test("pointerdown event received");
var pointerover_event;
on_event(target0, "pointerover", function(event) {
pointerover_event = event;
check_PointerEvent(event);
detected_pointertypes[ event.pointerType ] = true;
});
// TA: 2.1, 2.2, 2.3
on_event(target0, "pointerdown", function(event) {
check_PointerEvent(event);
// TA: 2.4
test_pointerdown.step(function() {
assert_equals(event.pointerType, pointerover_event.pointerType,
"pointerType is same for pointerover and pointerdown");
assert_equals(event.isPrimary, pointerover_event.isPrimary,
"isPrimary is same for pointerover and pointerdown");
});
detected_pointertypes[ event.pointerType ] = true;
test_pointerdown.done();
});
}
function showPointerTypes() {
var complete_notice = document.getElementById("complete-notice");
var pointertype_log = document.getElementById("pointertype-log");
var pointertypes = Object.keys(detected_pointertypes);
pointertype_log.innerHTML = pointertypes.length ?
pointertypes.join(",") : "(none)";
complete_notice.style.display = "block";
}
</script>
<style>
div {
margin: 0em;
padding: 2em;
}
#target0 {
background: yellow;
border: 1px solid orange;
}
#complete-notice {
background: #afa;
border: 1px solid #0a0;
display: none;
}
#pointertype-log {
font-weight: bold;
}
</style>
</head>
<body onload="run()">
<h1>Pointer Events pointerdown Tests</h1>
<div id="target0">
Start with your pointing device outside of this box, then click here.
</div>
<div id="complete-notice">
<p>The following pointer types were detected: <span id="pointertype-log"></span>.</p>
<p>Would you like to <a href="#">run the tests again</a> with a different pointer type?</p>
</div>
<div id="log"></div>
</body>
</html>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.