browser_webconsole_warn_about_replaced_api.js (1980B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const TEST_URI_REPLACED = 7 "data:text/html;charset=utf8,<!DOCTYPE html><script>console = {log: () => ''}</script>"; 8 const TEST_URI_NOT_REPLACED = 9 "data:text/html;charset=utf8,<!DOCTYPE html><script>console.log('foo')</script>"; 10 11 add_task(async function () { 12 await pushPref("devtools.webconsole.timestampMessages", true); 13 await pushPref("devtools.webconsole.persistlog", true); 14 15 let hud = await openNewTabAndConsole(TEST_URI_NOT_REPLACED); 16 17 await testWarningNotPresent(hud); 18 await closeToolboxIfOpen(); 19 20 // Use BrowserTestUtils instead of navigateTo as there is no toolbox opened 21 const onBrowserLoaded = BrowserTestUtils.browserLoaded( 22 gBrowser.selectedBrowser 23 ); 24 BrowserTestUtils.startLoadingURIString( 25 gBrowser.selectedBrowser, 26 TEST_URI_REPLACED 27 ); 28 await onBrowserLoaded; 29 30 const toolbox = await openToolboxForTab(gBrowser.selectedTab, "webconsole"); 31 hud = toolbox.getCurrentPanel().hud; 32 await testWarningPresent(hud); 33 }); 34 35 async function testWarningNotPresent(hud) { 36 ok(!findWarningMessage(hud, "logging API"), "no warning displayed"); 37 38 // Bug 862024: make sure the warning doesn't show after page reload. 39 info( 40 "wait for the page to refresh and make sure the warning still isn't there" 41 ); 42 await reloadBrowser(); 43 await waitFor(() => { 44 return ( 45 findConsoleAPIMessages(hud, "foo").length === 2 && 46 findMessagesByType(hud, "foo", ".navigationMarker").length === 1 47 ); 48 }); 49 50 ok(!findWarningMessage(hud, "logging API"), "no warning displayed"); 51 } 52 53 async function testWarningPresent(hud) { 54 info("wait for the warning to show"); 55 await waitFor(() => findWarningMessage(hud, "logging API")); 56 57 info("reload the test page and wait for the warning to show"); 58 await reloadBrowser(); 59 await waitFor(() => { 60 return findWarningMessages(hud, "logging API").length === 2; 61 }); 62 }