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