Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Side by Side Diff: third_party/WebKit/LayoutTests/svg/dom/fuzz-path-parser.html

Issue 1407133007: Convert the path fuzzer test to a unit test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Less C'n'P Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/svg/dom/fuzz-path-parser-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <html>
2 <head>
3 <script src="../../resources/js-test.js"></script>
4 <script src="resources/scripted-random.js"></script>
5 </head>
6 <body>
7 <p id="description"></p>
8 <div id="console"></div>
9 <script>
10 description("This test fuzzes the path parser with semi-random attribute val ues and dumps the results.");
11
12 var characters = [
13 [ "m", 2 ], // maps a character to the number of arguments it requires
14 [ "M", 2 ],
15 [ "l", 2 ],
16 [ "L", 2 ],
17 [ "h", 1 ],
18 [ "H", 1 ],
19 [ "v", 1 ],
20 [ "V", 1 ],
21 [ "z", 0 ],
22 [ "Z", 0 ],
23 [ "c", 6 ],
24 [ "C", 6 ],
25 [ "s", 4 ],
26 [ "S", 4 ],
27 [ "q", 4 ],
28 [ "Q", 4 ],
29 [ "t", 2 ],
30 [ "T", 2 ],
31 [ "a", 7 ],
32 [ "A", 7 ]
33 ];
34
35 var separators = [
36 " ",
37 ","
38 ];
39
40 var pathElement = document.createElementNS("http://www.w3.org/2000/svg", "pa th");
41 function parsePath(string)
42 {
43 pathElement.setAttributeNS(null, "d", string);
44
45 var pathSegList = pathElement.pathSegList;
46 var numberOfItems = pathSegList.numberOfItems;
47
48 if (!numberOfItems) {
49 debug("Could not parse: " + string);
50 return;
51 }
52
53 var pathCommands = "";
54 for (var i = 0; i < numberOfItems; i++) { //>
55 pathCommands += pathSegList.getItem(i).pathSegTypeAsLetter;
56 }
57 debug("Parsed as " + numberOfItems + " command(s) [" + pathCommands + "] : " + string);
58 }
59
60 function fuzz()
61 {
62 // Random assortments of valid characters with semi-valid argument count s
63 for (var i = 0; i < 250; i++) { //>
64 var pathString = "M1,1"; // path must start with moveto
65
66 var numPathCommands = Math.scriptedRandomInt(20);
67 for (var j = 0; j < numPathCommands; j++) { //>
68 var characterIndex = Math.scriptedRandomInt(characters.length);
69 pathString += characters[characterIndex][0];
70
71 var numArguments;
72 var argumentRandomizer = Math.scriptedRandomInt(10);
73 if (argumentRandomizer < 8) //>
74 numArguments = characters[characterIndex][1];
75 else if (argumentRandomizer < 9) //>
76 numArguments = characters[characterIndex][1] + 1;
77 else
78 numArguments = Math.max(characters[characterIndex][1] - 1, 0 );
79
80 for (var k = 0; k < numArguments; k++) { //>
81 pathString += String(Math.scriptedRandomInt(10));
82 pathString += separators[Math.scriptedRandomInt(separators.l ength)];
83 }
84 }
85 parsePath(pathString);
86 }
87 }
88 fuzz();
89
90 </script>
91 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/svg/dom/fuzz-path-parser-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698