browser/devtools/webconsole/test/browser_console_addonsdk_loader_exception.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /*
michael@0 2 * Any copyright is dedicated to the Public Domain.
michael@0 3 * http://creativecommons.org/publicdomain/zero/1.0/
michael@0 4 */
michael@0 5
michael@0 6 // Check that exceptions from scripts loaded with the addon-sdk loader are
michael@0 7 // opened correctly in View Source from the Browser Console.
michael@0 8 // See bug 866950.
michael@0 9
michael@0 10 const TEST_URI = "data:text/html;charset=utf8,<p>hello world from bug 866950";
michael@0 11
michael@0 12 function test()
michael@0 13 {
michael@0 14 requestLongerTimeout(2);
michael@0 15
michael@0 16 let webconsole, browserconsole;
michael@0 17
michael@0 18 Task.spawn(runner).then(finishTest);
michael@0 19
michael@0 20 function* runner() {
michael@0 21 let {tab} = yield loadTab(TEST_URI);
michael@0 22 webconsole = yield openConsole(tab);
michael@0 23 ok(webconsole, "web console opened");
michael@0 24
michael@0 25 browserconsole = yield HUDService.toggleBrowserConsole();
michael@0 26 ok(browserconsole, "browser console opened");
michael@0 27
michael@0 28 // Cause an exception in a script loaded with the addon-sdk loader.
michael@0 29 let toolbox = gDevTools.getToolbox(webconsole.target);
michael@0 30 let oldPanels = toolbox._toolPanels;
michael@0 31 toolbox._toolPanels = null;
michael@0 32
michael@0 33 function fixToolbox() {
michael@0 34 toolbox._toolPanels = oldPanels;
michael@0 35 }
michael@0 36
michael@0 37 info("generate exception and wait for message");
michael@0 38
michael@0 39 executeSoon(() => {
michael@0 40 executeSoon(fixToolbox);
michael@0 41 expectUncaughtException();
michael@0 42 toolbox.getToolPanels();
michael@0 43 });
michael@0 44
michael@0 45 let [result] = yield waitForMessages({
michael@0 46 webconsole: browserconsole,
michael@0 47 messages: [{
michael@0 48 text: "TypeError: can't convert null to object",
michael@0 49 category: CATEGORY_JS,
michael@0 50 severity: SEVERITY_ERROR,
michael@0 51 }],
michael@0 52 });
michael@0 53
michael@0 54 fixToolbox();
michael@0 55
michael@0 56 let msg = [...result.matched][0];
michael@0 57 ok(msg, "message element found");
michael@0 58 let locationNode = msg.querySelector(".message-location");
michael@0 59 ok(locationNode, "message location element found");
michael@0 60
michael@0 61 let title = locationNode.getAttribute("title");
michael@0 62 info("location node title: " + title);
michael@0 63 isnot(title.indexOf(" -> "), -1, "error comes from a subscript");
michael@0 64
michael@0 65 let viewSource = browserconsole.viewSource;
michael@0 66 let URL = null;
michael@0 67 let clickPromise = promise.defer();
michael@0 68 browserconsole.viewSource = (aURL) => {
michael@0 69 info("browserconsole.viewSource() was invoked: " + aURL);
michael@0 70 URL = aURL;
michael@0 71 clickPromise.resolve(null);
michael@0 72 };
michael@0 73
michael@0 74 msg.scrollIntoView();
michael@0 75 EventUtils.synthesizeMouse(locationNode, 2, 2, {},
michael@0 76 browserconsole.iframeWindow);
michael@0 77
michael@0 78 info("wait for click on locationNode");
michael@0 79 yield clickPromise;
michael@0 80
michael@0 81 info("view-source url: " + URL);
michael@0 82 ok(URL, "we have some source URL after the click");
michael@0 83 isnot(URL.indexOf("toolbox.js"), -1, "we have the expected view source URL");
michael@0 84 is(URL.indexOf("->"), -1, "no -> in the URL given to view-source");
michael@0 85
michael@0 86 browserconsole.viewSource = viewSource;
michael@0 87 }
michael@0 88 }

mercurial