Skip to content

Commit 0d75c47

Browse files
committed
Merge pull request #131 from fippo/no-datachannel-tests
dont use datachannels in tests
2 parents a46d99d + d9dd9ae commit 0d75c47

File tree

1 file changed

+139
-64
lines changed

1 file changed

+139
-64
lines changed

test/test.js

Lines changed: 139 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ test('basic connection establishment', function(t) {
475475
var pc2 = new RTCPeerConnection(null);
476476
var ended = false;
477477

478-
pc1.createDataChannel('somechannel');
479478
pc1.oniceconnectionstatechange = function() {
480479
if (pc1.iceConnectionState === 'connected' ||
481480
pc1.iceConnectionState === 'completed') {
@@ -507,67 +506,73 @@ test('basic connection establishment', function(t) {
507506
addCandidate(pc1, event);
508507
};
509508

510-
pc1.createOffer(
511-
function(offer) {
512-
t.pass('pc1.createOffer');
513-
pc1.setLocalDescription(offer,
514-
function() {
515-
t.pass('pc1.setLocalDescription');
516-
517-
offer = new RTCSessionDescription(offer);
518-
t.pass('created RTCSessionDescription from offer');
519-
pc2.setRemoteDescription(offer,
520-
function() {
521-
t.pass('pc2.setRemoteDescription');
522-
pc2.createAnswer(
523-
function(answer) {
524-
t.pass('pc2.createAnswer');
525-
pc2.setLocalDescription(answer,
526-
function() {
527-
t.pass('pc2.setLocalDescription');
528-
answer = new RTCSessionDescription(answer);
529-
t.pass('created RTCSessionDescription from answer');
530-
pc1.setRemoteDescription(answer,
531-
function() {
532-
t.pass('pc1.setRemoteDescription');
533-
},
534-
function(err) {
535-
t.fail('pc1.setRemoteDescription ' + err.toString());
536-
}
537-
);
538-
},
539-
function(err) {
540-
t.fail('pc2.setLocalDescription ' + err.toString());
541-
}
542-
);
543-
},
544-
function(err) {
545-
t.fail('pc2.createAnswer ' + err.toString());
546-
}
547-
);
548-
},
549-
function(err) {
550-
t.fail('pc2.setRemoteDescription ' + err.toString());
551-
}
552-
);
553-
},
554-
function(err) {
555-
t.fail('pc1.setLocalDescription ' + err.toString());
556-
}
557-
);
558-
},
559-
function(err) {
560-
t.fail('pc1 failed to create offer ' + err.toString());
561-
}
562-
);
509+
var constraints = {video: true, fake: true};
510+
navigator.mediaDevices.getUserMedia(constraints)
511+
.then(function(stream) {
512+
pc1.addStream(stream);
513+
514+
pc1.createOffer(
515+
function(offer) {
516+
t.pass('pc1.createOffer');
517+
pc1.setLocalDescription(offer,
518+
function() {
519+
t.pass('pc1.setLocalDescription');
520+
521+
offer = new RTCSessionDescription(offer);
522+
t.pass('created RTCSessionDescription from offer');
523+
pc2.setRemoteDescription(offer,
524+
function() {
525+
t.pass('pc2.setRemoteDescription');
526+
pc2.createAnswer(
527+
function(answer) {
528+
t.pass('pc2.createAnswer');
529+
pc2.setLocalDescription(answer,
530+
function() {
531+
t.pass('pc2.setLocalDescription');
532+
answer = new RTCSessionDescription(answer);
533+
t.pass('created RTCSessionDescription from answer');
534+
pc1.setRemoteDescription(answer,
535+
function() {
536+
t.pass('pc1.setRemoteDescription');
537+
},
538+
function(err) {
539+
t.fail('pc1.setRemoteDescription ' +
540+
err.toString());
541+
}
542+
);
543+
},
544+
function(err) {
545+
t.fail('pc2.setLocalDescription ' + err.toString());
546+
}
547+
);
548+
},
549+
function(err) {
550+
t.fail('pc2.createAnswer ' + err.toString());
551+
}
552+
);
553+
},
554+
function(err) {
555+
t.fail('pc2.setRemoteDescription ' + err.toString());
556+
}
557+
);
558+
},
559+
function(err) {
560+
t.fail('pc1.setLocalDescription ' + err.toString());
561+
}
562+
);
563+
},
564+
function(err) {
565+
t.fail('pc1 failed to create offer ' + err.toString());
566+
}
567+
);
568+
});
563569
});
564570

565571
test('basic connection establishment with promise', function(t) {
566572
var pc1 = new RTCPeerConnection(null);
567573
var pc2 = new RTCPeerConnection(null);
568574
var ended = false;
569575

570-
pc1.createDataChannel('somechannel');
571576
pc1.oniceconnectionstatechange = function() {
572577
if (pc1.iceConnectionState === 'connected' ||
573578
pc1.iceConnectionState === 'completed') {
@@ -594,6 +599,70 @@ test('basic connection establishment with promise', function(t) {
594599
addCandidate(pc1, event);
595600
};
596601

602+
var constraints = {video: true, fake: true};
603+
navigator.mediaDevices.getUserMedia(constraints)
604+
.then(function(stream) {
605+
pc1.addStream(stream);
606+
pc1.createOffer().then(function(offer) {
607+
t.pass('pc1.createOffer');
608+
return pc1.setLocalDescription(offer);
609+
}).then(function() {
610+
t.pass('pc1.setLocalDescription');
611+
return pc2.setRemoteDescription(pc1.localDescription);
612+
}).then(function() {
613+
t.pass('pc2.setRemoteDescription');
614+
return pc2.createAnswer();
615+
}).then(function(answer) {
616+
t.pass('pc2.createAnswer');
617+
return pc2.setLocalDescription(answer);
618+
}).then(function() {
619+
t.pass('pc2.setLocalDescription');
620+
return pc1.setRemoteDescription(pc2.localDescription);
621+
}).then(function() {
622+
t.pass('pc1.setRemoteDescription');
623+
}).catch(function(err) {
624+
t.fail(err.toString());
625+
});
626+
});
627+
});
628+
629+
test('basic connection establishment with datachannel', function(t) {
630+
var pc1 = new RTCPeerConnection(null);
631+
var pc2 = new RTCPeerConnection(null);
632+
var ended = false;
633+
if (typeof pc1.createDataChannel !== 'function') {
634+
t.pass('datachannel is not supported.');
635+
t.end();
636+
return;
637+
}
638+
639+
pc1.oniceconnectionstatechange = function() {
640+
if (pc1.iceConnectionState === 'connected' ||
641+
pc1.iceConnectionState === 'completed') {
642+
t.pass('P2P connection established');
643+
if (!ended) {
644+
ended = true;
645+
t.end();
646+
}
647+
}
648+
};
649+
650+
var addCandidate = function(pc, event) {
651+
if (event.candidate) {
652+
var cand = new RTCIceCandidate(event.candidate);
653+
pc.addIceCandidate(cand).catch(function(err) {
654+
t.fail('addIceCandidate ' + err.toString());
655+
});
656+
}
657+
};
658+
pc1.onicecandidate = function(event) {
659+
addCandidate(pc2, event);
660+
};
661+
pc2.onicecandidate = function(event) {
662+
addCandidate(pc1, event);
663+
};
664+
665+
pc1.createDataChannel('somechannel');
597666
pc1.createOffer().then(function(offer) {
598667
t.pass('pc1.createOffer');
599668
return pc1.setLocalDescription(offer);
@@ -734,10 +803,12 @@ test('getStats promise', function(t) {
734803
t.ok(typeof q === 'object', 'getStats with a selector returns a Promise');
735804
});
736805

737-
test('iceTransportPolicy is translated to iceTransports', function(t) {
806+
test('iceTransportPolicy relay functionality', function(t) {
807+
// iceTransportPolicy is renamed to iceTransports in Chrome by
808+
// adapter, this tests that when not setting any TURN server,
809+
// no candidates are generated.
738810
if (m.webrtcDetectedBrowser === 'firefox') {
739-
// not implemented yet.
740-
t.pass('iceTransportPolicy is not implemented by Firefox yet.');
811+
t.pass('iceTransportPolicy is not implemented in Firefox yet.');
741812
t.end();
742813
return;
743814
}
@@ -747,11 +818,10 @@ test('iceTransportPolicy is translated to iceTransports', function(t) {
747818
// Since we try to gather only relay candidates without specifying
748819
// a TURN server, we should not get any candidates.
749820
var candidates = [];
750-
pc1.createDataChannel('somechannel');
751821
pc1.onicecandidate = function(event) {
752822
if (!event.candidate) {
753823
if (candidates.length === 0) {
754-
t.pass('iceTransportPolicy was translated to iceTransport');
824+
t.pass('no candidates were gathered.');
755825
t.end();
756826
} else {
757827
t.fail('got unexpected candidates. ' + JSON.stringify(candidates));
@@ -761,10 +831,15 @@ test('iceTransportPolicy is translated to iceTransports', function(t) {
761831
}
762832
};
763833

764-
pc1.createOffer().then(function(offer) {
765-
return pc1.setLocalDescription(offer);
766-
}).catch(function(err) {
767-
t.fail(err.toString());
834+
var constraints = {video: true, fake: true};
835+
navigator.mediaDevices.getUserMedia(constraints)
836+
.then(function(stream) {
837+
pc1.addStream(stream);
838+
pc1.createOffer().then(function(offer) {
839+
return pc1.setLocalDescription(offer);
840+
}).catch(function(err) {
841+
t.fail(err.toString());
842+
});
768843
});
769844
});
770845

0 commit comments

Comments
 (0)