Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 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>dojox.layout.ContentPane test</title>
6
	<script >
7
	function fixPngIE6(){
8
		if(this.complete && dojo.isIE < 7){
9
			var r = this.runtimeStyle;
10
			if(/.png$/i.test(this.src)){
11
				r.height = this.height;
12
				r.width = this.width;
13
				r.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"');";
14
				this.src = this.currentStyle.backgroundImage.replace(/url\(\s*['"]?(.+?)['"]?\s*\)/, "$1");
15
			}
16
			this.className = this.className.replace('run_png_fix', "");
17
			r.behaviour = 'none';
18
		}
19
	}
20
	</script>
21
	<style type='text/css'>
22
		.run_png_fix {
23
			background-image:url(images/blank.gif);
24
			behaviour: expression(fixPngIE6.call(this));
25
		}
26
	</style>
27
	<script src='../../../dojo/dojo.js' djConfig='isDebug:true, parseOnLoad:true'></script>
28
	<script>
29
		dojo.require('doh.runner');
30
		dojo.require('dojox.layout.ContentPane');
31
		dojo.require('dojo.parser');
32
		dojo.require('dijit._Container');
33
		dojo.require('dijit._Templated');
34
 
35
 
36
		// create a do nothing, only for test widget
37
		dojo.declare("dojox.TestWidget",
38
			[dijit._Widget, dijit._Templated], {
39
			templateString: "<span class='dojoxTestWidget'></span>"
40
		});
41
 
42
		// used to test if we fire scrips to document scope
43
		function documentCallback(){
44
			arguments.callee.reached = true;
45
			//console.debug('reached');
46
		}
47
		var unTypedVarInDocScope; // a closure test to make sure we can reach this from evaled scripts
48
 
49
 
50
		var pane1, pane2;
51
 
52
		dojo.addOnLoad(function(){
53
 
54
			pane1 = dijit.byId('parsedPane');
55
 
56
			function ieTrimSpaceBetweenTags(str){
57
				return str.replace(/(<[a-z]*[^>]*>)\s*/ig, "$1");
58
			}
59
			function testHandle(t, handle){
60
				t.assertTrue(handle);
61
				t.assertTrue(dojo.isFunction(handle.cancel));
62
				t.assertTrue(dojo.isFunction(handle.addOnLoad));
63
				t.assertTrue(dojo.isFunction(handle.addOnUnload));
64
			}
65
 
66
 
67
			doh.register("basicChecks", [
68
					{
69
						name: 'setContent',
70
						runTest: function(t){
71
							var msg = "Simple Test";
72
							pane1.setContent(msg);
73
							t.assertEqual(msg, pane1.domNode.innerHTML);
74
						}
75
					},
76
					{
77
						name: 'setHref',
78
						timeout: 1800,
79
						runTest: function(t){
80
							var msg = "simple remote Test"
81
							pane1.setHref(dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?message='+encodeURI(msg)));
82
 
83
							var d = new t.Deferred();
84
							setTimeout(d.getTestCallback(function(){
85
								t.assertEqual(msg, pane1.domNode.innerHTML)
86
							}), 1500);
87
							return d;
88
						}
89
					},
90
					{
91
						name: 'setContent_with_Widgets',
92
						runTest: function(t){
93
							var cont = "<div dojoType='dojox.TestWidget'>Test</div>";
94
							pane1.setContent(cont);
95
							t.assertFalse(cont.toLowerCase() == pane1.domNode.innerHTML.toLowerCase());
96
							t.assertEqual(1, dijit._Container.prototype.getChildren.call(pane1).length);
97
						}
98
					},
99
					{
100
						name: 'changeContentTRHead',
101
						runTest: function(t){
102
							var trHead = dojo.query('table#tableTest > thead > tr')[0];
103
							pane2 = new dojox.layout.ContentPane({} , trHead);
104
							var html = "<td><div>This</div>Should<u>Work</u></td>";
105
							pane2.setContent(html);
106
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
107
							t.assertEqual(html.toLowerCase(), res);
108
						},
109
						tearDown: function(){
110
							pane2.destroy();
111
						}
112
					},
113
					{
114
						name: 'changeContentTHead',
115
						runTest: function(t){
116
							var tHead = dojo.query('table#tableTest > thead')[0];
117
							pane2 = new dojox.layout.ContentPane({}, tHead);
118
							var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>";
119
							pane2.setContent(html);
120
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
121
							t.assertEqual(html.toLowerCase(), res);
122
						},
123
						tearDown: function(){
124
							pane2.destroy();
125
						}
126
					},
127
					{
128
						name: 'changeContentTRBody',
129
						runTest: function(t){
130
							var trBody = dojo.query('table#tableTest > tbody > tr')[0];
131
							pane2 = new dojox.layout.ContentPane({}, trBody);
132
							var html = "<td><div>This</div>Should<u>Work</u></td>";
133
							pane2.setContent(html);
134
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
135
							t.assertEqual(html.toLowerCase(), res);
136
						},
137
						tearDown: function(){
138
							pane2.destroy();
139
						}
140
					},
141
					{
142
						name: 'changeContentTBody',
143
						runTest: function(t){
144
							var tBody = dojo.query('table#tableTest > tbody')[0];
145
							pane2 = new dojox.layout.ContentPane({}, tBody);
146
							var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>";
147
							pane2.setContent(html);
148
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
149
							t.assertEqual(html.toLowerCase(), res);
150
						},
151
						tearDown: function(){
152
							pane2.destroy();
153
						}
154
					},
155
					{
156
						name: 'changeContentTable',
157
						runTest: function(t){
158
							var table = dojo.query('table#tableTest')[0];
159
							pane2 = new dojox.layout.ContentPane({}, table);
160
							var html = "<tbody><tr><td><div>This</div>Should<u>Work</u></td></tr></tbody>";
161
							pane2.setContent(html);
162
							var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase());
163
							t.assertEqual(html.toLowerCase(), res);
164
						},
165
						tearDown: function(){
166
							pane2.destroy();
167
						}
168
					},
169
					{
170
						name: 'ioArgsSetSyncLoad',
171
						timeout: 1500,
172
						runTest: function(t){
173
							pane1.ioArgs.sync = true;
174
							pane1.setHref(dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=sync'));
175
 
176
							// since it was a sync fetch it should be loaded here
177
							t.assertEqual('sync', pane1.domNode.innerHTML);
178
						},
179
						tearDown: function(){
180
							pane1.ioArgs = {}; // back to defaults
181
						}
182
					},
183
					{
184
						name: 'ioArgsSetsHeader',
185
						timeout: 1800,
186
						runTest: function(t){
187
							// test if we can set a custom header on every request
188
							pane1.ioArgs.headers = {'X-TestHeader': 'Testing'};
189
							pane1.setHref('remote/getResponse.php?mode=bounceHeaders');
190
 
191
							var d = new t.Deferred();
192
							setTimeout(d.getTestCallback(function(){
193
								var cont = pane1.domNode.innerHTML;
194
								t.assertTrue(/X-TestHeader/i.test(cont));
195
								t.assertTrue(/Testing/i.test(cont));
196
							}), 1500);
197
 
198
							return d;
199
						},
200
						tearDown: function(){
201
							pane1.ioArgs = {}; // back to defaults
202
						}
203
					},
204
					{
205
						name: 'ioMethodPost',
206
						timeout: 1800,
207
						runTest: function(t){
208
							// test to post some content on each request
209
							pane1.ioMethod = dojo.xhrPost;
210
							pane1.ioArgs.content = {test:'it should work'};
211
							pane1.setHref('remote/getResponse.php?mode=bounceInput');
212
 
213
							var d = new t.Deferred();
214
							setTimeout(d.getTestCallback(function(){
215
								t.assertEqual('test=it%20should%20work', pane1.domNode.innerHTML);
216
							}), 1500);
217
							return d;
218
						},
219
						tearDown: function(){
220
							// back to defaults
221
							pane1.ioMethod = dojo.xhrGet;
222
							pane1.ioArgs = {};
223
						}
224
					},
225
					{
226
						name: 'handleFrom_setContent',
227
						runTest: function(t){
228
							var unLoadCalled, loadCalled;
229
							var handle = pane1.setContent("test 'var handle = setContent()'");
230
							testHandle(t, handle);
231
 
232
							handle.addOnLoad(function(){
233
								loadCalled = true;
234
							});
235
 
236
							t.assertTrue(loadCalled);
237
 
238
							handle.addOnUnload(function(){
239
								unLoadCalled = true;
240
							});
241
 
242
							// test unLoad callback above
243
							handle = pane1.setContent("testing 'addOnUnload(callback)'");
244
							t.assertTrue(unLoadCalled);
245
							testHandle(t, handle);
246
						}
247
					},
248
					{
249
						name: 'handleFrom_setHref_and_refresh_and_cancelWorking',
250
						timeout: 3400,
251
						runTest: function(t){
252
							var unloadCalled, loadCalled;
253
							var r_unloadCalled, r_loadCalled;
254
							var r_handle, href = dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=test');
255
 
256
							var handle = pane1.setHref(href);
257
							testHandle(t, handle);
258
							handle.addOnLoad(function(){
259
								loadCalled = 'loadCalled';
260
							});
261
							handle.addOnUnload(function(){
262
								unloadCalled = 'unloadCalled';
263
							});
264
 
265
							handle.cancel();
266
 
267
							setTimeout(function(){
268
								pane1.href = href;
269
								handle = pane1.refresh();
270
								testHandle(t, handle); // might throw and kill rest of test, infact we rely on that
271
								r_handle = 'refreshHandle ok';
272
								handle.addOnLoad(function(){
273
									r_loadCalled = 'refresh loadCalled';
274
									pane1.setContent(); // trigger unload
275
								});
276
								handle.addOnUnload(function(){
277
									r_unloadCalled = 'refresh unloadCalled';
278
								});
279
							}, 1500); // wait for page load in case cancel didn't work
280
 
281
							var d = new t.Deferred();
282
 
283
							setTimeout(d.getTestCallback(function(){
284
								// load from the href (was canceled)
285
								t.assertEqual(undefined, loadCalled);
286
								t.assertEqual(undefined, unloadCalled);
287
 
288
								// load from the refresh
289
								t.assertEqual('refreshHandle ok', r_handle);
290
								t.assertEqual('refresh loadCalled', r_loadCalled);
291
								t.assertEqual('refresh unloadCalled', r_unloadCalled);
292
							}), 3200);
293
 
294
							return d;
295
						}
296
					},
297
					{
298
						name: 'onLoadDeferred|onUnloadDeferred_call_order',
299
						timeout: 6200,
300
						runTest: function(t){
301
							pane1.preventCache = 1;
302
							var count = {u: 0, l: 0}; // need a object for the ref in closures
303
							var href = dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=test').toString();
304
 
305
 
306
							function next(){
307
								if(!isNaN(count.u) && !isNaN(count.l)){
308
									if(count.u < 4 && count.l < 4){
309
										pane1.setHref(href);
310
										pane1.onLoadDeferred.addCallback(makeCallback('l', 'u', 1));
311
										pane1.onUnloadDeferred.addCallback(makeCallback('u', 'l', 0));
312
									}else{
313
										pane1.setContent(); // unload to get even
314
									}
315
								}
316
							}
317
 
318
							function makeCallback(tryVar, compareVar, inc){
319
								return function(){
320
									//console.debug(tryVar, count[tryVar] + 1, count[compareVar] + inc)
321
									if((++count[tryVar]) === (count[compareVar] + inc)){
322
										count[tryVar];
323
										if(tryVar == 'l'){
324
											next(); // onload event, trigger new load
325
										}
326
									}else{
327
										tryVar = 'failed '+(tryVar=='u'?'unload':'load')+' on '+count[tryVar]+' try';
328
									}
329
								}
330
							}
331
 
332
							next(); // starts the loop
333
 
334
							var d = new t.Deferred();
335
							setTimeout(d.getTestCallback(function(){
336
								t.assertEqual(4, count.l);
337
								t.assertEqual(4, count.u)
338
							}), 6000); // 1.5 sec max on each load should be enough
339
							return d;
340
						},
341
						tearDown: function(){
342
							delete pane1.preventCache;
343
						}
344
					}
345
				]
346
			);
347
 
348
 
349
			doh.register("pathAdjustments",
350
				[
351
					{
352
						name: 'cssPathAdjustments',
353
						runTest: function(t){
354
 
355
							// we do this test as one big string to emulate as good as possible,
356
							// but split it later to easily see where we failed
357
							var cssText = ".easy{ background-image:url(images/image.png) }\n"
358
							+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n"
359
							+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\"  \t);}body{};\n"
360
							+".file{background-image: url(file:///home/nobody/image.png);}\n"
361
							+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
362
							+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
363
							+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
364
							+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n"
365
							+"@import 'http://dojotoolkit.org/dojo.css';\n"
366
							+"  @import 'you/never/thought/' print;\n"
367
							+' @import url("it/would/work") tv, screen;'+"\n"
368
							+' @import url(/did/you/now.css);'+"\n"
369
							+' @import "yes.i.did";';
370
 
371
							pane1.href = "deep/nested/file";
372
							pane1.adjustPaths = 1;
373
							pane1.renderStyles = 1;
374
							var adjustedCss;
375
 
376
							// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
377
							var oldFunc = pane1._renderStyles;
378
							return function(styles){
379
								adjustedCss = styles.join();
380
							}
381
							pane1._setContent.call(pane1, '<style>'+cssText+'</style>');
382
							pane1._renderStyles = oldFunc;
383
 
384
							adjustedCss = adjustedCss.split("\n");
385
 
386
							var expectedCss = (".easy{ background-image:url(deep/nested/images/image.png) }\n"
387
							+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n"
388
							+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n"
389
							+".file{background-image: url(file:///home/nobody/image.png);}\n"
390
							+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
391
							+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
392
							+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
393
							+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n"
394
							+"@import 'http://dojotoolkit.org/dojo.css';\n"
395
							+"  @import \"deep/nested/you/never/thought/\" print;\n"
396
							+' @import url(deep/nested/it/would/work) tv, screen;'+"\n"
397
							+' @import url(/did/you/now.css);'+"\n"
398
							+' @import "deep/nested/yes.i.did";').split("\n");
399
 
400
							// we split and loop to get a faster hint of where it failed
401
							for(var i = 0; i < expectedCss.length; i++){
402
								t.assertEqual(expectedCss[i], adjustedCss[i]);
403
							}
404
						},
405
						tearDown: function(){
406
							delete pane1.adjustPaths; // get back to defaults
407
							delete pane1.renderStyles;
408
						}
409
					},
410
					{
411
						name: 'htmlPathAdjustments',
412
						timeout: 1800,
413
						runTest: function(t){
414
 
415
							var d = new t.Deferred();
416
							setTimeout(d.getTestCallback(
417
								function(){
418
									// check that images and styles have been applied
419
									var cb = dojo.contentBox(dojo.byId('imgTest'));
420
											//dojo.getComputedStyle(dojo.byId('imgTest'));
421
									t.assertEqual(188, cb.w);
422
									t.assertEqual(125, cb.h);
423
 
424
									// make sure we didn't mess up the other inline styles
425
									cb = dojo.contentBox(dojo.byId('inlineStyleTest'));
426
									t.assertEqual(188, cb.w);
427
									t.assertEqual(125, cb.h);
428
 
429
									// make sure it is the correct image
430
									var cs = dojo.getComputedStyle(dojo.byId('inlineStyleTest'));
431
									var url = cs.backgroundImage;
432
									//remove url(..)
433
									url = url.replace(/^\s?url\(['"]?/, "").replace(/['"]?\);?\s?$/, "");
434
									// compare image url to full path of this document
435
									imageUrl = dojo.moduleUrl('dojox', 'layout/tests/images/testImage.gif');
436
									t.assertEqual(new dojo._Url(document.location, imageUrl), url);
437
 
438
									// make sure we loaded the <link rel='stylesheet' correctly
439
									var mb = dojo.marginBox(dojo.byId('linkCssTest'));
440
									t.assertEqual(112, mb.w); // 100px  + 2px border + 4px margin = 112px
441
									t.assertEqual(112, mb.h);
442
 
443
									// make sure we loaded the <style>@import '...'; correctly
444
									mb = dojo.marginBox(dojo.byId('importCssTest'));
445
									t.assertEqual(110, mb.w); // 100px + 1px border + 4px margin = 110px
446
									t.assertEqual(110, mb.h);
447
 
448
									// make sure we didn't render the <link media='print' rel='stylesheet'
449
									var mb = dojo.marginBox(dojo.byId('linkMediaTest'));
450
									t.assertEqual(212, mb.w); // 100px  + 2px border + 4px margin = 112px
451
									t.assertEqual(212, mb.h);
452
 
453
									// make sure we didn't render the <style media='print'>@import '...';
454
									mb = dojo.marginBox(dojo.byId('importMediaTest'));
455
									t.assertEqual(210, mb.w); // 100px + 1px border + 4px margin = 110px
456
									t.assertEqual(210, mb.h);
457
								}
458
							), 1500);
459
 
460
							pane1.adjustPaths = 1;pane1.renderStyles = 1;
461
							pane1.setHref('remote/getResponse.php?mode=htmlPaths');
462
							return d;
463
						},
464
						tearDown: function(){
465
							delete pane1.adjustPaths; // get back to defaults
466
							delete pane1.renderStyles;
467
						}
468
					},
469
					{
470
						name: 'renderStylesOfByDefaultAndOldDeleted',
471
						timeout: 1800,
472
						runTest: function(t){
473
							var d = new t.Deferred();
474
 
475
							setTimeout(d.getTestCallback(
476
								function(){
477
									// innerHTML'ing <link tags works in some browser (IE, moz), but not all
478
									// we can't test if LINK was loaded this way
479
 
480
									// make sure we didn't load the <link rel='stylesheet'
481
									//var mb = dojo.marginBox(dojo.byId('linkCssTest'));
482
									//t.assertFalse(112 == mb.w);
483
									//t.assertFalse(112 == mb.h);
484
 
485
									// make sure we didn't load the <style>@import '...';
486
									var mb = dojo.marginBox(dojo.byId('importCssTest'));
487
									t.assertFalse(110 == mb.w);
488
									t.assertFalse(110 == mb.h);
489
								}
490
							), 1500);
491
							pane1.adjustPaths = 1;
492
							pane1.setHref('remote/getResponse.php?mode=htmlPaths');
493
							return d;
494
						},
495
						tearDown: function(){
496
							delete pane1.adjustPaths;
497
						}
498
					}
499
				]
500
			);
501
 
502
			doh.register("scriptTests",
503
				[
504
					"t.assertTrue(pane1.executeScripts);",
505
					{
506
						name: 'leaveDojoMethodScriptsAsIs',
507
						runTest: function(t){
508
							pane1.setContent("<"
509
								+"script type='dojo/method'>unTypedVarInDocScope = 'failure';<"
510
								+"/script>");
511
 
512
							var d = new t.Deferred();
513
							// IE req to async this test
514
							setTimeout(d.getTestCallback(function(){
515
								t.assertEqual('undefined', typeof unTypedVarInDocScope);
516
								t.assertFalse(unTypedVarInDocScope == 'failure');
517
							}), 40);
518
 
519
							return d;
520
						}
521
					},
522
					{
523
						name: 'scripts_evals_in_global_scope',
524
						timeout: 1800, // grabing remote js, wait for that
525
						runTest: function(t){
526
							pane1.setContent("<"
527
								+"script>function scriptsInGlobalClicked(){ documentCallback(); }<"
528
								+"/script><"+"script src='remote/getResponse.php?mode=remoteJsTrue'></"
529
								+"script>"+"<a href='javascript:scriptsInGlobalClicked()' "
530
									+"onfocus='scriptsInGlobalClicked();' id='anchorTag'>test</a>");
531
 
532
							var link = dojo.byId('anchorTag');
533
							dojo.isFunction(link.click) ? /*others*/ link.click() : /*moz*/ link.focus();
534
							var d = new t.Deferred();
535
 
536
							setTimeout(d.getTestCallback(function(){
537
								t.assertEqual('boolean', typeof documentCallback.reached);
538
								t.assertTrue(documentCallback.reached);
539
								t.assertTrue(unTypedVarInDocScope);
540
							}), 40);
541
							return d;
542
						}
543
					},
544
					{
545
						name:'scriptsEvalsInOrder',
546
						timeout: 1800,// grabing remote js, wait for that
547
						runTest: function(t){
548
							pane1.setContent("<"
549
								+"script src='remote/getResponse.php?mode=remoteJsFalse'><"
550
								+"/script><"+"script>unTypedVarInDocScope = 1;<"
551
								+"/script>"); // scripts only test
552
 
553
							// we need to make this async because of IEs strange events loops
554
							var d = new t.Deferred();
555
							setTimeout(d.getTestCallback(function(){
556
								t.assertEqual('number', typeof unTypedVarInDocScope);
557
								t.assertEqual(1, unTypedVarInDocScope);
558
							}), 40);
559
							return d;
560
						}
561
					},
562
					{
563
						name: 'scriptsWithTypeTextJavascript',
564
						runTest: function(t){
565
							pane1.setContent("<"
566
								+"script type='text/javascript'> unTypedVarInDocScope = 'text/javascript'; <"
567
								+"/script>");
568
 
569
							var d = new t.Deferred();
570
							// IE needs async here
571
							setTimeout(d.getTestCallback(function(){
572
								t.assertEqual('text/javascript', unTypedVarInDocScope);
573
							}), 40);
574
							return d;
575
						}
576
					},
577
					{
578
						name:'scriptsWithHtmlComments',
579
						runTest: function(t){
580
							pane1.cleanContent = 1;
581
							pane1.setContent("<"
582
								+"script><!-- unTypedVarInDocScope = 2; --><"
583
								+"/script>");
584
 
585
							var d = new t.Deferred();
586
							// IE need a async here
587
							setTimeout(d.getTestCallback(function(){
588
								t.assertEqual('number', typeof unTypedVarInDocScope);
589
								t.assertEqual(2, unTypedVarInDocScope);
590
							}), 40);
591
 
592
							return d;
593
						},
594
						tearDown: function(){
595
							delete pane1.cleanContent; // go back to default
596
						}
597
					},
598
					{
599
						name:'scriptsWithCData',
600
						runTest: function(t){
601
							pane1.cleanContent = 1;
602
							pane1.setContent("<"
603
								+"script><![CDATA[ unTypedVarInDocScope = 3; ]]><"
604
								+"/script>");
605
 
606
							var d = new t.Deferred();
607
							// IE need a async here
608
							setTimeout(d.getTestCallback(function(){
609
								t.assertEqual('number', typeof unTypedVarInDocScope);
610
								t.assertEqual(3, unTypedVarInDocScope);
611
							}), 40);
612
 
613
							return d;
614
						},
615
						tearDown: function(){
616
							delete pane1.cleanContent; // go back to default
617
						}
618
					},
619
					{
620
						name: 'replace_container_with_dijit.byId()',
621
						runTest: function(t){
622
							unTypedVarInDocScope = 'failure';
623
							pane1.scriptHasHooks = true;
624
							pane1.setContent("<"
625
							+"script>function testReplace(){"
626
							+	"if(typeof _container_ != 'object'){return 'not replaced 1';}\n"
627
							+	"if(_container_ != pane1){ return 'not replaced 2';}\n"
628
							+	"if(!_container_ == pane1){ return 'not replaced 3';}\n"
629
							+	"var tmp =_container_=dojo;\n"
630
							+	"if(tmp != dojo){ return 'replaced when shouldnt 1';}\n"
631
							+	"var tmp = _container_  \t \t = dojo;\n"
632
							+	"if(tmp != dojo){ return 'replaced when shouldnt 2';}\n"
633
							+	"return 'success';\n"
634
							+"};\n"
635
							+"unTypedVarInDocScope = testReplace();"
636
							+"</"+"script>");
637
 
638
							// let IE inhale here
639
							var d = new t.Deferred();
640
							setTimeout(d.getTestCallback(function(){
641
								t.assertEqual('success', unTypedVarInDocScope);
642
							}), 40);
643
							return d;
644
						},
645
						tearDown: function(){
646
							delete pane1.scriptHasHooks; // get back to default
647
						}
648
					},
649
					{
650
						name:'_container_onLoadDeferred|onUnloadDeferred',
651
						runTest: function(t){
652
							pane1.scriptHasHooks = true;
653
							pane1.setContent("<"
654
								+"script>"
655
								+"var testConn;"
656
								+"_container_.onLoadDeferred.addCallback(function(){"
657
								+	"testConn = dojo.connect(dojo.byId('testForm'), 'onsubmit', null, function(){"
658
								+		"unTypedVarInDocScope = dojo.byId('testInput').value;"
659
								+	"});"
660
								+	"dojo.byId('testButton').click();"
661
								+"});"
662
								+"_container_.onUnloadDeferred.addCallback(function(){"
663
								+		"unTypedVarInDocScope = 'unloaded';"
664
								+	"dojo.disconnect(testConn);"
665
								+"});"
666
								+"<"+"/script><form onsubmit='return false;' id='testForm'>"
667
								+	"<input id='testInput' value='loaded'/>"
668
								+	"<input type='submit' id='testButton'/>"
669
								+"</form>");
670
 
671
							var d = new t.Deferred();
672
							// IE must breathe here
673
							setTimeout(d.getTestCallback(function(){
674
								t.assertEqual('loaded', unTypedVarInDocScope);
675
							}), 40);
676
							return d;
677
						},
678
						tearDown: function(){
679
							delete pane1.scriptHasHooks; // get back to default
680
							pane1.setContent();
681
						}
682
					},
683
					"t.assertEqual('unloaded', unTypedVarInDocScope)"
684
				]
685
			);
686
 
687
 
688
			doh.register('regexRegressionAndSpeedtest',[
689
				{
690
					name: 'cssPathAdjustments',
691
					runTest: function(t){
692
						// we do this test as one big string to emulate as good as possible,
693
						// but split it later to easily see where we failed
694
						var cssText = ".easy{ background-image:url(images/image.png) }\n"
695
						+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n"
696
						+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\"  \t);}body{};\n"
697
						+".file{background-image: url(file:///home/nobody/image.png);}\n"
698
						+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
699
						+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
700
						+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
701
						+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n"
702
						+"@import 'http://dojotoolkit.org/dojo.css';\n"
703
						+"  @import 'you/never/thought/' print;\n"
704
						+' @import url("it/would/work") tv, screen;'+"\n"
705
						+' @import url(/did/you/now.css);'+"\n"
706
						+' @import "yes.i.did";';
707
 
708
						var expectedCss = ".easy{ background-image:url(deep/nested/images/image.png) }\n"
709
						+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n"
710
						+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n"
711
						+".file{background-image: url(file:///home/nobody/image.png);}\n"
712
						+".http{background-image: url(http://dojotoolkit.org/image.png);}\n"
713
						+".https{background-image: url(https://dojotoolkit.org/image.png);}\n"
714
						+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n"
715
						+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n"
716
						+"@import 'http://dojotoolkit.org/dojo.css';\n"
717
						+"  @import \"deep/nested/you/never/thought/\" print;\n"
718
						+' @import url(deep/nested/it/would/work) tv, screen;'+"\n"
719
						+' @import url(/did/you/now.css);'+"\n"
720
						+' @import "deep/nested/yes.i.did";';
721
 
722
						for(var i = 0; i < 6; i++){
723
							cssText += cssText;
724
							expectedCss += expectedCss;
725
						}
726
 
727
						expectedCss = expectedCss.split("\n");
728
 
729
						pane1.href = "deep/nested/file";
730
						pane1.adjustPaths = 1;
731
						pane1.renderStyles = 1;
732
						var adjustedCss;
733
 
734
						// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
735
						var oldFunc = pane1._renderStyles;
736
						pane1._renderStyles = function(styles){
737
							adjustedCss = styles.join();
738
						}
739
 
740
						var start = new Date();
741
						pane1._setContent.call(pane1, '<style>'+cssText+'</style>');
742
						var end = new Date();
743
						pane1._renderStyles = oldFunc;
744
 
745
						adjustedCss = adjustedCss.split("\n");
746
						console.info('Time used to regex scan css and adjust relative paths within css:'+
747
								(end - start)+' ms on '+ cssText.split('\n').length
748
								+' css rows, with '+ cssText.length+' characters (roughly '
749
								+Math.round(cssText.length/1024)+ 'Kb) of infile css')
750
 
751
						// we split and loop to get a faster hint of where it failed
752
						for(var i = 0; i < expectedCss.length; i++){
753
							t.assertEqual(expectedCss[i], adjustedCss[i]);
754
						}
755
					},
756
					tearDown: function(){
757
						delete pane1.adjustPaths; // get back to defaults
758
						delete pane1.renderStyles;
759
						pane1.href = "";
760
					}
761
				}
762
				,
763
				{
764
					name:'htmlPathsSpeedTest',
765
					runTest: function(t){
766
						var htmlText = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n"
767
							+"<title>should be removed</title>\n"
768
							+"<img src=\"images/image.gif\"/>Testing\n"
769
							+"<a href=\"../../topmost.html\">\n"
770
							+"	<img src=\"/siteroot/top.html\">\n"
771
							+"	<p style='background:url(\"images/back.png\")'>\n"
772
							+"	testing link\n"
773
							+"</p></a>\n"
774
							+"<style \ntype='text/css'>\n"
775
							+"	@import 'http://dojotoolkit.org/visible.css' tv, screen;\n"
776
							+"	@import \"./audio.css\" audio;\n"
777
							+"	@import url(/topsite/css/main.css);\n"
778
							+"	div.mywidget, #someId {\n"
779
							+"		background-color:url(../../css/main.css);"
780
							+"		display:none;\n"
781
							+"		background:url(../tmp/css)\n"
782
							+"	}\n"
783
							+"</style>\n"
784
							+"<link rel=\"stylesheet\" href=\"../../css/theme.css\" media=\"all\">\n"
785
							+"<link media='print' type='text/css' rel='stylesheet' href='../../css/theme2.css'/>\n"
786
							+"<a style='display:block; background:url(/topmost/css)' href='../above'>above</a>\n"
787
							+"<sc"+"ript type=\"text/javascript\"\n src=\"..\\windows\\morons\"></scr"+"ipt>\n"
788
							+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n"
789
							+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n"
790
							+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n"
791
							+"<scr"+"ipt>JS CODE</scr"+"ipt>\n"
792
							+"<a href='javascript:void(0)'>void</a>";
793
 
794
 
795
						pane1.href = 'deep/nested/file';
796
 
797
						var expectedHtml = "\n\n<img src=\"deep/nested/images/image.gif\"/>Testing\n"
798
							+"<a href=\"topmost.html\">\n"
799
							+"	<img src=\"/siteroot/top.html\">\n"
800
							+"	<p style='background:url(deep/nested/images/back.png)'>\n"
801
							+"	testing link\n"
802
							+"</p></a>\n"
803
							+"\n"
804
							+"\n\n"
805
							+"<a style='display:block; background:url(/topmost/css)' href='deep/above'>above</a>\n\n"
806
							+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n"
807
							+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n"
808
							+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n\n"
809
							+"<a href='javascript:void(0)'>void</a>";
810
 
811
 
812
						var expectedCss = [
813
							"\n	@import 'http://dojotoolkit.org/visible.css' tv, screen;\n"
814
							+"	@import \"deep/nested/audio.css\" audio;\n"
815
							+"	@import url(/topsite/css/main.css);\n"
816
							+"	div.mywidget, #someId {\n"
817
							+"		background-color:url(css/main.css);"
818
							+"		display:none;\n"
819
							+"		background:url(deep/tmp/css)\n"
820
							+"	}\n", "@import \"css/theme.css\";", "@import \"css/theme2.css\";"];
821
 
822
						for(var i = 0; i < 6; i++){
823
							htmlText += htmlText;
824
							expectedHtml += expectedHtml;
825
							expectedCss = expectedCss.concat(expectedCss);
826
						}
827
 
828
 
829
						pane1.href = "deep/nested/file";
830
						pane1.adjustPaths = 1;
831
						pane1.renderStyles = 1;
832
						pane1.cleanContent = 1;
833
						var adjustedCss, adjustedHtml;
834
 
835
						// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating)
836
						var oldFunc = pane1._renderStyles;
837
						pane1._renderStyles = function(styles){
838
							adjustedCss = styles;
839
							pane1.executeScripts = 0;
840
						}
841
 
842
						var oldSetFunc = dijit.layout.ContentPane.prototype._setContent;
843
						dijit.layout.ContentPane.prototype._setContent = function(html){
844
							adjustedHtml = html;
845
						}
846
 
847
						var oldXhr = dojo.xhrGet;
848
						dojo.xhrGet = function(){}; // kill script download
849
 
850
						var start = new Date();
851
						pane1._setContent.call(pane1, htmlText);
852
						var end = new Date();
853
 
854
						// reset back to the way it was
855
						pane1._renderStyles = oldFunc;
856
						dijit.layout.ContentPane.prototype._setContent = oldSetFunc;
857
						dojo.xhrGet = oldXhr;
858
 
859
						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:'+
860
								(end - start)+' ms on '+ htmlText.split('\n').length
861
								+' html rows, with '+ htmlText.length+' characters (roughly '
862
								+Math.round(htmlText.length/1024)+ 'Kb)');
863
 
864
						// we split and loop to get a faster hint of where it failed
865
						adjustedHtml = adjustedHtml.split("\n");
866
						expectedHtml = expectedHtml.split("\n");
867
 
868
						for(var i = 0; i < expectedHtml.length; i++){
869
							//console.debug(expectedHtml[i], i);
870
							//console.debug(adjustedHtml[i], i);
871
							t.assertEqual(expectedHtml[i], adjustedHtml[i]);
872
						}
873
 
874
						var exCssBlock, adjCssBlock;
875
						for(var i = 0; i < expectedCss.length; i++){
876
							t.assertEqual('string', typeof adjustedCss[i]);
877
 
878
							exCssBlock = expectedCss[i].split('\n');
879
							adjCssBlock = adjustedCss[i].split('\n');
880
 
881
							for(var j = 0; j < exCssBlock.length;j++){
882
								t.assertEqual(dojo.trim(exCssBlock[j]), dojo.trim(adjCssBlock[j]));
883
							}
884
 
885
						}
886
					},
887
					tearDown: function(){
888
						delete pane1.cleanContent;
889
						delete pane1.adjustPaths;
890
						delete pane1.renderStyles;
891
						delete pane1.executeScripts;
892
					}
893
				}
894
				,
895
				{
896
					name:'IE_AlphaImageLoader_PathAdjustments',
897
					runTest: function(t){
898
						if(!dojo.isIE){
899
							console.info('aborting test IE_AlphaImageLoader_PathAdjustments, you dont use IE');
900
							return;
901
						}
902
 
903
						pane1.adjustPaths = 1;
904
						pane1.renderStyles = 1;
905
 
906
						pane1.href = "deep/";
907
 
908
						var html = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n"
909
						+" alpha png in IE 6 --></div>\n"
910
						+"<style>\n"
911
						+"	.ie_menu_png {"
912
						+"		filter: \t progid:\n"
913
						+"			DXImageTransform.Microsoft.AlphaImageLoader(\n"
914
						+"			src='../midlevel/alpha(2).png')\n"
915
						+"	}\n"
916
						+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n"
917
						+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n"
918
						+"</style>\n";
919
 
920
 
921
						var expectedHtml = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"deep/images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n"
922
						+" alpha png in IE 6 --></div>\n\n";
923
 
924
						var expectedCss = "\n"
925
						+"	.ie_menu_png {"
926
						+"		filter: \t progid:\n"
927
						+"			DXImageTransform.Microsoft.AlphaImageLoader(\n"
928
						+"			src='midlevel/alpha(2).png')\n"
929
						+"	}\n"
930
						+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n"
931
						+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n";
932
 
933
 
934
						for(var i = 0; i < 7; i++){
935
							html += html;
936
							expectedHtml += expectedHtml;
937
							expectedCss += expectedCss;
938
						}
939
 
940
						var adjustedHtml, adjustedCss;
941
 
942
						// hijack internals to snatch the content
943
						var oldRenderStyles = pane1._renderStyles;
944
						var oldSetContent = dijit.layout.ContentPane.prototype._setContent;
945
						pane1._renderStyles = function(styles){ adjustedCss = styles.join(''); };
946
						dijit.layout.ContentPane.prototype._setContent = function(cont){ adjustedHtml = cont; }
947
 
948
						var start = new Date();
949
						pane1._setContent.call(pane1, html);
950
						var end = new Date();
951
 
952
						console.info('Time used to replace AlphaImageLoader(src="...") '
953
									+(end - start) + "ms in HTML with "+html.length
954
									+' characters (roughly '+(Math.round(html.length/1024))+'Kb)');
955
 
956
						// reset hijacked
957
						pane1._renderStyles = oldRenderStyles;
958
						dijit.layout.ContentPane.prototype._setContent = oldSetContent;
959
 
960
 
961
						// split on newline and run a check on each row to help debugging
962
						expectedHtml = expectedHtml.split("\n");
963
						adjustedHtml = adjustedHtml.split("\n");
964
						for(var i = 0; i < expectedHtml.length; i++){
965
							t.assertEqual(expectedHtml[i], adjustedHtml[i]);
966
						}
967
 
968
						expectedCss = expectedCss.split("\n");
969
						adjustedCss = adjustedCss.split("\n");
970
						for(var i = 0; i < expectedCss.length; i++){
971
							t.assertEqual(expectedCss[i], adjustedCss[i]);
972
						}
973
 
974
					},
975
					tearDown: function(){
976
						delete pane1.renderStyles;
977
						delete pane1.adjustPaths;
978
					}
979
				}
980
			]);
981
 
982
			doh.register("A_AlphaImageLoader_inAction", [{
983
				name:"AlphaLoaderShowHow",
984
				runTest:function(t){
985
				// IE filter alphaimageloader paths must be relative to the page
986
				// not to the cssFile that declares it
987
 
988
				// demo a much better way of "Fixing" alpha png in IE6 than inlining in html
989
				var html = "<img src='images/dojoLogo.png' class='run_png_fix'/>"
990
 
991
				var showHowHtml = "<pre >\nCode used in IE transparent png example\n"
992
							+"code (declared in main page, not through ContentPane)\n"
993
							+"&lt;script type='text/javascript'&gt;\n"
994
							+fixPngIE6.toString().replace(/\n\t?/g, "\n")
995
							+"\n&lt;/script&gt;\n"
996
							+"&lt;style type='text/css'&gt;\n"
997
							+"	.run_png_fix {\n"
998
							+"		background-image:url(images/blank.gif);\n"
999
							+"		behaviour: expression(fixPngIE6.call(this));\n"
1000
							+"	}\n"
1001
							+"&lt;/style&gt;\n\n...\n\nHtml feeded to ContentPane (or your main page):\n"
1002
							+"&lt;img src='images/dojoLogo.png' class='run_png_fix'/&gt;\n</pre>";
1003
 
1004
				pane1.executeScripts = 1;
1005
				pane1.renderStyles = 1;
1006
				pane1.setContent(html+showHowHtml);
1007
 
1008
 
1009
				}
1010
			}]);
1011
 
1012
			doh.run();
1013
		});
1014
	</script>
1015
	<style>
1016
		@import "../../../dojo/resources/dojo.css";
1017
		@import "../../../dijit/themes/tundra/tundra.css";
1018
		@import "../../../dijit/tests/css/dijitTests.css";
1019
 
1020
		.box {
1021
			border: 1px solid black;
1022
			height: 190px;
1023
			width: 80%;
1024
			overflow: auto;
1025
		}
1026
 
1027
		.red {
1028
			color: red;
1029
		}
1030
 
1031
		.dojoxTestWidget {
1032
			border: 1px dashed red;
1033
			background-color: #C0E209 ;
1034
		}
1035
	</style>
1036
</head>
1037
<body class='tundra'>
1038
	<h1>dojox.layout.ContentPane</h1>
1039
	<h3>As dojox ContentPane is derived from dijit ContentPane, make sure that the dijit test passes before running this test</h3>
1040
	<h3 class='red'>Test relies on a php page as backend, so you need php installed on your server</h3>
1041
 
1042
	<div class='box' dojoType="dojox.layout.ContentPane" id='parsedPane'>
1043
		Initial value
1044
	</div>
1045
 
1046
	<table id='tableTest' class='box'>
1047
		<thead>
1048
			<tr>
1049
				<td></td>
1050
			</tr>
1051
		</thead>
1052
		<tbody>
1053
			<tr>
1054
				<td></td>
1055
			</tr>
1056
		<tbody>
1057
	</table>
1058
</body>
1059
</html>