OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <title>RTCPeerConnection.getSenders</title> | |
5 <script src="../../resources/testharness.js"></script> | |
6 <script src="../../resources/testharnessreport.js"></script> | |
7 </head> | |
8 <body> | |
9 <script> | |
10 promise_test(function() { | |
11 let pc = new RTCPeerConnection(); | |
12 return createStreams({audio:true, video:false}, 1) | |
13 .then(function(streams) { | |
14 let stream = streams[0]; | |
15 let track = stream.getAudioTracks()[0]; | |
16 let sender = pc.addTrack(track); | |
17 assert_equals(sender.track, track); | |
18 assert_array_equals(pc.getLocalStreams(), []); | |
19 }); | |
20 }, 'addTrack() for a single track.'); | |
21 | |
22 promise_test(function() { | |
23 let pc = new RTCPeerConnection(); | |
24 return createStreams({audio:true, video:false}, 1) | |
25 .then(function(streams) { | |
26 let stream = streams[0]; | |
27 let track = stream.getAudioTracks()[0]; | |
28 let sender = pc.addTrack(track, stream); | |
29 assert_equals(sender.track, track); | |
30 // TODO(hbos): |addTrack| does not add to the set of local streams. When | |
31 // |getLocalStreams| is updated to return the streams of all senders this | |
32 // would have an observable effect here. https://crbug.com/738918 | |
33 assert_array_equals(pc.getLocalStreams(), []); | |
34 }); | |
35 }, 'addTrack() for a single track and its stream.'); | |
36 | |
37 promise_test(function() { | |
38 let pc = new RTCPeerConnection(); | |
39 return createStreams({audio:true, video:false}, 2) | |
40 .then(function(streams) { | |
41 let streamA = streams[0]; | |
42 let trackA = streamA.getAudioTracks()[0]; | |
43 let streamB = streams[1]; | |
44 let sender = pc.addTrack(trackA, streamB); | |
45 assert_equals(sender.track, trackA); | |
46 // TODO(hbos): |addTrack| does not add to the set of local streams. When | |
47 // |getLocalStreams| is updated to return the streams of all senders this | |
48 // would have an observable effect here. https://crbug.com/738918 | |
49 assert_array_equals(pc.getLocalStreams(), []); | |
50 }); | |
51 }, 'addTrack() for a single track and a different stream.'); | |
52 | |
53 promise_test(function() { | |
54 let pc = new RTCPeerConnection(); | |
55 return createStreams({audio:true, video:false}, 2) | |
56 .then(function(streams) { | |
57 let streamA = streams[0]; | |
58 let streamB = streams[1]; | |
59 let track = streamA.getAudioTracks()[0]; | |
60 let exception = null; | |
61 try { | |
62 pc.addTrack(track, streamA, streamB); | |
63 } catch (e) { | |
64 exception = e; | |
65 } | |
66 // The spec supports multiple streams per track but our implementation | |
67 // doesn't. Fix test when resolving https://crbug.com/webrtc/7932. | |
68 assert_true(exception != null); | |
69 assert_equals('NotSupportedError', exception.name); | |
70 }); | |
71 }, 'addTrack() for a single track and two streams throws NotSupportedError.'); | |
72 | |
73 promise_test(function() { | |
74 let pc = new RTCPeerConnection(); | |
75 return createStreams({audio:true, video:false}, 1) | |
76 .then(function(streams) { | |
77 let stream = streams[0]; | |
78 let track = stream.getAudioTracks()[0]; | |
79 let sender = pc.addTrack(track); | |
80 assert_equals(sender.track, track); | |
81 let exception = null; | |
82 try { | |
83 pc.addTrack(track); | |
84 } catch (e) { | |
85 exception = e; | |
86 } | |
87 assert_equals('InvalidAccessError', exception.name); | |
88 }); | |
89 }, 'addTrack() when already added throws InvalidAccessError.'); | |
90 | |
91 promise_test(function() { | |
92 let pc = new RTCPeerConnection(); | |
93 return createStreams({audio:true, video:false}, 1) | |
94 .then(function(streams) { | |
95 let stream = streams[0]; | |
96 let track = stream.getAudioTracks()[0]; | |
97 pc.addStream(stream); | |
98 let exception = null; | |
99 try { | |
100 pc.addTrack(track); | |
101 } catch (e) { | |
102 exception = e; | |
103 } | |
104 assert_true(exception != null); | |
105 assert_equals('InvalidAccessError', exception.name); | |
106 }); | |
107 }, 'addTrack() after addStream() throws InvalidAccessError.'); | |
Taylor_Brandstetter
2017/07/06 22:45:14
May be helpful to call out the fact that the inter
hbos_chromium
2017/07/07 12:07:48
Done.
| |
108 | |
109 promise_test(function() { | |
110 let pc = new RTCPeerConnection(); | |
111 return createStreams({audio:true, video:false}, 1) | |
112 .then(function(streams) { | |
113 let stream = streams[0]; | |
114 let track = stream.getAudioTracks()[0]; | |
115 let sender = pc.addTrack(track); | |
116 assert_equals(sender.track, track); | |
117 assert_array_equals(pc.getSenders(), [ sender ]); | |
118 assert_array_equals(pc.getLocalStreams(), []); | |
119 pc.addStream(stream); | |
120 assert_array_equals(pc.getLocalStreams(), [ stream ]); | |
121 // The existing sender is reused by |addStream|. | |
122 assert_array_equals(pc.getSenders(), [ sender ]); | |
123 }); | |
124 }, 'addTrack() before addStream() works.'); | |
125 | |
126 /** | |
127 * Helper functions. | |
128 */ | |
129 | |
130 function createStreams(constraints, numStreams, streamsSoFar = []) { | |
131 if (numStreams == 0) { | |
132 return Promise.resolve(streamsSoFar);; | |
133 } | |
134 return navigator.mediaDevices.getUserMedia(constraints) | |
135 .then(function(stream) { | |
136 return createStreams(constraints, | |
137 numStreams - 1, | |
138 streamsSoFar.concat([stream])); | |
139 }); | |
140 } | |
141 </script> | |
142 </body> | |
143 </html> | |
OLD | NEW |