dom/media/tests/mochitest/templates.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /**
     2  * Default list of commands to execute for a PeerConnection test.
     3  */
     5 var STABLE = "stable";
     6 var HAVE_LOCAL_OFFER = "have-local-offer";
     7 var HAVE_REMOTE_OFFER = "have-remote-offer";
     8 var CLOSED = "closed";
    10 var commandsPeerConnection = [
    11   [
    12     'PC_LOCAL_GUM',
    13     function (test) {
    14       test.pcLocal.getAllUserMedia(function () {
    15         test.next();
    16       });
    17     }
    18   ],
    19   [
    20     'PC_REMOTE_GUM',
    21     function (test) {
    22       test.pcRemote.getAllUserMedia(function () {
    23         test.next();
    24       });
    25     }
    26   ],
    27   [
    28     'PC_LOCAL_CHECK_INITIAL_SIGNALINGSTATE',
    29     function (test) {
    30       is(test.pcLocal.signalingState, STABLE,
    31          "Initial local signalingState is 'stable'");
    32       test.next();
    33     }
    34   ],
    35   [
    36     'PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE',
    37     function (test) {
    38       is(test.pcRemote.signalingState, STABLE,
    39          "Initial remote signalingState is 'stable'");
    40       test.next();
    41     }
    42   ],
    43   [
    44     'PC_LOCAL_CREATE_OFFER',
    45     function (test) {
    46       test.createOffer(test.pcLocal, function () {
    47         is(test.pcLocal.signalingState, STABLE,
    48            "Local create offer does not change signaling state");
    49         if (!test.pcRemote) {
    50           send_message({"offer": test.pcLocal._last_offer,
    51                         "media_constraints": test.pcLocal.constraints});
    52         }
    53         test.next();
    54       });
    55     }
    56   ],
    57   [
    58     'PC_LOCAL_SET_LOCAL_DESCRIPTION',
    59     function (test) {
    60       test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, HAVE_LOCAL_OFFER, function () {
    61         is(test.pcLocal.signalingState, HAVE_LOCAL_OFFER,
    62            "signalingState after local setLocalDescription is 'have-local-offer'");
    63         test.next();
    64       });
    65     }
    66   ],
    67   [
    68     'PC_REMOTE_GET_OFFER',
    69     function (test) {
    70       if (test.pcLocal) {
    71         test._local_offer = test.pcLocal._last_offer;
    72         test._local_constraints = test.pcLocal.constraints;
    73         test.next();
    74       } else {
    75         wait_for_message().then(function(message) {
    76           ok("offer" in message, "Got an offer message");
    77           test._local_offer = new mozRTCSessionDescription(message.offer);
    78           test._local_constraints = message.media_constraints;
    79           test.next();
    80         });
    81       }
    82     }
    83   ],
    84   [
    85     'PC_REMOTE_SET_REMOTE_DESCRIPTION',
    86     function (test) {
    87       test.setRemoteDescription(test.pcRemote, test._local_offer, HAVE_REMOTE_OFFER, function () {
    88         is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER,
    89            "signalingState after remote setRemoteDescription is 'have-remote-offer'");
    90         test.next();
    91       });
    92     }
    93   ],
    94   [
    95     'PC_REMOTE_CREATE_ANSWER',
    96     function (test) {
    97       test.createAnswer(test.pcRemote, function () {
    98         is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER,
    99            "Remote createAnswer does not change signaling state");
   100         if (!test.pcLocal) {
   101           send_message({"answer": test.pcRemote._last_answer,
   102                         "media_constraints": test.pcRemote.constraints});
   103         }
   104         test.next();
   105       });
   106     }
   107   ],
   108   [
   109     'PC_LOCAL_GET_ANSWER',
   110     function (test) {
   111       if (test.pcRemote) {
   112         test._remote_answer = test.pcRemote._last_answer;
   113         test._remote_constraints = test.pcRemote.constraints;
   114         test.next();
   115       } else {
   116         wait_for_message().then(function(message) {
   117           ok("answer" in message, "Got an answer message");
   118           test._remote_answer = new mozRTCSessionDescription(message.answer);
   119           test._remote_constraints = message.media_constraints;
   120           test.next();
   121         });
   122       }
   123     }
   124   ],
   125   [
   126     'PC_LOCAL_SET_REMOTE_DESCRIPTION',
   127     function (test) {
   128       test.setRemoteDescription(test.pcLocal, test._remote_answer, STABLE, function () {
   129         is(test.pcLocal.signalingState, STABLE,
   130            "signalingState after local setRemoteDescription is 'stable'");
   131         test.next();
   132       });
   133     }
   134   ],
   135   [
   136     'PC_REMOTE_SET_LOCAL_DESCRIPTION',
   137     function (test) {
   138       test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer, STABLE, function () {
   139         is(test.pcRemote.signalingState, STABLE,
   140            "signalingState after remote setLocalDescription is 'stable'");
   141         test.next();
   142       });
   143     }
   144   ],
   145   [
   146     'PC_LOCAL_WAIT_FOR_ICE_CONNECTED',
   147     function (test) {
   148       var myTest = test;
   149       var myPc = myTest.pcLocal;
   151       function onIceConnectedSuccess () {
   152         ok(true, "pc_local: ICE switched to 'connected' state");
   153         myTest.next();
   154       };
   155       function onIceConnectedFailed () {
   156         dump("ERROR: pc_local: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, ''));
   157         dump("ERROR: pc_local: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, ''));
   158         ok(false, "pc_local: ICE failed to switch to 'connected' state: " + myPc.iceConnectionState);
   159         myTest.next();
   160       };
   162       if (myPc.isIceConnected()) {
   163         ok(true, "pc_local: ICE is in connected state");
   164         myTest.next();
   165       } else if (myPc.isIceConnectionPending()) {
   166         myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed);
   167       } else {
   168         dump("ERROR: pc_local: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, ''));
   169         dump("ERROR: pc_local: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, ''));
   170         ok(false, "pc_local: ICE is already in bad state: " + myPc.iceConnectionState);
   171         myTest.next();
   172       }
   173     }
   174   ],
   175   [
   176     'PC_REMOTE_WAIT_FOR_ICE_CONNECTED',
   177     function (test) {
   178       var myTest = test;
   179       var myPc = myTest.pcRemote;
   181       function onIceConnectedSuccess () {
   182         ok(true, "pc_remote: ICE switched to 'connected' state");
   183         myTest.next();
   184       };
   185       function onIceConnectedFailed () {
   186         dump("ERROR: pc_remote: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, ''));
   187         dump("ERROR: pc_remote: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, ''));
   188         ok(false, "pc_remote: ICE failed to switch to 'connected' state: " + myPc.iceConnectionState);
   189         myTest.next();
   190       };
   192       if (myPc.isIceConnected()) {
   193         ok(true, "pc_remote: ICE is in connected state");
   194         myTest.next();
   195       } else if (myPc.isIceConnectionPending()) {
   196         myPc.waitForIceConnected(onIceConnectedSuccess, onIceConnectedFailed);
   197       } else {
   198         dump("ERROR: pc_remote: SDP offer: " + myTest._local_offer.sdp.replace(/[\r]/g, ''));
   199         dump("ERROR: pc_remote: SDP answer: " + myTest._remote_answer.sdp.replace(/[\r]/g, ''));
   200         ok(false, "pc_remote: ICE is already in bad state: " + myPc.iceConnectionState);
   201         myTest.next();
   202       }
   203     }
   204   ],
   205   [
   206     'PC_LOCAL_CHECK_MEDIA_STREAMS',
   207     function (test) {
   208       test.pcLocal.checkMediaStreams(test._remote_constraints);
   209       test.next();
   210     }
   211   ],
   212   [
   213     'PC_REMOTE_CHECK_MEDIA_STREAMS',
   214     function (test) {
   215       test.pcRemote.checkMediaStreams(test._local_constraints);
   216       test.next();
   217     }
   218   ],
   219   [
   220     'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT',
   221     function (test) {
   222       test.pcLocal.checkMediaFlowPresent(function () {
   223         test.next();
   224       });
   225     }
   226   ],
   227   [
   228     'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT',
   229     function (test) {
   230       test.pcRemote.checkMediaFlowPresent(function () {
   231         test.next();
   232       });
   233     }
   234   ],
   235   [
   236     'PC_LOCAL_CHECK_STATS',
   237     function (test) {
   238       test.pcLocal.getStats(null, function(stats) {
   239         test.pcLocal.checkStats(stats);
   240         test.next();
   241       });
   242     }
   243   ],
   244   [
   245     'PC_REMOTE_CHECK_STATS',
   246     function (test) {
   247       test.pcRemote.getStats(null, function(stats) {
   248         test.pcRemote.checkStats(stats);
   249         test.next();
   250       });
   251     }
   252   ]
   253 ];
   256 /**
   257  * Default list of commands to execute for a Datachannel test.
   258  */
   259 var commandsDataChannel = [
   260   [
   261     'PC_LOCAL_GUM',
   262     function (test) {
   263       test.pcLocal.getAllUserMedia(function () {
   264         test.next();
   265       });
   266     }
   267   ],
   268   [
   269     'PC_LOCAL_INITIAL_SIGNALINGSTATE',
   270     function (test) {
   271       is(test.pcLocal.signalingState, STABLE,
   272          "Initial local signalingState is stable");
   273       test.next();
   274     }
   275   ],
   276   [
   277     'PC_REMOTE_GUM',
   278     function (test) {
   279       test.pcRemote.getAllUserMedia(function () {
   280       test.next();
   281       });
   282     }
   283   ],
   284   [
   285     'PC_REMOTE_INITIAL_SIGNALINGSTATE',
   286     function (test) {
   287       is(test.pcRemote.signalingState, STABLE,
   288          "Initial remote signalingState is stable");
   289       test.next();
   290     }
   291   ],
   292   [
   293     'PC_LOCAL_CREATE_DATA_CHANNEL',
   294     function (test) {
   295       var channel = test.pcLocal.createDataChannel({});
   297       is(channel.binaryType, "blob", channel + " is of binary type 'blob'");
   298       is(channel.readyState, "connecting", channel + " is in state: 'connecting'");
   300       is(test.pcLocal.signalingState, STABLE,
   301          "Create datachannel does not change signaling state");
   303       test.next();
   304     }
   305   ],
   306   [
   307     'PC_LOCAL_CREATE_OFFER',
   308     function (test) {
   309       test.pcLocal.createOffer(function (offer) {
   310         is(test.pcLocal.signalingState, STABLE,
   311            "Local create offer does not change signaling state");
   312         ok(offer.sdp.contains("m=application"),
   313            "m=application is contained in the SDP");
   314         test.next();
   315       });
   316     }
   317   ],
   318   [
   319     'PC_LOCAL_SET_LOCAL_DESCRIPTION',
   320     function (test) {
   321       test.setLocalDescription(test.pcLocal, test.pcLocal._last_offer, HAVE_LOCAL_OFFER,
   322         function () {
   323         is(test.pcLocal.signalingState, HAVE_LOCAL_OFFER,
   324            "signalingState after local setLocalDescription is 'have-local-offer'");
   325         test.next();
   326       });
   327     }
   328   ],
   329   [
   330     'PC_REMOTE_SET_REMOTE_DESCRIPTION',
   331     function (test) {
   332       test.setRemoteDescription(test.pcRemote, test.pcLocal._last_offer, HAVE_REMOTE_OFFER,
   333         function () {
   334         is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER,
   335            "signalingState after remote setRemoteDescription is 'have-remote-offer'");
   336         test.next();
   337       });
   338     }
   339   ],
   340   [
   341     'PC_REMOTE_CREATE_ANSWER',
   342     function (test) {
   343       test.createAnswer(test.pcRemote, function () {
   344         is(test.pcRemote.signalingState, HAVE_REMOTE_OFFER,
   345            "Remote create offer does not change signaling state");
   346         test.next();
   347       });
   348     }
   349   ],
   350   [
   351     'PC_LOCAL_SET_REMOTE_DESCRIPTION',
   352     function (test) {
   353       test.setRemoteDescription(test.pcLocal, test.pcRemote._last_answer, STABLE,
   354         function () {
   355         is(test.pcLocal.signalingState, STABLE,
   356            "signalingState after local setRemoteDescription is 'stable'");
   357         test.next();
   358       });
   359     }
   360   ],
   361   [
   362     'PC_REMOTE_SET_LOCAL_DESCRIPTION',
   363     function (test) {
   364       test.setLocalDescription(test.pcRemote, test.pcRemote._last_answer, STABLE,
   365         function (sourceChannel, targetChannel) {
   366           is(sourceChannel.readyState, "open", test.pcLocal + " is in state: 'open'");
   367           is(targetChannel.readyState, "open", test.pcRemote + " is in state: 'open'");
   369           is(test.pcRemote.signalingState, STABLE,
   370              "signalingState after remote setLocalDescription is 'stable'");
   371           test.next();
   372         }
   373       );
   374     }
   375   ],
   376   [
   377     'PC_LOCAL_CHECK_MEDIA_STREAMS',
   378     function (test) {
   379       test.pcLocal.checkMediaStreams(test.pcRemote.constraints);
   380       test.next();
   381     }
   382   ],
   383   [
   384     'PC_REMOTE_CHECK_MEDIA_STREAMS',
   385     function (test) {
   386       test.pcRemote.checkMediaStreams(test.pcLocal.constraints);
   387       test.next();
   388     }
   389   ],
   390   [
   391     'PC_LOCAL_CHECK_MEDIA_FLOW_PRESENT',
   392     function (test) {
   393       test.pcLocal.checkMediaFlowPresent(function () {
   394         test.next();
   395       });
   396     }
   397   ],
   398   [
   399     'PC_REMOTE_CHECK_MEDIA_FLOW_PRESENT',
   400     function (test) {
   401       test.pcRemote.checkMediaFlowPresent(function () {
   402         test.next();
   403       });
   404     }
   405   ],
   406   [
   407     'SEND_MESSAGE',
   408     function (test) {
   409       var message = "Lorem ipsum dolor sit amet";
   411       test.send(message, function (channel, data) {
   412         is(data, message, "Message correctly transmitted from pcLocal to pcRemote.");
   414         test.next();
   415       });
   416     }
   417   ],
   418   [
   419     'SEND_BLOB',
   420     function (test) {
   421       var contents = ["At vero eos et accusam et justo duo dolores et ea rebum."];
   422       var blob = new Blob(contents, { "type" : "text/plain" });
   424       test.send(blob, function (channel, data) {
   425         ok(data instanceof Blob, "Received data is of instance Blob");
   426         is(data.size, blob.size, "Received data has the correct size.");
   428         getBlobContent(data, function (recv_contents) {
   429           is(recv_contents, contents, "Received data has the correct content.");
   431           test.next();
   432         });
   433       });
   434     }
   435   ],
   436   [
   437     'CREATE_SECOND_DATA_CHANNEL',
   438     function (test) {
   439       test.createDataChannel({ }, function (sourceChannel, targetChannel) {
   440         is(sourceChannel.readyState, "open", sourceChannel + " is in state: 'open'");
   441         is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
   443         is(targetChannel.binaryType, "blob", targetChannel + " is of binary type 'blob'");
   444         is(targetChannel.readyState, "open", targetChannel + " is in state: 'open'");
   446         test.next();
   447       });
   448     }
   449   ],
   450   [
   451     'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL',
   452     function (test) {
   453       var channels = test.pcRemote.dataChannels;
   454       var message = "Lorem ipsum dolor sit amet";
   456       test.send(message, function (channel, data) {
   457         is(channels.indexOf(channel), channels.length - 1, "Last channel used");
   458         is(data, message, "Received message has the correct content.");
   460         test.next();
   461       });
   462     }
   463   ],
   464   [
   465     'SEND_MESSAGE_THROUGH_FIRST_CHANNEL',
   466     function (test) {
   467       var message = "Message through 1st channel";
   468       var options = {
   469         sourceChannel: test.pcLocal.dataChannels[0],
   470         targetChannel: test.pcRemote.dataChannels[0]
   471       };
   473       test.send(message, function (channel, data) {
   474         is(test.pcRemote.dataChannels.indexOf(channel), 0, "1st channel used");
   475         is(data, message, "Received message has the correct content.");
   477         test.next();
   478       }, options);
   479     }
   480   ],
   481   [
   482     'CREATE_NEGOTIATED_DATA_CHANNEL',
   483     function (test) {
   484       var options = {negotiated:true, id: 5, protocol:"foo/bar", ordered:false,
   485 		     maxRetransmits:500};
   486       test.createDataChannel(options, function (sourceChannel2, targetChannel2) {
   487         is(sourceChannel2.readyState, "open", sourceChannel2 + " is in state: 'open'");
   488         is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
   490         is(targetChannel2.binaryType, "blob", targetChannel2 + " is of binary type 'blob'");
   491         is(targetChannel2.readyState, "open", targetChannel2 + " is in state: 'open'");
   493         if (options.id != undefined) {
   494           is(sourceChannel2.id, options.id, sourceChannel2 + " id is:" + sourceChannel2.id);
   495 	} else {
   496 	  options.id = sourceChannel2.id;
   497 	}
   498 	var reliable = !options.ordered ? false : (options.maxRetransmits || options.maxRetransmitTime);
   499         is(sourceChannel2.protocol, options.protocol, sourceChannel2 + " protocol is:" + sourceChannel2.protocol);
   500         is(sourceChannel2.reliable, reliable, sourceChannel2 + " reliable is:" + sourceChannel2.reliable);
   501 /*
   502   These aren't exposed by IDL yet
   503         is(sourceChannel2.ordered, options.ordered, sourceChannel2 + " ordered is:" + sourceChannel2.ordered);
   504         is(sourceChannel2.maxRetransmits, options.maxRetransmits, sourceChannel2 + " maxRetransmits is:" +
   505 	   sourceChannel2.maxRetransmits);
   506         is(sourceChannel2.maxRetransmitTime, options.maxRetransmitTime, sourceChannel2 + " maxRetransmitTime is:" +
   507 	   sourceChannel2.maxRetransmitTime);
   508 */
   510         is(targetChannel2.id, options.id, targetChannel2 + " id is:" + targetChannel2.id);
   511         is(targetChannel2.protocol, options.protocol, targetChannel2 + " protocol is:" + targetChannel2.protocol);
   512         is(targetChannel2.reliable, reliable, targetChannel2 + " reliable is:" + targetChannel2.reliable);
   513 /*
   514   These aren't exposed by IDL yet
   515        is(targetChannel2.ordered, options.ordered, targetChannel2 + " ordered is:" + targetChannel2.ordered);
   516         is(targetChannel2.maxRetransmits, options.maxRetransmits, targetChannel2 + " maxRetransmits is:" +
   517 	   targetChannel2.maxRetransmits);
   518         is(targetChannel2.maxRetransmitTime, options.maxRetransmitTime, targetChannel2 + " maxRetransmitTime is:" +
   519 	   targetChannel2.maxRetransmitTime);
   520 */
   522         test.next();
   523       });
   524     }
   525   ],
   526   [
   527     'SEND_MESSAGE_THROUGH_LAST_OPENED_CHANNEL2',
   528     function (test) {
   529       var channels = test.pcRemote.dataChannels;
   530       var message = "Lorem ipsum dolor sit amet";
   532       test.send(message, function (channel, data) {
   533         is(channels.indexOf(channel), channels.length - 1, "Last channel used");
   534         is(data, message, "Received message has the correct content.");
   536         test.next();
   537       });
   538     }
   539   ],
   540   [
   541     'CLOSE_LAST_OPENED_DATA_CHANNEL2',
   542     function (test) {
   543       var channels = test.pcRemote.dataChannels;
   545       test.closeDataChannel(channels.length - 1, function (channel) {
   546         is(channel.readyState, "closed", "Channel is in state: 'closed'");
   548         test.next();
   549       });
   550     }
   551   ],
   552   [
   553     'CLOSE_LAST_OPENED_DATA_CHANNEL',
   554     function (test) {
   555       var channels = test.pcRemote.dataChannels;
   557       test.closeDataChannel(channels.length - 1, function (channel) {
   558         is(channel.readyState, "closed", "Channel is in state: 'closed'");
   560         test.next();
   561       });
   562     }
   563   ]
   564 ];

mercurial