summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/tests/mochitests/identity/identityPcTest.js
blob: c22130e23e0535a48d1acde3a163b2d05006b731 (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
80
81
82
83
84
85
86
function identityPcTest(remoteOptions) {
  var user = "someone";
  var domain1 = "test1.example.com";
  var domain2 = "test2.example.com";
  var id1 = user + "@" + domain1;
  var id2 = user + "@" + domain2;

  const audioContext = new AudioContext();
  // Start a tone so that the gUM call will record something even with
  // --use-test-media-devices.  TEST_AUDIO_FREQ matches the frequency of the
  // tone in fake microphone devices.
  const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
  tone.start();

  test = new PeerConnectionTest({
    config_local: {
      peerIdentity: id2,
    },
    config_remote: {
      peerIdentity: id1,
    },
  });
  test.setMediaConstraints(
    [
      {
        audio: true,
        video: true,
        peerIdentity: id2,
      },
    ],
    [
      remoteOptions || {
        audio: true,
        video: true,
        peerIdentity: id1,
      },
    ]
  );
  test.pcLocal.setIdentityProvider("test1.example.com", { protocol: "idp.js" });
  test.pcRemote.setIdentityProvider("test2.example.com", {
    protocol: "idp.js",
  });
  test.chain.append([
    function PEER_IDENTITY_IS_SET_CORRECTLY(test) {
      // no need to wait to check identity in this case,
      // setRemoteDescription should wait for the IdP to complete
      function checkIdentity(pc, pfx, idp, name) {
        return pc.peerIdentity.then(peerInfo => {
          is(peerInfo.idp, idp, pfx + "IdP check");
          is(peerInfo.name, name + "@" + idp, pfx + "identity check");
        });
      }

      return Promise.all([
        checkIdentity(
          test.pcLocal._pc,
          "local: ",
          "test2.example.com",
          "someone"
        ),
        checkIdentity(
          test.pcRemote._pc,
          "remote: ",
          "test1.example.com",
          "someone"
        ),
      ]);
    },

    function REMOTE_STREAMS_ARE_RESTRICTED(test) {
      var remoteStream = test.pcLocal._pc.getRemoteStreams()[0];
      for (const track of remoteStream.getTracks()) {
        mustThrowWith(
          `Freshly received ${track.kind} track with peerIdentity`,
          "SecurityError",
          () => new MediaRecorder(new MediaStream([track])).start()
        );
      }
      return Promise.all([
        audioIsSilence(true, remoteStream),
        videoIsBlack(true, remoteStream),
      ]);
    },
  ]);
  return test.run().finally(() => tone.stop());
}