Bug 1382377 - Test console against devtools.enabled pref. r=baku draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Mon, 28 Aug 2017 19:22:58 +0200
changeset 655873 4b571b1743e343820d6b3549019ff0214c07053a
parent 655872 7d7ffe14a50e4653f4dac1876a8ca66a5dbfaae1
child 728927 5ec0e63962873431a1aa530f5b2af2202c51ed1f
push id76974
push userbmo:poirot.alex@gmail.com
push dateWed, 30 Aug 2017 12:38:30 +0000
reviewersbaku
bugs1382377
milestone57.0a1
Bug 1382377 - Test console against devtools.enabled pref. r=baku MozReview-Commit-ID: GEayP1MP8PV
dom/console/tests/mochitest.ini
dom/console/tests/test_devtools_pref.html
--- 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>