You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1110 lines
39 KiB
1110 lines
39 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
|
"http://www.w3.org/TR/html4/strict.dtd"> |
|
<html> |
|
<head> |
|
<title>dojox.layout.ContentPane test</title> |
|
<script > |
|
function fixPngIE6(){ |
|
if(this.complete && dojo.isIE < 7){ |
|
var r = this.runtimeStyle; |
|
if(/.png$/i.test(this.src)){ |
|
r.height = this.height; |
|
r.width = this.width; |
|
r.filter="progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+this.src+"');"; |
|
this.src = this.currentStyle.backgroundImage.replace(/url\(\s*['"]?(.+?)['"]?\s*\)/, "$1"); |
|
} |
|
this.className = this.className.replace('run_png_fix', ""); |
|
r.behaviour = 'none'; |
|
} |
|
} |
|
</script> |
|
<style type='text/css'> |
|
.run_png_fix { |
|
background-image:url(images/blank.gif); |
|
behaviour: expression(fixPngIE6.call(this)); |
|
} |
|
</style> |
|
<script src="../../../dojo/dojo.js" data-dojo-config="isDebug:true"></script> |
|
<script> |
|
dojo.require('doh.runner'); |
|
dojo.require('dojox.layout.ContentPane'); |
|
dojo.require('dojo.parser'); |
|
dojo.require('dijit._Container'); |
|
dojo.require('dijit._Templated'); |
|
dojo.require('dojo._base.url'); |
|
|
|
|
|
// create a do nothing, only for test widget |
|
dojo.declare("dojox.TestWidget", |
|
[dijit._Widget, dijit._Templated], { |
|
templateString: "<span class='dojoxTestWidget'></span>" |
|
}); |
|
|
|
// used to test if we fire scrips to document scope |
|
function documentCallback(){ |
|
arguments.callee.reached = true; |
|
//console.debug('reached'); |
|
} |
|
var unTypedVarInDocScope; // a closure test to make sure we can reach this from evaled scripts |
|
|
|
|
|
var pane1, pane2; |
|
|
|
dojo.ready(function(){ |
|
|
|
function ieTrimSpaceBetweenTags(str){ |
|
return str.replace(/(<[a-z]*[^>]*>)\s*/ig, "$1"); |
|
} |
|
|
|
doh.register({ |
|
name: 'parse', |
|
timeout: 5000, |
|
runTest: function(t){ |
|
dojo.parser.parse().then(function(){ |
|
pane1 = dijit.byId('parsedPane'); |
|
}); |
|
} |
|
}); |
|
|
|
doh.register("basicChecks", [ |
|
{ |
|
name: 'setContent', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var msg = "Simple Test"; |
|
pane1.set('content', msg); |
|
t.is(msg, pane1.domNode.innerHTML); |
|
} |
|
}, |
|
{ |
|
name: 'setHref', |
|
timeout: 1800, |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var msg = "simple remote Test" |
|
pane1.set('href', dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?message='+encodeURI(msg))); |
|
|
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is(msg, pane1.domNode.innerHTML) |
|
}), 1500); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name: 'setContent_with_Widgets', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var cont = "<div dojoType='dojox.TestWidget'>Test</div>"; |
|
pane1.set('content', cont); |
|
t.isNot(cont.toLowerCase(),pane1.domNode.innerHTML.toLowerCase()); |
|
t.is(1, pane1.getChildren().length); |
|
} |
|
}, |
|
function startupCalled(){ |
|
doh.t(select._started, "select widget was created, and startup was called"); |
|
}, |
|
{ |
|
name: 'changeContentTRHead', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var trHead = dojo.query('table#tableTest > thead > tr')[0]; |
|
pane2 = new dojox.layout.ContentPane({} , trHead); |
|
var html = "<td><div>This</div>Should<u>Work</u></td>"; |
|
pane2.set('content', html); |
|
var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase()); |
|
t.is(html.toLowerCase(), res); |
|
}, |
|
tearDown: function(){ |
|
pane2.destroy(); |
|
} |
|
}, |
|
{ |
|
name: 'changeContentTHead', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var tHead = dojo.query('table#tableTest > thead')[0]; |
|
pane2 = new dojox.layout.ContentPane({}, tHead); |
|
var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>"; |
|
pane2.set('content', html); |
|
var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase()); |
|
t.is(html.toLowerCase(), res); |
|
}, |
|
tearDown: function(){ |
|
pane2.destroy(); |
|
} |
|
}, |
|
{ |
|
name: 'changeContentTRBody', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var trBody = dojo.query('table#tableTest > tbody > tr')[0]; |
|
pane2 = new dojox.layout.ContentPane({}, trBody); |
|
var html = "<td><div>This</div>Should<u>Work</u></td>"; |
|
pane2.set('content', html); |
|
var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase()); |
|
t.is(html.toLowerCase(), res); |
|
}, |
|
tearDown: function(){ |
|
pane2.destroy(); |
|
} |
|
}, |
|
{ |
|
name: 'changeContentTBody', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var tBody = dojo.query('table#tableTest > tbody')[0]; |
|
pane2 = new dojox.layout.ContentPane({}, tBody); |
|
var html = "<tr><td><div>This</div>Should<u>Work</u></td></tr>"; |
|
pane2.set('content', html); |
|
var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase()); |
|
t.is(html.toLowerCase(), res); |
|
}, |
|
tearDown: function(){ |
|
pane2.destroy(); |
|
} |
|
}, |
|
{ |
|
name: 'changeContentTable', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var table = dojo.query('table#tableTest')[0]; |
|
pane2 = new dojox.layout.ContentPane({}, table); |
|
var html = "<tbody><tr><td><div>This</div>Should<u>Work</u></td></tr></tbody>"; |
|
pane2.set('content', html); |
|
var res = ieTrimSpaceBetweenTags(pane2.domNode.innerHTML.toLowerCase()); |
|
t.is(html.toLowerCase(), res); |
|
}, |
|
tearDown: function(){ |
|
pane2.destroy(); |
|
} |
|
}, |
|
{ |
|
name: 'ioArgsSetSyncLoad', |
|
timeout: 1500, |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
pane1.ioArgs.sync = true; |
|
pane1.set('href', dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=sync')); |
|
|
|
// since it was a sync fetch it should be loaded here |
|
t.is('sync', pane1.domNode.innerHTML); |
|
}, |
|
tearDown: function(){ |
|
pane1.ioArgs = {}; // back to defaults |
|
} |
|
}, |
|
{ |
|
name: 'ioArgsSetsHeader', |
|
timeout: 1800, |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
// test if we can set a custom header on every request |
|
pane1.ioArgs.headers = {'X-TestHeader': 'Testing'}; |
|
pane1.set('href', 'remote/getResponse.php?mode=bounceHeaders'); |
|
|
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
var cont = pane1.domNode.innerHTML; |
|
t.t(/X-TestHeader/i.test(cont), "X-TestHeader"); |
|
t.t(/Testing/i.test(cont), "Testing"); |
|
}), 1500); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
pane1.ioArgs = {}; // back to defaults |
|
} |
|
}, |
|
{ |
|
name: 'ioMethodPost', |
|
timeout: 1800, |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
// test to post some content on each request |
|
pane1.ioMethod = dojo.xhrPost; |
|
pane1.ioArgs.content = {test:'it should work'}; |
|
pane1.set('href', 'remote/getResponse.php?mode=bounceInput'); |
|
|
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('test=it%20should%20work', pane1.domNode.innerHTML); |
|
}), 1500); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
// back to defaults |
|
pane1.ioMethod = dojo.xhrGet; |
|
pane1.ioArgs = {}; |
|
} |
|
}, |
|
{ |
|
name: 'handleFrom_setContent', |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var unLoadCalled, loadCalled; |
|
var handle = pane1.set('content', "test 'var handle = set('content', '')'"); |
|
|
|
handle.addCallback(function(){ |
|
loadCalled = true; |
|
}); |
|
|
|
t.t(loadCalled, "loadCalled"); |
|
} |
|
}, |
|
{ |
|
name: 'handleFrom_setHref_and_refresh_and_cancelWorking', |
|
timeout: 3400, |
|
runTest: function(t){ |
|
console.log("basicChecks: " + this.name); |
|
var loadCalled; |
|
var r_loadCalled; |
|
var r_handle, href = dojo.moduleUrl('dijit', 'tests/layout/getResponse.php?delay=100&message=test'); |
|
|
|
var handle = pane1.set('href', href); |
|
t.t(handle, "handle 1"); |
|
handle.addCallback(function(){ |
|
console.log("handleFrom_setHref_and_refresh_and_cancelWorking: handle onLoad"); |
|
loadCalled = 'loadCalled'; |
|
}); |
|
|
|
// Since we cancel immediately the deferred should never fire |
|
handle.cancel(); |
|
|
|
setTimeout(function(){ |
|
console.log("handleFrom_setHref_and_refresh_and_cancelWorking: setting href: " + href); |
|
pane1.href = href; |
|
handle = pane1.refresh(); |
|
t.t(handle, "handle 2"); |
|
r_handle = 'refreshHandle ok'; |
|
handle.addCallback(function(){ |
|
console.log("handleFrom_setHref_and_refresh_and_cancelWorking: 2ary handle onload"); |
|
r_loadCalled = 'refresh loadCalled'; |
|
pane1.set('content', ''); // trigger unload |
|
}); |
|
}, 1500); // wait for page load in case cancel didn't work |
|
|
|
var d = new t.Deferred(); |
|
|
|
setTimeout(d.getTestCallback(function(){ |
|
// load from the href (was canceled) |
|
t.is(undefined, loadCalled); |
|
|
|
// load from the refresh |
|
t.is('refreshHandle ok', r_handle); |
|
t.is('refresh loadCalled', r_loadCalled); |
|
}), 3200); |
|
|
|
return d; |
|
} |
|
} |
|
] |
|
); |
|
|
|
|
|
doh.register("pathAdjustments", |
|
[ |
|
{ |
|
setUp: function() { |
|
// setup text fixture for these pathAdjustments tests |
|
if(!pane1._contentSetter) { |
|
// make sure the contentSetter is created, by doing a simple setContent |
|
pane1.set("content", ""); |
|
} |
|
}, |
|
name: 'cssPathAdjustments', |
|
runTest: function(t){ |
|
// test that when you setContent, using the adjustPaths and renderStyles options |
|
// the paths in the css are corrected for the current document |
|
console.log("pathAdjustments: " + this.name); |
|
|
|
// we do this test as one big string to emulate as good as possible, |
|
// but split it later to easily see where we failed |
|
var cssText = ".easy{ background-image:url(images/image.png) }\n" |
|
+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n" |
|
+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\" \t);}body{};\n" |
|
+".file{background-image: url(file:///home/nobody/image.png);}\n" |
|
+".http{background-image: url(http://dojotoolkit.org/image.png);}\n" |
|
+".https{background-image: url(https://dojotoolkit.org/image.png);}\n" |
|
+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n" |
|
+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n" |
|
+"@import 'http://dojotoolkit.org/dojo.css';\n" |
|
+" @import 'you/never/thought/' print;\n" |
|
+' @import url("it/would/work") tv, screen;'+"\n" |
|
+' @import url(/did/you/now.css);'+"\n" |
|
+' @import "yes.i.did";'; |
|
|
|
pane1.referencePath = "deep/nested/file"; // hook for testing to trigger path adjustment on an set('content', ...) |
|
pane1.adjustPaths = true; |
|
pane1.renderStyles = true; |
|
var adjustedCss; |
|
|
|
// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating) |
|
var oldFunc = pane1._contentSetter._renderStyles; |
|
console.log("in cssPathAdjustments, returning function"); |
|
|
|
pane1._contentSetter._renderStyles = function(styles){ |
|
console.log("in replaced _renderStyles"); |
|
adjustedCss = styles.join(); |
|
}; |
|
console.log("in cssPathAdjustments, calling set"); |
|
pane1.set('content', '<style>'+cssText+'</style>'); |
|
console.log("in cssPathAdjustments, done calling set"); |
|
pane1._contentSetter._renderStyles = oldFunc; |
|
|
|
adjustedCss = adjustedCss.split("\n"); |
|
|
|
var expectedCss = (".easy{ background-image:url(deep/nested/images/image.png) }\n" |
|
+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n" |
|
+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n" |
|
+".file{background-image: url(file:///home/nobody/image.png);}\n" |
|
+".http{background-image: url(http://dojotoolkit.org/image.png);}\n" |
|
+".https{background-image: url(https://dojotoolkit.org/image.png);}\n" |
|
+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n" |
|
+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n" |
|
+"@import 'http://dojotoolkit.org/dojo.css';\n" |
|
+" @import \"deep/nested/you/never/thought/\" print;\n" |
|
+' @import url(deep/nested/it/would/work) tv, screen;'+"\n" |
|
+' @import url(/did/you/now.css);'+"\n" |
|
+' @import "deep/nested/yes.i.did";').split("\n"); |
|
|
|
// we split and loop to get a faster hint of where it failed |
|
for(var i = 0; i < expectedCss.length; i++){ |
|
t.is(expectedCss[i], adjustedCss[i]); |
|
} |
|
}, |
|
tearDown: function(){ |
|
delete pane1.adjustPaths; // get back to defaults |
|
delete pane1.renderStyles; |
|
delete pane1.referencePath; |
|
} |
|
}, |
|
{ |
|
name: 'htmlPathAdjustments', |
|
timeout: 1800, |
|
runTest: function(t){ |
|
console.log("pathAdjustments: " + this.name); |
|
|
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback( |
|
function(){ |
|
console.log("pathAdjustments: htmlPathAdjustments, in callback"); |
|
|
|
// check that images and styles have been applied |
|
var cb = dojo.contentBox(dojo.byId('imgTest')); |
|
//dojo.getComputedStyle(dojo.byId('imgTest')); |
|
t.is(188, cb.w); |
|
t.is(125, cb.h); |
|
|
|
// make sure we didn't mess up the other inline styles |
|
cb = dojo.contentBox(dojo.byId('inlineStyleTest')); |
|
t.is(188, cb.w); |
|
t.is(125, cb.h); |
|
|
|
// make sure it is the correct image |
|
var cs = dojo.getComputedStyle(dojo.byId('inlineStyleTest')); |
|
var url = cs.backgroundImage; |
|
//remove url(..) |
|
url = url.replace(/^\s?url\(['"]?/, "").replace(/['"]?\);?\s?$/, ""); |
|
// compare image url to full path of this document |
|
imageUrl = dojo.moduleUrl('dojox', 'layout/tests/images/testImage.gif'); |
|
t.is(new dojo._Url(document.location, imageUrl).toString(), url); |
|
|
|
// make sure we loaded the <link rel='stylesheet' correctly |
|
var mb = dojo.marginBox(dojo.byId('linkCssTest')); |
|
t.is(112, mb.w); // 100px + 2px border + 4px margin = 112px |
|
t.is(112, mb.h); |
|
|
|
// make sure we loaded the <style>@import '...'; correctly |
|
mb = dojo.marginBox(dojo.byId('importCssTest')); |
|
t.is(110, mb.w); // 100px + 1px border + 4px margin = 110px |
|
t.is(110, mb.h); |
|
|
|
// make sure we didn't render the <link media='print' rel='stylesheet' |
|
var mb = dojo.marginBox(dojo.byId('linkMediaTest')); |
|
t.is(212, mb.w); // 100px + 2px border + 4px margin = 112px |
|
t.is(212, mb.h); |
|
|
|
// make sure we didn't render the <style media='print'>@import '...'; |
|
mb = dojo.marginBox(dojo.byId('importMediaTest')); |
|
t.is(210, mb.w); // 100px + 1px border + 4px margin = 110px |
|
t.is(210, mb.h); |
|
} |
|
), 1500); |
|
|
|
pane1.adjustPaths=true; pane1.renderStyles=true; |
|
pane1.set('href', 'remote/getResponse.php?mode=htmlPaths'); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.adjustPaths; // get back to defaults |
|
delete pane1.renderStyles; |
|
} |
|
}, |
|
{ |
|
name: 'renderStylesOfByDefaultAndOldDeleted', |
|
timeout: 1800, |
|
runTest: function(t){ |
|
console.log("pathAdjustments: " + this.name); |
|
var d = new t.Deferred(); |
|
|
|
setTimeout(d.getTestCallback( |
|
function(){ |
|
// innerHTML'ing <link tags works in some browser (IE, moz), but not all |
|
// we can't test if LINK was loaded this way |
|
|
|
// make sure we didn't load the <link rel='stylesheet' |
|
//var mb = dojo.marginBox(dojo.byId('linkCssTest')); |
|
//t.isNot(112, mb.w, "width"); |
|
//t.isNot(112, mb.h, "height"); |
|
// make sure we didn't load the <style>@import '...'; |
|
|
|
var mb = dojo.marginBox(dojo.byId('importCssTest')); |
|
t.isNot(110, mb.w, "width 2"); |
|
t.isNot(110, mb.h, "height 2"); |
|
} |
|
), 1500); |
|
pane1.adjustPaths=true; |
|
pane1.set('href', 'remote/getResponse.php?mode=htmlPaths'); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.adjustPaths; |
|
} |
|
} |
|
] |
|
); |
|
|
|
doh.register("scriptTests", |
|
[ |
|
"t.t(pane1.executeScripts, 'executeScripts');", |
|
{ |
|
name: 'leaveDojoMethodScriptsAsIs', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.set('content', "<" |
|
+"script type='dojo/method'>unTypedVarInDocScope = 'failure';<" |
|
+"/script>"); |
|
|
|
var d = new t.Deferred(); |
|
// IE req to async this test |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('undefined', typeof unTypedVarInDocScope); |
|
t.isNot("failure", unTypedVarInDocScope); |
|
}), 40); |
|
|
|
return d; |
|
} |
|
}, |
|
{ |
|
name: 'scripts_evals_in_global_scope', |
|
timeout: 1800, // grabing remote js, wait for that |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.set('content', "<" |
|
+"script>function scriptsInGlobalClicked(){ documentCallback(); }<" |
|
+"/script><"+"script src='remote/getResponse.php?mode=remoteJsTrue'></" |
|
+"script>"+"<a href='javascript:scriptsInGlobalClicked()' " |
|
+"onfocus='scriptsInGlobalClicked();' id='anchorTag'>test</a>"); |
|
|
|
var link = dojo.byId('anchorTag'); |
|
dojo.isFunction(link.click) ? /*others*/ link.click() : /*moz*/ link.focus(); |
|
var d = new t.Deferred(); |
|
|
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('boolean', typeof documentCallback.reached); |
|
t.t(documentCallback.reached, "documentCallback.reached"); |
|
t.t(unTypedVarInDocScope, "unTypedVarInDocScope"); |
|
}), 40); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name:'scriptsEvalsInOrder', |
|
timeout: 1800,// grabing remote js, wait for that |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.set('content', "<" |
|
+"script src='remote/getResponse.php?mode=remoteJsFalse'><" |
|
+"/script><"+"script>unTypedVarInDocScope = 1;<" |
|
+"/script>"); // scripts only test |
|
|
|
// we need to make this async because of IEs strange events loops |
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('number', typeof unTypedVarInDocScope); |
|
t.is(1, unTypedVarInDocScope); |
|
}), 40); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name: 'scriptsWithTypeTextJavascript', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.set('content', "<" |
|
+"script type='text/javascript'> unTypedVarInDocScope = 'text/javascript'; <" |
|
+"/script>"); |
|
|
|
var d = new t.Deferred(); |
|
// IE needs async here |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('text/javascript', unTypedVarInDocScope); |
|
}), 40); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name:'scriptsWithHtmlComments', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.cleanContent = true; |
|
pane1.set('content', "<" |
|
+"script><!-- unTypedVarInDocScope = 2; --><" |
|
+"/script>"); |
|
|
|
var d = new t.Deferred(); |
|
// IE need a async here |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('number', typeof unTypedVarInDocScope); |
|
t.is(2, unTypedVarInDocScope); |
|
}), 40); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.cleanContent; // go back to default |
|
} |
|
}, |
|
{ |
|
name:'scriptsWithCData', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.cleanContent = true; |
|
pane1.set('content', "<" |
|
+"script><![CDATA[ unTypedVarInDocScope = 3; ]]><" |
|
+"/script>"); |
|
|
|
var d = new t.Deferred(); |
|
// IE need a async here |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('number', typeof unTypedVarInDocScope); |
|
t.is(3, unTypedVarInDocScope); |
|
}), 40); |
|
|
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.cleanContent; // go back to default |
|
} |
|
}, |
|
{ |
|
name: "scriptsCommentedOutAndEmptyComments", |
|
runTest: function(t){ |
|
var content = ["<html>\n", |
|
"<head>\n", |
|
"</head>\n", |
|
"<body>\n", |
|
"\n", |
|
"<!--\n", |
|
" Some random comment\n", |
|
"-->\n", |
|
"\n", |
|
"Random text before blank comment.\n", |
|
"\n", |
|
"<!-- -->\n", |
|
"\n", |
|
"<!--\n", |
|
" <" ,"script type=\"text/javascript\">\n", |
|
" shouldNotBeDefined = true;\n", |
|
" <", "/script>\n", |
|
"-->\n", |
|
"\n", |
|
"<script type=\"text/javascript\">\n", |
|
" // Junk JS.\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
" shouldBeDefined = true;\n", |
|
"<", "/script>\n", |
|
"</body>\n", |
|
"</html>\n"].join(""); |
|
pane1.set("content", content); |
|
|
|
// let IE inhale here |
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is("boolean" , typeof shouldBeDefined); |
|
t.is("undefined" , typeof shouldNotBeDefined); |
|
}), 40); |
|
return d; |
|
} |
|
}, |
|
{ |
|
name: 'replace_container_with_dijit.byId()', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
unTypedVarInDocScope = 'failure'; |
|
pane1.scriptHasHooks = true; |
|
pane1.set('content', "<" |
|
+"script>function testReplace(){" |
|
+ "if(typeof _container_ != 'object'){return 'not replaced 1';}\n" |
|
+ "if(_container_ != pane1){ return 'not replaced 2';}\n" |
|
+ "if(!_container_ == pane1){ return 'not replaced 3';}\n" |
|
+ "var tmp =_container_=dojo;\n" |
|
+ "if(tmp != dojo){ return 'replaced when shouldnt 1';}\n" |
|
+ "var tmp = _container_ \t \t = dojo;\n" |
|
+ "if(tmp != dojo){ return 'replaced when shouldnt 2';}\n" |
|
+ "return 'success';\n" |
|
+"};\n" |
|
+"unTypedVarInDocScope = testReplace();" |
|
+"</"+"script>"); |
|
|
|
// let IE inhale here |
|
var d = new t.Deferred(); |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('success', unTypedVarInDocScope); |
|
}), 40); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.scriptHasHooks; // get back to default |
|
} |
|
}/*, |
|
{ |
|
name:'_container_onLoadDeferred|onUnloadDeferred', |
|
runTest: function(t){ |
|
console.log("scriptTests: " + this.name); |
|
pane1.scriptHasHooks = true; |
|
pane1.set('content', "<" |
|
+"script>" |
|
+"var testConn;" |
|
+"_container_.onLoadDeferred.addCallback(function(){" |
|
+ "testConn = dojo.connect(dojo.byId('testForm'), 'onsubmit', null, function(){" |
|
+ "unTypedVarInDocScope = dojo.byId('testInput').value;" |
|
+ "});" |
|
+ "dojo.byId('testButton').click();" |
|
+"});" |
|
+"_container_.onUnloadDeferred.addCallback(function(){" |
|
+ "unTypedVarInDocScope = 'unloaded';" |
|
+ "dojo.disconnect(testConn);" |
|
+"});" |
|
+"<"+"/script><form onsubmit='return false;' id='testForm'>" |
|
+ "<input id='testInput' value='loaded'/>" |
|
+ "<input type='submit' id='testButton'/>" |
|
+"</form>"); |
|
|
|
var d = new t.Deferred(); |
|
// IE must breathe here |
|
setTimeout(d.getTestCallback(function(){ |
|
t.is('loaded', unTypedVarInDocScope); |
|
}), 40); |
|
return d; |
|
}, |
|
tearDown: function(){ |
|
delete pane1.scriptHasHooks; // get back to default |
|
pane1.set('content', ''); |
|
} |
|
}, |
|
"t.is('unloaded', unTypedVarInDocScope)" |
|
*/ |
|
] |
|
); |
|
|
|
|
|
doh.register('regexRegressionAndSpeedtest',[ |
|
{ |
|
name: 'cssPathAdjustments', |
|
runTest: function(t){ |
|
console.log("regexRegressionAndSpeedtest: " + this.name); |
|
// we do this test as one big string to emulate as good as possible, |
|
// but split it later to easily see where we failed |
|
var cssText = ".easy{ background-image:url(images/image.png) }\n" |
|
+".dontReplaceEasy{ background-image:url(images/images/image.png) }\n" |
|
+".hardurl{background-image:url(\t \"../../source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo\" \t);}body{};\n" |
|
+".file{background-image: url(file:///home/nobody/image.png);}\n" |
|
+".http{background-image: url(http://dojotoolkit.org/image.png);}\n" |
|
+".https{background-image: url(https://dojotoolkit.org/image.png);}\n" |
|
+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n" |
|
+'@import "css/main.css";' + "\n@import \t'css/Newbee Url.css'\t;\n" |
|
+"@import 'http://dojotoolkit.org/dojo.css';\n" |
|
+" @import 'you/never/thought/' print;\n" |
|
+' @import url("it/would/work") tv, screen;'+"\n" |
|
+' @import url(/did/you/now.css);'+"\n" |
|
+' @import "yes.i.did";'; |
|
|
|
var expectedCss = ".easy{ background-image:url(deep/nested/images/image.png) }\n" |
|
+".dontReplaceEasy{ background-image:url(deep/nested/images/images/image.png) }\n" |
|
+".hardurl{background-image:url(source/~test/%20t'e(s)t.gif(\"1')?foo=bar11103&bar=baz-foo);}body{};\n" |
|
+".file{background-image: url(file:///home/nobody/image.png);}\n" |
|
+".http{background-image: url(http://dojotoolkit.org/image.png);}\n" |
|
+".https{background-image: url(https://dojotoolkit.org/image.png);}\n" |
|
+".nonRelative{background-image:url(/toplevelfolder/image.gif);}\n" |
|
+"@import \"deep/nested/css/main.css\";\n@import \"deep/nested/css/Newbee Url.css\"\t;\n" |
|
+"@import 'http://dojotoolkit.org/dojo.css';\n" |
|
+" @import \"deep/nested/you/never/thought/\" print;\n" |
|
+' @import url(deep/nested/it/would/work) tv, screen;'+"\n" |
|
+' @import url(/did/you/now.css);'+"\n" |
|
+' @import "deep/nested/yes.i.did";'; |
|
|
|
for(var i = 0; i < 6; i++){ |
|
cssText += cssText; |
|
expectedCss += expectedCss; |
|
} |
|
|
|
expectedCss = expectedCss.split("\n"); |
|
|
|
pane1.referencePath = "deep/nested/file"; // hook for testing to trigger path adjustment on an set('content', ...) |
|
pane1.adjustPaths = true; |
|
pane1.renderStyles = true; |
|
var adjustedCss; |
|
|
|
// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating) |
|
var oldFunc = pane1._contentSetter._renderStyles; |
|
console.log("in cssPathAdjustments, returning function"); |
|
|
|
pane1._contentSetter._renderStyles = function(styles){ |
|
console.log("in replaced _renderStyles"); |
|
adjustedCss = styles.join(); |
|
} |
|
|
|
var start = new Date(); |
|
pane1.set('content', '<style>'+cssText+'</style>'); |
|
var end = new Date(); |
|
pane1._contentSetter._renderStyles = oldFunc; |
|
|
|
adjustedCss = adjustedCss.split("\n"); |
|
|
|
|
|
console.info('Time used to regex scan css and adjust relative paths within css:'+ |
|
(end - start)+' ms on '+ cssText.split('\n').length |
|
+' css rows, with '+ cssText.length+' characters (roughly ' |
|
+Math.round(cssText.length/1024)+ 'Kb) of infile css') |
|
|
|
// we split and loop to get a faster hint of where it failed |
|
for(var i = 0; i < expectedCss.length; i++){ |
|
t.is(expectedCss[i], adjustedCss[i]); |
|
} |
|
}, |
|
tearDown: function(){ |
|
delete pane1.adjustPaths; // get back to defaults |
|
delete pane1.renderStyles; |
|
delete pane1.referencePath; |
|
} |
|
} |
|
, |
|
{ |
|
name:'htmlPathsSpeedTest', |
|
runTest: function(t){ |
|
console.log("regexRegressionAndSpeedtest: " + this.name); |
|
var htmlText = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" |
|
+"<title>should be removed</title>\n" |
|
+"<img src=\"images/image.gif\"/>Testing\n" |
|
+"<a href=\"../../topmost.html\">\n" |
|
+" <img src=\"/siteroot/top.html\">\n" |
|
+" <p style='background:url(\"images/back.png\")'>\n" |
|
+" testing link\n" |
|
+"</p></a>\n" |
|
+"<style \ntype='text/css'>\n" |
|
+" @import 'http://dojotoolkit.org/visible.css' tv, screen;\n" |
|
+" @import \"./audio.css\" audio;\n" |
|
+" @import url(/topsite/css/main.css);\n" |
|
+" div.mywidget, #someId {\n" |
|
+" background-color:url(../../css/main.css);" |
|
+" display:none;\n" |
|
+" background:url(../tmp/css)\n" |
|
+" }\n" |
|
+"</style>\n" |
|
+"<link rel=\"stylesheet\" href=\"../../css/theme.css\" media=\"all\">\n" |
|
+"<link media='print' type='text/css' rel='stylesheet' href='../../css/theme2.css'>\n" |
|
+"<a style='display:block; background:url(/topmost/css)' href='../above'>above</a>\n" |
|
+"<sc"+"ript type=\"text/javascript\"\n src=\"..\\windows\\morons\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt>JS CODE</scr"+"ipt>\n" |
|
+"<a href='javascript:void(0)'>void</a>"; |
|
|
|
|
|
var expectedHtml = "\n\n<img src=\"deep/nested/images/image.gif\"/>Testing\n" |
|
+"<a href=\"topmost.html\">\n" |
|
+" <img src=\"/siteroot/top.html\">\n" |
|
+" <p style='background:url(deep/nested/images/back.png)'>\n" |
|
+" testing link\n" |
|
+"</p></a>\n" |
|
+"\n" |
|
+"\n\n" |
|
+"<a style='display:block; background:url(/topmost/css)' href='deep/above'>above</a>\n\n" |
|
+"<scr"+"ipt type=\"dojo/method\" src=\"/dont/mess/with/this\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt src=\"/dont/mess/here/either\" type=\"dojo/method\"></scr"+"ipt>\n" |
|
+"<scr"+"ipt event=\"/havent/you/listened\" type=\"dojo/method\"></scr"+"ipt>\n\n" |
|
+"<a href='javascript:void(0)'>void</a>"; |
|
|
|
|
|
var expectedCss = [ |
|
"\n @import 'http://dojotoolkit.org/visible.css' tv, screen;\n" |
|
+" @import \"deep/nested/audio.css\" audio;\n" |
|
+" @import url(/topsite/css/main.css);\n" |
|
+" div.mywidget, #someId {\n" |
|
+" background-color:url(css/main.css);" |
|
+" display:none;\n" |
|
+" background:url(deep/tmp/css)\n" |
|
+" }\n", "@import \"css/theme.css\";", "@import \"css/theme2.css\";"]; |
|
|
|
for(var i = 0; i < 6; i++){ |
|
htmlText += htmlText; |
|
expectedHtml += expectedHtml; |
|
expectedCss = expectedCss.concat(expectedCss); |
|
} |
|
|
|
|
|
pane1.referencePath = "deep/nested/file"; // hook for testing to trigger path adjustment on an set('content', ...) |
|
pane1.adjustPaths = true; |
|
pane1.renderStyles = true; |
|
pane1.cleanContent = true; |
|
var adjustedCss, adjustedHtml; |
|
|
|
|
|
// hijack internals to snatch the styles before they are inserted to DOM (DOM messes formating) |
|
var oldFunc = pane1._contentSetter._renderStyles; |
|
|
|
pane1._contentSetter._renderStyles = function(styles){ |
|
adjustedCss = styles; |
|
pane1._contentSetter.executeScripts = false; |
|
} |
|
|
|
// we want to inspect the string without actually inserting it into the DOM |
|
// to make exact markup-string matching easier |
|
var oldSetFunc = pane1._contentSetter.setContent; |
|
pane1._contentSetter.setContent = function(){ |
|
adjustedHtml = this.content; |
|
} |
|
|
|
var oldXhr = dojo.xhrGet; |
|
dojo.xhrGet = function(){}; // kill script download |
|
|
|
var start = new Date(); |
|
pane1.set('content', htmlText); |
|
var end = new Date(); |
|
|
|
// reset back to the way it was |
|
pane1._contentSetter._renderStyles = oldFunc; |
|
pane1._contentSetter.setContent = oldSetFunc; |
|
dojo.xhrGet = oldXhr; |
|
|
|
console.info('Time used to regex scan html/css and\n adjust relative paths (adjustPaths=true),\n copy scripts (executeScripts=true) and copy css innerText (renderStyles=true) and adjust paths in there \nTime:'+ |
|
(end - start)+' ms on '+ htmlText.split('\n').length |
|
+' html rows, with '+ htmlText.length+' characters (roughly ' |
|
+Math.round(htmlText.length/1024)+ 'Kb)'); |
|
|
|
// we split and loop to get a faster hint of where it failed |
|
adjustedHtml = adjustedHtml.split("\n"); |
|
expectedHtml = expectedHtml.split("\n"); |
|
|
|
for(var i = 0; i < expectedHtml.length; i++){ |
|
//console.debug(expectedHtml[i], i); |
|
//console.debug(adjustedHtml[i], i); |
|
t.is(expectedHtml[i], adjustedHtml[i]); |
|
} |
|
|
|
var exCssBlock, adjCssBlock; |
|
for(var i = 0; i < expectedCss.length; i++){ |
|
t.is('string', typeof adjustedCss[i]); |
|
|
|
exCssBlock = expectedCss[i].split('\n'); |
|
adjCssBlock = adjustedCss[i].split('\n'); |
|
|
|
for(var j = 0; j < exCssBlock.length;j++){ |
|
t.is(dojo.trim(exCssBlock[j]), dojo.trim(adjCssBlock[j])); |
|
} |
|
|
|
} |
|
}, |
|
tearDown: function(){ |
|
delete pane1.cleanContent; |
|
delete pane1.adjustPaths; |
|
delete pane1.referencePath; |
|
delete pane1.renderStyles; |
|
delete pane1.executeScripts; |
|
} |
|
}, |
|
{ |
|
name:'IE_AlphaImageLoader_PathAdjustments', |
|
runTest: function(t){ |
|
console.log("regexRegressionAndSpeedtest: " + this.name); |
|
if(!dojo.isIE){ |
|
console.info('aborting test IE_AlphaImageLoader_PathAdjustments, you dont use IE'); |
|
return; |
|
} |
|
|
|
pane1.adjustPaths = true; |
|
pane1.renderStyles = true; |
|
|
|
pane1.href = "deep/"; |
|
pane1.referencePath = "deep/"; // hook for testing to trigger path adjustment on an set('content', ...) |
|
|
|
var html = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n" |
|
+" alpha png in IE 6 --></div>\n" |
|
+"<style>\n" |
|
+" .ie_menu_png {" |
|
+" filter: \t progid:\n" |
|
+" DXImageTransform.Microsoft.AlphaImageLoader(\n" |
|
+" src='../midlevel/alpha(2).png')\n" |
|
+" }\n" |
|
+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n" |
|
+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n" |
|
+"</style>\n"; |
|
|
|
|
|
var expectedHtml = "<div style='width:10px;height:10px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\"scale\", src=\"deep/images/alpha(1).png\", nextProperty=\"useless\");'><!-- \n" |
|
+" alpha png in IE 6 --></div>\n\n"; |
|
|
|
var expectedCss = "\n" |
|
+" .ie_menu_png {" |
|
+" filter: \t progid:\n" |
|
+" DXImageTransform.Microsoft.AlphaImageLoader(\n" |
|
+" src='midlevel/alpha(2).png')\n" |
|
+" }\n" |
|
+" #my_transparent_png {filter: progid:DXImageTransform.Microsoft.AlphaImageLoader( src='/images/alpha(3).png') }\n" |
|
+" #my_transparent_png1 {filter: progid:DXImageTransform.Microsoft.AlhaImageLoader(src='http://no.se/images/alpha(4).png')}\n"; |
|
|
|
|
|
for(var i = 0; i < 7; i++){ |
|
html += html; |
|
expectedHtml += expectedHtml; |
|
expectedCss += expectedCss; |
|
} |
|
|
|
var adjustedHtml, adjustedCss; |
|
|
|
// hijack internals to snatch the content |
|
var oldRenderStyles = pane1._contentSetter._renderStyles; |
|
var oldSetFunc = pane1._contentSetter.setContent; |
|
|
|
pane1._contentSetter._renderStyles = function(styles){ adjustedCss = styles.join(''); }; |
|
pane1._contentSetter.setContent = function(){ |
|
adjustedHtml = this.content; |
|
}; |
|
|
|
var start = new Date(); |
|
pane1.set('content', html); |
|
var end = new Date(); |
|
|
|
console.info('Time used to replace AlphaImageLoader(src="...") ' |
|
+(end - start) + "ms in HTML with "+html.length |
|
+' characters (roughly '+(Math.round(html.length/1024))+'Kb)'); |
|
|
|
// reset hijacked |
|
pane1._contentSetter._renderStyles = oldRenderStyles; |
|
pane1._contentSetter.setContent = oldSetFunc; |
|
|
|
|
|
// split on newline and run a check on each row to help debugging |
|
expectedHtml = expectedHtml.split("\n"); |
|
adjustedHtml = adjustedHtml.split("\n"); |
|
for(var i = 0; i < expectedHtml.length; i++){ |
|
t.is(expectedHtml[i], adjustedHtml[i]); |
|
} |
|
|
|
expectedCss = expectedCss.split("\n"); |
|
adjustedCss = adjustedCss.split("\n"); |
|
for(var i = 0; i < expectedCss.length; i++){ |
|
t.is(expectedCss[i], adjustedCss[i]); |
|
} |
|
|
|
}, |
|
tearDown: function(){ |
|
delete pane1.renderStyles; |
|
delete pane1.adjustPaths; |
|
delete pane1.referencePath; |
|
} |
|
} |
|
]); |
|
|
|
doh.register("A_AlphaImageLoader_inAction", [{ |
|
name:"AlphaLoaderShowHow", |
|
runTest:function(t){ |
|
// IE filter alphaimageloader paths must be relative to the page |
|
// not to the cssFile that declares it |
|
|
|
// demo a much better way of "Fixing" alpha png in IE6 than inlining in html |
|
var html = "<img src='images/dojoLogo.png' class='run_png_fix'/>" |
|
|
|
var showHowHtml = "<pre >\nCode used in IE transparent png example\n" |
|
+"code (declared in main page, not through ContentPane)\n" |
|
+"<script type='text/javascript'>\n" |
|
+fixPngIE6.toString().replace(/\n\t?/g, "\n") |
|
+"\n</script>\n" |
|
+"<style type='text/css'>\n" |
|
+" .run_png_fix {\n" |
|
+" background-image:url(images/blank.gif);\n" |
|
+" behaviour: expression(fixPngIE6.call(this));\n" |
|
+" }\n" |
|
+"</style>\n\n...\n\nHtml feeded to ContentPane (or your main page):\n" |
|
+"<img src='images/dojoLogo.png' class='run_png_fix'/>\n</pre>"; |
|
|
|
pane1.executeScripts = true; |
|
pane1.renderStyles = true; |
|
pane1.set('content', html+showHowHtml); |
|
|
|
|
|
} |
|
}]); |
|
|
|
doh.run(); |
|
}); |
|
</script> |
|
<style> |
|
@import "../../../dojo/resources/dojo.css"; |
|
@import "../../../dijit/themes/tundra/tundra.css"; |
|
@import "../../../dijit/tests/css/dijitTests.css"; |
|
|
|
.box { |
|
border: 1px solid black; |
|
height: 190px; |
|
width: 80%; |
|
overflow: auto; |
|
} |
|
|
|
.red { |
|
color: red; |
|
} |
|
|
|
.dojoxTestWidget { |
|
border: 1px dashed red; |
|
background-color: #C0E209 ; |
|
} |
|
</style> |
|
</head> |
|
<body class='tundra'> |
|
<h1>dojox.layout.ContentPane</h1> |
|
<h3>As dojox ContentPane is derived from dijit ContentPane, make sure that the dijit test passes before running this test</h3> |
|
<h3 class='red'>Test relies on a php page as backend, so you need php installed on your server</h3> |
|
|
|
<div class='box' dojoType="dojox.layout.ContentPane" id='parsedPane'> |
|
Initial value |
|
</div> |
|
|
|
<table id='tableTest' class='box'> |
|
<thead> |
|
<tr> |
|
<td></td> |
|
</tr> |
|
</thead> |
|
<tbody> |
|
<tr> |
|
<td></td> |
|
</tr> |
|
<tbody> |
|
</table> |
|
|
|
<div data-dojo-type="dojox/layout/ContentPane" data-dojo-id="startupTest"> |
|
<select data-dojo-type="dijit/form/Select" data-dojo-id="select"> |
|
<option>hi</option> |
|
</select> |
|
</div> |
|
</body> |
|
</html>
|
|
|