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

Side by Side Diff: third_party/WebKit/LayoutTests/inspector/network/network-json-parser.html

Issue 1912973002: [DevTools] JSONView parsing smarter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 <html> 1 <html>
2 <head> 2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script> 3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/network-test.js"></script> 4 <script src="../../http/tests/inspector/network-test.js"></script>
5 <script> 5 <script>
6 function test() { 6 function test() {
7 var worker = new WorkerRuntime.Worker("formatter_worker");
7 function check(jsonText) 8 function check(jsonText)
8 { 9 {
9 var result = WebInspector.JSONView.parseJSON(jsonText); 10 var resultData = WebInspector.JSONView._extractJSON(jsonText);
10 InspectorTest.addResult(""); 11 if (!resultData) {
11 InspectorTest.addResult("Input: " + jsonText); 12 failure();
12 if (!result) { 13 return;
14 }
15
16 worker.onmessage = success;
17 worker.postMessage({method: "relaxedJSONParser", params:{content: result Data.data}});
18
19 function success(event)
20 {
21 var data = event.data;
22 if (data === null) {
23 failure();
24 return;
25 }
26 resultData.data = data;
27 InspectorTest.addResult("");
28 InspectorTest.addResult("Input: " + cleanData(jsonText));
29
30 InspectorTest.addResult("Prefix: " + cleanData(resultData.prefix));
31 InspectorTest.addResult("Suffix: " + cleanData(resultData.suffix));
32 InspectorTest.addResult("Data: " + cleanData(JSON.stringify(resultDa ta.data, function(k, v) {
33 if (v === undefined)
34 return "!<undefined>!";
35 else if (v === Infinity)
36 return "!<Infinity>!";
37 else if (v === -Infinity)
38 return "!<-Infinity>!";
39 return v;
40 })));
41 runNext();
42 }
43
44 function failure()
45 {
46 InspectorTest.addResult("");
47 InspectorTest.addResult("Input: " + cleanData(jsonText));
48
13 InspectorTest.addResult("Invalid JSON"); 49 InspectorTest.addResult("Invalid JSON");
50 runNext();
51 }
52 }
53 function cleanData(data)
54 {
55 return data.replace(/\0/g, "**NULL**").replace(/\r/g, "**CR**");
56 }
57 function runNext()
58 {
59 if (currentTestIndex < tests.length) {
60 currentTestIndex++;
61 check(tests[currentTestIndex - 1]);
14 } else { 62 } else {
15 InspectorTest.addResult("Prefix: " + result.prefix); 63 worker.terminate();
16 InspectorTest.addResult("Suffix: " + result.suffix); 64 InspectorTest.completeTest();
17 InspectorTest.addResult("Data: " + JSON.stringify(result.data));
18 } 65 }
19 } 66 }
20 67
21 check("plain text"); 68 var currentTestIndex = 0;
22 check("{\"x\": 5, \"y\": false, \"z\":\"foo\"}"); 69 var tests = [
23 check("{\"bar\": [,,,1, 2, 3,,,], \"baz\": {\"data\": []}}"); 70 "plain text",
24 check("[[],[],[]]"); 71 "{\"x\": 5, \"y\": false, \"z\":\"foo\"}",
25 check("/* GUARD */callback({\"a\": []]});"); 72 "{\"bar\": [,,,1, 2, 3,,,], \"baz\": {\"data\": []}}",
26 check("foo({a = 5});"); 73 "[[],[],[]]",
27 check("(function(){return {\"a\": []}})()"); 74 "/* GUARD */callback({\"a\": []]});",
75 "foo({a = 5});",
76 "(function(){return {\"a\": []}})()",
28 77
29 InspectorTest.completeTest(); 78 "{\"name\": \"value\"}",
79 "while(1); {\"name\": \"value\"}",
80 "[, \"foo\", -4.2, true, false, null]",
81 "[{\"foo\": {}, \"bar\": []},[[],{}]]",
82 "/* vanilla */ run ( [1, 2, 3] ) ;",
83 "[\"A\\\"B\\u0020C\\nD\\\\E\\u04ABF\"]",
84 "Text with with {}) inside",
85 "<html>404 Page not found with foo({}) inside</html>",
86 "/* vanilla prefix too large to be considered prefix Ok? */ run([1, 2, 3 ]); // since it is unlikely JSONP",
87 "[\"This is a really long string\"]{\"This is also a very long string\": \"short\"}",
88 "{010:4}",
89 "{\"foo\":bar}",
90 "{\"foo\":<\"bar\"}",
91 "{\"foo\":\"b\\ar\"}",
92 "[\"foo\"]",
93 "{foo:\"bar\"}",
94 "{ 10 : 4 }",
95 "{ \"foo\" : 010 }",
96 "{\"foo\": 3e3}",
97 "{\"foo\": 3e3,}",
98 "[,,false, null, true,1,0,,,]",
99 "[,,,]",
100 "{foo:\t{bar: null,\r},bar: [\n],foo1: 1,foo2:\r\n -1,\n\rfoo3: -1e-30 ,foo4: 1E+30,foo5: -1E+1,"+
101 "foo6: \"bar\",\"foo7\": false,\"\\\"\\f\\o\\o8\": true,'fo\\'o9 ': undefined,"+
102 "\"foo10\": [\"bar\", null],\"\": -Infinity,foo11: {},foo12: [{} ],}",
103 "",
104 "\n",
105 "[]",
106 "{}",
107 "()",
108 "foobar",
109 "\"foobar\"",
110 "\"foo\" \"bar\"",
111 "[010, 10, 0x10]",
112 "{010: 010, 0x10: 0x10, 10: 10}",
113 "{-010: -010}",
114 "{-0x10: -0x10}",
115 "{-10: -10}",
116 "{010: -010, 0x10: -0x10, 10: -10}",
117 "[10000, 0x1000000, 0xfEaB3, 01023456, 1234567901, 123.456, -123.456,12. 33E-5, 123.456e+5, 123.456e5]",
118 "[\"S\\\"0\u0000me\\\"teXt\"]",
119 " ",
120 " [ {} ] ",
121
122 "var i=0;",
123 "while(true) {}",
124 "while(true); {d:5}",
125 "while(true); {d:-5}",
126 "while(true); {d:[-5]}",
127 "while(true); {d:[-5,-0,03,0xF,0xFF]}",
128 "{d:function () {var i;}}",
129 "{5:d}",
130 "[-{},-[],{},[]]",
131 "[-foo, foo, -bar, bar]",
132 "[function(){}, -function(){}]",
133 "{-true:0}",
134 "{true: 0}",
135 "[-true]",
136 "[true]",
137 "[!true]",
138 "[~true]",
139 "{length: 0}",
140 "[true, false]",
141 "[true, -false]",
142 "[true, false, null, undefined, {}, [], \"\", \"1\", '', '1', 1, -1, -0, 0]",
143 "[-{}, !{}, -[{}], ![{}]]",
144 "[-1, -0, +1, +0, +-1, -!~0]",
145 "[0xFF, -0xFF, +0xFF, 1e1, -1e1, 1E-1, -1E-1, 010, -010, +010]",
146 // Test from json5 ( https://github.com/aseemk/json5 )
147 `{
148 foo: 'bar',
149 while: true,
150
151 this: 'is a \\
152 multi-line string',
153
154 // this is an inline comment
155 here: 'is another', // inline comment
156
157 /* this is a block comment
158 that continues on another line */
159
160 hex: 0xDEADbeef,
161 half: .5,
162 delta: +10,
163 to: Infinity, // and beyond!
164
165 finally: 'a trailing comma',
166 oh: [
167 "we shouldn't forget",
168 'arrays can have',
169 'trailing commas too',
170 ],
171 }`
172 ];
173 runNext();
30 } 174 }
31 175
32 </script> 176 </script>
33 </head> 177 </head>
34 <body onload="runTest()"> 178 <body onload="runTest()">
35 <p>Tests JSON parsing.</p> 179 <p>Tests JSON parsing.</p>
36 </body> 180 </body>
37 </html> 181 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698