1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_addonsdk_loader_exception.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,88 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Check that exceptions from scripts loaded with the addon-sdk loader are 1.10 +// opened correctly in View Source from the Browser Console. 1.11 +// See bug 866950. 1.12 + 1.13 +const TEST_URI = "data:text/html;charset=utf8,<p>hello world from bug 866950"; 1.14 + 1.15 +function test() 1.16 +{ 1.17 + requestLongerTimeout(2); 1.18 + 1.19 + let webconsole, browserconsole; 1.20 + 1.21 + Task.spawn(runner).then(finishTest); 1.22 + 1.23 + function* runner() { 1.24 + let {tab} = yield loadTab(TEST_URI); 1.25 + webconsole = yield openConsole(tab); 1.26 + ok(webconsole, "web console opened"); 1.27 + 1.28 + browserconsole = yield HUDService.toggleBrowserConsole(); 1.29 + ok(browserconsole, "browser console opened"); 1.30 + 1.31 + // Cause an exception in a script loaded with the addon-sdk loader. 1.32 + let toolbox = gDevTools.getToolbox(webconsole.target); 1.33 + let oldPanels = toolbox._toolPanels; 1.34 + toolbox._toolPanels = null; 1.35 + 1.36 + function fixToolbox() { 1.37 + toolbox._toolPanels = oldPanels; 1.38 + } 1.39 + 1.40 + info("generate exception and wait for message"); 1.41 + 1.42 + executeSoon(() => { 1.43 + executeSoon(fixToolbox); 1.44 + expectUncaughtException(); 1.45 + toolbox.getToolPanels(); 1.46 + }); 1.47 + 1.48 + let [result] = yield waitForMessages({ 1.49 + webconsole: browserconsole, 1.50 + messages: [{ 1.51 + text: "TypeError: can't convert null to object", 1.52 + category: CATEGORY_JS, 1.53 + severity: SEVERITY_ERROR, 1.54 + }], 1.55 + }); 1.56 + 1.57 + fixToolbox(); 1.58 + 1.59 + let msg = [...result.matched][0]; 1.60 + ok(msg, "message element found"); 1.61 + let locationNode = msg.querySelector(".message-location"); 1.62 + ok(locationNode, "message location element found"); 1.63 + 1.64 + let title = locationNode.getAttribute("title"); 1.65 + info("location node title: " + title); 1.66 + isnot(title.indexOf(" -> "), -1, "error comes from a subscript"); 1.67 + 1.68 + let viewSource = browserconsole.viewSource; 1.69 + let URL = null; 1.70 + let clickPromise = promise.defer(); 1.71 + browserconsole.viewSource = (aURL) => { 1.72 + info("browserconsole.viewSource() was invoked: " + aURL); 1.73 + URL = aURL; 1.74 + clickPromise.resolve(null); 1.75 + }; 1.76 + 1.77 + msg.scrollIntoView(); 1.78 + EventUtils.synthesizeMouse(locationNode, 2, 2, {}, 1.79 + browserconsole.iframeWindow); 1.80 + 1.81 + info("wait for click on locationNode"); 1.82 + yield clickPromise; 1.83 + 1.84 + info("view-source url: " + URL); 1.85 + ok(URL, "we have some source URL after the click"); 1.86 + isnot(URL.indexOf("toolbox.js"), -1, "we have the expected view source URL"); 1.87 + is(URL.indexOf("->"), -1, "no -> in the URL given to view-source"); 1.88 + 1.89 + browserconsole.viewSource = viewSource; 1.90 + } 1.91 +}