Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / test-runner.html
1 <html>
2 <script src="jsdifflib.js"></script>
3 <script src="utilities.js"></script>
4 <script src="DOMExtension.js"></script>
5 <script src="treeoutline.js"></script>
6
7 <link rel="stylesheet" type="text/css" href="inspector.css">
8 <style>
9 :focus {
10     outline: none;
11 }
12
13 .failed {
14     color: red;
15 }
16
17 .timeout {
18     color: brown;
19 }
20
21 iframe {
22     width: 0;
23     height: 0;
24     opacity: 0;
25 }
26
27 </style>
28
29 <script>
30
31 var layoutTestsServer = "http://localhost:8002/";
32 var scannerServer = "http://localhost:8002/";
33 var remoteDebuggingServer = "http://localhost:9222/";
34
35 var tests = [];
36 var skipList = [
37     // HALT
38     "inspector/console/console-api-on-call-frame.html",
39
40     // FAILED
41     "inspector/console/console-dir-global.html",
42     "inspector/console/console-log-toString-object.html",
43     "inspector/console/console-uncaught-exception-in-eval.html",
44     "inspector/elements/edit-dom-actions.html",
45     "inspector/elements/highlight-node-scaled.html",
46     "inspector/elements/highlight-node-scroll.html",
47     "inspector/elements/highlight-node.html",
48     "inspector/elements/highlight-svg-root.html",
49     "inspector/network-status-non-http.html",
50     "inspector/storage-panel-dom-storage-update.html",
51     "inspector/styles/inject-stylesheet.html",
52     "inspector/styles/protocol-css-regions-commands.html",
53     "inspector/styles/region-style-crash.html",
54     "inspector/styles/styles-disable-then-enable-overriden-ua.html",
55     "inspector/styles/styles-url-linkify.html",
56     "inspector/styles/vendor-prefixes.html",
57     "inspector/timeline/timeline-event-dispatch.html",
58     "inspector/timeline/timeline-frames.html",
59     "inspector/timeline/timeline-network-resource.html",
60     "inspector/timeline/timeline-paint.html",
61     "inspector/timeline/timeline-receive-response-event.html",
62
63     // TIMEOUT
64     "inspector/profiler/cpu-profiler-profiling-without-inspector.html",
65     "inspector/profiler/heap-snapshot-inspect-dom-wrapper.html",
66     "inspector/timeline/timeline-network-received-data.html",
67 ];
68 var treeOutline = null;
69
70 function run(debug)
71 {
72     if (window.runner && debug) {
73         window.runner.continueDebugging();
74         return;
75     }
76
77     if (window.testScannerIframe) 
78         document.body.removeChild(window.testScannerIframe);
79
80     if (window.runner)
81         window.runner.cleanup();
82
83     window.testScannerIframe = document.createElement("iframe");
84     window.testScannerIframe.src = scannerServer + "LayoutTests/http/tests/inspector/resources/test-scanner.html";
85     document.body.appendChild(window.testScannerIframe);
86     window.debug = debug;
87 }
88
89 function runTests()
90 {
91     document.getElementById("outline").removeChildren();
92     treeOutline = new TreeOutline(document.getElementById("outline"));
93
94     document.getElementById("pass").textContent = 0;
95     document.getElementById("skip").textContent = 0;
96     document.getElementById("fail").textContent = 0;
97     document.getElementById("timeout").textContent = 0;
98     document.getElementById("remaining").textContent = tests.length;
99
100     runNextTest();
101 }
102
103 function interrupt()
104 {
105     tests = [];
106 }
107
108 function runNextTest(lastResult)
109 {
110     if (lastResult) {
111         var element = document.getElementById(lastResult);
112         element.textContent = parseInt(element.textContent) + 1;
113
114         element = document.getElementById("remaining");
115         element.textContent = parseInt(element.textContent) - 1;
116         if (window.debug) {
117             document.getElementById("debug").textContent = "Debug";
118             return;
119         }
120     }
121
122     var test;
123     var filter = document.getElementById("filter").value;
124     while (test = tests.shift()) {
125         if (!filter || test[0].match(filter)) {
126             new StandaloneTestRunner(layoutTestsServer + test[0], test[1], runNextTest.bind(null));
127             return;
128         }
129     }
130 }
131
132 function StandaloneTestRunner(testPath, expected, next)
133 {
134     this._testPath = testPath;
135     this._next = next;
136     this._expected = expected;
137     this._pendingMessages = [];
138
139     this._treeElement = new TreeElement(testPath);
140     treeOutline.appendChild(this._treeElement);
141
142     for (var i = 0; !window.debug && i < skipList.length; ++i) {
143         if (testPath.indexOf(skipList[i]) !== -1) {
144             this._treeElement.title = testPath + ": SKIPPED";
145             this._next("skip");
146             return;
147         }
148     }
149     window.runner = this;
150     this._testPage = window.open("about:blank", "inspected", "width=800,height=600");
151
152     window.remoteDebuggingHandshake = this._remoteDebuggingHandshake.bind(this);
153     var script = document.createElement("script");
154     script.src = remoteDebuggingServer + "json?jsonp=remoteDebuggingHandshake";
155     document.head.appendChild(script);
156 }
157
158 StandaloneTestRunner.FrontendLocation = "inspector.html";
159
160 StandaloneTestRunner.prototype = {
161     _remoteDebuggingHandshake: function(data)
162     {
163         for (var i = 0; i < data.length; ++i) {
164             if (data[i].url !== "about:blank")
165                 continue;
166             this._debuggerURL = data[i].webSocketDebuggerUrl.replace("://", "=");
167             this._navigateTestPage();
168             break;
169         }
170     },
171
172     _navigateTestPage: function()
173     {
174         this._testPage.location.href = this._testPath;
175         var width = localStorage.getItem('inspectorWidth') || 600;
176         var height = localStorage.getItem('inspectorHeight') || 400;
177         var features = "width=" + Math.max(width , 600) + ",height=" + Math.max(height, 400);
178         this._inspectorWindowLoading = window.open(StandaloneTestRunner.FrontendLocation + "?" + this._debuggerURL, "inspector", features);
179         this._inspectorWindowLoading.dispatchStandaloneTestRunnerMessages = true;
180         
181         window.addEventListener('unload', this.cleanup.bind(this));
182
183         if (!window.debug)
184             this._watchDog = setTimeout(this._timeout.bind(this), 10000);
185     },
186
187     loadCompleted: function()
188     {
189         if (!window.debug) {
190             this._loadCompleted(this);
191             return;
192         }
193         document.getElementById("debug").textContent = "Continue";
194     },
195
196     continueDebugging: function()
197     {
198         this._loadCompleted();
199     },
200
201     _loadCompleted: function()
202     {
203         this._inspectorWindow = this._inspectorWindowLoading;
204         for (var i = 0; i < this._pendingMessages.length; ++i)
205             this._inspectorWindow.postMessage(this._pendingMessages[i], "*");
206         this._pendingMessages = [];
207     },
208
209     closeWebInspector: function()
210     {
211         if (!window.debug)
212             this._inspectorWindow.close();
213     },
214
215     notifyDone: function(actual)
216     {
217         if (this._done)
218             return;
219         this._done = true;
220
221         if (!window.debug) 
222             this.cleanup()
223
224         clearTimeout(this._watchDog);
225
226         this._treeElement.onselect = this.onTreeElementSelect.bind(this);
227
228         // TODO pavel  is the  RHS || condition wanted?
229         if (actual === this._expected || actual === this._expected + "\n") {
230             this._treeElement.title = this._testPath + ": SUCCESS";
231             this._next("pass");
232             return;
233         }
234
235         this._treeElement.title = this._testPath + ": FAILED";
236         this._treeElement.listItemElement.classList.add("failed");
237
238         var baseLines = difflib.stringAsLines(this._expected);
239         var newLines = difflib.stringAsLines(actual);
240         var sm = new difflib.SequenceMatcher(baseLines, newLines);
241         var opcodes = sm.get_opcodes();
242         var lastWasSeparator = false;
243
244         for (var idx = 0; idx < opcodes.length; idx++) {
245             var code = opcodes[idx];
246             var change = code[0];
247             var b = code[1];
248             var be = code[2];
249             var n = code[3];
250             var ne = code[4];
251             var rowCount = Math.max(be - b, ne - n);
252             var topRows = [];
253             var bottomRows = [];
254             for (var i = 0; i < rowCount; i++) {
255                 if (change === "delete" || (change === "replace" && b < be)) {
256                     var lineNumber = b++;
257                     this._treeElement.appendChild(new TreeElement("- [" + lineNumber + "] " + baseLines[lineNumber]));
258                 }
259
260                 if (change === "insert" || (change === "replace" && n < ne)) {
261                     var lineNumber = n++;
262                     this._treeElement.appendChild(new TreeElement("+ [" + lineNumber + "] " + newLines[lineNumber]));
263                 }
264
265                 if (change === "equal") {
266                     b++;
267                     n++;
268                 }
269             }
270         }
271
272         this._next("fail");
273     },
274
275     evaluateInWebInspector: function(callId, script)
276     {
277         if (this._inspectorWindow)
278             this._inspectorWindow.postMessage(["evaluateForTest", callId, script], "*");
279         else
280             this._pendingMessages.push(["evaluateForTest", callId, script]);
281     },
282
283     _timeout: function()
284     {
285         this._treeElement.title = this._testPath + ": TIMEOUT";
286         this._treeElement.listItemElement.classList.add("timeout");
287         this._done = true;
288         this.cleanup();
289         this._next("timeout");
290     },
291
292     cleanup: function ()
293     {
294         localStorage.setItem('inspectorWidth', this._inspectorWindowLoading.outerWidth);
295         localStorage.setItem('inspectorHeight', this._inspectorWindowLoading.outerHeight);
296         this._inspectorWindowLoading.close();
297         this._testPage.close();
298         delete window.runner;
299     },
300
301     onTreeElementSelect: function () 
302     {
303         var baseEndSentinel = '/inspector/';
304         var baseChars = this._testPath.indexOf(baseEndSentinel) + baseEndSentinel.length;
305         if (baseChars > 0) 
306             document.getElementById("filter").value = this._testPath.substr(baseChars);
307     },
308
309     display: function() { }
310 }
311
312 function onMessageFromTestPage(event)
313 {
314     var signature = event.data;
315     var method = signature.shift();
316     if (method === "tests") {
317         tests = signature[0];
318         runTests();
319         return;
320     }
321
322     if (window.runner)
323         window.runner[method].apply(window.runner, signature);
324 }
325
326 function onload()
327 {
328     var queryParamsObject = {};
329     var queryParams = window.location.search;
330     if (!queryParams)
331         return;
332     var params = queryParams.substring(1).split("&");
333     for (var i = 0; i < params.length; ++i) {
334         var pair = params[i].split("=");
335         queryParamsObject[pair[0]] = pair[1];
336     }
337     if ("filter" in queryParamsObject)
338         document.getElementById("filter").value = queryParamsObject["filter"];
339 }
340
341 window.addEventListener("message", onMessageFromTestPage, true);
342
343 </script>
344 <body onload="onload()">
345 This is a standalone test suite for inspector front-end. Here is how you run it:
346 <ul>
347 <li>Check out WebKit source tree: git clone http://git.chromium.org/external/Webkit.git</li>
348 <li>Run "Tools/Scripts/new-run-webkit-httpd --root=. --port=8002 --server=start"</li>
349 <li>Run Chrome Canary (ToT Chromium) with following flags: "--remote-debugging-port=9222 --user-data-dir=testProfile http://localhost:8002/Source/devtools/front_end/test-runner.html"</li>
350 </ul>
351
352 <button onclick="run()">Run</button>
353 <button id="debug" onclick="run(true)">Debug</button>
354 <button onclick="interrupt()">Interrupt</button>
355 Filter: <input id="filter" type="text" size="40"></input><small><i>Click on results to load filter</i></small><br>
356
357 <span>Passed: <span id="pass">0</span></span>
358 <span>Failed: <span id="fail">0</span></span>
359 <span>Timeout: <span id="timeout">0</span></span>
360 <span>Skipped: <span id="skip">0</span></span>
361 <span>Remaining: <span id="remaining">0</span><br>
362
363 <ol id="outline" style="font-size: 12px !important" class="source-code outline-disclosure"></ol>
364
365 </body>
366 </html>