| 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/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 5 </head> | 6 </head> |
| 6 <body> | 7 <body> |
| 7 <script> | 8 <script> |
| 8 description("Tests RTCPeerConnection [add|remove]Stream."); | 9 var testRTC = async_test('Tests RTCPeerConnection [add|remove]Stream.'); |
| 9 | 10 |
| 10 var stream = null; | |
| 11 var stream2 = null; | |
| 12 var pc = null; | 11 var pc = null; |
| 12 var options = {audio: true, video: true}; |
| 13 var errorCallback = () => assert_unreached('Stream generation failed.'); |
| 13 | 14 |
| 14 function error() { | 15 navigator.webkitGetUserMedia(options, (stream1) => { |
| 15 testFailed('Stream generation failed.'); | 16 navigator.webkitGetUserMedia(options, (stream2) => { |
| 16 finishJSTest(); | 17 assert_false(stream1.id === stream2.id); |
| 17 } | |
| 18 | 18 |
| 19 function getUserMedia(dictionary, callback) { | 19 pc = new webkitRTCPeerConnection(null, null); |
| 20 try { | |
| 21 navigator.webkitGetUserMedia(dictionary, callback, error); | |
| 22 } catch (e) { | |
| 23 testFailed('webkitGetUserMedia threw exception :' + e); | |
| 24 finishJSTest(); | |
| 25 } | |
| 26 } | |
| 27 | 20 |
| 28 function onErroneousNegotiationNeeded() { | 21 pc.onnegotiationneeded = (event) => { |
| 29 testFailed('onErroneousNegotiationNeeded was called.'); | 22 assert_equals(pc.getStreamById(stream1.id), stream1); |
| 30 finishJSTest(); | 23 assert_equals(pc.getStreamById(stream2.id), null); |
| 31 } | |
| 32 | 24 |
| 33 function onRemoveStream(event) { | 25 pc.onnegotiationneeded = () => { |
| 34 testPassed('onRemoveStream was called.'); | 26 assert_unreached('onErroneousNegotiationNeeded was called.'); |
| 27 }; |
| 35 | 28 |
| 36 shouldBe('pc.getLocalStreams().length', '0'); | 29 pc.addStream(stream1); |
| 30 assert_equals(pc.getLocalStreams().length, 1); |
| 31 pc.removeStream(stream2); |
| 32 assert_equals(pc.getLocalStreams().length, 1); |
| 37 | 33 |
| 38 finishJSTest(); | 34 pc.onnegotiationneeded = (event) => { |
| 39 } | 35 assert_equals(pc.getLocalStreams().length, 0); |
| 36 testRTC.done(); |
| 37 }; |
| 38 pc.removeStream(stream1); |
| 39 }; |
| 40 | 40 |
| 41 function onAddStream(event) { | 41 pc.addStream(stream1); |
| 42 testPassed('onAddStream was called.'); | 42 }, errorCallback); |
| 43 | 43 }, errorCallback); |
| 44 shouldBe('pc.getStreamById(stream.id)', 'stream'); | |
| 45 shouldBe('pc.getStreamById(stream2.id)', 'null'); | |
| 46 | |
| 47 pc.onnegotiationneeded = onErroneousNegotiationNeeded; | |
| 48 pc.addStream(stream); | |
| 49 shouldBe('pc.getLocalStreams().length', '1'); | |
| 50 pc.removeStream(stream2); | |
| 51 shouldBe('pc.getLocalStreams().length', '1'); | |
| 52 | |
| 53 pc.onnegotiationneeded = onRemoveStream; | |
| 54 pc.removeStream(stream); | |
| 55 } | |
| 56 | |
| 57 function gotStream2(s) { | |
| 58 testPassed('Got another stream.'); | |
| 59 stream2 = s; | |
| 60 | |
| 61 shouldBeFalse("stream.id === stream2.id"); | |
| 62 | |
| 63 pc = new webkitRTCPeerConnection(null, null); | |
| 64 pc.onnegotiationneeded = onAddStream; | |
| 65 pc.addStream(stream); | |
| 66 } | |
| 67 | |
| 68 function gotStream1(s) { | |
| 69 testPassed('Got a stream.'); | |
| 70 stream = s; | |
| 71 | |
| 72 getUserMedia({audio:true, video:true}, gotStream2); | |
| 73 } | |
| 74 | |
| 75 getUserMedia({audio:true, video:true}, gotStream1); | |
| 76 | |
| 77 window.jsTestIsAsync = true; | |
| 78 window.successfullyParsed = true; | |
| 79 </script> | 44 </script> |
| 80 </body> | 45 </body> |
| 81 </html> | 46 </html> |
| OLD | NEW |