Debian Codegraph @

dijit/tests/_base/robot/FocusManager.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3
4 <!-- Remove in 2.0, replaced by dijit/tests/focus.html -->
5
6 <html>
7 <head>
8 <title>Dijit focus manager DOH Robot test</title>
9
10 <style>
11 @import "../../../../util/doh/robot/robot.css";
12 </style>
13
14 <!-- required: dojo.js -->
15 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
16
17 <script type="text/javascript">
18 dojo.require("dijit.robotx");
19
20 dojo.ready(function(){
21 doh.robot.initRobot('../test_FocusManager.html');
22
23 doh.register("Dijit focus manager low level tests", [
24 {
25 name: "set timer to save focus and selection",
26 timeout: 4000,
27 runTest: function(){
28 var d = new doh.Deferred();
29
30 doh.robot.sequence(function(){
31 dojo.byId("delay_save").focus();
32 }, 500);
33 doh.robot.keyPress(dojo.keys.ENTER, 500);
34
35 doh.robot.sequence(d.getTestCallback(function(){
36 // This is just here to tell DOH that test is finished
37 }), 500);
38
39 return d;
40 }
41 },
42 {
43 name: "focus textarea and select some text",
44 timeout: 8000,
45 runTest: function(){
46 var d = new doh.Deferred();
47
48 dojo.byId("textarea").focus();
49
50 // Position caret at " there!"
51 if(dojo.isMac){
52 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 20, {meta: true});
53 }else{
54 doh.robot.keyPress(dojo.keys.HOME, 20, {});
55 }
56 for(var i=0; i<5; i++){
57 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 20, {});
58 }
59
60 // select " there"
61 for(i=0; i<6; i++){
62 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 20, {shift: true});
63 }
64
65 doh.robot.sequence(d.getTestCallback(function(){
66 // Wait for selection and focus to be copied
67 }), 3000);
68
69 return d;
70 }
71 },
72 {
73 name: "restore focus and selection",
74 timeout: 8000,
75 runTest: function(){
76 var d = new doh.Deferred();
77
78 // Focus somewhere else
79 doh.robot.sequence(function(){
80 dojo.byId("input1").focus();
81 }, 500);
82
83 // Press restore button
84 doh.robot.sequence(function(){
85 dojo.byId("restore").focus();
86 }, 500);
87
88 doh.robot.keyPress(dojo.keys.SPACE, 500);
89
90 //Move cursor to unselect the text
91 for(i=0; i<2; i++){
92 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 20, {shift: false});
93 }
94
95 // Press restore button again, should restore previous selection.
96 doh.robot.sequence(function(){
97 dojo.byId("restore").focus();
98 }, 500);
99
100 doh.robot.keyPress(dojo.keys.SPACE, 500);
101
102 // Focus should have been moved back to textarea, and
103 // " there" should be selected through the focus restorel
104 // by deleting the selection
105 doh.robot.keyPress(dojo.keys.BACKSPACE, 500);
106
107 doh.robot.sequence(d.getTestCallback(function(){
108 // Check that focus was returned to the textarea
109 doh.t(dojo.global.dijit.focus.curNode, "curFocus defined");
110 doh.is("textarea", dojo.global.dijit.focus.curNode.id, "focused on textarea");
111
112 // And that " there" was selected then deleted
113 doh.is("hello!", dojo.byId("textarea").value);
114 }), 500);
115 return d;
116 }
117 },
118 {
119 name: "Test select text, clear, and restore",
120 timeout: 8000,
121 runTest: function(){
122 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
123 var d = new doh.Deferred();
124
125 //Select the text in the p tag.
126 var p = dojo.byId("selectableText");
127 dijit._editor.selection.selectElementChildren(p);
128 var value = dijit._editor.selection.getSelectedText();
129 value = dojo.trim(value);
130 try{
131 doh.assertEqual(
132 "This paragraph contains text to select for testing purposes.",
133 value, "Original Text Selection");
134
135 //Get the current focus, which saves the selections too.
136 var curFocus = dijit.getFocus();
137
138 //Clear current selection.
139 dijit._editor.selection.collapse(true);
140
141 //Check it's cleared.
142 value = dijit._editor.selection.getSelectedText();
143 doh.assertEqual("",value);
144
145 //Restore it and check again.
146 dijit.focus(curFocus);
147 value = dijit._editor.selection.getSelectedText();
148 doh.assertEqual(
149 "This paragraph contains text to select for testing purposes.",
150 value, "Restored Text Selection");
151
152 //Clear the selection, we're complete.
153 dijit._editor.selection.collapse(true);
154 d.callback(true);
155 }catch(e){
156 d.errback(e);
157 }
158 return d;
159 }
160 }
161 }
162 ]);
163
164 doh.run();
165 });
166 </script>
167 </head>
168 </html>