Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / extensions-test.js
1 function extensionFunctions()
2 {
3     var functions = "";
4
5     for (symbol in window) {
6         if (/^extension_/.exec(symbol) && typeof window[symbol] === "function")
7             functions += window[symbol].toString();
8     }
9     return functions;
10 }
11
12 var initialize_ExtensionsTest = function()
13 {
14
15 WebInspector.extensionServer._overridePlatformExtensionAPIForTest = function(extensionInfo)
16 {
17     WebInspector.extensionServer._registerHandler("evaluateForTestInFrontEnd", onEvaluate);
18
19     function platformExtensionAPI(coreAPI)
20     {
21         window.webInspector = coreAPI;
22         window._extensionServerForTests = extensionServer;
23     }
24     return platformExtensionAPI.toString();
25 }
26
27 InspectorTest._replyToExtension = function(requestId, port)
28 {
29     WebInspector.extensionServer._dispatchCallback(requestId, port);
30 }
31
32 function onEvaluate(message, port)
33 {
34     function reply(param)
35     {
36         WebInspector.extensionServer._dispatchCallback(message.requestId, port, param);
37     }
38
39     try {
40         eval(message.expression);
41     } catch (e) {
42         InspectorTest.addResult("Exception while running: " + message.expression + "\n" + (e.stack || e));
43         InspectorTest.completeTest();
44     }
45 }
46
47 InspectorTest.showPanel = function(panelId)
48 {
49     if (panelId === "extension")
50         panelId = WebInspector.inspectorView._tabbedPane._tabs[WebInspector.inspectorView._tabbedPane._tabs.length - 1].id;
51     return WebInspector.inspectorView.showPanel(panelId);
52 }
53
54 InspectorTest.runExtensionTests = function()
55 {
56     RuntimeAgent.evaluate("location.href", "console", false, function(error, result) {
57         if (error)
58             return;
59         var pageURL = result.value;
60         var extensionURL = (/^https?:/.test(pageURL) ?
61             pageURL.replace(/^(https?:\/\/[^/]*\/).*$/,"$1") :
62             pageURL.replace(/\/inspector\/extensions\/[^/]*$/, "/http/tests")) +
63             "/inspector/resources/extension-main.html";
64         WebInspector.addExtensions([{ startPage: extensionURL, name: "test extension", exposeWebInspectorNamespace: true }]);
65         WebInspector.extensionServer.initializeExtensions();
66     });
67 }
68
69 }
70
71 function extension_showPanel(panelId, callback)
72 {
73     evaluateOnFrontend("InspectorTest.showPanel(unescape('" + escape(panelId) + "')).then(function() { reply(); });", callback);
74 }
75
76 var test = function()
77 {
78     InspectorTest.runExtensionTests();
79 }