| <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| <html> |
| <head> |
| <script src="../../resources/js-test-pre.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests RTCPeerConnection onnegotiationneeded."); |
| |
| var stream = null; |
| var pc = null; |
| var track = null; |
| |
| function error() |
| { |
| testFailed('Stream generation failed.'); |
| finishJSTest(); |
| } |
| |
| function getUserMedia(dictionary, callback) |
| { |
| try { |
| navigator.webkitGetUserMedia(dictionary, callback, error); |
| } catch (e) { |
| testFailed('webkitGetUserMedia threw exception :' + e); |
| finishJSTest(); |
| } |
| } |
| |
| function onNegotiationNeeded(event) |
| { |
| testPassed('onNegotiationNeeded was called.'); |
| removeTrack(); |
| } |
| |
| function onNegotiationNeeded2(event) |
| { |
| testPassed('onNegotiationNeeded was called when track was removed.'); |
| addTrack(); |
| } |
| |
| function onNegotiationNeeded3(event) |
| { |
| testPassed('onNegotiationNeeded was called when track was added.'); |
| finishJSTest(); |
| } |
| |
| function gotStream(s) |
| { |
| testPassed('Got a stream.'); |
| stream = s; |
| |
| pc = new webkitRTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]}); |
| pc.onnegotiationneeded = onNegotiationNeeded; |
| |
| pc.addStream(stream); |
| } |
| |
| function removeTrack() |
| { |
| pc.onnegotiationneeded = onNegotiationNeeded2; |
| shouldBe('stream.getAudioTracks().length', '1'); |
| track = stream.getAudioTracks()[0]; |
| stream.removeTrack(track); |
| shouldBe('stream.getAudioTracks().length', '0'); |
| } |
| |
| function addTrack() |
| { |
| pc.onnegotiationneeded = onNegotiationNeeded3; |
| shouldBe('stream.getAudioTracks().length', '0'); |
| stream.addTrack(track); |
| shouldBe('stream.getAudioTracks().length', '1'); |
| } |
| |
| getUserMedia({audio:true, video:true}, gotStream); |
| |
| window.jsTestIsAsync = true; |
| window.successfullyParsed = true; |
| </script> |
| <script src="../../resources/js-test-post.js"></script> |
| </body> |
| </html> |