browser/devtools/webconsole/test/browser_warn_user_about_replaced_api.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* vim:set ts=2 sw=2 sts=2 et: */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 const TEST_REPLACED_API_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console-replaced-api.html";
michael@0 7 const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/testscript.js";
michael@0 8
michael@0 9 function test() {
michael@0 10 waitForExplicitFinish();
michael@0 11
michael@0 12 const PREF = "devtools.webconsole.persistlog";
michael@0 13 Services.prefs.setBoolPref(PREF, true);
michael@0 14 registerCleanupFunction(() => Services.prefs.clearUserPref(PREF));
michael@0 15
michael@0 16 // First test that the warning does not appear on a page that doesn't override
michael@0 17 // the window.console object.
michael@0 18 addTab(TEST_URI);
michael@0 19 browser.addEventListener("load", function onLoad() {
michael@0 20 browser.removeEventListener("load", onLoad, true);
michael@0 21 openConsole(null, testWarningNotPresent);
michael@0 22 }, true);
michael@0 23
michael@0 24 function testWarningNotPresent(hud)
michael@0 25 {
michael@0 26 is(hud.outputNode.textContent.indexOf("logging API"), -1,
michael@0 27 "no warning displayed");
michael@0 28
michael@0 29 // Bug 862024: make sure the warning doesn't show after page reload.
michael@0 30 info("reload " + TEST_URI);
michael@0 31 executeSoon(() => content.location.reload());
michael@0 32
michael@0 33 waitForMessages({
michael@0 34 webconsole: hud,
michael@0 35 messages: [{
michael@0 36 text: "testscript.js",
michael@0 37 category: CATEGORY_NETWORK,
michael@0 38 }],
michael@0 39 }).then(() => executeSoon(() => {
michael@0 40 is(hud.outputNode.textContent.indexOf("logging API"), -1,
michael@0 41 "no warning displayed");
michael@0 42
michael@0 43 closeConsole(null, loadTestPage);
michael@0 44 }));
michael@0 45 }
michael@0 46
michael@0 47 function loadTestPage()
michael@0 48 {
michael@0 49 info("load test " + TEST_REPLACED_API_URI);
michael@0 50 browser.addEventListener("load", function onLoad() {
michael@0 51 browser.removeEventListener("load", onLoad, true);
michael@0 52 openConsole(null, testWarningPresent);
michael@0 53 }, true);
michael@0 54 content.location = TEST_REPLACED_API_URI;
michael@0 55 }
michael@0 56
michael@0 57 function testWarningPresent(hud)
michael@0 58 {
michael@0 59 info("wait for the warning to show");
michael@0 60 let warning = {
michael@0 61 webconsole: hud,
michael@0 62 messages: [{
michael@0 63 text: /logging API .+ disabled by a script/,
michael@0 64 category: CATEGORY_JS,
michael@0 65 severity: SEVERITY_WARNING,
michael@0 66 }],
michael@0 67 };
michael@0 68
michael@0 69 waitForMessages(warning).then(() => {
michael@0 70 hud.jsterm.clearOutput();
michael@0 71
michael@0 72 executeSoon(() => {
michael@0 73 info("reload the test page and wait for the warning to show");
michael@0 74 waitForMessages(warning).then(finishTest);
michael@0 75 content.location.reload();
michael@0 76 });
michael@0 77 });
michael@0 78 }
michael@0 79 }

mercurial