|
Line 0
LayoutTests/fast/mediastream/MediaStream-add-tracks-to-inactive-stream.html_sec1
|
|
|
1 |
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 |
<html> |
| 3 |
<head> |
| 4 |
<script src="../../resources/js-test-pre.js"></script> |
| 5 |
</head> |
| 6 |
<body> |
| 7 |
<p id="description"></p> |
| 8 |
<div id="console"></div> |
| 9 |
<script> |
| 10 |
description("Test adding tracks to inactive MediaStream."); |
| 11 |
|
| 12 |
var stream1; |
| 13 |
var stream2; |
| 14 |
var audioTrack; |
| 15 |
var videoTrack; |
| 16 |
|
| 17 |
function error() { |
| 18 |
testFailed('Stream generation failed.'); |
| 19 |
finishJSTest(); |
| 20 |
} |
| 21 |
|
| 22 |
function getUserMedia(dictionary, callback) { |
| 23 |
try { |
| 24 |
navigator.webkitGetUserMedia(dictionary, callback, error); |
| 25 |
} catch (e) { |
| 26 |
testFailed('webkitGetUserMedia threw exception :' + e); |
| 27 |
finishJSTest(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function tryAddTrack(stream, track) { |
| 32 |
try { |
| 33 |
stream.addTrack(track); |
| 34 |
} catch (exception) { |
| 35 |
testFailed("addTrack threw an exception."); |
| 36 |
finishJSTest(); |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
function shouldNotFire() { |
| 41 |
testFailed("\"addtrack\" or \"removetrack\" events should not fire as a result of local addTrack() or removeTrack() operations."); |
| 42 |
} |
| 43 |
|
| 44 |
function shouldFireActive() { |
| 45 |
debug("Stream2 is active."); |
| 46 |
finishJSTest(); |
| 47 |
} |
| 48 |
|
| 49 |
function shouldFireInActive() { |
| 50 |
debug("Stream2 is inactive."); |
| 51 |
finishJSTest(); |
| 52 |
} |
| 53 |
|
| 54 |
function createStreamAndAddTRacks() { |
| 55 |
stream2 = new webkitMediaStream(); |
| 56 |
debug("MediaStream without tracks created."); |
| 57 |
stream2.onactive = shouldFireActive; |
| 58 |
stream2.oninactive = shouldFireInActive; |
| 59 |
shouldBe('stream2.getAudioTracks().length', '0'); |
| 60 |
audioTrack = stream1.getAudioTracks()[0]; |
| 61 |
debug("Adding tracks to inactive stream"); |
| 62 |
tryAddTrack(stream2, audioTrack); |
| 63 |
shouldBe('stream2.getAudioTracks().length', '1'); |
| 64 |
finishJSTest(); |
| 65 |
} |
| 66 |
|
| 67 |
function gotStream1(s) { |
| 68 |
stream1 = s; |
| 69 |
createStreamAndAddTRacks(); |
| 70 |
} |
| 71 |
|
| 72 |
getUserMedia({audio:true, video:true}, gotStream1); |
| 73 |
|
| 74 |
window.jsTestIsAsync = true; |
| 75 |
window.successfullyParsed = true; |
| 76 |
</script> |
| 77 |
<script src="../../resources/js-test-post.js"></script> |
| 78 |
</body> |
| 79 |
</html> |