Bug 1119593 - Adding test for legacy PC callback functions, r=drno,jib, a=testonly
authorMartin Thomson <martin.thomson@gmail.com>
Sat, 21 Feb 2015 10:15:04 +1300
changeset 249894 336892fb1df2a799f1d9026bcfd3e79b517ca95b
parent 249893 60538ae8bc51d756bb69711b4f05c91d129fe54b
child 249895 20d9216b434fa748f993c702928ab79c7f67f086
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdrno, jib, testonly
bugs1119593
milestone37.0a2
Bug 1119593 - Adding test for legacy PC callback functions, r=drno,jib, a=testonly
dom/media/tests/mochitest/mochitest.ini
dom/media/tests/mochitest/test_peerConnection_callbacks.html
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -107,16 +107,18 @@ skip-if = toolkit == 'gonk' # b2g (Bug 1
 [test_peerConnection_offerRequiresReceiveAudio.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_offerRequiresReceiveVideo.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_offerRequiresReceiveVideoAudio.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_promiseSendOnly.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
+[test_peerConnection_callbacks.html]
+skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_replaceTrack.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_syncSetDescription.html]
 skip-if = toolkit == 'gonk' # b2g(Bug 960442, video support for WebRTC is disabled on b2g)
 [test_peerConnection_setLocalAnswerInHaveLocalOffer.html]
 skip-if = toolkit == 'gonk' # b2g (Bug 1059867)
 [test_peerConnection_setLocalAnswerInStable.html]
 skip-if = toolkit == 'gonk' # b2g (Bug 1059867)
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_callbacks.html
@@ -0,0 +1,96 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="head.js"></script>
+  <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<video id="v1" controls="controls" height="120" width="160" autoplay></video>
+<video id="v2" controls="controls" height="120" width="160" autoplay></video><br>
+<pre id="test">
+<script type="application/javascript;version=1.8">
+  createHTML({
+    title: "PeerConnection using callback functions",
+    visible: true
+  });
+
+// This still aggressively uses promises, but it is testing that the callback functions
+// are properly in place.
+var waituntil = func => new Promise(resolve => {
+  var inter = setInterval(() => func() && resolve(clearInterval(inter)), 200);
+});
+
+// wrapper that turns a callback-based function call into a promise
+function pcall(o, f, beforeArg) {
+  return new Promise((resolve, reject) => {
+    var args = [resolve, reject];
+    if (typeof beforeArg !== 'undefined') {
+      args.unshift(beforeArg);
+    }
+    info('Calling ' + f.name);
+    f.apply(o, args);
+  });
+}
+
+var pc1 = new mozRTCPeerConnection();
+var pc2 = new mozRTCPeerConnection();
+
+var pc2_haveRemoteOffer = new Promise(resolve => {
+  pc2.onsignalingstatechange =
+    e => (e.target.signalingState == "have-remote-offer") && resolve();
+});
+var pc1_stable = new Promise(resolve => {
+  pc1.onsignalingstatechange =
+    e => (e.target.signalingState == "stable") && resolve();
+});
+
+pc1.onicecandidate = e => {
+  pc2_haveRemoteOffer
+    .then(() => !e.candidate || pcall(pc2, pc2.addIceCandidate, e.candidate))
+    .catch(generateErrorCallback());
+};
+pc2.onicecandidate = e => {
+  pc1_stable
+    .then(() => !e.candidate || pcall(pc1, pc1.addIceCandidate, e.candidate))
+    .catch(generateErrorCallback());
+};
+
+var delivered = new Promise(resolve => {
+  pc2.onaddstream = e => {
+    v2.mozSrcObject = e.stream;
+    resolve(e.stream);
+  };
+});
+var canPlayThrough = new Promise(resolve => v2.canplaythrough = resolve);
+
+runNetworkTest(function() {
+  is(v2.currentTime, 0, "v2.currentTime is zero at outset");
+
+  // not testing legacy gUM here
+  navigator.mediaDevices.getUserMedia({ fake: true, video: true, audio: true })
+    .then(stream => pc1.addStream(v1.mozSrcObject = stream))
+    .then(() => pcall(pc1, pc1.createOffer))
+    .then(offer => pcall(pc1, pc1.setLocalDescription, offer))
+    .then(() => pcall(pc2, pc2.setRemoteDescription, pc1.localDescription))
+    .then(() => pcall(pc2, pc2.createAnswer))
+    .then(answer => pcall(pc2, pc2.setLocalDescription, answer))
+    .then(() => pcall(pc1, pc1.setRemoteDescription, pc2.localDescription))
+    .then(() => delivered)
+  //    .then(() => canPlayThrough)    // why doesn't this fire?
+    .then(() => waituntil(() => v2.currentTime > 0 && v2.mozSrcObject.currentTime > 0))
+    .then(() => ok(v2.currentTime > 0, "v2.currentTime is moving (" + v2.currentTime + ")"))
+    .then(() => ok(true, "Connected."))
+    .then(() => pcall(pc1, pc1.getStats, null))
+    .then(stats => ok(Object.keys(stats).length > 0, "pc1 has stats"))
+    .then(() => pcall(pc2, pc2.getStats, null))
+    .then(stats => ok(Object.keys(stats).length > 0, "pc2 has stats"))
+    .then(() => { v1.pause(); v2.pause(); })
+    .catch(reason => ok(false, "unexpected failure: " + reason))
+      .then(networkTestFinished);
+});
+</script>
+</pre>
+</body>
+</html>