1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_webconsole_view_source.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Tests that source URLs in the Web Console can be clicked to display the 1.8 +// standard View Source window. 1.9 + 1.10 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-error.html"; 1.11 + 1.12 +let containsValue; 1.13 +let Sources; 1.14 +let containsValueInvoked = false; 1.15 + 1.16 +function test() { 1.17 + addTab(TEST_URI); 1.18 + browser.addEventListener("load", function onLoad() { 1.19 + browser.removeEventListener("load", onLoad, true); 1.20 + openConsole(null, testViewSource); 1.21 + }, true); 1.22 +} 1.23 + 1.24 +function testViewSource(hud) { 1.25 + info("console opened"); 1.26 + 1.27 + let button = content.document.querySelector("button"); 1.28 + ok(button, "we have the button on the page"); 1.29 + 1.30 + expectUncaughtException(); 1.31 + EventUtils.sendMouseEvent({ type: "click" }, button, content); 1.32 + 1.33 + openDebugger().then(({panelWin: { DebuggerView }}) => { 1.34 + info("debugger opened"); 1.35 + Sources = DebuggerView.Sources; 1.36 + openConsole(null, (hud) => { 1.37 + info("console opened again"); 1.38 + 1.39 + waitForMessages({ 1.40 + webconsole: hud, 1.41 + messages: [{ 1.42 + text: "fooBazBaz is not defined", 1.43 + category: CATEGORY_JS, 1.44 + severity: SEVERITY_ERROR, 1.45 + }], 1.46 + }).then(onMessage); 1.47 + }); 1.48 + }); 1.49 + 1.50 + function onMessage([result]) { 1.51 + let msg = [...result.matched][0]; 1.52 + ok(msg, "error message"); 1.53 + let locationNode = msg.querySelector(".message-location"); 1.54 + ok(locationNode, "location node"); 1.55 + 1.56 + Services.ww.registerNotification(observer); 1.57 + 1.58 + containsValue = Sources.containsValue; 1.59 + Sources.containsValue = () => { 1.60 + containsValueInvoked = true; 1.61 + return false; 1.62 + }; 1.63 + 1.64 + EventUtils.sendMouseEvent({ type: "click" }, locationNode); 1.65 + } 1.66 +} 1.67 + 1.68 +let observer = { 1.69 + observe: function(aSubject, aTopic, aData) { 1.70 + if (aTopic != "domwindowopened") { 1.71 + return; 1.72 + } 1.73 + 1.74 + ok(true, "the view source window was opened in response to clicking " + 1.75 + "the location node"); 1.76 + 1.77 + aSubject.close(); 1.78 + ok(containsValueInvoked, "custom containsValue() was invoked"); 1.79 + Sources.containsValue = containsValue; 1.80 + Sources = containsValue = null; 1.81 + finishTest(); 1.82 + } 1.83 +}; 1.84 + 1.85 +registerCleanupFunction(function() { 1.86 + Services.ww.unregisterNotification(observer); 1.87 +});