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