Commit 229861b1 authored by Brian Grinstead's avatar Brian Grinstead
Browse files

Bug 1383022 - Log a message in the new console frontend when the Console API...

Bug 1383022 - Log a message in the new console frontend when the Console API has been replaced;r=nchevobbe

MozReview-Commit-ID: 56xyY04YM4S

--HG--
rename : devtools/client/webconsole/test/browser_warn_user_about_replaced_api.js => devtools/client/webconsole/new-console-output/test/mochitest/browser_webconsole_warn_about_replaced_api.js
extra : rebase_source : 32d28e3dbe97a64bfe489af9ad1c366120b39f53
parent 56c2b6e6
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52,3 +52,4 @@ skip-if = (os == 'linux' && bits == 32 && debug) # bug 1328915, disable linux32
[browser_webconsole_stacktrace_location_scratchpad_link.js]
[browser_webconsole_string.js]
[browser_webconsole_timestamps.js]
[browser_webconsole_warn_about_replaced_api.js]
+55 −0
Original line number Diff line number Diff line
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const TEST_URI_REPLACED =
  "data:text/html;charset=utf8,<script>console = {log: () => ''}</script>";
const TEST_URI_NOT_REPLACED =
  "data:text/html;charset=utf8,<script>console.log('foo')</script>";

add_task(async function () {
  await SpecialPowers.pushPrefEnv({"set": [
    ["devtools.webconsole.persistlog", true]
  ]});

  let hud = await openNewTabAndConsole(TEST_URI_NOT_REPLACED);

  await testWarningNotPresent(hud);
  await closeToolbox();

  const currentTab = gBrowser.selectedTab;
  await loadDocument(currentTab.linkedBrowser, TEST_URI_REPLACED);

  let toolbox = await openToolboxForTab(gBrowser.selectedTab, "webconsole");
  hud = toolbox.getCurrentPanel().hud;
  await testWarningPresent(hud);
});

async function testWarningNotPresent(hud) {
  ok(!findMessage(hud, "logging API"), "no warning displayed");

  // Bug 862024: make sure the warning doesn't show after page reload.
  info("wait for the page to refresh and make sure the warning still isn't there");
  await refreshTab();
  await waitFor(() => {
    // We need to wait for 3 messages because there are two logs, plus the
    // navigation message since messages are persisted
    return findMessages(hud, "foo").length === 3;
  });

  ok(!findMessage(hud, "logging API"), "no warning displayed");
}

async function testWarningPresent(hud) {
  info("wait for the warning to show");
  await waitFor(() => findMessage(hud, "logging API"));

  info("reload the test page and wait for the warning to show");
  await refreshTab();
  await waitFor(() => {
    return findMessages(hud, "logging API").length === 2;
  });
}
+2 −1
Original line number Diff line number Diff line
@@ -139,7 +139,8 @@ NewWebConsoleFrame.prototype = {
  },

  logWarningAboutReplacedAPI() {

    this.owner.target.logErrorInPage(l10n.getStr("ConsoleAPIDisabled"),
      "ConsoleAPIDisabled");
  },

  handleNetworkEventUpdate() {
+3 −3
Original line number Diff line number Diff line
@@ -267,10 +267,10 @@ WebConsoleConnectionProxy.prototype = {
      this.dispatchMessagesAdd(messages);
    } else {
      this.webConsoleFrame.displayCachedMessages(messages);
    }
    if (!this._hasNativeConsoleAPI) {
      this.webConsoleFrame.logWarningAboutReplacedAPI();
    }
    }

    this.connected = true;
    this._connectDefer.resolve(this);