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