3 <link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
4 <script src="../../fast/js/resources/js-test-pre.js"></script>
5 <script src="resources/scripted-random.js"></script>
8 <p id="description"></p>
9 <div id="console"></div>
11 description("This test fuzzes the transform parser with semi-random attribute values and dumps the results of any values that parse successfully.");
13 var attributes = { // maps a viewspec attribute to its minimum argument count
15 preserveAspectRatio: 1,
21 var preserveAspectRatioValues = [ "Min", "Max", "Mid" ];
27 "svgView(" + String.fromCharCode(0),
28 "svgView(" + String.fromCharCode(0) + ")",
29 "svgView(transform(scale(2));;)",
30 "svgView(transform(scale(2));x", // used to hang
31 "svgView(transform(scale(.5)))",
32 "svgView(;transform(scale(.5)))",
33 "svgView(;;transform(scale(.5)))",
34 "svgView(transform(scale(.5));transform(scale(2));transform(scale(2)))",
56 " ", // not a valid fragment char
57 "\t", // not a valid fragment char
61 function buildTestsToRun() {
62 for (var attribute in attributes) {
64 // Too few / too many arguments
65 for (var i = 0; i < 20; i++) { //>
66 var attributeString = "svgView(" + attribute + "(";
67 for (var j = 0; j < i; j++) { //>
68 attributeString += "0";
70 attributeString += ",";
72 attributeString += "))";
73 testsToRun.push(attributeString);
76 // Random assortments of valid characters
77 for (var i = 0; i < 100; i++) { //>
78 var attributeString = "svgView(" + attribute + "(";
79 var count = Math.scriptedRandomInt(20);
80 for (var j = 0; j < count; j++) { //>
81 attributeString += characters[Math.scriptedRandomInt(characters.length)];
83 testsToRun.push(attributeString);
86 // attribute names that are "off by one"
87 var extraChar = attribute.charAt(attribute.length - 1);
88 testsToRun.push("svgView(" + attribute + extraChar + "(0, 0)");
89 testsToRun.push("svgView(" + attribute.substring(0, attribute.length - 1) + "(0, 0)");
91 // Empty-ish attributes
92 testsToRun.push("svgView(" + attribute);
93 testsToRun.push("svgView(" + attribute + String.fromCharCode(0));
94 testsToRun.push("svgView(" + attribute + "(" + String.fromCharCode(0) + ")");
99 function viewSpecToString(viewSpec)
105 if (viewSpec.transform)
106 attributes.push("transform(" + viewSpec.transform + ")");
107 if (viewSpec.viewBox)
108 attributes.push("viewBox(" + viewSpec.viewBox + ")");
109 if (viewSpec.preserveAspectRatio)
110 attributes.push("preserveAspectRatio(" + viewSpec.preserveAspectRatio + ")");
111 if (viewSpec.zoomAndPan)
112 attributes.push("zoomAndPan(" + viewSpec.zoomAndPan + ")");
113 if (viewSpec.viewTarget)
114 attributes.push("viewTarget(" + viewSpac.viewTarget + ")");
116 return "svgView(" + attributes.join(";") + ")";
120 var testString = "[initial view]"
122 function makeURLRelative(url) {
123 return url.slice(url.indexOf("resources"));
126 function testFragment(string) {
127 var oldEmbed = document.getElementById("object");
129 oldEmbed.parentNode.removeChild(oldEmbed);
131 var embedElement = document.createElement("iframe");
132 embedElement.setAttribute("id", "object");
133 embedElement.setAttribute("width", "100");
134 embedElement.setAttribute("height", "100");
135 embedElement.setAttribute("onload", "continueFuzzing(event)");
136 var newURL = "resources/viewspec-parser.svg#" + string;
137 embedElement.src = newURL;
138 debug("Starting: " + makeURLRelative(embedElement.src));
139 document.body.appendChild(embedElement);
142 function startNextTest()
144 testFragment(testString);
147 function continueFuzzing(event)
149 var embedElement = document.getElementById("object");
150 if (embedElement.contentDocument) {
151 debug("Loaded: " + makeURLRelative(embedElement.contentDocument.URL));
152 debug("Parsed: " + viewSpecToString(embedElement.contentDocument.currentView) + " from: " + testString);
154 debug("no svgdocument");
156 if (testNumber < testsToRun.length)
157 testString = testsToRun[testNumber];
159 var scriptTag = document.createElement("script");
160 scriptTag.src = "../../fast/js/resources/js-test-post.js";
161 document.body.appendChild(scriptTag);
162 if (window.layoutTestController)
163 layoutTestController.notifyDone();
168 // this lets us out of the onload handler so we don't overrun the stack
169 window.setTimeout(startNextTest, 0);
171 if (window.layoutTestController)
172 layoutTestController.waitUntilDone();
176 successfullyParsed = true;