blob: afb9b2a12699dd5ba85254b3dcc847ea6aa4c207 [file] [log] [blame]
<html>
<head>
<script src="../../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 transforms = { // maps a transform name to its minimum argument count
matrix: 6,
rotate: 1,
scale: 1,
skewX: 1,
skewY: 1,
translate: 1
};
var characters = [
"0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
".",
"e",
"+",
"-",
"e",
"(",
")",
" ",
"\t",
","
];
var gElement = document.createElementNS("http://www.w3.org/2000/svg", "g");
function parseTransform(string)
{
gElement.setAttributeNS(null, "transform", string);
var transformList = gElement.transform.baseVal;
if (!transformList.numberOfItems)
return;
debug("Parsed as " + transformList.numberOfItems + " transform(s): " + string);
}
function fuzz()
{
for (var transform in transforms) {
// Too few / too many arguments
for (var i = 0; i < 50; i++) { //>
var transformString = transform + "(";
for (var j = 0; j < i; j++) { //>
transformString += "0";
if (j < i - 1) //>
transformString += ",";
}
transformString += ")";
parseTransform(transformString);
}
// Random assortments of valid characters
for (var i = 0; i < 100; i++) { //>
var transformString = transform + "(";
var count = Math.scriptedRandomInt(20);
for (var j = 0; j < count; j++) { //>
transformString += characters[Math.scriptedRandomInt(characters.length)];
}
parseTransform(transformString);
}
// Transform names that are "off by one"
var extraChar = transform.charAt(transform.length - 1);
parseTransform(transform + extraChar + "(0, 0)");
parseTransform(transform.substring(0, transform.length - 1) + "(0, 0)");
// Empty-ish transforms
parseTransform(transform);
parseTransform(transform + String.fromCharCode(0));
parseTransform(transform + "(" + String.fromCharCode(0) + ")");
}
}
fuzz();
</script>
<script src="../../resources/js-test-post.js"></script>
</html>