Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/peerconnection/RTCPeerConnection-AddRemoveTrack.html

Issue 2951713002: RTCPeerConnection.addTrack and removeTrack added (behind flag) (Closed)
Patch Set: Addressed deadbeef's comments Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 // The interaction between |addStream| and |addTrack| is not
101 // standardized (|addStream| is non-standard). Because |addStream|
102 // creates a sender for the track and |addTrack| throws if there already
103 // exists a sender for the track.
104 pc.addTrack(track);
105 } catch (e) {
106 exception = e;
107 }
108 assert_true(exception != null);
109 assert_equals('InvalidAccessError', exception.name);
110 });
111 }, 'addTrack() after addStream() throws InvalidAccessError.');
112
113 promise_test(function() {
114 let pc = new RTCPeerConnection();
115 return createStreams({audio:true, video:false}, 1)
116 .then(function(streams) {
117 let stream = streams[0];
118 let track = stream.getAudioTracks()[0];
119 let sender = pc.addTrack(track);
120 assert_equals(sender.track, track);
121 assert_array_equals(pc.getSenders(), [ sender ]);
122 assert_array_equals(pc.getLocalStreams(), []);
123 pc.addStream(stream);
124 assert_array_equals(pc.getLocalStreams(), [ stream ]);
125 // The interaction between |addStream| and |addTrack| is not standardized
126 // (|addStream| is non-standard). In our implementation, the existing
127 // sender is reused by |addStream|.
128 assert_array_equals(pc.getSenders(), [ sender ]);
129 });
130 }, 'addTrack() before addStream() works.');
131
132 /**
133 * Helper functions.
134 */
135
136 function createStreams(constraints, numStreams, streamsSoFar = []) {
137 if (numStreams == 0) {
138 return Promise.resolve(streamsSoFar);;
139 }
140 return navigator.mediaDevices.getUserMedia(constraints)
141 .then(function(stream) {
142 return createStreams(constraints,
143 numStreams - 1,
144 streamsSoFar.concat([stream]));
145 });
146 }
147 </script>
148 </body>
149 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698