michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const TEST_REPLACED_API_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-replaced-api.html"; michael@0: const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/testscript.js"; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: const PREF = "devtools.webconsole.persistlog"; michael@0: Services.prefs.setBoolPref(PREF, true); michael@0: registerCleanupFunction(() => Services.prefs.clearUserPref(PREF)); michael@0: michael@0: // First test that the warning does not appear on a page that doesn't override michael@0: // the window.console object. michael@0: addTab(TEST_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, testWarningNotPresent); michael@0: }, true); michael@0: michael@0: function testWarningNotPresent(hud) michael@0: { michael@0: is(hud.outputNode.textContent.indexOf("logging API"), -1, michael@0: "no warning displayed"); michael@0: michael@0: // Bug 862024: make sure the warning doesn't show after page reload. michael@0: info("reload " + TEST_URI); michael@0: executeSoon(() => content.location.reload()); michael@0: michael@0: waitForMessages({ michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: "testscript.js", michael@0: category: CATEGORY_NETWORK, michael@0: }], michael@0: }).then(() => executeSoon(() => { michael@0: is(hud.outputNode.textContent.indexOf("logging API"), -1, michael@0: "no warning displayed"); michael@0: michael@0: closeConsole(null, loadTestPage); michael@0: })); michael@0: } michael@0: michael@0: function loadTestPage() michael@0: { michael@0: info("load test " + TEST_REPLACED_API_URI); michael@0: browser.addEventListener("load", function onLoad() { michael@0: browser.removeEventListener("load", onLoad, true); michael@0: openConsole(null, testWarningPresent); michael@0: }, true); michael@0: content.location = TEST_REPLACED_API_URI; michael@0: } michael@0: michael@0: function testWarningPresent(hud) michael@0: { michael@0: info("wait for the warning to show"); michael@0: let warning = { michael@0: webconsole: hud, michael@0: messages: [{ michael@0: text: /logging API .+ disabled by a script/, michael@0: category: CATEGORY_JS, michael@0: severity: SEVERITY_WARNING, michael@0: }], michael@0: }; michael@0: michael@0: waitForMessages(warning).then(() => { michael@0: hud.jsterm.clearOutput(); michael@0: michael@0: executeSoon(() => { michael@0: info("reload the test page and wait for the warning to show"); michael@0: waitForMessages(warning).then(finishTest); michael@0: content.location.reload(); michael@0: }); michael@0: }); michael@0: } michael@0: }