2011-06-24 Andrey Kosyakov <caseq@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / inspector / resources / extension-main.html
1 <html>
2 <head>
3 <script type="text/javascript">
4
5 function dumpObject(object, nondeterministicProps, prefix, firstLinePrefix)
6 {
7     prefix = prefix || "";
8     firstLinePrefix = firstLinePrefix || prefix;
9     output(firstLinePrefix + "{");
10     for (var prop in object) {
11         var prefixWithName = prefix + "    " + prop + " : ";
12         var propValue = object[prop];
13         if (nondeterministicProps && prop in nondeterministicProps)
14             output(prefixWithName + "<" + typeof propValue + ">");
15         else if (propValue === null)
16             output(prefixWithName + "null");
17         else if (typeof propValue === "object")
18             dumpObject(propValue, nondeterministicProps, prefix + "    ", prefixWithName);
19         else if (typeof propValue === "string")
20             output(prefixWithName + "\"" + propValue + "\"");
21         else if (typeof propValue === "function")
22             output(prefixWithName + "<function>");
23         else
24             output(prefixWithName + propValue);
25     }
26     output(prefix + "}");
27 }
28
29 function dumpArray(result)
30 {
31     if (result instanceof Array) {
32         for (var i = 0; i < result.length; ++i)
33             output(result[i]);
34     } else
35         output(result);
36 }
37
38 function evaluateOnFrontend(expression, callback)
39 {
40     function callbackWrapper(event)
41     {
42         channel.port1.removeEventListener("message", callbackWrapper, false);
43         callback(event.data.response);
44     }
45     var channel = new MessageChannel();
46     channel.port1.start();
47     if (callback)
48         channel.port1.addEventListener("message", callbackWrapper, false);
49     top.postMessage({ expression: expression }, [ channel.port2 ], "*");
50 }
51
52 function output(message)
53 {
54     evaluateOnFrontend("InspectorTest.addResult(unescape('" + escape(message) + "'));");
55 }
56
57 output("Started extension.");
58 </script>
59 <script src="extension-main.js"></script>
60 </head>
61 </html>