Bug 1382377 - Test console against devtools.enabled pref. r=baku
MozReview-Commit-ID: GEayP1MP8PV
--- a/dom/console/tests/mochitest.ini
+++ b/dom/console/tests/mochitest.ini
@@ -4,8 +4,9 @@ support-files =
[test_bug659625.html]
[test_bug978522.html]
[test_bug979109.html]
[test_bug989665.html]
[test_consoleEmptyStack.html]
[test_console_binding.html]
[test_console_proto.html]
+[test_devtools_pref.html]
new file mode 100644
--- /dev/null
+++ b/dom/console/tests/test_devtools_pref.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test Console with devtools preference</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+ <script type="application/javascript">
+
+function consoleListener(expected) {
+ var messages = [];
+ return new Promise(done => {
+ let observer = {
+ observe: function listener(aSubject, aTopic, aData) {
+ var obj = aSubject.wrappedJSObject;
+ messages.push(parseInt(obj.arguments[0]));
+ if (messages.length == expected) {
+ SpecialPowers.removeObserver(observer, "console-api-log-event");
+ SpecialPowers.removeObserver(observer, "console-api-profiler");
+ done(messages);
+ return;
+ }
+ }
+ };
+ SpecialPowers.addObserver(observer, "console-api-log-event");
+ SpecialPowers.addObserver(observer, "console-api-profiler");
+ });
+}
+
+SimpleTest.waitForExplicitFinish();
+(async function () {
+ var onMessages = consoleListener(4);
+
+ await SpecialPowers.pushPrefEnv({set: [["devtools.enabled", false]]});
+ console.log(1);
+ console.profile(2);
+
+ await SpecialPowers.pushPrefEnv({set: [["devtools.enabled", true]]});
+ console.log(3);
+ console.profile(4);
+
+ await SpecialPowers.pushPrefEnv({set: [["devtools.enabled", false]]});
+ console.log(5);
+ console.profile(6);
+
+ await SpecialPowers.pushPrefEnv({set: [["devtools.enabled", true]]});
+ console.log(7);
+ console.profile(8);
+
+ var messages = await onMessages;
+
+ is(messages[0], 3, "Got only console message while pref was true");
+ is(messages[1], 4, "Got only profile message while pref was true");
+ is(messages[2], 7, "Got only console message while pref was true");
+ is(messages[3], 8, "Got only profile message while pref was true");
+
+ SimpleTest.finish();
+})();
+
+
+ </script>
+</body>
+</html>