browser/devtools/webconsole/test/browser_warn_user_about_replaced_api.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/webconsole/test/browser_warn_user_about_replaced_api.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,79 @@
     1.4 +/* vim:set ts=2 sw=2 sts=2 et: */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +const TEST_REPLACED_API_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-replaced-api.html";
    1.10 +const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/testscript.js";
    1.11 +
    1.12 +function test() {
    1.13 +  waitForExplicitFinish();
    1.14 +
    1.15 +  const PREF = "devtools.webconsole.persistlog";
    1.16 +  Services.prefs.setBoolPref(PREF, true);
    1.17 +  registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
    1.18 +
    1.19 +  // First test that the warning does not appear on a page that doesn't override
    1.20 +  // the window.console object.
    1.21 +  addTab(TEST_URI);
    1.22 +  browser.addEventListener("load", function onLoad() {
    1.23 +    browser.removeEventListener("load", onLoad, true);
    1.24 +    openConsole(null, testWarningNotPresent);
    1.25 +  }, true);
    1.26 +
    1.27 +  function testWarningNotPresent(hud)
    1.28 +  {
    1.29 +    is(hud.outputNode.textContent.indexOf("logging API"), -1,
    1.30 +       "no warning displayed");
    1.31 +
    1.32 +    // Bug 862024: make sure the warning doesn't show after page reload.
    1.33 +    info("reload " + TEST_URI);
    1.34 +    executeSoon(() => content.location.reload());
    1.35 +
    1.36 +    waitForMessages({
    1.37 +      webconsole: hud,
    1.38 +      messages: [{
    1.39 +        text: "testscript.js",
    1.40 +        category: CATEGORY_NETWORK,
    1.41 +      }],
    1.42 +    }).then(() => executeSoon(() => {
    1.43 +      is(hud.outputNode.textContent.indexOf("logging API"), -1,
    1.44 +         "no warning displayed");
    1.45 +
    1.46 +      closeConsole(null, loadTestPage);
    1.47 +    }));
    1.48 +  }
    1.49 +
    1.50 +  function loadTestPage()
    1.51 +  {
    1.52 +    info("load test " + TEST_REPLACED_API_URI);
    1.53 +    browser.addEventListener("load", function onLoad() {
    1.54 +      browser.removeEventListener("load", onLoad, true);
    1.55 +      openConsole(null, testWarningPresent);
    1.56 +    }, true);
    1.57 +    content.location = TEST_REPLACED_API_URI;
    1.58 +  }
    1.59 +
    1.60 +  function testWarningPresent(hud)
    1.61 +  {
    1.62 +    info("wait for the warning to show");
    1.63 +    let warning = {
    1.64 +      webconsole: hud,
    1.65 +      messages: [{
    1.66 +        text: /logging API .+ disabled by a script/,
    1.67 +        category: CATEGORY_JS,
    1.68 +        severity: SEVERITY_WARNING,
    1.69 +      }],
    1.70 +    };
    1.71 +
    1.72 +    waitForMessages(warning).then(() => {
    1.73 +      hud.jsterm.clearOutput();
    1.74 +
    1.75 +      executeSoon(() => {
    1.76 +        info("reload the test page and wait for the warning to show");
    1.77 +        waitForMessages(warning).then(finishTest);
    1.78 +        content.location.reload();
    1.79 +      });
    1.80 +    });
    1.81 +  }
    1.82 +}

mercurial