|
|
@ -18,7 +18,6 @@ var base = fs.realpathSync(process.argv[2]); |
|
|
|
|
|
|
|
// first read in the static test data |
|
|
|
var testprog = fs.readFileSync(base + "/sanitizer-api/support/testcases.sub.js").toString() + "\n\n"; |
|
|
|
|
|
|
|
// next extract the tests proper from the containing HTML file |
|
|
|
var testfile = fs.readFileSync(base + "/sanitizer-api/sanitizer-sanitize.https.tentative.html").toString(); |
|
|
|
testprog += (new JSDOM(testfile)).window.document.body.getElementsByTagName("script")[0].textContent; |
|
|
@ -78,6 +77,7 @@ window.test = function(prog, message) { |
|
|
|
inputType: undefined, |
|
|
|
output: undefined, |
|
|
|
exceptionType: undefined, |
|
|
|
negativeTest: false, |
|
|
|
message: message, |
|
|
|
}; |
|
|
|
prog(); |
|
|
@ -116,4 +116,78 @@ window.assert_equals = function(result, exp) { |
|
|
|
|
|
|
|
// Finally execute the tests to produce our output |
|
|
|
window.eval(testprog); |
|
|
|
console.log(JSON.stringify(window.genericTestSet, null, 2)); |
|
|
|
var out = window.genericTestSet; |
|
|
|
|
|
|
|
// Now do the same for namespace tests |
|
|
|
|
|
|
|
var window = (new JSDOM("", {runScripts: "outside-only"})).window; |
|
|
|
var testfile = fs.readFileSync(base + "/sanitizer-api/sanitizer-names.https.html").toString(); |
|
|
|
testprog = (new JSDOM(testfile)).window.document.body.getElementsByTagName("script")[0].textContent; |
|
|
|
|
|
|
|
window.genericTestSet = []; |
|
|
|
window.configTestSet = []; |
|
|
|
window.test = function(prog, message) { |
|
|
|
window.genericTest = { |
|
|
|
config: undefined, |
|
|
|
input: undefined, |
|
|
|
inputType: undefined, |
|
|
|
output: undefined, |
|
|
|
exceptionType: undefined, |
|
|
|
negativeTest: false, |
|
|
|
message: message, |
|
|
|
}; |
|
|
|
window.wrapOutput = false; |
|
|
|
prog(); |
|
|
|
}; |
|
|
|
window.Sanitizer = function(conf) { |
|
|
|
window.genericTest.config = conf || null; |
|
|
|
return { |
|
|
|
getConfiguration: function() { |
|
|
|
return window.genericTest.config || {}; |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
window.assert_array_equals = function(act, exp) {}; |
|
|
|
window.document.origCreateElement = window.document.createElement; |
|
|
|
window.document.createElement = function(type) { |
|
|
|
if (type === "template") { |
|
|
|
return new window.FakeTemplate(); |
|
|
|
} |
|
|
|
return window.document.origCreateElement(type); |
|
|
|
}; |
|
|
|
window.FakeTemplate = class { |
|
|
|
innerHTML = ""; |
|
|
|
setHTML = function(str) { |
|
|
|
this.innerHTML = str; |
|
|
|
window.genericTest.input = str; |
|
|
|
} |
|
|
|
get content() { |
|
|
|
return this; |
|
|
|
} |
|
|
|
get firstElementChild() { |
|
|
|
window.wrapOutput = true; |
|
|
|
return this; |
|
|
|
} |
|
|
|
}; |
|
|
|
window.assert_equals = function(result, exp) { |
|
|
|
if (!window.wrapOutput) { |
|
|
|
window.genericTest.output = exp; |
|
|
|
} else { |
|
|
|
window.genericTest.output = "<svg>" + exp + "</svg>"; |
|
|
|
} |
|
|
|
window.genericTestSet.push(window.genericTest); |
|
|
|
}; |
|
|
|
window.assert_not_equals = function(result, exp) { |
|
|
|
if (!window.wrapOutput) { |
|
|
|
window.genericTest.output = exp; |
|
|
|
} else { |
|
|
|
window.genericTest.output = "<svg>" + exp + "</svg>"; |
|
|
|
} |
|
|
|
window.genericTest.negativeTest = true; |
|
|
|
window.genericTestSet.push(window.genericTest); |
|
|
|
}; |
|
|
|
|
|
|
|
window.eval(testprog); |
|
|
|
out = out.concat(window.genericTestSet); |
|
|
|
|
|
|
|
console.log(JSON.stringify(out, null, 2)); |