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