summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/test_peerConnection_insertDTMF.html
blob: ca8b866a6d1171ac9509508e9f8a028d18235ca5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript" src="pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
createHTML({
  bug: "1291715",
  title: "Test insertDTMF on sender",
  visible: true
});

function insertdtmftest(pc) {
  ok(pc.getSenders().length, "have senders");
  var sender = pc.getSenders()[0];
  ok(sender.dtmf, "sender has dtmf object");

  ok(sender.dtmf.toneBuffer === "", "sender should start with empty tonebuffer");

  // These will trigger assertions on debug builds if we do not enforce the
  // specified minimums and maximums for duration and interToneGap.
  sender.dtmf.insertDTMF("A", 10);
  sender.dtmf.insertDTMF("A", 10000);
  sender.dtmf.insertDTMF("A", 70, 10);

  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.includes("A"), "calling insertDTMF should replace current characters");

  sender.dtmf.insertDTMF("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
  ok(sender.dtmf.toneBuffer.includes("A"), "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 pushPrefs(['media.peerconnection.dtmf.enabled', true])
    .then(() => test.run());
});

</script>
</pre>
</body>
</html>