Debian Codegraph @

dijit/tests/editor/robot/Editor_misc.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 <title>doh.robot Editor Miscellaneous Tests</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
12
13 <script type="text/javascript">
14 require([
15 "doh/runner", "dojo/robotx",
16 "dojo/_base/array", "dojo/dom", "dojo/dom-style", "dojo/keys", "dojo/sniff", "dojo/window",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, array, dom, domStyle, keys, has, winUtils, helpers){
19
20 robot.initRobot('../test_Editor.html');
21 var editor0;
22 var height;
23 var value;
24 var editor1;
25 var editor1OriginalBackgroundColor;
26
27 function getPlugin(/*Editor*/ editor, /*String*/ command){
28 return array.filter(editor._plugins, function(p){
29 return p.command == command;
30 })[0];
31 }
32
33 var registry;
34 doh.register("setup", [
35 {
36 name: "wait for editors to load",
37 timeout: 5000,
38 runTest: helpers.waitForLoad
39 },
40 function setVars(){
41 registry = robot.window.require("dijit/registry");
42 }
43 ]);
44
45 doh.register("Miscellaneous_tests", [
46 {
47 name: "addStylesheet",
48 timeout: 3000,
49 setUp: function(){
50 editor1 = registry.byId("editor1");
51 editor1.setValue("<h1>header one</h1>");
52 var editorTextNode = editor1.editNode.firstChild;
53 editor1OriginalBackgroundColor = domStyle.getComputedStyle(editorTextNode).backgroundColor;
54 },
55 runTest: function(){
56 var d = new doh.Deferred();
57
58 winUtils.scrollIntoView(editor1.domNode);
59 editor1.addStyleSheet('test_editor.css');
60
61 setTimeout(d.getTestCallback(function(){
62 var editorTextNode = editor1.editNode.firstChild;
63 var backgroundColor = domStyle.getComputedStyle(editorTextNode).backgroundColor;
64 var borderStyle = domStyle.getComputedStyle(editorTextNode).borderBottomStyle;
65 var borderWidth = domStyle.getComputedStyle(editorTextNode).borderBottomWidth;
66 doh.is("header one", editorTextNode.innerHTML);
67 doh.t(backgroundColor==="rgb(255, 0, 0)" || backgroundColor==="red" || backgroundColor==="#ff0000", "backgroundColor " + backgroundColor);
68 doh.is("solid", borderStyle);
69 doh.is("1px", borderWidth);
70 }), 1000);
71
72 return d;
73 }
74 },
75 {
76 name: "removeStylesheet",
77 timeout: 3000,
78 runTest: function(){
79 var d = new doh.Deferred();
80 editor1.removeStyleSheet('test_editor.css');
81
82 setTimeout(d.getTestCallback(function(){
83 var editorNodeText = editor1.editNode.firstChild;
84 var backgroundColor = domStyle.getComputedStyle(editorNodeText).backgroundColor;
85 doh.is("header one", editorNodeText.innerHTML);
86 doh.is(editor1OriginalBackgroundColor, backgroundColor, "backgroundColor");
87 }), 1000);
88
89 return d;
90 }
91 },
92 {
93 name: "auto expand",
94 timeout: 20000,
95 setUp: function(){
96 editor0 = registry.byId("thud");
97 height = dojo.style(editor0.domNode, "height");
98 value = editor0.get("value");
99 },
100 runTest: function(){
101 var d = new doh.Deferred();
102
103 // Focus on the editor window
104 winUtils.scrollIntoView(editor0.domNode);
105 robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
106 robot.mouseClick({left:true}, 500);
107 robot.keyPress(keys.ENTER, 500);
108 robot.keyPress(keys.ENTER, 500);
109 robot.keyPress(keys.ENTER, 500);
110 robot.keyPress(keys.ENTER, 500);
111 robot.keyPress(keys.ENTER, 500);
112 robot.keyPress(keys.ENTER, 500);
113 robot.keyPress(keys.ENTER, 500);
114 robot.keyPress(keys.ENTER, 500);
115 robot.sequence(d.getTestCallback(function(){
116 // Now check the state!
117 var newHeight = dojo.style(editor0.domNode, "height");
118 doh.t(height < newHeight, "height decreased from " + height + " to " + newHeight);
119 }), 1000);
120
121 return d;
122 },
123 tearDown: function(){
124 if(editor0){editor0.set("value", value);}
125 }
126 },
127 {
128 name: "font-size style migrated to editor body",
129 runTest: function(){
130 editor0 = registry.byId("fontSizedEditor");
131 var bStyle = editor0.document.body.style["fontSize"];
132 doh.t(bStyle != null, "bStyle set");
133 doh.is("30pt", bStyle.toLowerCase());
134 }
135 },
136 {
137 name: "prefilters do process initial content",
138 timeout: 20000,
139 setUp: function(){
140 editor0 = registry.byId("filteredEditor");
141 },
142 runTest: function(){
143 var d = new doh.Deferred();
144
145 // Focus on the editor window
146 winUtils.scrollIntoView(editor0.domNode);
147 robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
148 robot.mouseClick({left:true}, 500);
149
150 robot.sequence(d.getTestCallback(function(){
151 // Now check the state!
152 var val = editor0.get("value");
153 doh.t(val.indexOf("DOJO") >= 0, "dojo in val " + val);
154 doh.t(val.indexOf("notdojo") < 0, "notdojo not in val " + val);
155 }), 500);
156
157 return d;
158 }
159 },
160 {
161 name: "placeCursorAtStart (br tag) moves input before br, not inside",
162 timeout: 20000,
163 setUp: function(){
164 editor0 = registry.byId("brEditor");
165 value = editor0.get("value");
166 },
167 runTest: function(){
168 var d = new doh.Deferred();
169
170 // Focus on the editor window
171 winUtils.scrollIntoView(editor0.domNode);
172 robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
173 robot.mouseClick({left:true}, 500);
174 robot.sequence(d.getTestErrback(function(){
175 editor0.placeCursorAtStart();
176 }), 500);
177 robot.typeKeys("abc", 500);
178 robot.sequence(d.getTestCallback(function(){
179 // Now check the state!
180 var content = editor0.get("value").replace(/[\s]/g, "");
181 doh.t(content.indexOf("abc<br") >= 0, "looked for 'abc<br', found: " + content);
182 }), 1000);
183
184 return d;
185 },
186 tearDown: function(){
187 if(editor0){editor0.set("value", value);}
188 }
189 },
190 {
191 name: "custom editor content (programmatic creation)",
192 timeout: 20000,
193 setUp: function(){
194 editor0 = registry.byId("programmatic3");
195 value = editor0.get("value");
196 },
197 runTest: function(){
198 var d = new doh.Deferred();
199
200 // Focus on the editor window
201 winUtils.scrollIntoView(editor0.domNode);
202 robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
203 robot.mouseClick({left:true}, 500);
204 robot.sequence(d.getTestCallback(function(){
205 // Now check the state!
206 var content = editor0.get("value");
207 doh.t(content.indexOf("Custom Initial Content.") >= 0);
208 }), 1000);
209
210 return d;
211 },
212 tearDown: function(){
213 if(editor0){editor0.set("value", value);}
214 }
215 },
216 {
217 name: "custom filters passed in constructor are not lost",
218 timeout: 20000,
219 setUp: function(){
220 editor0 = registry.byId("programmatic4");
221 value = editor0.get("value");
222 },
223 runTest: function(){
224 var d = new doh.Deferred();
225
226 // Focus on the editor window
227 winUtils.scrollIntoView(editor0.domNode);
228 robot.mouseMoveAt(editor0.iframe, 500, null, 10, 10);
229 robot.mouseClick({left:true}, 500);
230 robot.sequence(d.getTestCallback(function(){
231 // Now check the state!
232 doh.t(editor0.contentPreFilters.length > 1);
233 }), 1000);
234
235 return d;
236 },
237 tearDown: function(){
238 if(editor0){editor0.set("value", value);}
239 }
240 },
241 {
242 name: "replaceValue",
243 timeout: 20000,
244 setUp: function(){
245 editor0 = registry.byId("programmatic4");
246 value = editor0.get("value");
247 },
248 runTest: function(){
249 var d = new doh.Deferred();
250
251 // Focus on the editor window
252 winUtils.scrollIntoView(editor0.domNode);
253 dojo.style(editor0.domNode, "display", "none");
254 editor0.replaceValue("New Value");
255 dojo.style(editor0.domNode, "display", "none");
256 robot.sequence(d.getTestCallback(function(){
257 // Now check the state!
258 dojo.style(editor0.domNode, "display", "");
259 winUtils.scrollIntoView(editor0.domNode);
260 var newValue = editor0.get("value");
261 editor0.undo();
262 var curValue = editor0.get("value");
263 doh.t(newValue.indexOf(value) < 0, "content changed with no trace of old content");
264 doh.t(curValue != newValue, "undo undid the change");
265 doh.t(curValue == value, "original value was restored");
266 }), 1000);
267
268 return d;
269 },
270 tearDown: function(){
271 if(editor0){editor0.set("value", value);}
272 }
273 },
274 {
275 name: "page up/down",
276 timeout: 6000,
277 setUp: function(){
278 editor0 = registry.byId("editor0");
279 value = editor0.get("value");
280 },
281 runTest: function(){
282 var d = new doh.Deferred();
283
284 // Focus on the editor window
285 winUtils.scrollIntoView(editor0.domNode);
286 robot.sequence(d.getTestErrback(function(){
287 editor0.focus();
288 }), 500);
289
290 robot.keyPress(keys.PAGE_UP, 500);
291 robot.typeKeys("abc", 500);
292 robot.keyPress(keys.PAGE_DOWN, 500);
293 robot.typeKeys("def", 500);
294
295 robot.sequence(d.getTestCallback(function(){
296 var value = editor0.get("value");
297 if(!has("webkit")){ // commented out due to #14193
298 doh.t(value.indexOf("abcdef") == 0, "editor value = " + value);
299 }
300 }), 500);
301
302 return d;
303 },
304 tearDown: function(){
305 if(editor0){editor0.set("value", value);}
306 }
307 },
308 {
309 name: "emptyAltTag",
310 timeout: 20000,
311 setUp: function(){
312 editor0 = registry.byId("programmatic4");
313 value = editor0.get("value");
314 },
315 runTest: function(){
316 var d = new doh.Deferred();
317 // Focus on the editor window
318 winUtils.scrollIntoView(editor0.domNode);
319 editor0.set("value", "<img alt=\"''\" src=\"http://blogsearch.google.com/blogsearch/intl/en_ALL/images/blogs_logo.gif\">");
320 robot.sequence(d.getTestCallback(function(){
321 // Now check the state!
322 winUtils.scrollIntoView(editor0.domNode);
323 var newValue = editor0.get("value");
324 var test = "alt=\"''\"";
325 doh.t(newValue.indexOf(test) > 0, "content includes empty string alt");
326 }), 1000);
327
328 return d;
329 },
330 tearDown: function(){
331 if(editor0){editor0.set("value", value);}
332 }
333 },
334 {
335 name: "caret pos #1",
336 timeout: 20000,
337 setUp: function(){
338 editor1 = registry.byId("editor1");
339
340 // Scroll editor into view, set content to list except for middle item isn't part of list
341 winUtils.scrollIntoView(editor1.domNode);
342 editor1.set("value", "<ul><li>one</li><li>two</li></ul><p id='three'>three</p><ul><li>four</li><li>five</li></ul>");
343 },
344 runTest: function(){
345 var d = new doh.Deferred();
346
347 // Select middle item ("three")
348 robot.mouseMoveAt(dom.byId("three", editor1.document), 500);
349 robot.mouseClick({left:true}, 500);
350
351 // Press indent button, so that "three" becomes part of list
352 robot.mouseMoveAt(function(){
353 return getPlugin(editor1, "indent").button.domNode;
354 }, 500);
355 robot.mouseClick({left:true}, 500);
356
357 robot.sequence(d.getTestCallback(function(){
358 var value = editor1.get("value").toLowerCase();
359 value = value.replace(/blockquote[^>]*>/, "blockquote>").replace(/ id="three"/, "");
360
361 // Ideally three would become part of the list, but it becomes a separate block quote.
362 // Maybe it would be part of the list w/dojox/Editor/plugins/NormalizeIndentOutdent.
363 doh.is(
364 "<ul><li>one</li><li>two</li></ul>" +
365 "<blockquote><p>three</p></blockquote>" +
366 "<ul><li>four</li><li>five</li></ul>",
367 value, "element 'three' indented")
368 }), 500);
369
370 return d;
371 }
372 }
373 ]);
374
375 doh.run();
376 });
377 </script>
378 </head>
379 </html>