summaryrefslogtreecommitdiff
path: root/includes/js/dojox/layout/tests/ContentPane.html
blob: cb3a9f6ca2a342e4c1acd900fae4a1f71c4d7b55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>dojox.layout.ContentPane test</title>
	<script >
	function fixPngIE6(){
		if(this.complete && dojo.isIE < 7){
			var r = this.runtimeStyle;
			if(/.png$/i.test(this.src)){
				r.height = this.height;
				r.width = this.width;
				r.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"');";
				this.src = this.currentStyle.backgroundImage.replace(/url\(\s*['"]?(.+?)['"]?\s*\)/, "$1");
			}
			this.className = this.className.replace('run_png_fix', "");
			r.behaviour = 'none';
		}
	}
	</script>
	<style type='text/css'>
		.run_png_fix {
			background-image:url(images/blank.gif);
			behaviour: expression(fixPngIE6.call(this));
		}
	</style>
	<script src='../../../dojo/dojo.js' djConfig='isDebug:true, parseOnLoad:true'></script>
	<script>
		dojo.require('doh.runner');
		dojo.require('dojox.layout.ContentPane');
		dojo.require('dojo.parser');
		dojo.require('dijit._Container');
		dojo.require('dijit._Templated');


		// create a do nothing, only for test widget
		dojo.declare("dojox.TestWidget",
			[dijit._Widget, dijit._Templated], {
			templateString: "<span class='dojoxTestWidget'></span>"
		});

		// used to test if we fire scrips to document scope
		function documentCallback(){
			arguments.callee.reached = true;
			//console.debug('reached');
		}
		var unTypedVarInDocScope; // a closure test to make sure we can reach this from evaled scripts


		var pane1, pane2;

		dojo.addOnLoad(function(){

			pane1 = dijit.byId('parsedPane');

			function ieTrimSpaceBetweenTags(str){
				return str.replace(/(<[a-z]*[^>]*>)\s*/ig, "$1");
			}
			function testHandle(t, handle){
				t.assertTrue(handle);
				t.assertTrue(dojo.isFunction(handle.cancel));
				t.assertTrue(dojo.isFunction(handle.addOnLoad));
				t.assertTrue(dojo.isFunction(handle.addOnUnload));
			}


			doh.register("basicChecks", [
					{
						name: 'setContent',
						runTest: function(t){
							var msg = "Simple Test";
							pane1.setContent(msg);
							t.assertEqual(msg, pane1.domNode.innerHTML);
						}
					},
					{
						name: 'setHref',
						timeout: 1800,
						runTest: function(t){
							var msg = "simple remote Test"
							pane1.setHref(dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?message='+encodeURI(msg)));

							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								t.assertEqual(msg, pane1.domNode.innerHTML)
							}), 1500);
							return d;
						}
					},
					{
						name: 'setContent_with_Widgets',
						runTest: function(t){
							var cont = "<div dojoType='dojox.TestWidget'>Test</div>";
							pane1.setContent(cont);
							t.assertFalse(cont.toLowerCase() == pane1.domNode.innerHTML.toLowerCase());
							t.assertEqual(1, dijit._Container.prototype.getChildren.call(pane1).length);
						}
					},
					{
						name: 'changeContentTRHead',
						runTest: function(t){
							var trHead = dojo.query('table#tableTest > thead > tr')[0];
							pane2 = new dojox.layout.ContentPane({} , trHead);
							var html = "<td><div>This</div>Should<u>Work</u></td>";
							pane2.setContent(html);
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
							t.assertEqual(html.toLowerCase(), res);
						},
						tearDown: function(){
							pane2.destroy();
						}
					},
					{
						name: 'changeContentTHead',
						runTest: function(t){
							var tHead = dojo.query('table#tableTest > thead')[0];
							pane2 = new dojox.layout.ContentPane({}, tHead);
							var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>";
							pane2.setContent(html);
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
							t.assertEqual(html.toLowerCase(), res);
						},
						tearDown: function(){
							pane2.destroy();
						}
					},
					{
						name: 'changeContentTRBody',
						runTest: function(t){
							var trBody = dojo.query('table#tableTest > tbody > tr')[0];
							pane2 = new dojox.layout.ContentPane({}, trBody);
							var html = "<td><div>This</div>Should<u>Work</u></td>";
							pane2.setContent(html);
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
							t.assertEqual(html.toLowerCase(), res);
						},
						tearDown: function(){
							pane2.destroy();
						}
					},
					{
						name: 'changeContentTBody',
						runTest: function(t){
							var tBody = dojo.query('table#tableTest > tbody')[0];
							pane2 = new dojox.layout.ContentPane({}, tBody);
							var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>";
							pane2.setContent(html);
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
							t.assertEqual(html.toLowerCase(), res);
						},
						tearDown: function(){
							pane2.destroy();
						}
					},
					{
						name: 'changeContentTable',
						runTest: function(t){
							var table = dojo.query('table#tableTest')[0];
							pane2 = new dojox.layout.ContentPane({}, table);
							var html = "<tbody><tr><td><div>This</div>Should<u>Work</u></td></tr></tbody>";
							pane2.setContent(html);
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
							t.assertEqual(html.toLowerCase(), res);
						},
						tearDown: function(){
							pane2.destroy();
						}
					},
					{
						name: 'ioArgsSetSyncLoad',
						timeout: 1500,
						runTest: function(t){
							pane1.ioArgs.sync = true;
							pane1.setHref(dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=sync'));

							// since it was a sync fetch it should be loaded here
							t.assertEqual('sync', pane1.domNode.innerHTML);
						},
						tearDown: function(){
							pane1.ioArgs = {}; // back to defaults
						}
					},
					{
						name: 'ioArgsSetsHeader',
						timeout: 1800,
						runTest: function(t){
							// test if we can set a custom header on every request
							pane1.ioArgs.headers = {'X-TestHeader': 'Testing'};
							pane1.setHref('remote/getResponse.php?mode=bounceHeaders');

							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								var cont = pane1.domNode.innerHTML;
								t.assertTrue(/X-TestHeader/i.test(cont));
								t.assertTrue(/Testing/i.test(cont));
							}), 1500);

							return d;
						},
						tearDown: function(){
							pane1.ioArgs = {}; // back to defaults
						}
					},
					{
						name: 'ioMethodPost',
						timeout: 1800,
						runTest: function(t){
							// test to post some content on each request
							pane1.ioMethod = dojo.xhrPost;
							pane1.ioArgs.content = {test:'it should work'};
							pane1.setHref('remote/getResponse.php?mode=bounceInput');

							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('test=it%20should%20work', pane1.domNode.innerHTML);
							}), 1500);
							return d;
						},
						tearDown: function(){
							// back to defaults
							pane1.ioMethod = dojo.xhrGet;
							pane1.ioArgs = {};
						}
					},
					{
						name: 'handleFrom_setContent',
						runTest: function(t){
							var unLoadCalled, loadCalled;
							var handle = pane1.setContent("test 'var handle = setContent()'");
							testHandle(t, handle);

							handle.addOnLoad(function(){
								loadCalled = true;
							});

							t.assertTrue(loadCalled);

							handle.addOnUnload(function(){
								unLoadCalled = true;
							});

							// test unLoad callback above
							handle = pane1.setContent("testing 'addOnUnload(callback)'");
							t.assertTrue(unLoadCalled);
							testHandle(t, handle);
						}
					},
					{
						name: 'handleFrom_setHref_and_refresh_and_cancelWorking',
						timeout: 3400,
						runTest: function(t){
							var unloadCalled, loadCalled;
							var r_unloadCalled, r_loadCalled;
							var r_handle, href = dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=test');

							var handle = pane1.setHref(href);
							testHandle(t, handle);
							handle.addOnLoad(function(){
								loadCalled = 'loadCalled';
							});
							handle.addOnUnload(function(){
								unloadCalled = 'unloadCalled';
							});

							handle.cancel();

							setTimeout(function(){
								pane1.href = href;
								handle = pane1.refresh();
								testHandle(t, handle); // might throw and kill rest of test, infact we rely on that
								r_handle = 'refreshHandle ok';
								handle.addOnLoad(function(){
									r_loadCalled = 'refresh loadCalled';
									pane1.setContent(); // trigger unload
								});
								handle.addOnUnload(function(){
									r_unloadCalled = 'refresh unloadCalled';
								});
							}, 1500); // wait for page load in case cancel didn't work

							var d = new t.Deferred();

							setTimeout(d.getTestCallback(function(){
								// load from the href (was canceled)
								t.assertEqual(undefined, loadCalled);
								t.assertEqual(undefined, unloadCalled);

								// load from the refresh
								t.assertEqual('refreshHandle ok', r_handle);
								t.assertEqual('refresh loadCalled', r_loadCalled);
								t.assertEqual('refresh unloadCalled', r_unloadCalled);
							}), 3200);

							return d;
						}
					},
					{
						name: 'onLoadDeferred|onUnloadDeferred_call_order',
						timeout: 6200,
						runTest: function(t){
							pane1.preventCache = 1;
							var count = {u: 0, l: 0}; // need a object for the ref in closures
							var href = dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=test').toString();
		

							function next(){
								if(!isNaN(count.u) && !isNaN(count.l)){
									if(count.u < 4 && count.l < 4){
										pane1.setHref(href);
										pane1.onLoadDeferred.addCallback(makeCallback('l', 'u', 1));
										pane1.onUnloadDeferred.addCallback(makeCallback('u', 'l', 0));
									}else{
										pane1.setContent(); // unload to get even
									}
								}
							}

							function makeCallback(tryVar, compareVar, inc){
								return function(){
									//console.debug(tryVar, count[tryVar] + 1, count[compareVar] + inc)
									if((++count[tryVar]) === (count[compareVar] + inc)){
										count[tryVar];
										if(tryVar == 'l'){
											next(); // onload event, trigger new load
										}
									}else{
										tryVar = 'failed '+(tryVar=='u'?'unload':'load')+' on '+count[tryVar]+' try';
									}
								}
							}
							
							next(); // starts the loop
	
							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								t.assertEqual(4, count.l);
								t.assertEqual(4, count.u)
							}), 6000); // 1.5 sec max on each load should be enough
							return d;
						},
						tearDown: function(){
							delete pane1.preventCache;
						}
					}
				]
			);


			doh.register("pathAdjustments",
				[
					{
						name: 'cssPathAdjustments',
						runTest: function(t){

							// we do this test as one big string to emulate as good as possible, 
							// but split it later to easily see where we failed
							var cssText = ".easy{ background-image:url(images/image.png) }\n"
							+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n"
							+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\"  \t);}body{};\n"
							+".file{background-image: url(file:///home/nobody/image.png);}\n"
							+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
							+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
							+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
							+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n"
							+"@import 'http://dojotoolkit.org/dojo.css';\n"
							+"  @import 'you/never/thought/' print;\n"
							+' @import url("it/would/work") tv, screen;'+"\n"
							+' @import url(/did/you/now.css);'+"\n"
							+' @import "yes.i.did";';

							pane1.href = "deep/nested/file";
							pane1.adjustPaths = 1;
							pane1.renderStyles = 1;
							var adjustedCss;

							// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
							var oldFunc = pane1._renderStyles;
							return function(styles){
								adjustedCss = styles.join();
							}
							pane1._setContent.call(pane1, '<style>'+cssText+'</style>');
							pane1._renderStyles = oldFunc;

							adjustedCss = adjustedCss.split("\n");

							var expectedCss = (".easy{ background-image:url(deep/nested/images/image.png) }\n"
							+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n"
							+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n"
							+".file{background-image: url(file:///home/nobody/image.png);}\n"
							+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
							+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
							+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
							+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n"
							+"@import 'http://dojotoolkit.org/dojo.css';\n"
							+"  @import \"deep/nested/you/never/thought/\" print;\n"
							+' @import url(deep/nested/it/would/work) tv, screen;'+"\n"
							+' @import url(/did/you/now.css);'+"\n"
							+' @import "deep/nested/yes.i.did";').split("\n");

							// we split and loop to get a faster hint of where it failed
							for(var i = 0; i < expectedCss.length; i++){
								t.assertEqual(expectedCss[i], adjustedCss[i]);
							}
						},
						tearDown: function(){
							delete pane1.adjustPaths; // get back to defaults
							delete pane1.renderStyles;
						}
					},
					{
						name: 'htmlPathAdjustments',
						timeout: 1800,
						runTest: function(t){

							var d = new t.Deferred();
							setTimeout(d.getTestCallback(
								function(){
									// check that images and styles have been applied
									var cb = dojo.contentBox(dojo.byId('imgTest'));
											//dojo.getComputedStyle(dojo.byId('imgTest'));
									t.assertEqual(188, cb.w);
									t.assertEqual(125, cb.h);

									// make sure we didn't mess up the other inline styles
									cb = dojo.contentBox(dojo.byId('inlineStyleTest'));
									t.assertEqual(188, cb.w);
									t.assertEqual(125, cb.h);

									// make sure it is the correct image
									var cs = dojo.getComputedStyle(dojo.byId('inlineStyleTest'));
									var url = cs.backgroundImage;
									//remove url(..)
									url = url.replace(/^\s?url\(['"]?/, "").replace(/['"]?\);?\s?$/, ""); 
									// compare image url to full path of this document
									imageUrl = dojo.moduleUrl('dojox', 'layout/tests/images/testImage.gif');
									t.assertEqual(new dojo._Url(document.location, imageUrl), url);

									// make sure we loaded the <link rel='stylesheet' correctly
									var mb = dojo.marginBox(dojo.byId('linkCssTest'));
									t.assertEqual(112, mb.w); // 100px  + 2px border + 4px margin = 112px
									t.assertEqual(112, mb.h);

									// make sure we loaded the <style>@import '...'; correctly
									mb = dojo.marginBox(dojo.byId('importCssTest'));
									t.assertEqual(110, mb.w); // 100px + 1px border + 4px margin = 110px
									t.assertEqual(110, mb.h);

									// make sure we didn't render the <link media='print' rel='stylesheet'
									var mb = dojo.marginBox(dojo.byId('linkMediaTest'));
									t.assertEqual(212, mb.w); // 100px  + 2px border + 4px margin = 112px
									t.assertEqual(212, mb.h);

									// make sure we didn't render the <style media='print'>@import '...';
									mb = dojo.marginBox(dojo.byId('importMediaTest'));
									t.assertEqual(210, mb.w); // 100px + 1px border + 4px margin = 110px
									t.assertEqual(210, mb.h);
								}
							), 1500);

							pane1.adjustPaths = 1;pane1.renderStyles = 1;
							pane1.setHref('remote/getResponse.php?mode=htmlPaths');
							return d;
						},
						tearDown: function(){
							delete pane1.adjustPaths; // get back to defaults
							delete pane1.renderStyles;
						}
					},
					{
						name: 'renderStylesOfByDefaultAndOldDeleted',
						timeout: 1800,
						runTest: function(t){
							var d = new t.Deferred();

							setTimeout(d.getTestCallback(
								function(){
									// innerHTML'ing <link tags works in some browser (IE, moz), but not all
									// we can't test if LINK was loaded this way

									// make sure we didn't load the <link rel='stylesheet'
									//var mb = dojo.marginBox(dojo.byId('linkCssTest'));
									//t.assertFalse(112 == mb.w);
									//t.assertFalse(112 == mb.h);

									// make sure we didn't load the <style>@import '...';
									var mb = dojo.marginBox(dojo.byId('importCssTest'));
									t.assertFalse(110 == mb.w);
									t.assertFalse(110 == mb.h);
								}
							), 1500);
							pane1.adjustPaths = 1;
							pane1.setHref('remote/getResponse.php?mode=htmlPaths');
							return d;
						},
						tearDown: function(){
							delete pane1.adjustPaths;
						}
					}
				]
			);

			doh.register("scriptTests",
				[
					"t.assertTrue(pane1.executeScripts);",
					{
						name: 'leaveDojoMethodScriptsAsIs',
						runTest: function(t){
							pane1.setContent("<"
								+"script type='dojo/method'>unTypedVarInDocScope = 'failure';<"
								+"/script>");

							var d = new t.Deferred();
							// IE req to async this test
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('undefined', typeof unTypedVarInDocScope);
								t.assertFalse(unTypedVarInDocScope == 'failure');
							}), 40);

							return d;
						}
					},
					{
						name: 'scripts_evals_in_global_scope',
						timeout: 1800, // grabing remote js, wait for that
						runTest: function(t){
							pane1.setContent("<"
								+"script>function scriptsInGlobalClicked(){ documentCallback(); }<"
								+"/script><"+"script src='remote/getResponse.php?mode=remoteJsTrue'></"
								+"script>"+"<a href='javascript:scriptsInGlobalClicked()' "
									+"onfocus='scriptsInGlobalClicked();' id='anchorTag'>test</a>");

							var link = dojo.byId('anchorTag');
							dojo.isFunction(link.click) ? /*others*/ link.click() : /*moz*/ link.focus();
							var d = new t.Deferred();
					
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('boolean', typeof documentCallback.reached);
								t.assertTrue(documentCallback.reached);
								t.assertTrue(unTypedVarInDocScope);
							}), 40);
							return d;
						}
					},
					{
						name:'scriptsEvalsInOrder',
						timeout: 1800,// grabing remote js, wait for that
						runTest: function(t){
							pane1.setContent("<"
								+"script src='remote/getResponse.php?mode=remoteJsFalse'><"
								+"/script><"+"script>unTypedVarInDocScope = 1;<"
								+"/script>"); // scripts only test

							// we need to make this async because of IEs strange events loops
							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('number', typeof unTypedVarInDocScope);
								t.assertEqual(1, unTypedVarInDocScope);
							}), 40);
							return d;
						}
					},
					{
						name: 'scriptsWithTypeTextJavascript',
						runTest: function(t){
							pane1.setContent("<"
								+"script type='text/javascript'> unTypedVarInDocScope = 'text/javascript'; <"
								+"/script>");

							var d = new t.Deferred();
							// IE needs async here
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('text/javascript', unTypedVarInDocScope);
							}), 40);
							return d;
						}
					},
					{
						name:'scriptsWithHtmlComments',
						runTest: function(t){
							pane1.cleanContent = 1;
							pane1.setContent("<"
								+"script><!-- unTypedVarInDocScope = 2; --><"
								+"/script>");

							var d = new t.Deferred();
							// IE need a async here
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('number', typeof unTypedVarInDocScope);
								t.assertEqual(2, unTypedVarInDocScope);
							}), 40);

							return d;
						},
						tearDown: function(){
							delete pane1.cleanContent; // go back to default
						}
					},
					{
						name:'scriptsWithCData',
						runTest: function(t){
							pane1.cleanContent = 1;
							pane1.setContent("<"
								+"script><![CDATA[ unTypedVarInDocScope = 3; ]]><"
								+"/script>");

							var d = new t.Deferred();
							// IE need a async here
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('number', typeof unTypedVarInDocScope);
								t.assertEqual(3, unTypedVarInDocScope);
							}), 40);

							return d;
						},
						tearDown: function(){
							delete pane1.cleanContent; // go back to default
						}
					},
					{
						name: 'replace_container_with_dijit.byId()',
						runTest: function(t){
							unTypedVarInDocScope = 'failure';
							pane1.scriptHasHooks = true;
							pane1.setContent("<"
							+"script>function testReplace(){"
							+	"if(typeof _container_ != 'object'){return 'not replaced 1';}\n"
							+	"if(_container_ != pane1){ return 'not replaced 2';}\n"
							+	"if(!_container_ == pane1){ return 'not replaced 3';}\n"
							+	"var tmp =_container_=dojo;\n"
							+	"if(tmp != dojo){ return 'replaced when shouldnt 1';}\n"
							+	"var tmp = _container_  \t \t = dojo;\n"
							+	"if(tmp != dojo){ return 'replaced when shouldnt 2';}\n"
							+	"return 'success';\n"
							+"};\n"
							+"unTypedVarInDocScope = testReplace();"
							+"</"+"script>");

							// let IE inhale here
							var d = new t.Deferred();
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('success', unTypedVarInDocScope);
							}), 40);
							return d;
						},
						tearDown: function(){
							delete pane1.scriptHasHooks; // get back to default
						}
					},
					{
						name:'_container_onLoadDeferred|onUnloadDeferred',
						runTest: function(t){
							pane1.scriptHasHooks = true;
							pane1.setContent("<"
								+"script>"
								+"var testConn;"
								+"_container_.onLoadDeferred.addCallback(function(){"
								+	"testConn = dojo.connect(dojo.byId('testForm'), 'onsubmit', null, function(){"
								+		"unTypedVarInDocScope = dojo.byId('testInput').value;"
								+	"});"
								+	"dojo.byId('testButton').click();"
								+"});"
								+"_container_.onUnloadDeferred.addCallback(function(){"
								+		"unTypedVarInDocScope = 'unloaded';"
								+	"dojo.disconnect(testConn);"
								+"});"
								+"<"+"/script><form onsubmit='return false;' id='testForm'>"
								+	"<input id='testInput' value='loaded'/>"
								+	"<input type='submit' id='testButton'/>"
								+"</form>");

							var d = new t.Deferred();
							// IE must breathe here
							setTimeout(d.getTestCallback(function(){
								t.assertEqual('loaded', unTypedVarInDocScope);
							}), 40);
							return d;
						},
						tearDown: function(){
							delete pane1.scriptHasHooks; // get back to default
							pane1.setContent();
						}
					},
					"t.assertEqual('unloaded', unTypedVarInDocScope)"
				]
			);


			doh.register('regexRegressionAndSpeedtest',[
				{
					name: 'cssPathAdjustments',
					runTest: function(t){
						// we do this test as one big string to emulate as good as possible, 
						// but split it later to easily see where we failed
						var cssText = ".easy{ background-image:url(images/image.png) }\n"
						+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n"
						+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\"  \t);}body{};\n"
						+".file{background-image: url(file:///home/nobody/image.png);}\n"
						+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
						+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
						+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
						+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n"
						+"@import 'http://dojotoolkit.org/dojo.css';\n"
						+"  @import 'you/never/thought/' print;\n"
						+' @import url("it/would/work") tv, screen;'+"\n"
						+' @import url(/did/you/now.css);'+"\n"
						+' @import "yes.i.did";';

						var expectedCss = ".easy{ background-image:url(deep/nested/images/image.png) }\n"
						+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n"
						+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n"
						+".file{background-image: url(file:///home/nobody/image.png);}\n"
						+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
						+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
						+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
						+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n"
						+"@import 'http://dojotoolkit.org/dojo.css';\n"
						+"  @import \"deep/nested/you/never/thought/\" print;\n"
						+' @import url(deep/nested/it/would/work) tv, screen;'+"\n"
						+' @import url(/did/you/now.css);'+"\n"
						+' @import "deep/nested/yes.i.did";';

						for(var i = 0; i < 6; i++){
							cssText += cssText;
							expectedCss += expectedCss;
						}

						expectedCss = expectedCss.split("\n");

						pane1.href = "deep/nested/file";
						pane1.adjustPaths = 1;
						pane1.renderStyles = 1;
						var adjustedCss;

						// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
						var oldFunc = pane1._renderStyles;
						pane1._renderStyles = function(styles){
							adjustedCss = styles.join();
						}

						var start = new Date();
						pane1._setContent.call(pane1, '<style>'+cssText+'</style>');
						var end = new Date();
						pane1._renderStyles = oldFunc;

						adjustedCss = adjustedCss.split("\n");
						console.info('Time used to regex scan css and adjust relative paths within css:'+
								(end - start)+' ms on '+ cssText.split('\n').length
								+' css rows, with '+ cssText.length+' characters (roughly '
								+Math.round(cssText.length/1024)+ 'Kb) of infile css')

						// we split and loop to get a faster hint of where it failed
						for(var i = 0; i < expectedCss.length; i++){
							t.assertEqual(expectedCss[i], adjustedCss[i]);
						}
					},
					tearDown: function(){
						delete pane1.adjustPaths; // get back to defaults
						delete pane1.renderStyles;
						pane1.href = "";
					}
				}
				,
				{
					name:'htmlPathsSpeedTest',
					runTest: function(t){
						var htmlText = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
							+"<title>should be removed</title>\n"
							+"<img src=\"images/image.gif\"/>Testing\n"
							+"<a href=\"../../topmost.html\">\n"
							+"	<img src=\"/siteroot/top.html\">\n"
							+"	<p style='background:url(\"images/back.png\")'>\n"
							+"	testing link\n"
							+"</p></a>\n"
							+"<style \ntype='text/css'>\n"
							+"	@import 'http://dojotoolkit.org/visible.css' tv, screen;\n"
							+"	@import \"./audio.css\" audio;\n"
							+"	@import url(/topsite/css/main.css);\n"
							+"	div.mywidget, #someId {\n"
							+"		background-color:url(../../css/main.css);"
							+"		display:none;\n"
							+"		background:url(../tmp/css)\n"
							+"	}\n"
							+"</style>\n"
							+"<link rel=\"stylesheet\" href=\"../../css/theme.css\" media=\"all\">\n"
							+"<link media='print' type='text/css' rel='stylesheet' href='../../css/theme2.css'/>\n"
							+"<a style='display:block; background:url(/topmost/css)' href='../above'>above</a>\n"
							+"<sc"+"ript type=\"text/javascript\"\n src=\"..\\windows\\morons\"></scr"+"ipt>\n"
							+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n"
							+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n"
							+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n"
							+"<scr"+"ipt>JS CODE</scr"+"ipt>\n"
							+"<a href='javascript:void(0)'>void</a>";


						pane1.href = 'deep/nested/file';

						var expectedHtml = "\n\n<img src=\"deep/nested/images/image.gif\"/>Testing\n"
							+"<a href=\"topmost.html\">\n"
							+"	<img src=\"/siteroot/top.html\">\n"
							+"	<p style='background:url(deep/nested/images/back.png)'>\n"
							+"	testing link\n"
							+"</p></a>\n"
							+"\n"
							+"\n\n"
							+"<a style='display:block; background:url(/topmost/css)' href='deep/above'>above</a>\n\n"
							+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n"
							+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n"
							+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n\n"
							+"<a href='javascript:void(0)'>void</a>";


						var expectedCss = [
							"\n	@import 'http://dojotoolkit.org/visible.css' tv, screen;\n"
							+"	@import \"deep/nested/audio.css\" audio;\n"
							+"	@import url(/topsite/css/main.css);\n"
							+"	div.mywidget, #someId {\n"
							+"		background-color:url(css/main.css);"
							+"		display:none;\n"
							+"		background:url(deep/tmp/css)\n"
							+"	}\n", "@import \"css/theme.css\";", "@import \"css/theme2.css\";"];

						for(var i = 0; i < 6; i++){
							htmlText += htmlText;
							expectedHtml += expectedHtml;
							expectedCss = expectedCss.concat(expectedCss);
						}


						pane1.href = "deep/nested/file";
						pane1.adjustPaths = 1;
						pane1.renderStyles = 1;
						pane1.cleanContent = 1;
						var adjustedCss, adjustedHtml;

						// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
						var oldFunc = pane1._renderStyles;
						pane1._renderStyles = function(styles){
							adjustedCss = styles;
							pane1.executeScripts = 0;
						}

						var oldSetFunc = dijit.layout.ContentPane.prototype._setContent;
						dijit.layout.ContentPane.prototype._setContent = function(html){
							adjustedHtml = html;
						}

						var oldXhr = dojo.xhrGet;
						dojo.xhrGet = function(){}; // kill script download

						var start = new Date();
						pane1._setContent.call(pane1, htmlText);
						var end = new Date();

						// reset back to the way it was
						pane1._renderStyles = oldFunc;
						dijit.layout.ContentPane.prototype._setContent = oldSetFunc;
						dojo.xhrGet = oldXhr;

						console.info('Time used to regex scan html/css and\n adjust relative paths (adjustPaths=true),\n copy scripts (executeScripts=true) and copy css innerText (renderStyles=true) and adjust paths in there \nTime:'+
								(end - start)+' ms on '+ htmlText.split('\n').length
								+' html rows, with '+ htmlText.length+' characters (roughly '
								+Math.round(htmlText.length/1024)+ 'Kb)');

						// we split and loop to get a faster hint of where it failed
						adjustedHtml = adjustedHtml.split("\n");
						expectedHtml = expectedHtml.split("\n");

						for(var i = 0; i < expectedHtml.length; i++){
							//console.debug(expectedHtml[i], i);
							//console.debug(adjustedHtml[i], i);
							t.assertEqual(expectedHtml[i], adjustedHtml[i]);
						}

						var exCssBlock, adjCssBlock;
						for(var i = 0; i < expectedCss.length; i++){
							t.assertEqual('string', typeof adjustedCss[i]);

							exCssBlock = expectedCss[i].split('\n');
							adjCssBlock = adjustedCss[i].split('\n');

							for(var j = 0; j < exCssBlock.length;j++){
								t.assertEqual(dojo.trim(exCssBlock[j]), dojo.trim(adjCssBlock[j]));
							}
							
						}
					},
					tearDown: function(){
						delete pane1.cleanContent;
						delete pane1.adjustPaths;
						delete pane1.renderStyles;
						delete pane1.executeScripts;
					}
				}
				,
				{
					name:'IE_AlphaImageLoader_PathAdjustments',
					runTest: function(t){
						if(!dojo.isIE){
							console.info('aborting test IE_AlphaImageLoader_PathAdjustments, you dont use IE');
							return;
						}

						pane1.adjustPaths = 1;
						pane1.renderStyles = 1;

						pane1.href = "deep/";

						var html = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n"
						+" alpha png in IE 6 --></div>\n"
						+"<style>\n"
						+"	.ie_menu_png {"
						+"		filter: \t progid:\n"
						+"			DXImageTransform.Microsoft.AlphaImageLoader(\n"
						+"			src='../midlevel/alpha(2).png')\n"
						+"	}\n"
						+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n"
						+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n"
						+"</style>\n";


						var expectedHtml = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"deep/images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n"
						+" alpha png in IE 6 --></div>\n\n";

						var expectedCss = "\n"
						+"	.ie_menu_png {"
						+"		filter: \t progid:\n"
						+"			DXImageTransform.Microsoft.AlphaImageLoader(\n"
						+"			src='midlevel/alpha(2).png')\n"
						+"	}\n"
						+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n"
						+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n";


						for(var i = 0; i < 7; i++){
							html += html;	
							expectedHtml += expectedHtml;
							expectedCss += expectedCss;
						}

						var adjustedHtml, adjustedCss;

						// hijack internals to snatch the content
						var oldRenderStyles = pane1._renderStyles;
						var oldSetContent = dijit.layout.ContentPane.prototype._setContent;
						pane1._renderStyles = function(styles){ adjustedCss = styles.join(''); };
						dijit.layout.ContentPane.prototype._setContent = function(cont){ adjustedHtml = cont; }

						var start = new Date();
						pane1._setContent.call(pane1, html);
						var end = new Date();

						console.info('Time used to replace AlphaImageLoader(src="...") '
									+(end - start) + "ms in HTML with "+html.length
									+' characters (roughly '+(Math.round(html.length/1024))+'Kb)');

						// reset hijacked
						pane1._renderStyles = oldRenderStyles;
						dijit.layout.ContentPane.prototype._setContent = oldSetContent;


						// split on newline and run a check on each row to help debugging
						expectedHtml = expectedHtml.split("\n");
						adjustedHtml = adjustedHtml.split("\n");
						for(var i = 0; i < expectedHtml.length; i++){
							t.assertEqual(expectedHtml[i], adjustedHtml[i]);
						}

						expectedCss = expectedCss.split("\n");
						adjustedCss = adjustedCss.split("\n");
						for(var i = 0; i < expectedCss.length; i++){
							t.assertEqual(expectedCss[i], adjustedCss[i]);
						}
						
					},
					tearDown: function(){
						delete pane1.renderStyles;
						delete pane1.adjustPaths;
					}
				}
			]);

			doh.register("A_AlphaImageLoader_inAction", [{
				name:"AlphaLoaderShowHow",
				runTest:function(t){
				// IE filter alphaimageloader paths must be relative to the page
				// not to the cssFile that declares it

				// demo a much better way of "Fixing" alpha png in IE6 than inlining in html
				var html = "<img src='images/dojoLogo.png' class='run_png_fix'/>"

				var showHowHtml = "<pre >\nCode used in IE transparent png example\n"
							+"code (declared in main page, not through ContentPane)\n"
							+"&lt;script type='text/javascript'&gt;\n"
							+fixPngIE6.toString().replace(/\n\t?/g, "\n")
							+"\n&lt;/script&gt;\n"
							+"&lt;style type='text/css'&gt;\n"
							+"	.run_png_fix {\n"
							+"		background-image:url(images/blank.gif);\n"
							+"		behaviour: expression(fixPngIE6.call(this));\n"
							+"	}\n"
							+"&lt;/style&gt;\n\n...\n\nHtml feeded to ContentPane (or your main page):\n"
							+"&lt;img src='images/dojoLogo.png' class='run_png_fix'/&gt;\n</pre>";

				pane1.executeScripts = 1;
				pane1.renderStyles = 1;
				pane1.setContent(html+showHowHtml);
				

				}
			}]);

			doh.run();
		});
	</script>
	<style>
		@import "../../../dojo/resources/dojo.css";
		@import "../../../dijit/themes/tundra/tundra.css";
		@import "../../../dijit/tests/css/dijitTests.css";

		.box {
			border: 1px solid black;
			height: 190px;
			width: 80%;
			overflow: auto;
		}

		.red {
			color: red;
		}

		.dojoxTestWidget {
			border: 1px dashed red;
			background-color: #C0E209 ;
		}
	</style>
</head>
<body class='tundra'>
	<h1>dojox.layout.ContentPane</h1>
	<h3>As dojox ContentPane is derived from dijit ContentPane, make sure that the dijit test passes before running this test</h3>
	<h3 class='red'>Test relies on a php page as backend, so you need php installed on your server</h3>

	<div class='box' dojoType="dojox.layout.ContentPane" id='parsedPane'>
		Initial value
	</div>

	<table id='tableTest' class='box'>
		<thead>
			<tr>
				<td></td>
			</tr>
		</thead>
		<tbody>
			<tr>
				<td></td>
			</tr>
		<tbody>
	</table>
</body>
</html>