blob: dac5cd7565ccafc3113087f4ebfbde514389133d [file] [log] [blame]
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
<script src="resources/scripted-random.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<script>
description("This test fuzzes the transform parser with semi-random attribute values and dumps the results of any values that parse successfully.");
var attributes = { // maps a viewspec attribute to its minimum argument count
viewBox: 6,
preserveAspectRatio: 1,
transform: 1,
zoomAndPan: 1,
viewTarget: 1
};
var preserveAspectRatioValues = [ "Min", "Max", "Mid" ];
var testsToRun = [
"svgView",
"svgView(",
"svgView()",
"svgView(" + String.fromCharCode(0),
"svgView(" + String.fromCharCode(0) + ")",
"svgView(transform(scale(2));;)",
"svgView(transform(scale(2));x", // used to hang
"svgView(transform(scale(.5)))",
"svgView(;transform(scale(.5)))",
"svgView(;;transform(scale(.5)))",
"svgView(transform(scale(.5));transform(scale(2));transform(scale(2)))",
];
var characters = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
".",
"e",
"+",
"-",
"e",
"(",
")",
" ", // not a valid fragment char
"\t", // not a valid fragment char
","
];
function buildTestsToRun() {
for (var attribute in attributes) {
// Too few / too many arguments
for (var i = 0; i < 20; i++) { //>
var attributeString = "svgView(" + attribute + "(";
for (var j = 0; j < i; j++) { //>
attributeString += "0";
if (j < i - 1) //>
attributeString += ",";
}
attributeString += "))";
testsToRun.push(attributeString);
}
// Random assortments of valid characters
for (var i = 0; i < 100; i++) { //>
var attributeString = "svgView(" + attribute + "(";
var count = Math.scriptedRandomInt(20);
for (var j = 0; j < count; j++) { //>
attributeString += characters[Math.scriptedRandomInt(characters.length)];
}
testsToRun.push(attributeString);
}
// attribute names that are "off by one"
var extraChar = attribute.charAt(attribute.length - 1);
testsToRun.push("svgView(" + attribute + extraChar + "(0, 0)");
testsToRun.push("svgView(" + attribute.substring(0, attribute.length - 1) + "(0, 0)");
// Empty-ish attributes
testsToRun.push("svgView(" + attribute);
testsToRun.push("svgView(" + attribute + String.fromCharCode(0));
testsToRun.push("svgView(" + attribute + "(" + String.fromCharCode(0) + ")");
}
}
function viewSpecToString(viewSpec)
{
if (!viewSpec)
return viewSpec;
var attributes = [];
if (viewSpec.transform)
attributes.push("transform(" + viewSpec.transform + ")");
if (viewSpec.viewBox)
attributes.push("viewBox(" + viewSpec.viewBox + ")");
if (viewSpec.preserveAspectRatio)
attributes.push("preserveAspectRatio(" + viewSpec.preserveAspectRatio + ")");
if (viewSpec.zoomAndPan)
attributes.push("zoomAndPan(" + viewSpec.zoomAndPan + ")");
if (viewSpec.viewTarget)
attributes.push("viewTarget(" + viewSpac.viewTarget + ")");
return "svgView(" + attributes.join(";") + ")";
}
var testNumber = 0;
var testString = "[initial view]"
function makeURLRelative(url) {
return url.slice(url.indexOf("resources"));
}
function testFragment(string) {
var oldEmbed = document.getElementById("object");
if (oldEmbed) {
oldEmbed.parentNode.removeChild(oldEmbed);
}
var embedElement = document.createElement("iframe");
embedElement.setAttribute("id", "object");
embedElement.setAttribute("width", "100");
embedElement.setAttribute("height", "100");
embedElement.setAttribute("onload", "continueFuzzing(event)");
var newURL = "resources/viewspec-parser.svg#" + string;
embedElement.src = newURL;
debug("Starting: " + makeURLRelative(embedElement.src));
document.body.appendChild(embedElement);
}
function startNextTest()
{
testFragment(testString);
}
function continueFuzzing(event)
{
var embedElement = document.getElementById("object");
if (embedElement.contentDocument) {
debug("Loaded: " + makeURLRelative(embedElement.contentDocument.URL));
debug("Parsed: " + viewSpecToString(embedElement.contentDocument.currentView) + " from: " + testString);
} else
debug("no svgdocument");
if (testNumber < testsToRun.length)
testString = testsToRun[testNumber];
else {
var scriptTag = document.createElement("script");
scriptTag.src = "../../fast/js/resources/js-test-post.js";
document.body.appendChild(scriptTag);
if (window.layoutTestController)
layoutTestController.notifyDone();
return;
}
testNumber++;
// this lets us out of the onload handler so we don't overrun the stack
window.setTimeout(startNextTest, 0);
}
if (window.layoutTestController)
layoutTestController.waitUntilDone();
buildTestsToRun();
testFragment("");
successfullyParsed = true;
</script>
</html>