summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/test_peerConnection_insertDTMF.html
blob: 0bfb4eef6e1e3f9778f66da32a34f83890ead75a (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
77
78
79
<!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");

  // 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.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);
    }
  ]);

  var pushPrefs = (...p) => new Promise(r => SpecialPowers.pushPrefEnv({set: p}, r));

  return pushPrefs(['media.peerconnection.dtmf.enabled', true])
    .then(() => { test.run() })
    .catch(e => ok(false, "unexpected failure: " + e));
});

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