|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Tests that source URLs in the Web Console can be clicked to display the |
|
5 // standard View Source window. |
|
6 |
|
7 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-error.html"; |
|
8 |
|
9 let containsValue; |
|
10 let Sources; |
|
11 let containsValueInvoked = false; |
|
12 |
|
13 function test() { |
|
14 addTab(TEST_URI); |
|
15 browser.addEventListener("load", function onLoad() { |
|
16 browser.removeEventListener("load", onLoad, true); |
|
17 openConsole(null, testViewSource); |
|
18 }, true); |
|
19 } |
|
20 |
|
21 function testViewSource(hud) { |
|
22 info("console opened"); |
|
23 |
|
24 let button = content.document.querySelector("button"); |
|
25 ok(button, "we have the button on the page"); |
|
26 |
|
27 expectUncaughtException(); |
|
28 EventUtils.sendMouseEvent({ type: "click" }, button, content); |
|
29 |
|
30 openDebugger().then(({panelWin: { DebuggerView }}) => { |
|
31 info("debugger opened"); |
|
32 Sources = DebuggerView.Sources; |
|
33 openConsole(null, (hud) => { |
|
34 info("console opened again"); |
|
35 |
|
36 waitForMessages({ |
|
37 webconsole: hud, |
|
38 messages: [{ |
|
39 text: "fooBazBaz is not defined", |
|
40 category: CATEGORY_JS, |
|
41 severity: SEVERITY_ERROR, |
|
42 }], |
|
43 }).then(onMessage); |
|
44 }); |
|
45 }); |
|
46 |
|
47 function onMessage([result]) { |
|
48 let msg = [...result.matched][0]; |
|
49 ok(msg, "error message"); |
|
50 let locationNode = msg.querySelector(".message-location"); |
|
51 ok(locationNode, "location node"); |
|
52 |
|
53 Services.ww.registerNotification(observer); |
|
54 |
|
55 containsValue = Sources.containsValue; |
|
56 Sources.containsValue = () => { |
|
57 containsValueInvoked = true; |
|
58 return false; |
|
59 }; |
|
60 |
|
61 EventUtils.sendMouseEvent({ type: "click" }, locationNode); |
|
62 } |
|
63 } |
|
64 |
|
65 let observer = { |
|
66 observe: function(aSubject, aTopic, aData) { |
|
67 if (aTopic != "domwindowopened") { |
|
68 return; |
|
69 } |
|
70 |
|
71 ok(true, "the view source window was opened in response to clicking " + |
|
72 "the location node"); |
|
73 |
|
74 aSubject.close(); |
|
75 ok(containsValueInvoked, "custom containsValue() was invoked"); |
|
76 Sources.containsValue = containsValue; |
|
77 Sources = containsValue = null; |
|
78 finishTest(); |
|
79 } |
|
80 }; |
|
81 |
|
82 registerCleanupFunction(function() { |
|
83 Services.ww.unregisterNotification(observer); |
|
84 }); |