2007-10-18 Eric Seidel <eric@webkit.org>
[WebKit-https.git] / LayoutTests / svg / dom / viewspec-parser.html-disabled
1 <html>
2 <head>
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>
6 </head>
7 <body>
8 <p id="description"></p>
9 <div id="console"></div>
10 <script>
11     description("This test fuzzes the transform parser with semi-random attribute values and dumps the results of any values that parse successfully.");
12
13     var attributes = { // maps a viewspec attribute to its minimum argument count
14         viewBox: 6,
15         preserveAspectRatio: 1,
16         transform: 1,
17         zoomAndPan: 1,
18         viewTarget: 1
19     };
20     
21     var preserveAspectRatioValues = [ "Min", "Max", "Mid" ];
22     
23     var testsToRun = [
24       "svgView",
25       "svgView(",
26       "svgView()",
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)))",
35       ];
36     
37     
38     var characters = [
39         "0",
40         "1",
41         "2",
42         "3",
43         "4",
44         "5",
45         "6",
46         "7",
47         "8",
48         "9",
49         ".",
50         "e",
51         "+",
52         "-",
53         "e",
54         "(",
55         ")",
56         " ", // not a valid fragment char
57         "\t", // not a valid fragment char
58         ","
59     ];
60     
61     function buildTestsToRun() {
62       for (var attribute in attributes) {
63
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";
69                   if (j < i - 1) //>
70                       attributeString += ",";
71               }
72               attributeString += "))";
73               testsToRun.push(attributeString);
74           }
75
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)];
82               }
83               testsToRun.push(attributeString);
84           }
85           
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)");
90           
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) + ")");
95       }
96       
97     }
98     
99     function viewSpecToString(viewSpec)
100     {
101         if (!viewSpec)
102           return viewSpec;
103         
104         var attributes = [];
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 + ")");
115           
116         return "svgView(" + attributes.join(";") + ")";
117     }
118     
119     var testNumber = 0;
120     var testString = "[initial view]"
121     
122     function makeURLRelative(url) {
123       return url.slice(url.indexOf("resources"));
124     }
125
126     function testFragment(string) {
127       var oldEmbed = document.getElementById("object");
128       if (oldEmbed) {
129         oldEmbed.parentNode.removeChild(oldEmbed);
130       }
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);
140     }
141
142     function startNextTest()
143     {
144       testFragment(testString);
145     }
146     
147     function continueFuzzing(event)
148     {
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);      
153         } else
154           debug("no svgdocument");
155         
156         if (testNumber < testsToRun.length)
157           testString = testsToRun[testNumber];
158         else {
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();
164           return;
165         }
166         testNumber++;
167         
168         // this lets us out of the onload handler so we don't overrun the stack
169         window.setTimeout(startNextTest, 0);
170     }
171     if (window.layoutTestController)
172       layoutTestController.waitUntilDone();
173     
174     buildTestsToRun();
175     testFragment("");
176     successfullyParsed = true;
177 </script>
178 </html>