Bug 1291715 - Add mochitest for DTMF; r=jib
MozReview-Commit-ID: 4acq5uMLxe9
--- a/dom/media/tests/mochitest/mochitest.ini
+++ b/dom/media/tests/mochitest/mochitest.ini
@@ -134,16 +134,17 @@ skip-if = (android_version == '18' && de
# [test_peerConnection_certificates.html] # bug 1180968
[test_peerConnection_close.html]
[test_peerConnection_closeDuringIce.html]
[test_peerConnection_constructedStream.html]
skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_errorCallbacks.html]
[test_peerConnection_iceFailure.html]
skip-if = os == 'linux' || os == 'mac' || os == 'win' || android_version == '18' # (Bug 1180388 for win, mac and linux), android(Bug 1189784, timeouts on 4.3 emulator)
+[test_peerConnection_insertDTMF.html]
[test_peerConnection_forwarding_basicAudioVideoCombined.html]
skip-if = android_version == '18' # android(Bug 1189784, timeouts on 4.3 emulator)
[test_peerConnection_noTrickleAnswer.html]
[test_peerConnection_noTrickleOffer.html]
[test_peerConnection_noTrickleOfferAnswer.html]
[test_peerConnection_offerRequiresReceiveAudio.html]
[test_peerConnection_offerRequiresReceiveVideo.html]
[test_peerConnection_offerRequiresReceiveVideoAudio.html]
new file mode 100644
--- /dev/null
+++ b/dom/media/tests/mochitest/test_peerConnection_insertDTMF.html
@@ -0,0 +1,82 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <script type="application/javascript" src="pc.js"></script>
+</head>
+<body>
+<pre id="test">
+<script type="application/javascript;version=1.8">
+createHTML({
+ bug: "1291715",
+ title: "Test insertDTMF on sender",
+ visible: true
+});
+
+function insertdtmftest(pc) {
+ ok(pc.getSenders().length > 0, "have senders");
+ var sender = pc.getSenders()[0];
+ ok(sender.dtmf, "sender has dtmf object");
+
+ ok(sender.dtmf.toneBuffer === "", "sender should start with empty tonebuffer");
+
+ sender.dtmf.insertDTMF("A", 10);
+ is(sender.dtmf.duration, 40, "minimum duration is 40");
+ sender.dtmf.insertDTMF("A", 10000);
+ is(sender.dtmf.duration, 6000, "maximum duration is 6000");
+ sender.dtmf.insertDTMF("A", 70, 10);
+ is(sender.dtmf.duration, 70, "default duration is 70");
+ is(sender.dtmf.interToneGap, 30, "minimum interToneGap is 30");
+ sender.dtmf.insertDTMF("", 100, 40);
+ is(sender.dtmf.duration, 100, "duration is 70");
+ is(sender.dtmf.interToneGap, 40, "interToneGap is 40");
+
+ var threw = false;
+ try {
+ sender.dtmf.insertDTMF("bad tones");
+ } catch (ex) {
+ threw = true;
+ is(ex.code, DOMException.INVALID_CHARACTER_ERR, "Expected InvalidCharacterError");
+ }
+ ok(threw, "Expected exception");
+
+ sender.dtmf.insertDTMF("A");
+ sender.dtmf.insertDTMF("B");
+ ok(sender.dtmf.toneBuffer.indexOf("A") == -1, "calling insertDTMF should replace current characters");
+
+ sender.dtmf.insertDTMF("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+ ok(sender.dtmf.toneBuffer.indexOf("A") != -1, "lowercase characters should be normalized");
+
+ pc.removeTrack(sender);
+ threw = false;
+ try {
+ sender.dtmf.insertDTMF("AAA");
+ } catch (ex) {
+ threw = true;
+ is(ex.code, DOMException.INVALID_STATE_ERR, "Expected InvalidStateError");
+ }
+ ok(threw, "Expected exception");
+}
+
+runNetworkTest(() => {
+
+ test = new PeerConnectionTest();
+ test.setMediaConstraints([{audio: true}], [{audio: true}]);
+ test.chain.removeAfter("PC_REMOTE_WAIT_FOR_MEDIA_FLOW");
+
+ // Test sender dtmf.
+ test.chain.append([
+ function PC_LOCAL_INSERT_DTMF(test) {
+ // We want to call removeTrack
+ test.pcLocal.expectNegotiationNeeded();
+ return insertdtmftest(test.pcLocal._pc);
+ }
+ ]);
+
+ return test.run()
+ .catch(e => ok(false, "unexpected failure: " + e));
+});
+
+</script>
+</pre>
+</body>
+</html>