1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/webconsole/test/browser_console_error_source_click.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* 1.5 + * Any copyright is dedicated to the Public Domain. 1.6 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.7 + */ 1.8 + 1.9 +// Check that JS errors and CSS warnings open view source when their source link 1.10 +// is clicked in the Browser Console. See bug 877778. 1.11 + 1.12 +const TEST_URI = "data:text/html;charset=utf8,<p>hello world from bug 877778 " + 1.13 + "<button onclick='foobar.explode()' " + 1.14 + "style='test-color: green-please'>click!</button>"; 1.15 +function test() 1.16 +{ 1.17 + let hud; 1.18 + 1.19 + addTab(TEST_URI); 1.20 + browser.addEventListener("load", function onLoad() { 1.21 + browser.removeEventListener("load", onLoad, true); 1.22 + HUDService.toggleBrowserConsole().then(browserConsoleOpened); 1.23 + }, true); 1.24 + 1.25 + function browserConsoleOpened(aHud) 1.26 + { 1.27 + hud = aHud; 1.28 + ok(hud, "browser console opened"); 1.29 + 1.30 + let button = content.document.querySelector("button"); 1.31 + ok(button, "button element found"); 1.32 + 1.33 + info("generate exception and wait for the message"); 1.34 + executeSoon(() => { 1.35 + expectUncaughtException(); 1.36 + button.click(); 1.37 + }); 1.38 + 1.39 + waitForMessages({ 1.40 + webconsole: hud, 1.41 + messages: [ 1.42 + { 1.43 + text: "ReferenceError: foobar is not defined", 1.44 + category: CATEGORY_JS, 1.45 + severity: SEVERITY_ERROR, 1.46 + }, 1.47 + { 1.48 + text: "Unknown property 'test-color'", 1.49 + category: CATEGORY_CSS, 1.50 + severity: SEVERITY_WARNING, 1.51 + }, 1.52 + ], 1.53 + }).then(onMessageFound); 1.54 + } 1.55 + 1.56 + function onMessageFound(results) 1.57 + { 1.58 + let viewSource = hud.viewSource; 1.59 + let viewSourceCalled = false; 1.60 + hud.viewSource = () => viewSourceCalled = true; 1.61 + 1.62 + for (let result of results) { 1.63 + viewSourceCalled = false; 1.64 + 1.65 + let msg = [...results[0].matched][0]; 1.66 + ok(msg, "message element found for: " + result.text); 1.67 + let locationNode = msg.querySelector(".message-location"); 1.68 + ok(locationNode, "message location element found"); 1.69 + 1.70 + EventUtils.synthesizeMouse(locationNode, 2, 2, {}, hud.iframeWindow); 1.71 + 1.72 + ok(viewSourceCalled, "view source opened"); 1.73 + } 1.74 + 1.75 + hud.viewSource = viewSource; 1.76 + finishTest(); 1.77 + } 1.78 +}