summaryrefslogtreecommitdiffstats
path: root/devtools/client/webconsole/test/browser/browser_webconsole_warn_about_replaced_api.js
blob: eaa94095a8aa92d3a3ffdf95d4e52d89280982fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* 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,<!DOCTYPE html><script>console = {log: () => ''}</script>";
const TEST_URI_NOT_REPLACED =
  "data:text/html;charset=utf8,<!DOCTYPE html><script>console.log('foo')</script>";

add_task(async function () {
  await pushPref("devtools.webconsole.timestampMessages", true);
  await pushPref("devtools.webconsole.persistlog", true);

  let hud = await openNewTabAndConsole(TEST_URI_NOT_REPLACED);

  await testWarningNotPresent(hud);
  await closeToolbox();

  // Use BrowserTestUtils instead of navigateTo as there is no toolbox opened
  const onBrowserLoaded = BrowserTestUtils.browserLoaded(
    gBrowser.selectedBrowser
  );
  BrowserTestUtils.startLoadingURIString(
    gBrowser.selectedBrowser,
    TEST_URI_REPLACED
  );
  await onBrowserLoaded;

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

async function testWarningNotPresent(hud) {
  ok(!findWarningMessage(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 reloadBrowser();
  await waitFor(() => {
    return (
      findConsoleAPIMessages(hud, "foo").length === 2 &&
      findMessagesByType(hud, "foo", ".navigationMarker").length === 1
    );
  });

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

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

  info("reload the test page and wait for the warning to show");
  await reloadBrowser();
  await waitFor(() => {
    return findWarningMessages(hud, "logging API").length === 2;
  });
}