Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / mediastream / MediaStream-add-remove-tracks.html
blob9d406b29b43d47ffb8ecbbaf676cdb5920042bf3
1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2 <html>
3 <head>
4 <script src="../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <script>
8 description("Test adding and removing tracks.");
10 var stream1;
11 var stream2;
12 var stream3;
13 var audioTrack;
14 var videoTrack;
16 function error() {
17 testFailed('Stream generation failed.');
18 finishJSTest();
21 function getUserMedia(dictionary, callback) {
22 try {
23 navigator.webkitGetUserMedia(dictionary, callback, error);
24 } catch (e) {
25 testFailed('webkitGetUserMedia threw exception :' + e);
26 finishJSTest();
30 function tryAddTrack(stream, track) {
31 try {
32 stream.addTrack(track);
33 } catch (exception) {
34 testFailed("addTrack threw an exception.");
35 finishJSTest();
39 function tryRemoveTrack(stream, track) {
40 try {
41 stream.removeTrack(track);
42 } catch (exception) {
43 testFailed("removeTrack threw an exception.");
44 finishJSTest();
48 function shouldNotFire() {
49 testFailed("\"addtrack\" or \"removetrack\" events should not fire as a result of local addTrack() or removeTrack() operations.");
52 function onStreamInactive() {
53 testPassed('Stream1 inactive.');
54 shouldBeFalse('stream1.active');
55 setTimeout(finishJSTest, 0);
58 function onStreamActive() {
59 testPassed('Stream1 active.');
60 shouldBeTrue('stream1.active');
61 stream1.oninactive = onStreamInactive;
62 tryRemoveTrack(stream1, stream3.getAudioTracks()[0]);
65 function gotStream3(s) {
66 stream3 = s;
67 stream1.onactive = onStreamActive;
68 tryAddTrack(stream1, stream3.getAudioTracks()[0]);
71 function gotStream2(s) {
72 stream2 = s;
74 shouldBe('stream1.getAudioTracks().length', '1');
75 shouldBe('stream1.getVideoTracks().length', '1');
76 shouldBe('stream1.getTracks().length', '2');
78 shouldBe('stream2.getAudioTracks().length', '1');
79 shouldBe('stream2.getVideoTracks().length', '1');
80 shouldBe('stream2.getTracks().length', '2');
82 stream1.onaddtrack = shouldNotFire;
83 stream1.onremovetrack = shouldNotFire;
85 // remove a track of each kind
86 audioTrack = stream1.getAudioTracks()[0];
87 videoTrack = stream1.getVideoTracks()[0];
89 tryRemoveTrack(stream1, audioTrack);
90 // verify removed tracks
91 shouldBe('stream1.getAudioTracks().length', '0');
92 // verify that gettracks length is reduced by 1
93 shouldBe('stream1.getTracks().length', '1');
94 shouldBeNull('stream1.getTrackById(audioTrack.id)');
95 // remove a non-existent (already removed) track (should not throw)
96 tryRemoveTrack(stream1, audioTrack);
97 // (re-)add tracks
98 tryAddTrack(stream1, audioTrack);
99 shouldBeNonNull('stream1.getTrackById(audioTrack.id)');
100 shouldBe('audioTrack', 'stream1.getAudioTracks()[0]');
102 tryRemoveTrack(stream1, videoTrack);
103 shouldBe('stream1.getVideoTracks().length', '0');
104 // verify that gettracks length is reduced by 1
105 shouldBe('stream1.getTracks().length', '1');
106 shouldBeNull('stream1.getTrackById(videoTrack.id)');
107 tryRemoveTrack(stream1, videoTrack);
108 tryAddTrack(stream1, videoTrack);
110 // verify added tracks
111 shouldBe('stream1.getAudioTracks().length', '1');
112 shouldBe('stream1.getVideoTracks().length', '1');
113 shouldBe('stream1.getTracks().length', '2');
115 // verify that kind and label is preserved
116 shouldBe('stream1.getAudioTracks()[0].kind', 'audioTrack.kind');
117 shouldBe('stream1.getAudioTracks()[0].label', 'audioTrack.label');
118 shouldBe('stream1.getVideoTracks()[0].kind', 'videoTrack.kind');
119 shouldBe('stream1.getVideoTracks()[0].label', 'videoTrack.label');
121 // try adding stream1's own tracks
122 tryAddTrack(stream1, stream1.getAudioTracks()[0]);
123 tryAddTrack(stream1, stream1.getVideoTracks()[0]);
125 // verify that nothing has changed
126 shouldBe('stream1.getAudioTracks().length', '1');
127 shouldBe('stream1.getVideoTracks().length', '1');
128 shouldBe('stream1.getTracks().length', '2');
130 // add new tracks (from stream2)
131 tryAddTrack(stream1, stream2.getAudioTracks()[0]);
132 tryAddTrack(stream1, stream2.getVideoTracks()[0]);
134 // verify added tracks
135 shouldBe('stream1.getAudioTracks().length', '2');
136 shouldBe('stream1.getVideoTracks().length', '2');
137 shouldBe('stream1.getTracks().length', '4');
139 // when all tracks have been removed, stream.active should return false.
140 tryRemoveTrack(stream2, stream2.getAudioTracks()[0]);
141 tryRemoveTrack(stream2, stream2.getVideoTracks()[0]);
142 shouldBeFalse('stream2.active');
144 // when all tracks have been stopped, stream.active should return false.
145 for (var i = 0; i < stream1.getAudioTracks().length; i++)
146 stream1.getAudioTracks()[i].stop();
147 for (var i = 0; i < stream1.getVideoTracks().length; i++)
148 stream1.getVideoTracks()[i].stop();
149 shouldBeFalse('stream1.active');
150 getUserMedia({audio:true, video:true}, gotStream3);
153 function gotStream1(s) {
154 stream1 = s;
155 getUserMedia({audio:true, video:true}, gotStream2);
158 getUserMedia({audio:true, video:true}, gotStream1);
160 window.jsTestIsAsync = true;
161 window.successfullyParsed = true;
162 </script>
163 </body>
164 </html>