Debian Codegraph @

dijit/tests/form/robot/Textarea.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6 <title>robot Textarea Test</title>
7
8 <style>
9 @import "../../../../util/doh/robot/robot.css";
10 </style>
11
12 <!-- required: dojo.js -->
13 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
14
15 <script type="text/javascript">
16 require([
17 "doh/runner", "dojo/robotx",
18 "dojo/dom-geometry", "dojo/keys", "dojo/sniff",
19 "dojo/domReady!"
20 ], function(doh, robot, domGeom, keys, has){
21 robot.initRobot('../test_Textarea.html');
22
23 // execute some test as soon as the widget gets focus
24 function focusThenRun(widget, fcn){
25 if(!widget.focused){
26 var handle = widget.on('focus', function(){
27 handle.remove();
28 setTimeout(fcn, 1);
29 });
30 widget.focus();
31 }else{
32 fcn();
33 }
34 }
35
36 doh.register("init", function init(){
37 registry = robot.window.require("dijit/registry");
38
39 // Wait for Textarea widgets to size themselves... it's done on a setTimeout(func, 0)
40 var d = new doh.Deferred();
41 setTimeout(function(){
42 d.callback(true);
43 }, 100);
44 return d;
45 });
46
47 doh.register("height tests", [
48 {
49 name: "initial height",
50 runTest: function(){
51 var blank = domGeom.getMarginBox("blank").h,
52 large = domGeom.getMarginBox("largeTextArea").h;
53 doh.t(blank > 8, "blank: " + blank);
54 doh.t(large > blank, "blank: " + blank + ", large: " + large);
55 }
56 },
57 {
58 name: "expansion/contraction by newline",
59 timeout: 10000,
60 runTest: function(){
61 var
62 d = new doh.Deferred(),
63 w = registry.byId("blank"),
64 height1 = domGeom.getMarginBox(w.domNode).h,
65 height2, height3;
66
67 focusThenRun(w, function(){
68 // Test expand on newline
69 robot.typeKeys('Row of text.', 1, 2000);
70 robot.keyPress(keys.ENTER, 100, {});
71 robot.keyPress(keys.ENTER, 100, {});
72 robot.sequence(d.getTestErrback(function(){
73 height2 = domGeom.getMarginBox(w.domNode).h;
74 }), 1000);
75
76 // Test shrink on delete of newline
77 robot.keyPress(keys.BACKSPACE, 200, {});
78 robot.sequence(d.getTestCallback(function(){
79 height3 = domGeom.getMarginBox(w.domNode).h;
80 doh.t(height2 > height1, "height ("+height2+") should have increased from " + height1);
81 doh.t(height3 < height2, "height ("+height3+") should have decreased from " + height2);
82 }), 1000);
83 });
84
85 return d;
86 }
87 },
88 {
89 name: "expansion/contraction by word wrap",
90 timeout: 50000,
91 runTest: function(){
92 var
93 d = new doh.Deferred(),
94 w = registry.byId("blank"),
95 height1 = domGeom.getMarginBox(w.domNode).h,
96 height2,
97 height3,
98 handler,
99 pos,
100 i = 0,
101 text = 'The quick brown fox jumped over the lazy dog.',
102 typing = true;
103
104 w.set('intermediateChanges', true);
105 // Test expand by wordwrap
106 text = text+text+text+text;
107 // onChange handler enables very fast typing and deleting, but not too fast
108 handler = w.on('change', function(nv){
109 if(typing){
110 pos = nv.indexOf(text);
111 if(pos <= 0){
112 robot.typeKeys(text.substr(i++,1), 1, 0);
113 return;
114 } // still typing
115 height2 = domGeom.getMarginBox(w.domNode).h;
116 typing = false;
117 // Test shrink on delete (backspace) of text
118 robot.keyPress(keys.BACKSPACE, 0, {});
119 }else{
120 if(nv.length > pos){
121 robot.keyPress(keys.BACKSPACE, 0, {});
122 return; // still deleting
123 }
124 handler.remove();
125 robot.sequence(d.getTestCallback(function(){
126 doh.t(height2 > height1, "height ("+height2+") should have increased from " + height1);
127 height3 = domGeom.getMarginBox(w.domNode).h;
128 doh.t(height3 < height2, "height ("+height3+") should have decreased from " + height2);
129 }), 1);
130 }
131 });
132 robot.typeKeys(text.substr(i++,1), 1, 0);
133
134 return d;
135 }
136 },
137 {
138 name: "expansion/contraction by cut/paste",
139 timeout: 9000,
140 runTest: function(){
141 var
142 d = new doh.Deferred(),
143 modifier = has("mac") ? {meta: true} : {ctrl: true},
144 w = registry.byId("blank"),
145 height1, height2, height3;
146
147 robot.keyPress(keys.ENTER, 500, {});
148 robot.sequence(function(){
149 height1 = domGeom.getMarginBox(w.domNode).h;
150 w.domNode.select();
151 }, 500);
152 // Cut text, height should decrease
153 robot.keyPress("x", 500, modifier);
154 robot.sequence(function(){
155 height2 = domGeom.getMarginBox(w.domNode).h;
156 doh.t(height2 < height1, "height2 (" + height2 + ") < height1 (" + height1 + ")");
157 }, 500);
158
159 // Paste text, height should increase
160 robot.keyPress("v", 500, modifier);
161 robot.keyPress("v", 500, modifier);
162 robot.sequence(d.getTestCallback(function(){
163 height3 = domGeom.getMarginBox(w.domNode).h;
164 doh.t(height3 > height2, "height3 (" + height3 + ") > height2 (" + height2 + ")");
165 }), 500);
166
167 return d;
168 }
169 }
170
171 ]);
172
173 doh.register("maxLength",
174 {
175 name: "maxLength",
176 timeout: 10000,
177 runTest: function(){
178 var
179 d = new doh.Deferred(),
180 ta = registry.byId("simple"),
181 value1, value2, value3;
182
183 focusThenRun(ta, function(){
184 // Limit is 50, and there's text there already, so not all of
185 // these characters will fit; some should be rejected.
186 robot.typeKeys('0123456789', 1, 2000);
187 robot.sequence(function(){
188 value1 = ta.get("value");
189 }, 500);
190
191 // Erase a character
192 robot.keyPress(keys.BACKSPACE, 500, {});
193 robot.sequence(function(){
194 value2 = ta.get("value");
195 }, 500);
196
197 // And try to type a new character, there should be room now,
198 // but just for one character
199 robot.typeKeys('AB', 500, 400);
200 robot.sequence(d.getTestCallback(function(){
201 value3 = ta.get("value");
202 doh.is(50, value1.length, "should have stopped at 50, value is " + value1);
203 doh.is(49, value2.length, "erased a char, value is " + value2);
204 doh.is(50, value3.length, "tried to type 2 chars but only 1 should fit, value is " + value3);
205 }), 500);
206 });
207
208 return d;
209 }
210 });
211 doh.register("min/max height", [
212 {
213 name: "initial height",
214 timeout: 1000,
215 runTest: function(){
216 var w = registry.byId("programmatic");
217 var h = w.domNode.offsetHeight;
218 doh.t(h > 64, "initial 3 line height " + h);
219 }
220 },
221 {
222 name: "#13166",
223 timeout: 5000,
224 runTest: function(){
225 var
226 d = new doh.Deferred(),
227 w = registry.byId("programmatic");
228
229 focusThenRun(w, function(){
230 var h = w.domNode.offsetHeight;
231 robot.keyPress(keys.SPACE, 500, {});
232 robot.sequence(d.getTestCallback(function(){
233 doh.is(0, w.domNode.scrollTop, "no scroll");
234 doh.is(h, w.domNode.offsetHeight, "height should not change");
235 }), 500);
236 });
237
238 return d;
239 }
240 },
241 {
242 name: "less than max-height",
243 timeout: 5000,
244 runTest: function(){
245 var
246 d = new doh.Deferred(),
247 w = registry.byId("programmatic");
248
249 var h = w.domNode.offsetHeight;
250 w.set('value', '');
251 doh.t(h > w.domNode.offsetHeight, "min-height is smaller than 3 lines: " + w.domNode.offsetHeight);
252 doh.t(40 < w.domNode.offsetHeight, "min-height is at least 1 line: " + w.domNode.offsetHeight);
253 robot.keyPress(keys.ENTER, 500, {});
254 robot.keyPress(keys.ENTER, 500, {});
255 robot.keyPress(keys.ENTER, 500, {});
256 robot.sequence(d.getTestCallback(function(){
257 doh.is(0, w.domNode.scrollTop, "no scroll");
258 doh.t(h < w.domNode.offsetHeight, "height grew " + w.domNode.offsetHeight);
259 if(has("ie") <= 7){
260 doh.t(w.domNode.parentNode.parentNode.clientHeight >= w.domNode.parentNode.parentNode.scrollHeight, "non-scrolled parent");
261 }
262 }), 500);
263
264 return d;
265 }
266 },
267 {
268 name: "more than max-height",
269 timeout: 5000,
270 runTest: function(){
271 var
272 d = new doh.Deferred(),
273 w = registry.byId("programmatic");
274
275 var h = w.domNode.offsetHeight;
276 robot.keyPress(keys.ENTER, 500, {});
277 robot.keyPress(keys.ENTER, 500, {});
278 robot.keyPress(keys.ENTER, 500, {});
279 robot.keyPress(keys.ENTER, 500, {});
280 robot.keyPress(keys.ENTER, 500, {});
281 robot.sequence(d.getTestCallback(function(){
282 if(has("ie") <= 6){
283 doh.is(0, w.domNode.scrollTop, "no scroll");
284 doh.t(w.domNode.parentNode.parentNode.clientHeight < w.domNode.parentNode.parentNode.scrollHeight, "scrolled parent");
285 }else{
286 doh.isNot(0, w.domNode.scrollTop, "scroll");
287 }
288 doh.t(h < w.domNode.offsetHeight, "height grew " + w.domNode.offsetHeight);
289 }), 500);
290
291 return d;
292 }
293 },
294 {
295 name: "delete until less than max-height",
296 timeout: 5000,
297 runTest: function(){
298 var
299 d = new doh.Deferred(),
300 w = registry.byId("programmatic");
301
302 var h = w.domNode.offsetHeight;
303 robot.keyPress(keys.BACKSPACE, 500, {});
304 robot.keyPress(keys.BACKSPACE, 500, {});
305 robot.keyPress(keys.BACKSPACE, 500, {});
306 robot.keyPress(keys.BACKSPACE, 500, {});
307 robot.keyPress(keys.BACKSPACE, 500, {});
308 robot.sequence(d.getTestCallback(function(){
309 doh.is(0, w.domNode.scrollTop, "no scroll");
310 if(has("ie") <= 7){
311 doh.t(w.domNode.parentNode.parentNode.clientHeight >= w.domNode.parentNode.parentNode.scrollHeight, "non-scrolled parent");
312 }
313 doh.t(h > w.domNode.offsetHeight, "height shrank " + w.domNode.offsetHeight);
314 }), 500);
315
316 return d;
317 }
318 }
319
320 ]);
321
322 doh.run();
323 });
324 </script>
325 </head>
326 </html>