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.

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

mercurial