Debian Codegraph @

dijit/tests/editor/robot/Editor_ViewSource.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 View Source Plugin Test</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/dom-attr", "dojo/dom-style", "dojo/keys", "dojo/sniff", "dojo/window",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, domAttr, domStyle, keys, has, winUtils, helpers){
19
20 robot.initRobot('../test_ViewSource.html');
21
22 var editor0, editor1, editor2, editor3;
23 var fsPlugin;
24 var vsPlugin;
25
26 var registry;
27 doh.register("setup", [
28 {
29 name: "wait for editors to load",
30 timeout: 5000,
31 runTest: helpers.waitForLoad
32 },
33 function setVars(){
34 registry = robot.window.require("dijit/registry");
35 }
36 ]);
37
38 doh.register("ViewSource_Tests", [
39 {
40 name: "Keyboard: Go to view source (CTRL-SHIFT-F12)",
41 timeout: 20000,
42 setUp: function(){
43 editor0 = registry.byId("editor0");
44 var edPlugins = editor0._plugins, i;
45 for(i = 0; i < edPlugins.length; i++){
46 var p = edPlugins[i];
47 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
48 vsPlugin = p;
49 }
50 if(vsPlugin){
51 break;
52 }
53 }
54 doh.t(vsPlugin != null, "Checking for VS plugin.");
55 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
56 },
57 runTest: function(){
58 var d = new doh.Deferred();
59
60 //Timing gets wonky here, so we need to do this on a timeout
61 //so the browser has time to shift focus.
62 robot.sequence(d.getTestErrback(function(){
63 editor0.focus();
64 }), 500);
65
66 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
67
68 robot.sequence(d.getTestCallback(function(){
69 //Now check the state!
70 doh.t(vsPlugin._sourceShown, "Verifying the plugin believes the source is shown.");
71 doh.is("hidden", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is invisible");
72 doh.is("block", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is visible");
73 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
74 }), 3000);
75
76 return d;
77 },
78 tearDown: function(){
79 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
80 fsPlugin = null;
81 vsPlugin = null;
82 }
83 },
84 {
85 name: "Keyboard: Go to source mode and back",
86 timeout: 20000,
87 setUp: function(){
88 editor0 = registry.byId("editor0");
89 var edPlugins = editor0._plugins, i;
90 for(i = 0; i < edPlugins.length; i++){
91 var p = edPlugins[i];
92 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
93 vsPlugin = p;
94 }
95 if(vsPlugin){
96 break;
97 }
98 }
99 doh.t(vsPlugin != null, "Checking that the view source plugin was found.");
100 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
101 },
102 runTest: function(){
103 var d = new doh.Deferred();
104
105 robot.sequence(d.getTestErrback(function(){
106 editor0.focus();
107 }), 1000);
108
109 robot.keyPress(keys.F12, 500, {ctrl:true,shift:true});
110 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
111
112 robot.sequence(d.getTestCallback(function(){
113 //Now check the state!
114 doh.f(vsPlugin._sourceShown, "Verifying the plugin states the source is not shown.");
115 doh.is("visible", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is visible");
116 doh.is("none", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is invisible");
117 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
118 }), 2000);
119
120 return d;
121 },
122 tearDown: function(){
123 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
124 }
125 },
126 {
127 name: "Mouse Click: Go to View Source",
128 timeout: 20000,
129 setUp: function(){
130 editor0 = registry.byId("editor0");
131 var edPlugins = editor0._plugins, i;
132 for(i = 0; i < edPlugins.length; i++){
133 var p = edPlugins[i];
134 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
135 vsPlugin = p;
136 break;
137 }
138 }
139 doh.t(vsPlugin != null, "Checking that the view source plugin was found.");
140 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
141 },
142 runTest: function(){
143 var d = new doh.Deferred();
144
145 robot.sequence(d.getTestErrback(function(){
146 editor0.focus();
147 }), 1000);
148
149 robot.mouseMoveAt(vsPlugin.button.domNode, 500);
150 robot.mouseClick({left: true}, 750);
151
152 robot.sequence(d.getTestCallback(function(){
153 //Now check the state!
154 doh.t(vsPlugin._sourceShown, "Verifying the plugin believes the source is shown.");
155 doh.is("hidden", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is invisible");
156 doh.is("block", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is visible");
157 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
158 }), 1000);
159
160 return d;
161 },
162 tearDown: function(){
163 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
164 fsPlugin = null;
165 vsPlugin = null;
166 }
167 },
168 {
169 name: "Mouse Click: Go to View Source, then mouseclick twice (open/close sourceview)",
170 timeout: 20000,
171 setUp: function(){
172 editor0 = registry.byId("editor0");
173 var edPlugins = editor0._plugins, i;
174 for(i = 0; i < edPlugins.length; i++){
175 var p = edPlugins[i];
176 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
177 vsPlugin = p;
178 break;
179 }
180 }
181 doh.t(vsPlugin != null);
182 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
183 },
184 runTest: function(){
185 var d = new doh.Deferred();
186
187 robot.sequence(d.getTestErrback(function(){
188 editor0.focus();
189 }), 500);
190
191 robot.mouseMoveAt(vsPlugin.button.domNode, 500);
192 robot.mouseClick({left: true}, 750);
193 robot.mouseMoveAt(vsPlugin.button.domNode, 500);
194 robot.mouseClick({left: true}, 750);
195
196 robot.sequence(d.getTestCallback(function(){
197 //Now check the state!
198 doh.t(!vsPlugin._sourceShown, "Verifying the plugin believes the source is not shown.");
199 doh.is("visible", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is visible");
200 doh.is("none", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is invisible");
201 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
202 }), 1000);
203
204 return d;
205 },
206 tearDown: function(){
207 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
208 fsPlugin = null;
209 vsPlugin = null;
210 }
211 },
212 {
213 name: "Combination Test: FullScreen + ViewSource (Verify view source works in fullscreen mode)",
214 timeout: 20000,
215 setUp: function(){
216 editor1 = registry.byId("editor1");
217 var edPlugins = editor1._plugins, i;
218 for(i = 0; i < edPlugins.length; i++){
219 var p = edPlugins[i];
220 if(p.declaredClass === "dijit._editor.plugins.FullScreen"){
221 fsPlugin = p;
222 }
223 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
224 vsPlugin = p;
225 }
226 if(vsPlugin && fsPlugin){
227 break;
228 }
229 }
230 doh.t(vsPlugin != null, "Checking for viewSource plugin.");
231 doh.t(fsPlugin != null, "Checking for fullScreen plugin.");
232 if(fsPlugin){fsPlugin.button.set("checked", false);}
233 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
234 },
235 runTest: function(){
236 var d = new doh.Deferred();
237
238 robot.sequence(d.getTestErrback(function(){
239 editor1.focus();
240 }), 1000);
241
242 robot.mouseMoveAt(fsPlugin.button.domNode, 1000);
243 robot.mouseClick({left: true}, 500);
244 robot.mouseMoveAt(vsPlugin.button.domNode, 1000);
245 robot.mouseClick({left: true}, 500);
246
247 robot.sequence(d.getTestCallback(function(){
248 //Now check the state!
249 doh.t(fsPlugin.isFullscreen, "Verifying the plugin believes the editor is in full screen mode.");
250 doh.t(vsPlugin._sourceShown, "Verifying the plugin believes the source is shown.");
251 doh.is("hidden", domStyle.get(editor1.iframe, "visibility"), "Verifying iframe is invisible");
252 doh.is("block", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is visible");
253 doh.is(vsPlugin.sourceArea.nextSibling, editor1.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
254 }), 2000);
255
256 return d;
257 },
258 tearDown: function(){
259 if(fsPlugin){fsPlugin.button.set("checked", false);}
260 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
261 fsPlugin = null;
262 vsPlugin = null;
263 }
264 },
265 {
266 name: "Combination Test: FullScreen + ViewSource (toggle on and off)",
267 timeout: 20000,
268 setUp: function(){
269 editor1 = registry.byId("editor1");
270 var edPlugins = editor1._plugins, i;
271 for(i = 0; i < edPlugins.length; i++){
272 var p = edPlugins[i];
273 if(p.declaredClass === "dijit._editor.plugins.FullScreen"){
274 fsPlugin = p;
275 }
276 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
277 vsPlugin = p;
278 }
279 if(vsPlugin && fsPlugin){
280 break;
281 }
282 }
283 doh.t(vsPlugin != null, "Checking for viewSource plugin.");
284 doh.t(fsPlugin != null, "Checking for fullScreen plugin.");
285 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
286 if(fsPlugin){fsPlugin.button.set("checked", false);}
287 },
288 runTest: function(){
289 var d = new doh.Deferred();
290
291 robot.sequence(d.getTestErrback(function(){
292 //Focus on the editor window
293 winUtils.scrollIntoView(editor1.domNode);
294 editor1.focus();
295 }), 1000);
296
297 //Toggle fs on, the source on.
298 robot.mouseMoveAt(fsPlugin.button.domNode, 500);
299 robot.mouseClick({left: true}, 750);
300 robot.mouseMoveAt(vsPlugin.button.domNode, 1000);
301 robot.mouseClick({left: true}, 1000);
302 robot.mouseMoveAt(vsPlugin.button.domNode, 500);
303 robot.mouseClick({left: true}, 1000);
304 robot.mouseMoveAt(fsPlugin.button.domNode, 500);
305 robot.mouseClick({left: true}, 1000);
306 robot.sequence(d.getTestCallback(function(){
307 //Now check the state!
308 doh.t(!fsPlugin.isFullscreen, "Verifying the plugin believes the editor is not in full screen mode.");
309 doh.t(!vsPlugin._sourceShown, "Verifying the plugin believes the source is not shown.");
310 doh.is("visible", domStyle.get(editor1.iframe, "visibility"), "Verifying iframe is visible");
311 doh.is("none", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is invisible");
312 doh.is(vsPlugin.sourceArea.nextSibling, editor1.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
313 }), 1000);
314
315 return d;
316 },
317 tearDown: function(){
318 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
319 if(fsPlugin){fsPlugin.button.set("checked", false);}
320 fsPlugin = null;
321 vsPlugin = null;
322 }
323 },
324 {
325 name: "XSS: Verify simple script tags get stripped.",
326 timeout: 30000,
327 setUp: function(){
328 editor0 = registry.byId("editor0");
329 var edPlugins = editor0._plugins, i;
330 for(i = 0; i < edPlugins.length; i++){
331 var p = edPlugins[i];
332 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
333 vsPlugin = p;
334 }
335 if(vsPlugin){
336 break;
337 }
338 }
339 doh.t(vsPlugin != null, "Checking for VS plugin.");
340 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
341 },
342 runTest: function(){
343 var d = new doh.Deferred();
344
345 var oldValue = editor0.get("value");
346
347 //Timing gets wonky here, so we need to do this on a timeout
348 //so the browser has time to shift focus.
349 robot.sequence(d.getTestErrback(function(){
350 //Focus on the editor window
351 winUtils.scrollIntoView(editor0.domNode);
352 editor0.focus();
353 }), 500);
354
355 var simpleScript0 = '<scr' + 'ipt type="text/javascript">var foo = "Hack!"</scr' + 'ipt>';
356 var simpleScript1 = '<scr' + 'ipt type="text/javascript" src="http://example.com/hack.js"></scr' + 'ipt>';
357
358 //Type in some script stuff.
359
360 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
361 robot.sequence(d.getTestErrback(function(){
362 vsPlugin.sourceArea.value = "\n\n" +
363 simpleScript0 +
364 "\n\n" +
365 simpleScript1 +
366 "\n" +
367 vsPlugin.sourceArea.value;
368 }), 1000);
369 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
370 robot.sequence(d.getTestCallback(function(){
371 //Now check the state!
372 var val = editor0.get("value");
373 doh.is(-1, val.indexOf("Hack!"), "Validating inline script tag was stripped");
374 doh.is(-1, val.indexOf("hack.js"), "Validating import script tag was stripped");
375 editor0.set("value", oldValue);
376 }), 2000);
377
378 return d;
379 },
380 tearDown: function(){
381 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
382 fsPlugin = null;
383 vsPlugin = null;
384 }
385 },
386 {
387 name: "XSS: Verify complex/odd script tags get stripped.",
388 timeout: 30000,
389 setUp: function(){
390 editor0 = registry.byId("editor0");
391 var edPlugins = editor0._plugins, i;
392 for(i = 0; i < edPlugins.length; i++){
393 var p = edPlugins[i];
394 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
395 vsPlugin = p;
396 }
397 if(vsPlugin){
398 break;
399 }
400 }
401 doh.t(vsPlugin != null, "Checking for VS plugin.");
402 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
403 },
404 runTest: function(){
405 var d = new doh.Deferred();
406
407 var oldValue = editor0.get("value");
408
409 //Timing gets wonky here, so we need to do this on a timeout
410 //so the browser has time to shift focus.
411 robot.sequence(d.getTestErrback(function(){
412 //Focus on the editor window
413 winUtils.scrollIntoView(editor0.domNode);
414 editor0.focus();
415 }), 500);
416
417 var complexScript = '< scr' + 'IPt type="text/javascript" \n>\n var foo = "Hack!" \n</SCr' + 'ipt >';
418 robot.keyPress(keys.F12, 500, {ctrl:true,shift:true});
419 robot.sequence(d.getTestErrback(function(){
420 vsPlugin.sourceArea.value = "\n\n" +
421 complexScript +
422 "\n\n" +
423 vsPlugin.sourceArea.value;
424 }), 1000);
425 robot.keyPress(keys.F12, 500, {ctrl:true,shift:true});
426 robot.sequence(d.getTestCallback(function(){
427 //Now check the state!
428 var val = editor0.get("value");
429 doh.is(-1, val.indexOf("< scrIPt "), "Validating script tag was stripped");
430 editor0.set("value", oldValue);
431 }), 2000);
432
433 return d;
434 },
435 tearDown: function(){
436 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
437 fsPlugin = null;
438 vsPlugin = null;
439 }
440 },
441 {
442 name: "XSS: Verify single line comment blocks are stripped.",
443 timeout: 30000,
444 setUp: function(){
445 editor0 = registry.byId("editor0");
446 var edPlugins = editor0._plugins, i;
447 for(i = 0; i < edPlugins.length; i++){
448 var p = edPlugins[i];
449 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
450 vsPlugin = p;
451 }
452 if(vsPlugin){
453 break;
454 }
455 }
456 doh.t(vsPlugin != null, "Checking for VS plugin.");
457 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
458 },
459 runTest: function(){
460 var d = new doh.Deferred();
461 var oldValue = editor0.get("value");
462
463 //Timing gets wonky here, so we need to do this on a timeout
464 //so the browser has time to shift focus.
465 robot.sequence(d.getTestErrback(function(){
466 //Focus on the editor window
467 winUtils.scrollIntoView(editor0.domNode);
468 editor0.focus();
469 }), 500);
470
471 var simpleComment = '<!-- Hello, this is a comment! -->';
472
473 //Type in some script stuff.
474 robot.keyPress(keys.F12, 500, {ctrl:true,shift:true});
475 robot.sequence(d.getTestErrback(function(){
476 vsPlugin.sourceArea.value = "\n\n" +
477 simpleComment +
478 "\n\n" +
479 vsPlugin.sourceArea.value;
480 }), 1000);
481 robot.keyPress(keys.F12, 500, {ctrl:true,shift:true});
482
483 robot.sequence(d.getTestCallback(function(){
484 //Now check the state!
485 var val = editor0.get("value");
486 doh.is(-1, val.indexOf("Hello, this is a comment!"), "Validating comment block was stripped");
487 editor0.set("value", oldValue);
488 }), 2000);
489
490 return d;
491 },
492 tearDown: function(){
493 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
494 fsPlugin = null;
495 vsPlugin = null;
496 }
497 },
498 {
499 name: "XSS: Verify multi line comment blocks are stripped.",
500 timeout: 30000,
501 setUp: function(){
502 editor0 = registry.byId("editor0");
503 var edPlugins = editor0._plugins, i;
504 for(i = 0; i < edPlugins.length; i++){
505 var p = edPlugins[i];
506 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
507 vsPlugin = p;
508 }
509 if(vsPlugin){
510 break;
511 }
512 }
513 doh.t(vsPlugin != null, "Checking for VS plugin.");
514 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
515 },
516 runTest: function(){
517 var d = new doh.Deferred();
518
519 var oldValue = editor0.get("value");
520
521 //Timing gets wonky here, so we need to do this on a timeout
522 //so the browser has time to shift focus.
523 robot.sequence(d.getTestErrback(function(){
524 //Focus on the editor window
525 winUtils.scrollIntoView(editor0.domNode);
526 editor0.focus();
527 }), 500);
528
529 //Type in some script stuff.
530 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
531 robot.sequence(d.getTestErrback(function(){
532 vsPlugin.sourceArea.value = "\n\n" +
533 "<!--\n" +
534 "Hello, this is a comment!\n" +
535 "-->\n" +
536 "\n\n" +
537 vsPlugin.sourceArea.value;
538 }), 1000);
539 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
540
541 robot.sequence(d.getTestCallback(function(){
542 //Now check the state!
543 var val = editor0.get("value");
544 doh.is(-1, val.indexOf("Hello, this is a comment!"), "Validating multiline comment block was stripped");
545 editor0.set("value", oldValue);
546 }), 2000);
547
548 return d;
549 },
550 tearDown: function(){
551 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
552 fsPlugin = null;
553 vsPlugin = null;
554 }
555 },
556 {
557 //This is probably paranoia, but I think there's a chance iframes
558 //can be used to pull in hack scripts, so check that we can strip those too.
559 name: "XSS: Verify iframe tags are stripped.",
560 timeout: 30000,
561 setUp: function(){
562 editor0 = registry.byId("editor0");
563 var edPlugins = editor0._plugins, i;
564 for(i = 0; i < edPlugins.length; i++){
565 var p = edPlugins[i];
566 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
567 vsPlugin = p;
568 }
569 if(vsPlugin){
570 break;
571 }
572 }
573 doh.t(vsPlugin != null, "Checking for VS plugin.");
574 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
575 },
576 runTest: function(){
577 var d = new doh.Deferred();
578
579 var oldValue = editor0.get("value");
580
581
582 //Timing gets wonky here, so we need to do this on a timeout
583 //so the browser has time to shift focus.
584 robot.sequence(d.getTestErrback(function(){
585 //Focus on the editor window
586 winUtils.scrollIntoView(editor0.domNode);
587 editor0.focus();
588 }), 500);
589
590 var simpleIFrame = '<iframe src="http://example.com/hack.html" width=0 height=0 style="display: none;"></iframe>';
591
592 //Type in some script stuff.
593 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
594 robot.sequence(d.getTestErrback(function(){
595 vsPlugin.sourceArea.value = "\n\n" +
596 simpleIFrame +
597 "\n\n" +
598 vsPlugin.sourceArea.value;
599 }), 1000);
600 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
601
602 robot.sequence(d.getTestCallback(function(){
603 //Now check the state!
604 var val = editor0.get("value");
605 doh.is(-1, val.indexOf("<iframe"), "Validating iframe tag was stripped stripped");
606 editor0.set("value", oldValue);
607 }), 2000);
608
609 return d;
610 },
611 tearDown: function(){
612 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
613 fsPlugin = null;
614 vsPlugin = null;
615 }
616 },
617 {
618 name: "XSS Disabled: Verify script, comment, and iframes are not stripped.",
619 timeout: 30000,
620 setUp: function(){
621 editor3 = registry.byId("editor3");
622 var edPlugins = editor3._plugins, i;
623 for(i = 0; i < edPlugins.length; i++){
624 var p = edPlugins[i];
625 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
626 vsPlugin = p;
627 }
628 if(vsPlugin){
629 break;
630 }
631 }
632 doh.t(vsPlugin != null, "Checking for VS plugin.");
633 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
634 },
635 runTest: function(){
636 var d = new doh.Deferred();
637 var oldValue = editor3.get("value");
638
639 //Timing gets wonky here, so we need to do this on a timeout
640 //so the browser has time to shift focus.
641 robot.sequence(d.getTestErrback(function(){
642 //Focus on the editor window
643 winUtils.scrollIntoView(editor3.domNode);
644 editor3.focus();
645 }), 500);
646
647 var simpleScript0 = '<scr' + 'ipt type="text/javascript">var foo = "Hack!"</scr' + 'ipt>';
648 var simpleScript1 = '<scr' + 'ipt type="text/javascript" src="http://example.com/hack.js"></scr' + 'ipt>';
649 var simpleiFrame = '<iframe src="http://example.com/hack.html" width=0 height=0 style="display: none;"></iframe>';
650 var simpleComment = '<!-- Hello, this is a comment! -->';
651
652 //Type in some script stuff.
653 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
654
655 robot.sequence(d.getTestErrback(function(){
656 vsPlugin.sourceArea.value = "\n\n" +
657 "<div>\n" +
658 simpleScript0 +
659 "\n\n" +
660 simpleScript1 +
661 "\n" +
662 "</div>" +
663 "\n\n" +
664 simpleiFrame +
665 "\n\n" +
666 simpleComment +
667 "\n\n" +
668 vsPlugin.sourceArea.value;
669 }), 1000);
670 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
671 robot.sequence(d.getTestCallback(function(){
672 //Now check the state!
673 var val = editor3.get("value");
674 // IE strips scripts anyway, need to look more at this sometime.
675 // It's not the plugin doing it.
676 doh.t((0 <= val.indexOf("Hack!")) || has("ie"), "Validating inline script tag was left");
677 doh.t((0 <= val.indexOf("hack.js") || has("ie")), "Validating import script tag was left");
678 doh.t(0 <= val.indexOf("<iframe"), "Validating iframe tag was left");
679 doh.t(0 <= val.indexOf("Hello, this is a comment!"), "Validating comment was left");
680 editor3.set("value", oldValue);
681 }), 2000);
682
683 return d;
684 },
685 tearDown: function(){
686 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
687 fsPlugin = null;
688 vsPlugin = null;
689 }
690 },
691 {
692 name: "ReadOnly: Verify View Source can be put in ReadOnly mode.",
693 timeout: 30000,
694 setUp: function(){
695 editor2 = registry.byId("editor2");
696 var edPlugins = editor2._plugins, i;
697 for(i = 0; i < edPlugins.length; i++){
698 var p = edPlugins[i];
699 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
700 vsPlugin = p;
701 }
702 if(vsPlugin){
703 break;
704 }
705 }
706 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
707 },
708 runTest: function(){
709 var d = new doh.Deferred();
710
711 //Timing gets wonky here, so we need to do this on a timeout
712 //so the browser has time to shift focus.
713 robot.sequence(d.getTestErrback(function(){
714 //Focus on the editor window
715 winUtils.scrollIntoView(editor2.domNode);
716 editor2.focus();
717 }), 500);
718
719 robot.mouseMoveAt(vsPlugin.button.domNode, 500);
720 robot.mouseClick({left: true}, 750);
721
722 robot.sequence(d.getTestCallback(function(){
723 //Now check the state!
724 doh.is(true, domAttr.has(vsPlugin.sourceArea, "readOnly"), "Verify the source area is read only.");
725 }), 2000);
726
727 return d;
728 },
729 tearDown: function(){
730 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
731 fsPlugin = null;
732 vsPlugin = null;
733 }
734 },
735 {
736 name: "ViewSource: GetValue",
737 timeout: 20000,
738 setUp: function(){
739 editor0 = registry.byId("editor0");
740 value = editor0.get("value");
741 var edPlugins = editor0._plugins, i;
742 for(i = 0; i < edPlugins.length; i++){
743 var p = edPlugins[i];
744 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
745 vsPlugin = p;
746 }
747 if(vsPlugin){
748 break;
749 }
750 }
751 doh.t(vsPlugin != null, "Checking for VS plugin.");
752 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
753 },
754 runTest: function(){
755 var d = new doh.Deferred();
756
757 //Timing gets wonky here, so we need to do this on a timeout
758 //so the browser has time to shift focus.
759 robot.sequence(d.getTestErrback(function(){
760 //Focus on the editor window
761 winUtils.scrollIntoView(editor0.domNode);
762 editor0.focus();
763 }), 500);
764
765 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
766
767 robot.sequence(d.getTestCallback(function(){
768 //Now check the state!
769 doh.t(vsPlugin._sourceShown, "Verifying the plugin believes the source is shown.");
770 doh.is("hidden", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is invisible");
771 doh.is("block", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is visible");
772 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
773 vsPlugin.sourceArea.value = "FOO";
774 doh.is("FOO", editor0.get("value"), "Verifying the source area returns foo when getValue is called.");
775 }), 3000);
776
777 return d;
778 },
779 tearDown: function(){
780 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
781 editor0.set("value", value);
782 fsPlugin = null;
783 vsPlugin = null;
784 }
785 },
786 {
787 name: "ViewSource: SetValue",
788 timeout: 20000,
789 setUp: function(){
790 editor0 = registry.byId("editor0");
791 value = editor0.get("value");
792 var edPlugins = editor0._plugins, i;
793 for(i = 0; i < edPlugins.length; i++){
794 var p = edPlugins[i];
795 if(p.declaredClass === "dijit._editor.plugins.ViewSource"){
796 vsPlugin = p;
797 }
798 if(vsPlugin){
799 break;
800 }
801 }
802 doh.t(vsPlugin != null, "Checking for VS plugin.");
803 if(vsPlugin){ vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
804 },
805 runTest: function(){
806 var d = new doh.Deferred();
807
808 //Timing gets wonky here, so we need to do this on a timeout
809 //so the browser has time to shift focus.
810 robot.sequence(d.getTestErrback(function(){
811 //Focus on the editor window
812 winUtils.scrollIntoView(editor0.domNode);
813 editor0.focus();
814 }), 500);
815
816 robot.keyPress(keys.F12, 1000, {ctrl:true,shift:true});
817
818 robot.sequence(d.getTestCallback(function(){
819 //Now check the state!
820 doh.t(vsPlugin._sourceShown, "Verifying the plugin believes the source is shown.");
821 doh.is("hidden", domStyle.get(editor0.iframe, "visibility"), "Verifying iframe is invisible");
822 doh.is("block", domStyle.get(vsPlugin.sourceArea, "display"), "Verifying source view node is visible");
823 doh.is(vsPlugin.sourceArea.nextSibling, editor0.iframe, "Verifying source view node's next sibling is the hidden iframe node.");
824 editor0.set("value", "FOO");
825 doh.is("FOO", editor0.get("value"), "Verifying the source area returns FOO when getValue is called.");
826 }), 3000);
827
828 return d;
829 },
830 tearDown: function(){
831 if(vsPlugin){vsPlugin.button.focus(); vsPlugin.button.set("checked", false);}
832 editor0.set("value", value);
833 fsPlugin = null;
834 vsPlugin = null;
835 }
836 }
837 ]);
838 doh.run();
839 });
840 </script>
841 </head>
842 </html>