Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / inspector / extensions / extensions-panel.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4 <script src="../../http/tests/inspector/console-test.js"></script>
5 <script src="../../http/tests/inspector/network-test.js"></script>
6 <script src="../../http/tests/inspector/sources-test.js"></script>
7 <script src="../../http/tests/inspector/resources-test.js"></script>
8 <script src="../../http/tests/inspector/extensions-test.js"></script>
9 <script type="text/javascript">
10 function logMessage()
11 {
12     console.log("hello");
13 }
14
15 function initialize_extensionsPanelTest()
16 {
17     InspectorTest.getPanelSize = function()
18     {
19         var boundingRect = WebInspector.inspectorView._tabbedPane._contentElement.getBoundingClientRect();
20         return {
21             width: boundingRect.width,
22             height: boundingRect.height
23         };
24     }
25
26     InspectorTest.dumpStatusBarButtons = function()
27     {
28         var panel = WebInspector.inspectorView.currentPanel();
29         var items = panel._panelStatusBarElement.children;
30         InspectorTest.addResult("Status bar buttons state:");
31         for (var i = 0; i < items.length; ++i) {
32             var item = items[i];
33             if (!(item instanceof HTMLButtonElement)) {
34                 InspectorTest.addResult("status bar item " + i + " is not a button.");
35                 continue;
36             }
37             // Strip url(...) and prefix of the URL within, leave just last 3 components.
38             var url = item.style.backgroundImage.replace(/^url\(.*(([/][^/]*){3}[^/)]*)\)$/, "...$1");
39             InspectorTest.addResult("status bar item " + i + ", icon: " + url + ", tooltip: '" + item.title + "', disabled: " + item.disabled);
40         }
41     }
42
43     InspectorTest.clickButton = function(index)
44     {
45         var panel = WebInspector.inspectorView.currentPanel();
46         panel._panelStatusBarElement.children[index].click();
47     }
48
49     InspectorTest.clickOnURL = function()
50     {
51         InspectorTest.disableConsoleViewport();
52         var xpathResult = document.evaluate("//a[starts-with(., 'extensions-panel.html')]", WebInspector.ConsolePanel._view()._viewport.element, null, XPathResult.ANY_UNORDERED_NODE_TYPE, null);
53         var click = document.createEvent("MouseEvent");
54         click.initMouseEvent("click", true, true);
55         xpathResult.singleNodeValue.dispatchEvent(click);
56     }
57
58     InspectorTest.installShowResourceLocationHooks = function()
59     {
60         function showURL(panelName, url, lineNumber)
61         {
62             var url = url.replace(/^.*(([/][^/]*){3}[^/)]*)$/, "...$1");
63             InspectorTest.addResult("Showing resource " + url + " in panel " + panelName + " (" + WebInspector.inspectorView.currentPanel().name + "), line: " + lineNumber);
64         }
65         InspectorTest.recordNetwork();
66
67         InspectorTest.addSniffer(WebInspector.panels.sources, "showUILocation", showUILocationHook, true);
68         InspectorTest.addSniffer(WebInspector.panels.resources, "showResource", showResourceHook, true);
69         InspectorTest.addSniffer(WebInspector.panels.network, "revealAndHighlightRequest", showRequestHook, true);
70
71         function showUILocationHook(uiLocation)
72         {
73             showURL("sources", uiLocation.uiSourceCode.url, uiLocation.lineNumber);
74         }
75
76         function showResourceHook(resource, lineNumber)
77         {
78             showURL("resources", resource.url, lineNumber);
79         }
80
81         function showRequestHook(request)
82         {
83             showURL("network", request.url);
84         }
85     }
86
87     InspectorTest.switchToLastPanel = function()
88     {
89         var lastPanelName = WebInspector.inspectorView._tabbedPane._tabs.peekLast().id;
90         return WebInspector.inspectorView.showPanel(lastPanelName);
91     }
92 }
93
94 function extension_testCreatePanel(nextTest)
95 {
96     var expectOnShown = false;
97
98     function onPanelShown(panel, window)
99     {
100         if (!expectOnShown) {
101             output("FAIL: unexpected onShown event");
102             nextTest();
103             return;
104         }
105         output("Panel shown");
106         panel.onShown.removeListener(onPanelShown);
107         evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
108             if (result.width !== window.innerWidth)
109                 output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
110             else if (result.height !== window.innerHeight)
111                 output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
112             else
113                 output("Extension panel size correct");
114             nextTest();
115         });
116     }
117
118     function onPanelCreated(panel)
119     {
120         function onPanelShown(window)
121         {
122             if (!expectOnShown) {
123                  output("FAIL: unexpected onShown event");
124                  nextTest();
125                  return;
126             }
127             output("Panel shown");
128             panel.onShown.removeListener(onPanelShown);
129             panel.onHidden.addListener(onPanelHidden);
130             evaluateOnFrontend("reply(InspectorTest.getPanelSize())", function(result) {
131                  if (result.width !== window.innerWidth)
132                      output("panel width mismatch, outer: " + result.width + ", inner:" + window.innerWidth);
133                  else if (result.height !== window.innerHeight)
134                      output("panel height mismatch, outer: " + result.height + ", inner:" + window.innerHeight);
135                  else
136                      output("Extension panel size correct");
137                  extension_showPanel("console");
138             });
139          }
140
141          function onPanelHidden()
142          {
143              panel.onHidden.removeListener(onPanelHidden);
144              output("Panel hidden");
145              nextTest();
146          }
147
148         output("Panel created");
149         dumpObject(panel);
150         panel.onShown.addListener(onPanelShown);
151
152         // This is not authorized and therefore should not produce any output
153         panel.show();
154         extension_showPanel("console");
155
156         function handleOpenResource(resource, lineNumber)
157         {
158             // This will force extension iframe to be really loaded.
159             panel.show();
160         }
161         webInspector.panels.setOpenResourceHandler(handleOpenResource);
162         evaluateOnFrontend("WebInspector.openAnchorLocationRegistry._activeHandler = 'test extension'");
163         webInspector.inspectedWindow.eval("logMessage()", function() {
164             expectOnShown = true;
165             evaluateOnFrontend("InspectorTest.clickOnURL();");
166         });
167     }
168     var basePath = location.pathname.replace(/\/[^/]*$/, "/");
169     webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
170 }
171
172 function extension_testSearch(nextTest)
173 {
174     var callbackCount = 0;
175
176     function onPanelCreated(panel)
177     {
178         var callback = function(action, queryString)
179         {
180             output("Panel searched:");
181             dumpObject(Array.prototype.slice.call(arguments));
182             callbackCount++;
183             if (callbackCount === 2) {
184                 nextTest();
185                 panel.onSearch.removeListener(callback);
186             }
187         };
188         panel.onSearch.addListener(callback);
189
190         extension_showPanel("extension");
191         
192         function performSearch(query)
193         {
194             var panel = WebInspector.inspectorView.currentPanel();
195             panel.searchableView().showSearchField();
196             panel.searchableView()._searchInputElement.value = query;
197             panel.searchableView()._performSearch(true, true);
198             panel.searchableView().cancelSearch();
199         }
200
201         evaluateOnFrontend(performSearch.toString() + " performSearch(\"hello\");");
202     }
203     var basePath = location.pathname.replace(/\/[^/]*$/, "/");
204     webInspector.panels.create("Test Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
205 }
206
207 function extension_testStatusBarButtons(nextTest)
208 {
209     var basePath = location.pathname.replace(/\/[^/]*$/, "/");
210
211     function onPanelCreated(panel)
212     {
213         var button1 = panel.createStatusBarButton(basePath + "button1.png", "Button One tooltip");
214         var button2 = panel.createStatusBarButton(basePath + "button2.png", "Button Two tooltip", true);
215         output("Created a status bar button, dump follows:");
216         dumpObject(button1);
217         function updateButtons()
218         {
219             button1.update(basePath + "button1-updated.png");
220             button2.update(null, "Button Two updated tooltip", false);
221             output("Updated status bar buttons");
222             evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); InspectorTest.clickButton(1);");
223         }
224         button1.onClicked.addListener(function() {
225             output("button1 clicked");
226             evaluateOnFrontend("InspectorTest.dumpStatusBarButtons(); reply();", updateButtons);
227         });
228         button2.onClicked.addListener(function() {
229             output("button2 clicked");
230             nextTest();
231         });
232         // First we click on button2 (that is [1] in array). But it is disabled, so this should be a noop. Then we click on button1.
233         // button1 click updates buttons. and clicks button2.
234         evaluateOnFrontend("InspectorTest.showPanel('extension').then(function() { InspectorTest.clickButton(1); InspectorTest.clickButton(0); })");
235     }
236
237     webInspector.panels.create("Buttons Panel", basePath + "extension-panel.png", basePath + "non-existent.html", onPanelCreated);
238 }
239
240 function extension_testOpenResource(nextTest)
241 {
242     var urls;
243     var urlIndex = 0;
244
245     evaluateOnFrontend("InspectorTest.installShowResourceLocationHooks(); reply();", function() {
246         webInspector.inspectedWindow.eval("loadResources(); location.href", function(inspectedPageURL) {
247             var basePath = inspectedPageURL.replace(/\/[^/]*$/, "/");
248             urls = [inspectedPageURL, basePath + "resources/abe.png", basePath + "resources/missing.txt", "not-found.html", "javascript:console.error('oh no!')"];
249             showNextURL();
250         });
251     });
252     function showNextURL()
253     {
254         if (urlIndex >= urls.length) {
255             nextTest();
256             return;
257         }
258         var url = urls[urlIndex++];
259         output("Showing " + trimURL(url));
260         webInspector.panels.openResource(url, 1000 + urlIndex, showNextURL);
261     }
262 }
263
264 function extension_testGlobalShortcuts(nextTest)
265 {
266     var platform;
267     var testPanel;
268     evaluateOnFrontend("reply(WebInspector.platform())", function(result) {
269         platform = result;
270         var basePath = location.pathname.replace(/\/[^/]*$/, "/");
271         webInspector.panels.create("Shortcuts Test Panel", basePath + "extension-panel.png", basePath + "extension-panel.html", onPanelCreated);
272     });
273     function dispatchKeydownEvent(attributes)
274     {
275         var event = new KeyboardEvent("keydown", attributes);
276         document.dispatchEvent(event);
277     }
278     function onPanelCreated(panel)
279     {
280         testPanel = panel;
281         testPanel.onShown.addListener(onPanelShown);
282         testPanel.onHidden.addListener(onPanelHidden);
283         evaluateOnFrontend("InspectorTest.switchToLastPanel();");
284     }
285     var panelWindow;
286     function onPanelShown(win)
287     {
288         panelWindow = win;
289         testPanel.onShown.removeListener(onPanelShown);
290         output("Panel shown, now toggling console...");
291         panelWindow.addEventListener("resize", onPanelResized);
292         dispatchKeydownEvent({ keyIdentifier: "U+001B" });
293     }
294     function onPanelResized()
295     {
296         panelWindow.removeEventListener("resize", onPanelResized);
297         output("Panel resized, switching away...");
298         var isMac = platform === "mac";
299         dispatchKeydownEvent({ ctrlKey: !isMac, metaKey: isMac, keyIdentifier: "U+005D" });
300     }
301     function onPanelHidden()
302     {
303         output("Panel hidden, test passed.");
304         testPanel.onShown.removeListener(onPanelHidden);
305         evaluateOnFrontend("reply(WebInspector.inspectorView.closeDrawer())", nextTest);
306     }
307 }
308
309 function loadResources()
310 {
311     var xhr = new XMLHttpRequest();
312     xhr.open("GET", "resources/missing.txt", false);
313     xhr.send();
314     var img = document.createElement("img");
315     img.src = "resources/abe.png";
316     document.body.appendChild(img);
317 }
318 </script>
319 </head>
320 <body onload="runTest()">
321 <p>Tests WebInspector extension API</p>
322 </body>
323 </html>