/trunk/api/js/dojo1.0/dojo/tests/io/iframeUploadTest.html |
---|
New file |
0,0 → 1,50 |
<html> |
<head> |
<style type="text/css"> |
@import "../../resources/dojo.css"; |
</style> |
<script type="text/javascript" |
djConfig="isDebug: true, dojoIframeHistoryUrl: '../../resource/blank.html'" |
src="../../dojo.js"></script> |
<script type="text/javascript"> |
dojo.require("dojo.io.iframe"); |
var callCount = 0; |
var ioResponse; |
function sendIt(){ |
dojo.io.iframe.send({ |
form: dojo.byId("uploadForm"), |
handleAs: "application/json", |
content: { |
increment: callCount++, |
fileFields: "ul1" |
}, |
handle: function(response, ioArgs){ |
if(response instanceof Error){ |
console.debug("Request FAILED: ", response); |
}else{ |
console.debug("Request complete: ", response); |
} |
ioResponse = response; // to get at afterwards in debugger. |
} |
}); |
} |
</script> |
</head> |
<body> |
<p>This file tests dojo.io.iframe upload using a form POST with a file upload button.</p> |
<p> |
<b>Note:</b> This test makes a form POST to upload.cgi. This cgi needs to be made executable for this test to work, and it won't work from local disk. |
</p> |
<form action="upload.cgi" id="uploadForm" |
method="POST" enctype="multipart/form-data"> |
<input type="text" name="foo" value="bar"> |
<input type="file" name="ul1"> |
<input type="button" onclick="sendIt(); return false;" value="send it!"> |
</form> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/iframeResponse.json.html |
---|
New file |
0,0 → 1,7 |
<html> |
<head> |
</head> |
<body> |
<textarea style="width: 100%%; height: 100px;">{ color: "blue", size: 42 }</textarea> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/iframe.js |
---|
New file |
0,0 → 1,8 |
if(!dojo._hasResource["tests.io.iframe"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
dojo._hasResource["tests.io.iframe"] = true; |
dojo.provide("tests.io.iframe"); |
if(dojo.isBrowser){ |
doh.registerUrl("tests.io.iframe", dojo.moduleUrl("tests.io", "iframe.html")); |
} |
} |
/trunk/api/js/dojo1.0/dojo/tests/io/scriptTimeout.html |
---|
New file |
0,0 → 1,67 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<title>Testing dojo.io.script</title> |
<style type="text/css"> |
@import "../../resources/dojo.css"; |
</style> |
<script type="text/javascript" |
src="../../dojo.js" djConfig="isDebug: true"></script> |
<script type="text/javascript"> |
dojo.require("dojo.io.script"); |
function startTest(){ |
var td = dojo.io.script.get({ |
url: "../_base/timeout.php", |
callbackParamName: "callback", |
content: {Foo: 'Bar'}, |
timeout: 500, |
handleAs: "json", |
preventCache: true, |
handle: function(response, ioArgs){ |
if(response instanceof Error && response.dojoType == "timeout"){ |
console.debug("TEST OK. No errors should be seen after this timeout error."); |
}else{ |
console.debug("TEST FAILED: some other error or response received: ", response); |
} |
} |
}); |
} |
</script> |
</head> |
<body> |
<h1>Timeout test</h1> |
<p> |
This test page tests the timeout functionality of dojo.io.script, and to make |
sure that requests that time out get removed quickly. If the server response |
is received after the script has been timed out, there should not be weird |
errors as the browser tries to evaluate the responses after the desired time |
period. |
</p> |
<p>This test requires a server running PHP to work.</p> |
<p> |
<p><strong>Firefox Oddity:</strong> Firefox |
will print an error after the script response is received from the server:<br /> |
<span style="color: red">dojo.io.script.jsonp_dojoIoScript1 has no properties</span> |
This is bad because Firefox goes ahead and evaluates the script contents in the page's |
JavaScript space (this happens even when I turn off Firefox Add-Ons). All other browsers |
do not evaluate the script (given the weird Opera 9.22 behavior below). You can test this |
by clicking the <b>Test for SuperXFooBarVariable</b> button after receiving the response |
for timeout.php (check Firebug Net tab to see when request is received). All other browsers |
show an error or show the "undefined" value for SuperXFooBarVariable, but Firefox will show its |
value as being: "Oh no! SuperXFooBarVariable is defined (should not be for timeout case)". |
<p><strong>Opera Oddity:</strong> Opera 9.22 does not seem to trigger the timeout case, |
but rather it waits for the server to send a response to the script before continuing past the |
point where the script is added to the DOM? That seems wrong. Dynamic script tags are no longer |
an async operation? |
</p> |
<button onclick="startTest()">Start Test</button> |
<button onclick="alert(SuperXFooBarVariable)">Test for SuperXFooBarVariable</button> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/script.js |
---|
New file |
0,0 → 1,8 |
if(!dojo._hasResource["tests.io.script"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. |
dojo._hasResource["tests.io.script"] = true; |
dojo.provide("tests.io.script"); |
if(dojo.isBrowser){ |
doh.registerUrl("tests.io.script", dojo.moduleUrl("tests.io", "script.html")); |
} |
} |
/trunk/api/js/dojo1.0/dojo/tests/io/iframeResponse.js.html |
---|
New file |
0,0 → 1,7 |
<html> |
<head> |
</head> |
<body> |
<textarea style="width: 100%%; height: 100px;">window.iframeTestingFunction = function(){ return 42; };</textarea> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/iframeResponse.html |
---|
New file |
0,0 → 1,8 |
<html lang="en"> |
<head> |
</head> |
<body> |
<h1>SUCCESSFUL HTML response</h1> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/upload.cgi |
---|
New file |
0,0 → 1,60 |
#!/usr/bin/python |
# FROM: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/273844 |
import cgi |
import cgitb; cgitb.enable() |
import os, sys |
import string |
UPLOAD_DIR = "/tmp/upload/" |
form = cgi.FieldStorage() |
dbg = [] |
def debug(dbgstr): |
dbg.append(str(dbgstr)) |
def save_uploaded_file(form_field, upload_dir): |
global form |
if not form.has_key(form_field): |
debug("didn't find it! (1)") |
return |
fileitem = form[form_field] |
if not fileitem.file: |
debug(form.getvalue(form_field, "")) |
debug(fileitem.__dict__) |
debug("didn't find it! (2)") |
return |
fout = file(os.path.join(upload_dir, fileitem.filename), 'wb') |
while 1: |
chunk = fileitem.file.read(100000) |
if not chunk: break |
fout.write (chunk) |
fout.close() |
retval = "false"; |
fileFields = "" |
if form.has_key("fileFields"): |
fval = str(form.getvalue("fileFields", "")) |
fileFields = fval.split(",") |
debug("'fileCount': '" + str(len(fileFields)) + "',") |
for field in fileFields: |
debug("'fileField' : '"+field + "',") |
save_uploaded_file(str(field).strip(), UPLOAD_DIR) |
retval = "true"; |
debug("'retval': " + retval) |
print """Content-Type: text/html |
<html> |
<head> |
</head> |
<body> |
<textarea style="width: 100%%; height: 100px;">{ %s }</textarea> |
</body> |
</html> |
""" % (string.join(dbg, "\n")) |
/trunk/api/js/dojo1.0/dojo/tests/io/iframe.html |
---|
New file |
0,0 → 1,124 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<title>Testing dojo.io.iframe</title> |
<style type="text/css"> |
@import "../../resources/dojo.css"; |
</style> |
<script type="text/javascript" |
src="../../dojo.js" djConfig="isDebug: true"></script> |
<script type="text/javascript"> |
dojo.require("doh.runner"); |
dojo.require("dojo.io.iframe"); |
dojo.addOnLoad(function(){ |
doh.register("t", |
[ |
function ioIframeGetText(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.iframe.send({ |
url: "iframeResponse.text.html", |
method: "GET", |
timeoutSeconds: 5, |
preventCache: true, |
handle: function(res, ioArgs){ |
if(!(res instanceof Error) && |
t.is("iframe succeeded", res)){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
} |
}); |
return d; |
}, |
function ioIframeGetJson(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.iframe.send({ |
url: "iframeResponse.json.html", |
method: "GET", |
timeoutSeconds: 5, |
preventCache: true, |
handleAs: "json", |
handle: function(res, ioArgs){ |
if(!(res instanceof Error) && |
t.is("blue", res.color)){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
} |
}); |
return d; |
}, |
function ioIframeGetJavascript(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.iframe.send({ |
url: "iframeResponse.js.html", |
method: "GET", |
timeoutSeconds: 5, |
preventCache: true, |
handleAs: "javascript", |
handle: function(res, ioArgs){ |
console.log("RES: ", res); |
if(!(res instanceof Error) && |
t.is(42, window.iframeTestingFunction())){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
} |
}); |
return d; |
}, |
function ioIframeGetHtml(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.iframe.send({ |
url: "iframeResponse.html", |
method: "GET", |
timeoutSeconds: 5, |
preventCache: true, |
handleAs: "html", |
handle: function(res, ioArgs){ |
if(!(res instanceof Error) && |
t.is("SUCCESSFUL HTML response", res.getElementsByTagName("h1")[0].innerHTML)){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
} |
}); |
return d; |
} |
] |
); |
doh.run(); |
}); |
/* |
dojo.addOnLoad(function(){ |
var td = dojo.io.iframe.get({ |
url: "iframeResponse.text.html", |
timeoutSeconds: 5, |
preventCache: true, |
handle: function(res, ioArgs){ |
if(!(res instanceof Error) && |
"iframe succeeded" == res){ |
console.debug("OK"); |
}else{ |
console.debug("Error", res); |
} |
} |
}); |
}); |
*/ |
</script> |
</head> |
<body> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/script.html |
---|
New file |
0,0 → 1,101 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" |
"http://www.w3.org/TR/html4/strict.dtd"> |
<html> |
<head> |
<title>Testing dojo.io.script</title> |
<style type="text/css"> |
@import "../../resources/dojo.css"; |
</style> |
<script type="text/javascript" |
src="../../dojo.js" djConfig="isDebug: true"></script> |
<script type="text/javascript"> |
dojo.require("doh.runner"); |
dojo.require("dojo.io.script"); |
dojo.addOnLoad(function(){ |
doh.register("t", |
[ |
function ioScriptSimple(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.script.get({ |
url: "scriptSimple.js", |
checkString: "myTasks" |
}); |
td.addBoth(function(res){ |
if(typeof(myTasks) != "undefined" |
&& t.is("Do dishes.", myTasks[1])){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
}); |
return d; |
}, |
function ioScriptJsonp(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.script.get({ |
url: "scriptJsonp.js", |
content: { foo: "bar" }, |
callbackParamName: "callback" |
}); |
td.addBoth(function(res){ |
if(!(res instanceof Error) && |
t.is("mammal", res.animalType)){ |
d.callback(true); |
}else{ |
d.errback(false); |
} |
}); |
return d; |
}, |
function ioScriptJsonpTimeout(t){ |
var d = new doh.Deferred(); |
var td = dojo.io.script.get({ |
url: "../_base/timeout.php", |
callbackParamName: "callback", |
content: {Foo: 'Bar'}, |
timeout: 500, |
handleAs: "json", |
preventCache: true, |
handle: function(response, ioArgs){ |
if(response instanceof Error && response.dojoType == "timeout"){ |
console.debug("FOO OK TEST"); |
d.callback(true); |
}else{ |
console.debug("FOO FAIL TEST"); |
d.errback(false); |
} |
} |
}); |
return d; |
} |
] |
); |
doh.run(); |
}); |
/* |
dojo.addOnLoad(function(){ |
td = dojo.io.script.get({ |
url: "scriptSimple.js", |
checkString: "myTasks" |
}); |
td.addCallback(function(res){ |
alert(myTasks); |
alert(myTasks[1]); |
if(typeof(myTasks) != "undefined" |
&& "Do dishes." == myTasks[1]){ |
alert("yeah"); |
}else{ |
alert("boo"); |
} |
}); |
}); |
*/ |
</script> |
</head> |
<body> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/iframeResponse.text.html |
---|
New file |
0,0 → 1,7 |
<html> |
<head> |
</head> |
<body> |
<textarea style="width: 100%%; height: 100px;">iframe succeeded</textarea> |
</body> |
</html> |
/trunk/api/js/dojo1.0/dojo/tests/io/scriptJsonp.js |
---|
New file |
0,0 → 1,57 |
function getJsonpCallback(url){ |
var result = null; |
var idMatch = url.match(/jsonp=(.*?)(&|$)/); |
if(idMatch){ |
result = idMatch[1]; |
}else{ |
//jsonp didn't match, so maybe it is the jsonCallback thing. |
idMatch = url.match(/callback=(.*?)(&|$)/); |
if(idMatch){ |
result = idMatch[1]; |
} |
} |
if(result){ |
result = decodeURIComponent(result); |
} |
return result; |
} |
function findJsonpDone(){ |
var result = false; |
var scriptUrls = getScriptUrls(); |
for(var i = 0; i < scriptUrls.length; i++){ |
var jsonp = getJsonpCallback(scriptUrls[i]); |
if(jsonp){ |
eval(jsonp + "({animalType: 'mammal'});"); |
result = true; |
break; |
} |
} |
return result; |
} |
function getScriptUrls(){ |
//Get the script tags in the page to figure what state we are in. |
var scripts = document.getElementsByTagName('script'); |
var scriptUrls = new Array(); |
for(var i = 0; scripts && i < scripts.length; i++){ |
var scriptTag = scripts[i]; |
if(scriptTag.id.indexOf("dojoIoScript") == 0){ |
scriptUrls.push(scriptTag.src); |
} |
} |
return scriptUrls; |
} |
function doJsonpCallback(){ |
if(!findJsonpDone()){ |
alert('ERROR: Could not jsonp callback!'); |
} |
} |
//Set a timeout to do the callback check, since MSIE won't see the SCRIPT tag until |
//we complete processing of this page. |
setTimeout('doJsonpCallback()', 300); |
/trunk/api/js/dojo1.0/dojo/tests/io/scriptSimple.js |
---|
New file |
0,0 → 1,5 |
myTasks = new Array(); |
myTasks[0] = 'Take out trash.'; |
myTasks[1] = 'Do dishes.'; |
myTasks[2] = 'Brush teeth.'; |