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