|
1 /* |
|
2 * Any copyright is dedicated to the Public Domain. |
|
3 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
4 */ |
|
5 |
|
6 // Check that JS errors and CSS warnings open view source when their source link |
|
7 // is clicked in the Browser Console. See bug 877778. |
|
8 |
|
9 const TEST_URI = "data:text/html;charset=utf8,<p>hello world from bug 877778 " + |
|
10 "<button onclick='foobar.explode()' " + |
|
11 "style='test-color: green-please'>click!</button>"; |
|
12 function test() |
|
13 { |
|
14 let hud; |
|
15 |
|
16 addTab(TEST_URI); |
|
17 browser.addEventListener("load", function onLoad() { |
|
18 browser.removeEventListener("load", onLoad, true); |
|
19 HUDService.toggleBrowserConsole().then(browserConsoleOpened); |
|
20 }, true); |
|
21 |
|
22 function browserConsoleOpened(aHud) |
|
23 { |
|
24 hud = aHud; |
|
25 ok(hud, "browser console opened"); |
|
26 |
|
27 let button = content.document.querySelector("button"); |
|
28 ok(button, "button element found"); |
|
29 |
|
30 info("generate exception and wait for the message"); |
|
31 executeSoon(() => { |
|
32 expectUncaughtException(); |
|
33 button.click(); |
|
34 }); |
|
35 |
|
36 waitForMessages({ |
|
37 webconsole: hud, |
|
38 messages: [ |
|
39 { |
|
40 text: "ReferenceError: foobar is not defined", |
|
41 category: CATEGORY_JS, |
|
42 severity: SEVERITY_ERROR, |
|
43 }, |
|
44 { |
|
45 text: "Unknown property 'test-color'", |
|
46 category: CATEGORY_CSS, |
|
47 severity: SEVERITY_WARNING, |
|
48 }, |
|
49 ], |
|
50 }).then(onMessageFound); |
|
51 } |
|
52 |
|
53 function onMessageFound(results) |
|
54 { |
|
55 let viewSource = hud.viewSource; |
|
56 let viewSourceCalled = false; |
|
57 hud.viewSource = () => viewSourceCalled = true; |
|
58 |
|
59 for (let result of results) { |
|
60 viewSourceCalled = false; |
|
61 |
|
62 let msg = [...results[0].matched][0]; |
|
63 ok(msg, "message element found for: " + result.text); |
|
64 let locationNode = msg.querySelector(".message-location"); |
|
65 ok(locationNode, "message location element found"); |
|
66 |
|
67 EventUtils.synthesizeMouse(locationNode, 2, 2, {}, hud.iframeWindow); |
|
68 |
|
69 ok(viewSourceCalled, "view source opened"); |
|
70 } |
|
71 |
|
72 hud.viewSource = viewSource; |
|
73 finishTest(); |
|
74 } |
|
75 } |