browser/devtools/webconsole/test/browser_webconsole_view_source.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial