michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Tests that source URLs in the Web Console can be clicked to display the michael@0: // standard View Source window. michael@0: michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-error.html"; michael@0: michael@0: let containsValue; michael@0: let Sources; michael@0: let containsValueInvoked = false; michael@0: michael@0: function test() { michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, testViewSource); michael@0: }, true); michael@0: } michael@0: michael@0: function testViewSource(hud) { michael@0: info("console opened"); michael@0: michael@0: let button = content.document.querySelector("button"); michael@0: ok(button, "we have the button on the page"); michael@0: michael@0: expectUncaughtException(); michael@0: EventUtils.sendMouseEvent({ type: "click" }, button, content); michael@0: michael@0: openDebugger().then(({panelWin: { DebuggerView }}) => { michael@0: info("debugger opened"); michael@0: Sources = DebuggerView.Sources; michael@0: openConsole(null, (hud) => { michael@0: info("console opened again"); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "fooBazBaz is not defined", michael@0: category: CATEGORY_JS, michael@0: severity: SEVERITY_ERROR, michael@0: }], michael@0: }).then(onMessage); michael@0: }); michael@0: }); michael@0: michael@0: function onMessage([result]) { michael@0: let msg = [...result.matched][0]; michael@0: ok(msg, "error message"); michael@0: let locationNode = msg.querySelector(".message-location"); michael@0: ok(locationNode, "location node"); michael@0: michael@0: Services.ww.registerNotification(observer); michael@0: michael@0: containsValue = Sources.containsValue; michael@0: Sources.containsValue = () => { michael@0: containsValueInvoked = true; michael@0: return false; michael@0: }; michael@0: michael@0: EventUtils.sendMouseEvent({ type: "click" }, locationNode); michael@0: } michael@0: } michael@0: michael@0: let observer = { michael@0: observe: function(aSubject, aTopic, aData) { michael@0: if (aTopic != "domwindowopened") { michael@0: return; michael@0: } michael@0: michael@0: ok(true, "the view source window was opened in response to clicking " + michael@0: "the location node"); michael@0: michael@0: aSubject.close(); michael@0: ok(containsValueInvoked, "custom containsValue() was invoked"); michael@0: Sources.containsValue = containsValue; michael@0: Sources = containsValue = null; michael@0: finishTest(); michael@0: } michael@0: }; michael@0: michael@0: registerCleanupFunction(function() { michael@0: Services.ww.unregisterNotification(observer); michael@0: });