| OLD | NEW |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> | 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/js-test.js"></script> |
| 5 </head> | 5 </head> |
| 6 <body> | 6 <body> |
| 7 <script> | 7 <script> |
| 8 description("Test adding and removing tracks."); | 8 description("Test adding and removing tracks."); |
| 9 | 9 |
| 10 var stream1; | 10 var stream1; |
| 11 var stream2; | 11 var stream2; |
| 12 var stream3; |
| 12 var audioTrack; | 13 var audioTrack; |
| 13 var videoTrack; | 14 var videoTrack; |
| 14 | 15 |
| 15 function error() { | 16 function error() { |
| 16 testFailed('Stream generation failed.'); | 17 testFailed('Stream generation failed.'); |
| 17 finishJSTest(); | 18 finishJSTest(); |
| 18 } | 19 } |
| 19 | 20 |
| 20 function getUserMedia(dictionary, callback) { | 21 function getUserMedia(dictionary, callback) { |
| 21 try { | 22 try { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 41 } catch (exception) { | 42 } catch (exception) { |
| 42 testFailed("removeTrack threw an exception."); | 43 testFailed("removeTrack threw an exception."); |
| 43 finishJSTest(); | 44 finishJSTest(); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 function shouldNotFire() { | 48 function shouldNotFire() { |
| 48 testFailed("\"addtrack\" or \"removetrack\" events should not fire as a resu
lt of local addTrack() or removeTrack() operations."); | 49 testFailed("\"addtrack\" or \"removetrack\" events should not fire as a resu
lt of local addTrack() or removeTrack() operations."); |
| 49 } | 50 } |
| 50 | 51 |
| 52 function onStreamInactive() { |
| 53 testPassed('Stream1 inactive.'); |
| 54 shouldBeFalse('stream1.active'); |
| 55 setTimeout(finishJSTest, 0); |
| 56 } |
| 57 |
| 58 function onStreamActive() { |
| 59 testPassed('Stream1 active.'); |
| 60 shouldBeTrue('stream1.active'); |
| 61 stream1.oninactive = onStreamInactive; |
| 62 tryRemoveTrack(stream1, stream3.getAudioTracks()[0]); |
| 63 } |
| 64 |
| 65 function gotStream3(s) { |
| 66 stream3 = s; |
| 67 stream1.onactive = onStreamActive; |
| 68 tryAddTrack(stream1, stream3.getAudioTracks()[0]); |
| 69 } |
| 70 |
| 51 function gotStream2(s) { | 71 function gotStream2(s) { |
| 52 stream2 = s; | 72 stream2 = s; |
| 53 | 73 |
| 54 shouldBe('stream1.getAudioTracks().length', '1'); | 74 shouldBe('stream1.getAudioTracks().length', '1'); |
| 55 shouldBe('stream1.getVideoTracks().length', '1'); | 75 shouldBe('stream1.getVideoTracks().length', '1'); |
| 56 shouldBe('stream1.getTracks().length', '2'); | 76 shouldBe('stream1.getTracks().length', '2'); |
| 57 | 77 |
| 58 shouldBe('stream2.getAudioTracks().length', '1'); | 78 shouldBe('stream2.getAudioTracks().length', '1'); |
| 59 shouldBe('stream2.getVideoTracks().length', '1'); | 79 shouldBe('stream2.getVideoTracks().length', '1'); |
| 60 shouldBe('stream2.getTracks().length', '2'); | 80 shouldBe('stream2.getTracks().length', '2'); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 129 |
| 110 // add new tracks (from stream2) | 130 // add new tracks (from stream2) |
| 111 tryAddTrack(stream1, stream2.getAudioTracks()[0]); | 131 tryAddTrack(stream1, stream2.getAudioTracks()[0]); |
| 112 tryAddTrack(stream1, stream2.getVideoTracks()[0]); | 132 tryAddTrack(stream1, stream2.getVideoTracks()[0]); |
| 113 | 133 |
| 114 // verify added tracks | 134 // verify added tracks |
| 115 shouldBe('stream1.getAudioTracks().length', '2'); | 135 shouldBe('stream1.getAudioTracks().length', '2'); |
| 116 shouldBe('stream1.getVideoTracks().length', '2'); | 136 shouldBe('stream1.getVideoTracks().length', '2'); |
| 117 shouldBe('stream1.getTracks().length', '4'); | 137 shouldBe('stream1.getTracks().length', '4'); |
| 118 | 138 |
| 119 // when all tracks have been removed, stream.ended should return true. | 139 // when all tracks have been removed, stream.active should return false. |
| 120 tryRemoveTrack(stream2, stream2.getAudioTracks()[0]); | 140 tryRemoveTrack(stream2, stream2.getAudioTracks()[0]); |
| 121 tryRemoveTrack(stream2, stream2.getVideoTracks()[0]); | 141 tryRemoveTrack(stream2, stream2.getVideoTracks()[0]); |
| 122 shouldBeTrue('stream2.ended'); | 142 shouldBeFalse('stream2.active'); |
| 123 | 143 |
| 124 stream1.stop(); | 144 // when all tracks have been stopped, stream.active should return false. |
| 125 | 145 for (var i = 0; i < stream1.getAudioTracks().length; i++) |
| 126 shouldThrow('stream1.addTrack(audioTrack)'); | 146 stream1.getAudioTracks()[i].stop(); |
| 127 shouldThrow('stream1.removeTrack(audioTrack)'); | 147 for (var i = 0; i < stream1.getVideoTracks().length; i++) |
| 128 | 148 stream1.getVideoTracks()[i].stop(); |
| 129 setTimeout(finishJSTest, 0); | 149 shouldBeFalse('stream1.active'); |
| 150 getUserMedia({audio:true, video:true}, gotStream3); |
| 130 } | 151 } |
| 131 | 152 |
| 132 function gotStream1(s) { | 153 function gotStream1(s) { |
| 133 stream1 = s; | 154 stream1 = s; |
| 134 getUserMedia({audio:true, video:true}, gotStream2); | 155 getUserMedia({audio:true, video:true}, gotStream2); |
| 135 } | 156 } |
| 136 | 157 |
| 137 getUserMedia({audio:true, video:true}, gotStream1); | 158 getUserMedia({audio:true, video:true}, gotStream1); |
| 138 | 159 |
| 139 window.jsTestIsAsync = true; | 160 window.jsTestIsAsync = true; |
| 140 window.successfullyParsed = true; | 161 window.successfullyParsed = true; |
| 141 </script> | 162 </script> |
| 142 </body> | 163 </body> |
| 143 </html> | 164 </html> |
| OLD | NEW |