browser/devtools/webconsole/test/browser_console_nsiconsolemessage.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_console_nsiconsolemessage.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,80 @@
     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 nsIConsoleMessages are displayed in the Browser Console.
    1.10 +// See bug 859756.
    1.11 +
    1.12 +const TEST_URI = "data:text/html;charset=utf8,<title>bug859756</title>\n" +
    1.13 +                 "<p>hello world\n<p>nsIConsoleMessages ftw!";
    1.14 +
    1.15 +function test()
    1.16 +{
    1.17 +  const FILTER_PREF = "devtools.browserconsole.filter.jslog";
    1.18 +  Services.prefs.setBoolPref(FILTER_PREF, true);
    1.19 +
    1.20 +  registerCleanupFunction(() => {
    1.21 +    Services.prefs.clearUserPref(FILTER_PREF);
    1.22 +  });
    1.23 +
    1.24 +  Task.spawn(function*() {
    1.25 +    const {tab} = yield loadTab(TEST_URI);
    1.26 +
    1.27 +    // Test for cached nsIConsoleMessages.
    1.28 +    Services.console.logStringMessage("test1 for bug859756");
    1.29 +
    1.30 +    info("open web console");
    1.31 +    let hud = yield openConsole(tab);
    1.32 +
    1.33 +    ok(hud, "web console opened");
    1.34 +    Services.console.logStringMessage("do-not-show-me");
    1.35 +    content.console.log("foobarz");
    1.36 +
    1.37 +    yield waitForMessages({
    1.38 +      webconsole: hud,
    1.39 +      messages: [{
    1.40 +        text: "foobarz",
    1.41 +        category: CATEGORY_WEBDEV,
    1.42 +        severity: SEVERITY_LOG,
    1.43 +      }],
    1.44 +    });
    1.45 +
    1.46 +    let text = hud.outputNode.textContent;
    1.47 +    is(text.indexOf("do-not-show-me"), -1,
    1.48 +       "nsIConsoleMessages are not displayed");
    1.49 +    is(text.indexOf("test1 for bug859756"), -1,
    1.50 +       "nsIConsoleMessages are not displayed (confirmed)");
    1.51 +
    1.52 +    yield closeConsole(tab);
    1.53 +
    1.54 +    info("web console closed");
    1.55 +    hud = yield HUDService.toggleBrowserConsole();
    1.56 +    ok(hud, "browser console opened");
    1.57 +
    1.58 +    Services.console.logStringMessage("test2 for bug859756");
    1.59 +
    1.60 +    let results = yield waitForMessages({
    1.61 +      webconsole: hud,
    1.62 +      messages: [{
    1.63 +        text: "test1 for bug859756",
    1.64 +        category: CATEGORY_JS,
    1.65 +      }, {
    1.66 +        text: "test2 for bug859756",
    1.67 +        category: CATEGORY_JS,
    1.68 +      }, {
    1.69 +        text: "do-not-show-me",
    1.70 +        category: CATEGORY_JS,
    1.71 +      }],
    1.72 +    });
    1.73 +
    1.74 +    let msg = [...results[2].matched][0];
    1.75 +    ok(msg, "message element for do-not-show-me (nsIConsoleMessage)");
    1.76 +    isnot(msg.textContent.indexOf("do-not-show"), -1, "element content is correct");
    1.77 +    ok(!msg.classList.contains("filtered-by-type"), "element is not filtered");
    1.78 +
    1.79 +    hud.setFilterState("jslog", false);
    1.80 +
    1.81 +    ok(msg.classList.contains("filtered-by-type"), "element is filtered");
    1.82 +  }).then(finishTest);
    1.83 +}

mercurial