194 lines
5.8 KiB
HTML
194 lines
5.8 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|
|
"http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
|
|
<title>Test Dijit Internal Event: "ondijitclick"</title>
|
|
|
|
<script type="text/javascript" src="../../../dojo/dojo.js" djConfig="isDebug: true"></script>
|
|
<script type="text/javascript">
|
|
dojo.require("dijit.robotx");
|
|
|
|
dojo.ready(function(){
|
|
doh.robot.initRobot('../_Widget-ondijitclick.html');
|
|
|
|
// Event monitoring
|
|
var widgetClicks = 0, buttonClicks = 0, button2Clicks = 0, thirdClicks = 0;
|
|
var w;
|
|
|
|
doh.register("setup", function(){
|
|
doh.robot.sequence(function(){
|
|
w = dijit.byId("first");
|
|
dojo.connect(w, "_onClick", function(){
|
|
widgetClicks++;
|
|
});
|
|
dojo.connect(dojo.byId("plainbutton"), "onclick", function(){
|
|
buttonClicks++;
|
|
});
|
|
dojo.connect(dojo.byId("plainbutton2"), "onclick", function(){
|
|
button2Clicks++;
|
|
});
|
|
dojo.connect(dojo.byId("third"), "onclick", function(){
|
|
thirdClicks++;
|
|
});
|
|
});
|
|
});
|
|
|
|
// Test ondijitclick on a <div> which refocuses onto a native <button> node.
|
|
// Make sure that the <button> doesn't get a spurious click event.
|
|
dojo.forEach(["SPACE", "ENTER"], function(key){
|
|
|
|
doh.register("ondijitclick by " + key, [
|
|
{
|
|
name: "ondijitclick by " + key,
|
|
timeout: 5000,
|
|
runTest: function(){
|
|
widgetClicks = buttonClicks = 0;
|
|
var d = new doh.Deferred();
|
|
|
|
// Keyboard-click the widget
|
|
doh.robot.sequence(function(){
|
|
w.domNode.focus();
|
|
}, 500);
|
|
doh.robot.keyDown(dojo.keys[key], 250, {});
|
|
doh.robot.keyUp(dojo.keys[key], 250, {});
|
|
|
|
// Check that ondijitclick fired but no spurious event
|
|
// on the widget that got focused in the ondijitclick handler
|
|
doh.robot.sequence(d.getTestCallback(function(){
|
|
doh.is(1, widgetClicks, "ondijitclick handler fired");
|
|
doh.is(0, buttonClicks, "spurious button click event");
|
|
}), 500);
|
|
|
|
return d;
|
|
}
|
|
},
|
|
{
|
|
name: "ondijitclick by " + key + " w/modifier",
|
|
timeout: 5000,
|
|
runTest: function(){
|
|
widgetClicks = buttonClicks = 0;
|
|
var d = new doh.Deferred();
|
|
|
|
doh.robot.sequence(function(){
|
|
w.domNode.focus();
|
|
}, 500);
|
|
|
|
// Try shift-space/shift-enter just to make sure it doesn't do anything.
|
|
// Don't try ctrl-space or meta-space since those keystrokes have special functions
|
|
// (like context menu) in various browsers
|
|
doh.robot.keyPress(dojo.keys[key], 100, {shift: true});
|
|
|
|
// Check that ondijitclick didn't fire
|
|
doh.robot.sequence(d.getTestCallback(function(){
|
|
doh.is(0, widgetClicks, "ondijitclick handler wasn't fired");
|
|
doh.is(0, buttonClicks, "button click handler wasn't fired");
|
|
}), 500);
|
|
|
|
return d;
|
|
}
|
|
}
|
|
]);
|
|
});
|
|
|
|
// Test ondijitclick on a <div> which refocuses onto a native <textarea> node.
|
|
// Tests that the keyboard event gets supressed so it doesn't modify the focused node.
|
|
dojo.forEach(["SPACE","ENTER"], function(key){
|
|
|
|
doh.register("focus to textarea by " + key, [
|
|
{
|
|
name: "ondijitclick by " + key,
|
|
timeout: 5000,
|
|
runTest: function(){
|
|
var d = new doh.Deferred(),
|
|
w = dijit.byId("second");
|
|
|
|
// Keyboard-click the widget
|
|
doh.robot.sequence(function(){
|
|
w.domNode.focus();
|
|
}, 500);
|
|
doh.robot.keyPress(dojo.keys[key], 500, {});
|
|
|
|
// Check that ondijitclick fired but that focused textarea didn't get the key
|
|
doh.robot.sequence(d.getTestCallback(function(){
|
|
doh.is("hello world", dojo.byId("textarea").value);
|
|
}), 500);
|
|
|
|
return d;
|
|
}
|
|
}
|
|
]);
|
|
});
|
|
|
|
// Test onclick on a <button> which refocuses onto a <div> w/an ondijitclick handler.
|
|
// Make sure that the <div> doesn't get a spurious click event.
|
|
dojo.forEach(["SPACE", "ENTER" ], function(key){
|
|
|
|
doh.register("focus to ondijitclick-div by " + key, [
|
|
{
|
|
name: "click by " + key,
|
|
timeout: 5000,
|
|
runTest: function(){
|
|
button2Clicks = thirdClicks = 0;
|
|
|
|
var d = new doh.Deferred(),
|
|
button = dojo.byId("plainbutton2");
|
|
|
|
// Keyboard-click the native button
|
|
doh.robot.sequence(function(){
|
|
button.focus();
|
|
}, 500);
|
|
doh.robot.keyPress(dojo.keys[key], 500, {});
|
|
|
|
// Check that ondijitclick didn't fire
|
|
doh.robot.sequence(d.getTestCallback(function(){
|
|
doh.is(1, button2Clicks, "button2 was clicked (and focus moved to ondijitclick-div)");
|
|
doh.is(0, thirdClicks, "ondijitclick-div didn't get a spurious click event");
|
|
}), 500);
|
|
|
|
return d;
|
|
}
|
|
}
|
|
]);
|
|
});
|
|
|
|
// Test clicking on a <button> with an ondijitclick handler.
|
|
// The main danger is getting two click events because the browser natively handles space-->click
|
|
dojo.forEach(["SPACE", "ENTER" ], function(key){
|
|
|
|
doh.register("click ondijitclick button by " + key, [
|
|
{
|
|
name: "click by " + key,
|
|
timeout: 5000,
|
|
runTest: function(){
|
|
|
|
var d = new doh.Deferred(),
|
|
buttonWidget = dijit.byId("widgetbutton"),
|
|
buttonNode = dojo.byId("widgetbutton");
|
|
|
|
buttonWidget.clickCount = 0;
|
|
|
|
// Keyboard-click the widget button
|
|
doh.robot.sequence(function(){
|
|
buttonNode.focus();
|
|
}, 500);
|
|
doh.robot.keyPress(dojo.keys[key], 500, {});
|
|
|
|
// Check that ondijitclick fired exactly once
|
|
doh.robot.sequence(d.getTestCallback(function(){
|
|
doh.is(1, buttonWidget.clickCount, "one click event");
|
|
}), 500);
|
|
|
|
return d;
|
|
}
|
|
}
|
|
]);
|
|
});
|
|
|
|
doh.run();
|
|
});
|
|
|
|
</script>
|
|
</head>
|
|
</html>
|