Bug 1254839 - add test for RTCPeerConnection deprecation warnings. r=bz
authorJan-Ivar Bruaroey <jib@mozilla.com>
Tue, 15 Mar 2016 17:49:57 -0400
changeset 289397 a36185985ee818459fa885ed12fba63b03828f72
parent 289396 b74f559972724f3c81b9bfc46caaf4e5362dd44a
child 289398 becc2eec160165d310830b65ae823973e2849865
push id30102
push userryanvm@gmail.com
push dateSat, 19 Mar 2016 15:23:17 +0000
treeherdermozilla-central@720fb3d55e28 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs1254839
milestone48.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1254839 - add test for RTCPeerConnection deprecation warnings. r=bz MozReview-Commit-ID: 5tBbn4WW3cq
dom/media/tests/mochitest/test_peerConnection_bug825703.html
--- a/dom/media/tests/mochitest/test_peerConnection_bug825703.html
+++ b/dom/media/tests/mochitest/test_peerConnection_bug825703.html
@@ -6,16 +6,22 @@
 <body>
 <pre id="test">
 <script type="application/javascript">
   createHTML({
     bug: "825703",
     title: "RTCConfiguration valid/invalid permutations"
   });
 
+// ^^^ Don't insert data above this line without adjusting line number below!
+var lineNumberAndFunction = {
+// <--- 16 is the line this must be.
+  line: 17, func: () => new RTCPeerConnection().onaddstream = () => {}
+};
+
 var makePC = (config, expected_error) => {
   var exception;
   try {
     new RTCPeerConnection(config).close();
   } catch (e) {
     exception = e;
   }
   is((exception? exception.name : "success"), expected_error || "success",
@@ -92,28 +98,63 @@ runNetworkTest(() => {
       { urls: ["turn:[::1]:3478"], username:"p", credential:"p", credentialType:"token" },
     ],
   };
   var pc = new RTCPeerConnection(config);
   is(JSON.stringify(toComparable(pc.getConfiguration())),
      JSON.stringify(toComparable(config)), "getConfiguration");
   pc.close();
 
-  // Below tests are setting the about:config User preferences for default
-  // ice servers and checking the outputs when RTCPeerConnection() is
-  // invoked. See Bug 1167922 for more information.
-  // Note - We use promises here since the SpecialPowers API will be
-  // performed asynchronously.
   var push = prefs => new Promise(resolve =>
       SpecialPowers.pushPrefEnv(prefs, resolve));
 
-  push({ set: [['media.peerconnection.default_iceservers', ""]] })
-      .then(() => makePC())
-      .then(() => push({ set: [['media.peerconnection.default_iceservers', "k"]] }))
-      .then(() => makePC())
-      .then(() => push({ set: [['media.peerconnection.default_iceservers', "[{\"urls\": [\"stun:stun.services.mozilla.com\"]}]"]] }))
-      .then(() => makePC())
-      .then(networkTestFinished);
+  Promise.resolve()
+  // This set of tests are setting the about:config User preferences for default
+  // ice servers and checking the outputs when RTCPeerConnection() is
+  // invoked. See Bug 1167922 for more information.
+  .then(() => push({ set: [['media.peerconnection.default_iceservers', ""]] })
+    .then(() => makePC())
+    .then(() => push({ set: [['media.peerconnection.default_iceservers', "k"]] }))
+    .then(() => makePC())
+    .then(() => push({ set: [['media.peerconnection.default_iceservers', "[{\"urls\": [\"stun:stun.services.mozilla.com\"]}]"]] }))
+    .then(() => makePC()))
+  // This set of tests check that warnings work. See Bug 1254839 for more.
+  .then(() => {
+    var consoleService = SpecialPowers.Cc["@mozilla.org/consoleservice;1"]
+                         .getService(SpecialPowers.Ci.nsIConsoleService);
+    var warning = "";
+    var listener = SpecialPowers.wrapCallbackObject({
+      QueryInterface(iid) {
+        if (![SpecialPowers.Ci.nsIConsoleListener,
+              SpecialPowers.Ci.nsISupports].some(i => iid.equals(i))) {
+          throw SpecialPowers.Cr.NS_NOINTERFACE;
+        }
+        return this;
+      },
+
+      observe(msg) {
+        if (msg.message.includes("JavaScript Warning")) {
+          warning = msg.message;
+        }
+      }
+    });
+    consoleService.registerListener(listener);
+    lineNumberAndFunction.func();
+    // Console output is asynchronous, so we must queue a task.
+    return wait(0).then(() => {
+      is(warning.split('"')[1],
+         "onaddstream is deprecated! Use peerConnection.ontrack instead.",
+         "warning logged");
+      var remainder = warning.split('"').slice(2).join('"');
+      info(remainder);
+      ok(remainder.includes('file: "' + window.location + '"'),
+         "warning has this file");
+      ok(remainder.includes('line: ' + lineNumberAndFunction.line),
+         "warning has correct line number");
+      consoleService.unregisterListener(listener);
+    });
+  })
+  .then(networkTestFinished);
 });
 </script>
 </pre>
 </body>
 </html>