2011-04-06 Andrey Kosyakov <caseq@chromium.org>
[WebKit-https.git] / LayoutTests / http / tests / inspector / extensions-test.js
1 function log(message)
2 {
3     output(message);
4 }
5
6 function extensionFunctions()
7 {
8     var functions = "";
9
10     for (symbol in window) {
11         if (/^extension_/.exec(symbol) && typeof window[symbol] === "function")
12             functions += window[symbol].toString();
13     }
14     return functions;
15 }
16
17 var initialize_ExtensionsTest = function()
18 {
19
20 InspectorTest.dispatchOnMessage = function(messageId, callback, recurring)
21 {
22     function onMessage(event)
23     {
24         if (typeof(event.data) !== "object" || event.data.command !== messageId)
25             return;
26         if (!recurring)
27             window.removeEventListener("message", onMessage, false);
28         var port = event.ports && event.ports[0];
29         if (callback(event.data, port) && port)
30             port.postMessage("");
31     }
32     window.addEventListener("message", onMessage, false);
33 }
34
35 InspectorTest.runExtensionTests = function()
36 {
37     RuntimeAgent.evaluate("location.href", "console", false, function(error, result) {
38         if (error)
39             return;
40         var pageURL = result.description;
41         var extensionURL = (/^https?:/.test(pageURL) ?
42             pageURL.replace(/^(https?:\/\/[^/]*\/).*$/,"$1") :
43             pageURL.replace(/\/inspector\/extensions\/[^/]*$/, "/http/tests")) +
44             "/inspector/resources/extension-main.html";
45         WebInspector.addExtensions([{ startPage: extensionURL }]);
46     });
47 }
48
49 InspectorTest.dispatchOnMessage("extension-tests-done", InspectorTest.completeTest, true);
50
51 function extensionOutput(message)
52 {
53     InspectorTest.addResult(message.text);
54 }
55 InspectorTest.dispatchOnMessage("output", extensionOutput, true);
56
57 function dumpSidebarContent(message, port)
58 {
59     var sidebarPanes = WebInspector.panels.elements.sidebarPanes;
60     // the sidebar of interest is presumed to always be last.
61     var sidebar = sidebarPanes[Object.keys(sidebarPanes).pop()];
62     InspectorTest.runAfterPendingDispatches(function() {
63         InspectorTest.addResult("Sidebar content: " + sidebar.bodyElement.textContent);
64         port.postMessage("");
65     });
66 }
67 InspectorTest.dispatchOnMessage("dump-sidebar-content", dumpSidebarContent, true);
68
69 function showPanel(message, port)
70 {
71     var panelId = message.panelId;
72     if (panelId === "extension")
73         panelId = WebInspector.panelOrder[WebInspector.panelOrder.length - 1].name;
74     WebInspector.showPanel(panelId);
75     port.postMessage("");
76 }
77 InspectorTest.dispatchOnMessage("show-panel", showPanel, true);
78
79 function reloadPage(data, port)
80 {
81     InspectorTest.reloadPage(function() {
82         port.postMessage("");
83     });
84 }
85 InspectorTest.dispatchOnMessage("reload", reloadPage, true);
86
87 function runWhenPageLoads(data, port)
88 {
89     InspectorTest.runWhenPageLoads(function() {
90         port.postMessage("");
91     });
92 }
93 InspectorTest.dispatchOnMessage("run-when-page-loads", runWhenPageLoads, true);
94
95 }
96
97 var test = function()
98 {
99     InspectorTest.runExtensionTests();
100 }