Skip to content

Commit

Permalink
Merge pull request #107 from scottgonzalez/submissions/jquery
Browse files Browse the repository at this point in the history
Pointer Events: Ported jQuery submission from mercurial.
  • Loading branch information
cynthia committed Jun 28, 2013
2 parents f93af80 + 65fd40b commit cb5dd9c
Showing 1 changed file with 179 additions and 0 deletions.
179 changes: 179 additions & 0 deletions pointerevents/pointerdown.html
@@ -0,0 +1,179 @@
<!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.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.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_true(event.isPrimary,
event.type + ".isPrimary is true for mouse");
}, event.type + " properties for pointerType=mouse");
}
}

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>

0 comments on commit cb5dd9c

Please sign in to comment.