Bug 491201 - Turn on XHR::Send tests, wrap the call to nsIFile.remove in try/catch to avoid orange on Windows machines.r+sr=sicking

This commit is contained in:
Matin Movassate 2009-09-15 16:53:32 -07:00
parent b8fc782588
commit b89b3dac76
2 changed files with 35 additions and 57 deletions

View File

@ -154,6 +154,10 @@ _TEST_FILES = test_bug5141.html \
test_bug414796.html \
test_bug416317-1.html \
test_bug416317-2.html \
test_XHRSendData.html \
file_XHRSendData.sjs \
file_XHRSendData_doc.xml \
file_XHRSendData_doc.xml^headers^ \
file_bug416317.xhtml \
test_bug416383.html \
test_bug417255.html \

View File

@ -36,12 +36,21 @@ is(testDoc2.inputEncoding, null, "wrong encoding");
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var testData = "blahblahblahblahblahblahblaaaaaaaah. blah.";
testFileTxt = createFileWithDataExt(testData, ".txt");
testFilePng = createFileWithDataExt(testData, ".png");
testFileJpg = createFileWithDataExt(testData, ".jpg");
testFileGif = createFileWithDataExt(testData, ".gif");
testFileXml = createFileWithDataExt(testData, ".xml");
testFileUnknown = createFileWithDataExt(testData, "noext");
var extensions = [".txt",".png",".jpg",".gif",".xml", "noext"];
var fileTypes = ["text/plain", "image/png", "image/jpeg", "image/gif", "text/xml", null];
var testFiles = new Array;
var testDOMFiles = new Array;
extensions.forEach(
function (extension) {
var testFile = createFileWithDataExt(testData, extension);
testFiles.push(testFile);
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
testDOMFiles.push(fileList.files[0]);
}
);
function createFileWithDataExt(fileData, extension) {
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
@ -52,10 +61,7 @@ function createFileWithDataExt(fileData, extension) {
outStream.write(fileData, fileData.length);
outStream.close();
var fileList = document.getElementById('fileList');
fileList.value = testFile.path;
return fileList.files[0];
return testFile;
}
tests = [{ body: null,
@ -135,42 +141,20 @@ tests = [{ body: null,
resBody: "<!-- doc 2 -->\n<res>text</res>",
resContentType: "foo/bar; charset=uTf-8",
},
{ body: testFileTxt,
resBody: testData,
resContentType: "text/plain",
resContentLength: testData.length,
},
{ body: testFilePng,
resBody: testData,
resContentType: "image/png",
resContentLength: testData.length,
},
{ body: testFileJpg,
resBody: testData,
resContentType: "image/jpeg",
resContentLength: testData.length,
},
{ body: testFileGif,
resBody: testData,
resContentType: "image/gif",
resContentLength: testData.length,
},
{ body: testFileXml,
resBody: testData,
resContentType: "text/xml",
resContentLength: testData.length,
},
{ body: testFileUnknown,
resBody: testData,
resContentType: "",
resContentLength: testData.length,
},
{ //will trigger a redirect test server-side
body: ("TEST_REDIRECT_STR&url=" + window.location.host + window.location.pathname),
redirect: true,
},
];
for (var i = 0; i < testDOMFiles.length; i++) {
tests.push({ body: testDOMFiles[i],
resBody: testData,
resContentType: fileTypes[i],
resContentLength: testData.length,
});
}
try {
for each(test in tests) {
xhr = new XMLHttpRequest;
@ -210,25 +194,15 @@ finally {
}
function cleanUpData() {
removeFileWithExt(".txt");
removeFileWithExt(".png");
removeFileWithExt(".jpg");
removeFileWithExt(".gif");
removeFileWithExt(".xml");
removeFileWithExt("noext");
testFiles.forEach(
function (testFile) {
try {
testFile.remove(false);
} catch (e) {}
}
);
}
function removeFileWithExt(extension)
{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var dirSvc = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties);
var testFile = dirSvc.get("ProfD", Components.interfaces.nsIFile);
testFile.append("testfile" + extension);
testFile.remove(false);
}
</script>
</pre>
</body>