michael@0: /** michael@0: * Default list of commands to execute for a PeerConnection test. michael@0: */ michael@0: michael@0: var STABLE = "stable"; michael@0: var HAVE_LOCAL_OFFER = "have-local-offer"; michael@0: var HAVE_REMOTE_OFFER = "have-remote-offer"; michael@0: var CLOSED = "closed"; michael@0: michael@0: var commandsPeerConnection = [ michael@0: [ michael@0: 'PC_LOCAL_GUM', michael@0: function (test) { michael@0: test.pcLocal.getAllUserMedia(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_GUM', michael@0: function (test) { michael@0: test.pcRemote.getAllUserMedia(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_INITIAL_SIGNALINGSTATE', michael@0: function (test) { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "Initial local signalingState is 'stable'"); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE', michael@0: function (test) { michael@0: is(test.pcRemote.signalingState, STABLE, michael@0: "Initial remote signalingState is 'stable'"); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CREATE_OFFER', michael@0: function (test) { michael@0: test.createOffer(test.pcLocal, function () { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "Local create offer does not change signaling state"); michael@0: if (!test.pcRemote) { michael@0: send_message({"offer": test.pcLocal._last_offer, michael@0: "media_constraints": test.pcLocal.constraints}); michael@0: } michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_SET_LOCAL_DESCRIPTION', michael@0: function (test) { michael@0: test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, HAVE_LOCAL_OFFER, function () { michael@0: is(test.pcLocal.signalingState, HAVE_LOCAL_OFFER, michael@0: "signalingState after local setLocalDescription is 'have-local-offer'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_GET_OFFER', michael@0: function (test) { michael@0: if (test.pcLocal) { michael@0: test._local_offer = test.pcLocal._last_offer; michael@0: test._local_constraints = test.pcLocal.constraints; michael@0: test.next(); michael@0: } else { michael@0: wait_for_message().then(function(message) { michael@0: ok("offer" in message, "Got an offer message"); michael@0: test._local_offer = new mozRTCSessionDescription(message.offer); michael@0: test._local_constraints = message.media_constraints; michael@0: test.next(); michael@0: }); michael@0: } michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_SET_REMOTE_DESCRIPTION', michael@0: function (test) { michael@0: test.setRemoteDescription(test.pcRemote, test._local_offer, HAVE_REMOTE_OFFER, function () { michael@0: is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER, michael@0: "signalingState after remote setRemoteDescription is 'have-remote-offer'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CREATE_ANSWER', michael@0: function (test) { michael@0: test.createAnswer(test.pcRemote, function () { michael@0: is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER, michael@0: "Remote createAnswer does not change signaling state"); michael@0: if (!test.pcLocal) { michael@0: send_message({"answer": test.pcRemote._last_answer, michael@0: "media_constraints": test.pcRemote.constraints}); michael@0: } michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_GET_ANSWER', michael@0: function (test) { michael@0: if (test.pcRemote) { michael@0: test._remote_answer = test.pcRemote._last_answer; michael@0: test._remote_constraints = test.pcRemote.constraints; michael@0: test.next(); michael@0: } else { michael@0: wait_for_message().then(function(message) { michael@0: ok("answer" in message, "Got an answer message"); michael@0: test._remote_answer = new mozRTCSessionDescription(message.answer); michael@0: test._remote_constraints = message.media_constraints; michael@0: test.next(); michael@0: }); michael@0: } michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_SET_REMOTE_DESCRIPTION', michael@0: function (test) { michael@0: test.setRemoteDescription(test.pcLocal, test._remote_answer, STABLE, function () { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "signalingState after local setRemoteDescription is 'stable'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_SET_LOCAL_DESCRIPTION', michael@0: function (test) { michael@0: test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer, STABLE, function () { michael@0: is(test.pcRemote.signalingState, STABLE, michael@0: "signalingState after remote setLocalDescription is 'stable'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_WAIT_FOR_ICE_CONNECTED', michael@0: function (test) { michael@0: var myTest = test; michael@0: var myPc = myTest.pcLocal; michael@0: michael@0: function onIceConnectedSuccess () { michael@0: ok(true, "pc_local: ICE switched to 'connected' state"); michael@0: myTest.next(); michael@0: }; michael@0: function onIceConnectedFailed () { michael@0: dump("ERROR: pc_local: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, '')); michael@0: dump("ERROR: pc_local: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, '')); michael@0: ok(false, "pc_local: ICE failed to switch to 'connected' state: " + myPc.iceConnectionState); michael@0: myTest.next(); michael@0: }; michael@0: michael@0: if (myPc.isIceConnected()) { michael@0: ok(true, "pc_local: ICE is in connected state"); michael@0: myTest.next(); michael@0: } else if (myPc.isIceConnectionPending()) { michael@0: myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed); michael@0: } else { michael@0: dump("ERROR: pc_local: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, '')); michael@0: dump("ERROR: pc_local: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, '')); michael@0: ok(false, "pc_local: ICE is already in bad state: " + myPc.iceConnectionState); michael@0: myTest.next(); michael@0: } michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_WAIT_FOR_ICE_CONNECTED', michael@0: function (test) { michael@0: var myTest = test; michael@0: var myPc = myTest.pcRemote; michael@0: michael@0: function onIceConnectedSuccess () { michael@0: ok(true, "pc_remote: ICE switched to 'connected' state"); michael@0: myTest.next(); michael@0: }; michael@0: function onIceConnectedFailed () { michael@0: dump("ERROR: pc_remote: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, '')); michael@0: dump("ERROR: pc_remote: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, '')); michael@0: ok(false, "pc_remote: ICE failed to switch to 'connected' state: " + myPc.iceConnectionState); michael@0: myTest.next(); michael@0: }; michael@0: michael@0: if (myPc.isIceConnected()) { michael@0: ok(true, "pc_remote: ICE is in connected state"); michael@0: myTest.next(); michael@0: } else if (myPc.isIceConnectionPending()) { michael@0: myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed); michael@0: } else { michael@0: dump("ERROR: pc_remote: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, '')); michael@0: dump("ERROR: pc_remote: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, '')); michael@0: ok(false, "pc_remote: ICE is already in bad state: " + myPc.iceConnectionState); michael@0: myTest.next(); michael@0: } michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_MEDIA_STREAMS', michael@0: function (test) { michael@0: test.pcLocal.checkMediaStreams(test._remote_constraints); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_MEDIA_STREAMS', michael@0: function (test) { michael@0: test.pcRemote.checkMediaStreams(test._local_constraints); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT', michael@0: function (test) { michael@0: test.pcLocal.checkMediaFlowPresent(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT', michael@0: function (test) { michael@0: test.pcRemote.checkMediaFlowPresent(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_STATS', michael@0: function (test) { michael@0: test.pcLocal.getStats(null, function(stats) { michael@0: test.pcLocal.checkStats(stats); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_STATS', michael@0: function (test) { michael@0: test.pcRemote.getStats(null, function(stats) { michael@0: test.pcRemote.checkStats(stats); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ] michael@0: ]; michael@0: michael@0: michael@0: /** michael@0: * Default list of commands to execute for a Datachannel test. michael@0: */ michael@0: var commandsDataChannel = [ michael@0: [ michael@0: 'PC_LOCAL_GUM', michael@0: function (test) { michael@0: test.pcLocal.getAllUserMedia(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_INITIAL_SIGNALINGSTATE', michael@0: function (test) { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "Initial local signalingState is stable"); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_GUM', michael@0: function (test) { michael@0: test.pcRemote.getAllUserMedia(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_INITIAL_SIGNALINGSTATE', michael@0: function (test) { michael@0: is(test.pcRemote.signalingState, STABLE, michael@0: "Initial remote signalingState is stable"); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CREATE_DATA_CHANNEL', michael@0: function (test) { michael@0: var channel = test.pcLocal.createDataChannel({}); michael@0: michael@0: is(channel.binaryType, "blob", channel + " is of binary type 'blob'"); michael@0: is(channel.readyState, "connecting", channel + " is in state: 'connecting'"); michael@0: michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "Create datachannel does not change signaling state"); michael@0: michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CREATE_OFFER', michael@0: function (test) { michael@0: test.pcLocal.createOffer(function (offer) { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "Local create offer does not change signaling state"); michael@0: ok(offer.sdp.contains("m=application"), michael@0: "m=application is contained in the SDP"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_SET_LOCAL_DESCRIPTION', michael@0: function (test) { michael@0: test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, HAVE_LOCAL_OFFER, michael@0: function () { michael@0: is(test.pcLocal.signalingState, HAVE_LOCAL_OFFER, michael@0: "signalingState after local setLocalDescription is 'have-local-offer'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_SET_REMOTE_DESCRIPTION', michael@0: function (test) { michael@0: test.setRemoteDescription(test.pcRemote, test.pcLocal._last_offer, HAVE_REMOTE_OFFER, michael@0: function () { michael@0: is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER, michael@0: "signalingState after remote setRemoteDescription is 'have-remote-offer'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CREATE_ANSWER', michael@0: function (test) { michael@0: test.createAnswer(test.pcRemote, function () { michael@0: is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER, michael@0: "Remote create offer does not change signaling state"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_SET_REMOTE_DESCRIPTION', michael@0: function (test) { michael@0: test.setRemoteDescription(test.pcLocal, test.pcRemote._last_answer, STABLE, michael@0: function () { michael@0: is(test.pcLocal.signalingState, STABLE, michael@0: "signalingState after local setRemoteDescription is 'stable'"); michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_SET_LOCAL_DESCRIPTION', michael@0: function (test) { michael@0: test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer, STABLE, michael@0: function (sourceChannel, targetChannel) { michael@0: is(sourceChannel.readyState, "open", test.pcLocal + " is in state: 'open'"); michael@0: is(targetChannel.readyState, "open", test.pcRemote + " is in state: 'open'"); michael@0: michael@0: is(test.pcRemote.signalingState, STABLE, michael@0: "signalingState after remote setLocalDescription is 'stable'"); michael@0: test.next(); michael@0: } michael@0: ); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_MEDIA_STREAMS', michael@0: function (test) { michael@0: test.pcLocal.checkMediaStreams(test.pcRemote.constraints); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_MEDIA_STREAMS', michael@0: function (test) { michael@0: test.pcRemote.checkMediaStreams(test.pcLocal.constraints); michael@0: test.next(); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT', michael@0: function (test) { michael@0: test.pcLocal.checkMediaFlowPresent(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT', michael@0: function (test) { michael@0: test.pcRemote.checkMediaFlowPresent(function () { michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'SEND_MESSAGE', michael@0: function (test) { michael@0: var message = "Lorem ipsum dolor sit amet"; michael@0: michael@0: test.send(message, function (channel, data) { michael@0: is(data, message, "Message correctly transmitted from pcLocal to pcRemote."); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'SEND_BLOB', michael@0: function (test) { michael@0: var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."]; michael@0: var blob = new Blob(contents, { "type" : "text/plain" }); michael@0: michael@0: test.send(blob, function (channel, data) { michael@0: ok(data instanceof Blob, "Received data is of instance Blob"); michael@0: is(data.size, blob.size, "Received data has the correct size."); michael@0: michael@0: getBlobContent(data, function (recv_contents) { michael@0: is(recv_contents, contents, "Received data has the correct content."); michael@0: michael@0: test.next(); michael@0: }); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'CREATE_SECOND_DATA_CHANNEL', michael@0: function (test) { michael@0: test.createDataChannel({ }, function (sourceChannel, targetChannel) { michael@0: is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'"); michael@0: is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'"); michael@0: michael@0: is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'"); michael@0: is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'"); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL', michael@0: function (test) { michael@0: var channels = test.pcRemote.dataChannels; michael@0: var message = "Lorem ipsum dolor sit amet"; michael@0: michael@0: test.send(message, function (channel, data) { michael@0: is(channels.indexOf(channel), channels.length - 1, "Last channel used"); michael@0: is(data, message, "Received message has the correct content."); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'SEND_MESSAGE_THROUGH_FIRST_CHANNEL', michael@0: function (test) { michael@0: var message = "Message through 1st channel"; michael@0: var options = { michael@0: sourceChannel: test.pcLocal.dataChannels[0], michael@0: targetChannel: test.pcRemote.dataChannels[0] michael@0: }; michael@0: michael@0: test.send(message, function (channel, data) { michael@0: is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used"); michael@0: is(data, message, "Received message has the correct content."); michael@0: michael@0: test.next(); michael@0: }, options); michael@0: } michael@0: ], michael@0: [ michael@0: 'CREATE_NEGOTIATED_DATA_CHANNEL', michael@0: function (test) { michael@0: var options = {negotiated:true, id: 5, protocol:"foo/bar", ordered:false, michael@0: maxRetransmits:500}; michael@0: test.createDataChannel(options, function (sourceChannel2, targetChannel2) { michael@0: is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'"); michael@0: is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'"); michael@0: michael@0: is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'"); michael@0: is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'"); michael@0: michael@0: if (options.id != undefined) { michael@0: is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id); michael@0: } else { michael@0: options.id = sourceChannel2.id; michael@0: } michael@0: var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime); michael@0: is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol); michael@0: is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable); michael@0: /* michael@0: These aren't exposed by IDL yet michael@0: is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered); michael@0: is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" + michael@0: sourceChannel2.maxRetransmits); michael@0: is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" + michael@0: sourceChannel2.maxRetransmitTime); michael@0: */ michael@0: michael@0: is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id); michael@0: is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol); michael@0: is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable); michael@0: /* michael@0: These aren't exposed by IDL yet michael@0: is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered); michael@0: is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" + michael@0: targetChannel2.maxRetransmits); michael@0: is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" + michael@0: targetChannel2.maxRetransmitTime); michael@0: */ michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2', michael@0: function (test) { michael@0: var channels = test.pcRemote.dataChannels; michael@0: var message = "Lorem ipsum dolor sit amet"; michael@0: michael@0: test.send(message, function (channel, data) { michael@0: is(channels.indexOf(channel), channels.length - 1, "Last channel used"); michael@0: is(data, message, "Received message has the correct content."); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'CLOSE_LAST_OPENED_DATA_CHANNEL2', michael@0: function (test) { michael@0: var channels = test.pcRemote.dataChannels; michael@0: michael@0: test.closeDataChannel(channels.length - 1, function (channel) { michael@0: is(channel.readyState, "closed", "Channel is in state: 'closed'"); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ], michael@0: [ michael@0: 'CLOSE_LAST_OPENED_DATA_CHANNEL', michael@0: function (test) { michael@0: var channels = test.pcRemote.dataChannels; michael@0: michael@0: test.closeDataChannel(channels.length - 1, function (channel) { michael@0: is(channel.readyState, "closed", "Channel is in state: 'closed'"); michael@0: michael@0: test.next(); michael@0: }); michael@0: } michael@0: ] michael@0: ];