You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
168 lines
4.7 KiB
168 lines
4.7 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
|
"http://www.w3.org/TR/html4/strict.dtd"> |
|
|
|
<!-- Remove in 2.0, replaced by dijit/tests/focus.html --> |
|
|
|
<html> |
|
<head> |
|
<title>Dijit focus manager DOH Robot test</title> |
|
|
|
<style> |
|
@import "../../../../util/doh/robot/robot.css"; |
|
</style> |
|
|
|
<!-- required: dojo.js --> |
|
<script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
|
|
|
<script type="text/javascript"> |
|
dojo.require("dijit.robotx"); |
|
|
|
dojo.ready(function(){ |
|
doh.robot.initRobot('../test_FocusManager.html'); |
|
|
|
doh.register("Dijit focus manager low level tests", [ |
|
{ |
|
name: "set timer to save focus and selection", |
|
timeout: 4000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
doh.robot.sequence(function(){ |
|
dojo.byId("delay_save").focus(); |
|
}, 500); |
|
doh.robot.keyPress(dojo.keys.ENTER, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// This is just here to tell DOH that test is finished |
|
}), 500); |
|
|
|
return d; |
|
} |
|
}, |
|
{ |
|
name: "focus textarea and select some text", |
|
timeout: 8000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
dojo.byId("textarea").focus(); |
|
|
|
// Position caret at " there!" |
|
if(dojo.isMac){ |
|
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 20, {meta: true}); |
|
}else{ |
|
doh.robot.keyPress(dojo.keys.HOME, 20, {}); |
|
} |
|
for(var i=0; i<5; i++){ |
|
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 20, {}); |
|
} |
|
|
|
// select " there" |
|
for(i=0; i<6; i++){ |
|
doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 20, {shift: true}); |
|
} |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// Wait for selection and focus to be copied |
|
}), 3000); |
|
|
|
return d; |
|
} |
|
}, |
|
{ |
|
name: "restore focus and selection", |
|
timeout: 8000, |
|
runTest: function(){ |
|
var d = new doh.Deferred(); |
|
|
|
// Focus somewhere else |
|
doh.robot.sequence(function(){ |
|
dojo.byId("input1").focus(); |
|
}, 500); |
|
|
|
// Press restore button |
|
doh.robot.sequence(function(){ |
|
dojo.byId("restore").focus(); |
|
}, 500); |
|
|
|
doh.robot.keyPress(dojo.keys.SPACE, 500); |
|
|
|
//Move cursor to unselect the text |
|
for(i=0; i<2; i++){ |
|
doh.robot.keyPress(dojo.keys.LEFT_ARROW, 20, {shift: false}); |
|
} |
|
|
|
// Press restore button again, should restore previous selection. |
|
doh.robot.sequence(function(){ |
|
dojo.byId("restore").focus(); |
|
}, 500); |
|
|
|
doh.robot.keyPress(dojo.keys.SPACE, 500); |
|
|
|
// Focus should have been moved back to textarea, and |
|
// " there" should be selected through the focus restorel |
|
// by deleting the selection |
|
doh.robot.keyPress(dojo.keys.BACKSPACE, 500); |
|
|
|
doh.robot.sequence(d.getTestCallback(function(){ |
|
// Check that focus was returned to the textarea |
|
doh.t(dojo.global.dijit.focus.curNode, "curFocus defined"); |
|
doh.is("textarea", dojo.global.dijit.focus.curNode.id, "focused on textarea"); |
|
|
|
// And that " there" was selected then deleted |
|
doh.is("hello!", dojo.byId("textarea").value); |
|
}), 500); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name: "Test select text, clear, and restore", |
|
timeout: 8000, |
|
runTest: function(){ |
|
if(!dojo.isIE){ // IE only supports selecting form elements and the whole body from a plain non-Editor page, see the MSDN article on createTextRange |
|
var d = new doh.Deferred(); |
|
|
|
//Select the text in the p tag. |
|
var p = dojo.byId("selectableText"); |
|
dijit._editor.selection.selectElementChildren(p); |
|
var value = dijit._editor.selection.getSelectedText(); |
|
value = dojo.trim(value); |
|
try{ |
|
doh.assertEqual( |
|
"This paragraph contains text to select for testing purposes.", |
|
value, "Original Text Selection"); |
|
|
|
//Get the current focus, which saves the selections too. |
|
var curFocus = dijit.getFocus(); |
|
|
|
//Clear current selection. |
|
dijit._editor.selection.collapse(true); |
|
|
|
//Check it's cleared. |
|
value = dijit._editor.selection.getSelectedText(); |
|
doh.assertEqual("",value); |
|
|
|
//Restore it and check again. |
|
dijit.focus(curFocus); |
|
value = dijit._editor.selection.getSelectedText(); |
|
doh.assertEqual( |
|
"This paragraph contains text to select for testing purposes.", |
|
value, "Restored Text Selection"); |
|
|
|
//Clear the selection, we're complete. |
|
dijit._editor.selection.collapse(true); |
|
d.callback(true); |
|
}catch(e){ |
|
d.errback(e); |
|
} |
|
return d; |
|
} |
|
} |
|
} |
|
]); |
|
|
|
doh.run(); |
|
}); |
|
</script> |
|
</head> |
|
</html>
|
|
|