mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1038494 - Rewrite test cases of track interfaces when consuming a media stream. r=roc
This commit is contained in:
parent
9d5c6c8fed
commit
9f0205643e
@ -381,7 +381,8 @@ skip-if = buildapp == 'b2g' || toolkit == 'android' # mimetype check, bug 969289
|
||||
[test_mediarecorder_unsupported_src.html]
|
||||
[test_mediarecorder_record_getdata_afterstart.html]
|
||||
[test_mediatrack_consuming_mediaresource.html]
|
||||
[test_mediatrack_events_and_consuming_ms.html]
|
||||
[test_mediatrack_consuming_mediastream.html]
|
||||
[test_mediatrack_events.html]
|
||||
[test_mediatrack_replay_from_end.html]
|
||||
[test_metadata.html]
|
||||
[test_mixed_principals.html]
|
||||
|
157
content/media/test/test_mediatrack_consuming_mediastream.html
Normal file
157
content/media/test/test_mediatrack_consuming_mediastream.html
Normal file
@ -0,0 +1,157 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test track interfaces when consuming a MediaStream from gUM</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="text/javascript" src="manifest.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
function startTest() {
|
||||
navigator.mozGetUserMedia({audio:true, video:true, fake:true},
|
||||
function(stream) {
|
||||
var element = document.createElement("video");
|
||||
|
||||
var audioOnchange = 0;
|
||||
var audioOnaddtrack = 0;
|
||||
var audioOnremovetrack = 0;
|
||||
var videoOnchange = 0;
|
||||
var videoOnaddtrack = 0;
|
||||
var videoOnremovetrack = 0;
|
||||
var isPlaying = false;
|
||||
|
||||
element.audioTracks.onaddtrack = function(e) {
|
||||
audioOnaddtrack++;
|
||||
}
|
||||
|
||||
element.audioTracks.onremovetrack = function(e) {
|
||||
audioOnremovetrack++;
|
||||
}
|
||||
|
||||
element.audioTracks.onchange = function(e) {
|
||||
audioOnchange++;
|
||||
}
|
||||
|
||||
element.videoTracks.onaddtrack = function(e) {
|
||||
videoOnaddtrack++;
|
||||
}
|
||||
|
||||
element.videoTracks.onremovetrack = function(e) {
|
||||
videoOnremovetrack++;
|
||||
}
|
||||
|
||||
element.videoTracks.onchange = function(e) {
|
||||
videoOnchange++;
|
||||
}
|
||||
|
||||
function checkTrackRemoved() {
|
||||
if (isPlaying) {
|
||||
is(audioOnremovetrack, 1, 'Calls of onremovetrack on audioTracks should be 1.');
|
||||
is(element.audioTracks.length, 0, 'The length of audioTracks should be 0.');
|
||||
is(videoOnremovetrack, 1, 'Calls of onremovetrack on videoTracks should be 1.');
|
||||
is(element.videoTracks.length, 0, 'The length of videoTracks should be 0.');
|
||||
}
|
||||
}
|
||||
|
||||
function onended() {
|
||||
ok(true, 'Event ended is expected to be fired on element.');
|
||||
checkTrackRemoved();
|
||||
element.onended = null;
|
||||
element.onplaying = null;
|
||||
element.onpause = null;
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function checkTrackAdded() {
|
||||
isPlaying = true;
|
||||
is(audioOnaddtrack, 1, 'Calls of onaddtrack on audioTracks should be 1.');
|
||||
is(element.audioTracks.length, 1, 'The length of audioTracks should be 1.');
|
||||
ok(element.audioTracks[0].enabled, 'Audio track should be enabled as default.');
|
||||
is(videoOnaddtrack, 1, 'Calls of onaddtrack on videoTracks should be 1.');
|
||||
is(element.videoTracks.length, 1, 'The length of videoTracks should be 1.');
|
||||
is(element.videoTracks.selectedIndex, 0,
|
||||
'The first video track is set selected as default.');
|
||||
}
|
||||
|
||||
function setTrackEnabled(enabled) {
|
||||
element.audioTracks[0].enabled = enabled;
|
||||
element.videoTracks[0].selected = enabled;
|
||||
}
|
||||
|
||||
function checkTrackChanged(calls, enabled) {
|
||||
is(audioOnchange, calls, 'Calls of onchange on audioTracks should be '+calls);
|
||||
is(element.audioTracks[0].enabled, enabled,
|
||||
'Enabled value of the audio track should be ' +enabled);
|
||||
is(videoOnchange, calls, 'Calls of onchange on videoTracks should be '+calls);
|
||||
is(element.videoTracks[0].selected, enabled,
|
||||
'Selected value of the video track should be ' +enabled);
|
||||
var index = enabled ? 0 : -1;
|
||||
is(element.videoTracks.selectedIndex, index,
|
||||
'SelectedIndex of video tracks should be ' +index);
|
||||
}
|
||||
|
||||
function onpause() {
|
||||
element.onpause = null;
|
||||
if (element.ended) {
|
||||
return;
|
||||
}
|
||||
if (steps == 1) {
|
||||
setTrackEnabled(false);
|
||||
element.onplaying = onplaying;
|
||||
element.play();
|
||||
steps++;
|
||||
} else if (steps == 2) {
|
||||
setTrackEnabled(true);
|
||||
element.onplaying = onplaying;
|
||||
element.play();
|
||||
steps++;
|
||||
}
|
||||
}
|
||||
|
||||
function onplaying() {
|
||||
element.onplaying = null;
|
||||
if (element.ended) {
|
||||
return;
|
||||
}
|
||||
if (steps == 1) {
|
||||
element.onpause = onpause;
|
||||
element.pause();
|
||||
checkTrackAdded();
|
||||
} else if (steps == 2) {
|
||||
element.onpause = onpause;
|
||||
element.pause();
|
||||
checkTrackChanged(1, false);
|
||||
} else if (steps == 3) {
|
||||
checkTrackChanged(2, true);
|
||||
stream.stop();
|
||||
}
|
||||
}
|
||||
|
||||
var steps = 0;
|
||||
element.mozSrcObject = stream;
|
||||
element.onplaying = onplaying;
|
||||
element.onended = onended;
|
||||
element.play();
|
||||
steps++;
|
||||
},
|
||||
function(err) {
|
||||
ok(false, 'Unexpected error fired with: ' + err);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{
|
||||
"set": [
|
||||
["media.track.enabled", true]
|
||||
]
|
||||
}, startTest);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
125
content/media/test/test_mediatrack_events.html
Normal file
125
content/media/test/test_mediatrack_events.html
Normal file
@ -0,0 +1,125 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test events of media track interfaces</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="text/javascript" src="manifest.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
function startTest() {
|
||||
navigator.mozGetUserMedia({audio:true, video:true, fake:true},
|
||||
function(stream) {
|
||||
var element = document.createElement("video");
|
||||
|
||||
isnot(element.audioTracks, undefined,
|
||||
'HTMLMediaElement::AudioTracks() property should be available.');
|
||||
isnot(element.videoTracks, undefined,
|
||||
'HTMLMediaElement::VideoTracks() property should be available.');
|
||||
|
||||
function verifyEvent(e, type) {
|
||||
is(e.type, type, "Event type should be " + type);
|
||||
ok(e.isTrusted, "Event should be trusted.");
|
||||
ok(!e.bubbles, "Event shouldn't bubble.");
|
||||
ok(!e.cancelable, "Event shouldn't be cancelable.");
|
||||
}
|
||||
|
||||
element.audioTracks.onaddtrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onaddtrack should be a TrackEvent");
|
||||
ok(true, 'onaddtrack is expected to be called from audioTracks.');
|
||||
verifyEvent(e, "addtrack");
|
||||
}
|
||||
|
||||
element.audioTracks.onremovetrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onremovetrack should be a TrackEvent");
|
||||
ok(true, 'onremovetrack is expected to be called from audioTracks.');
|
||||
verifyEvent(e, "removetrack");
|
||||
}
|
||||
|
||||
element.audioTracks.onchange = function(e) {
|
||||
ok(e instanceof window.Event, "Event fired from onchange should be a simple event.");
|
||||
ok(true, 'onchange is expected to be called from audioTracks.');
|
||||
verifyEvent(e, "change");
|
||||
}
|
||||
|
||||
element.videoTracks.onaddtrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onaddtrack should be a TrackEvent");
|
||||
ok(true, 'onaddtrack is expected to be called from videoTracks.');
|
||||
verifyEvent(e, "addtrack");
|
||||
}
|
||||
|
||||
element.videoTracks.onremovetrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onremovetrack should be a TrackEvent");
|
||||
ok(true, 'onremovetrack is expected to be called from videoTracks.');
|
||||
verifyEvent(e, "removetrack");
|
||||
}
|
||||
|
||||
element.videoTracks.onchange = function(e) {
|
||||
ok(e instanceof window.Event, "Event fired from onchange should be a simple event.");
|
||||
ok(true, 'onchange is expected to be called from videoTracks.');
|
||||
verifyEvent(e, "change");
|
||||
}
|
||||
|
||||
function onended() {
|
||||
ok(true, 'Event ended is expected to be fired on element.');
|
||||
element.onended = null;
|
||||
element.onplaying = null;
|
||||
element.onpause = null;
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function onpause() {
|
||||
element.onpause = null;
|
||||
if (element.ended) {
|
||||
return;
|
||||
}
|
||||
if (steps == 1) {
|
||||
element.audioTracks[0].enabled = false;
|
||||
element.videoTracks[0].selected = false;
|
||||
element.onplaying = onplaying;
|
||||
element.play();
|
||||
steps++;
|
||||
}
|
||||
}
|
||||
|
||||
function onplaying() {
|
||||
element.onplaying = null;
|
||||
if (element.ended) {
|
||||
return;
|
||||
}
|
||||
if (steps == 1) {
|
||||
element.onpause = onpause;
|
||||
element.pause();
|
||||
} else if (steps == 2) {
|
||||
stream.stop();
|
||||
}
|
||||
}
|
||||
|
||||
var steps = 0;
|
||||
element.mozSrcObject = stream;
|
||||
element.onplaying = onplaying;
|
||||
element.onended = onended;
|
||||
element.play();
|
||||
steps++;
|
||||
},
|
||||
function(err) {
|
||||
ok(false, 'Unexpected error fired with: ' + err);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{
|
||||
"set": [
|
||||
["media.track.enabled", true]
|
||||
]
|
||||
}, startTest);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
@ -1,189 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test track interfaces when consuming a MediaStream from gUM</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
<script type="text/javascript" src="manifest.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<pre id="test">
|
||||
<script class="testbody" type="text/javascript">
|
||||
function startTest() {
|
||||
navigator.mozGetUserMedia({audio:true, video:true, fake:true},
|
||||
function(stream) {
|
||||
var audioStreamTracks = stream.getAudioTracks();
|
||||
var videoStreamTracks = stream.getVideoTracks();
|
||||
|
||||
var audioOnchange = 0;
|
||||
var audioOnaddtrack = 0;
|
||||
var audioOnremovetrack = 0;
|
||||
var videoOnchange = 0;
|
||||
var videoOnaddtrack = 0;
|
||||
var videoOnremovetrack = 0;
|
||||
|
||||
var element = document.createElement("video");
|
||||
isnot(element.audioTracks, undefined, "HTMLMediaElement::AudioTracks() property should be available.");
|
||||
isnot(element.videoTracks, undefined, "HTMLMediaElement::VideoTracks() property should be available.");
|
||||
|
||||
function verify_event(e, type) {
|
||||
is(e.type, type, "Event type should be " + type);
|
||||
ok(e.isTrusted, "Event should be trusted.");
|
||||
ok(!e.bubbles, "Event shouldn't bubble.");
|
||||
ok(!e.cancelable, "Event shouldn't be cancelable.");
|
||||
}
|
||||
|
||||
function setAudioEnabled(enabled, index) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
element.audioTracks[index].enabled = enabled;
|
||||
element.audioTracks.onchange = function(e) {
|
||||
ok(e instanceof window.Event, "Event fired from onchange should be a simple event.");
|
||||
ok(true, 'onchange is expected to be called from audioTracks.');
|
||||
verify_event(e, "change");
|
||||
audioOnchange++;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function setVideoSelected(selected, index) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
element.videoTracks[index].selected = selected;
|
||||
element.videoTracks.onchange = function(e) {
|
||||
ok(e instanceof window.Event, "Event fired from onchange should be a simple event.");
|
||||
ok(true, 'onchange is expected to be called from videoTracks.');
|
||||
verify_event(e, "change");
|
||||
|
||||
var noVideoSelected = true;
|
||||
for (var i=0; i < element.videoTracks.length; ++i) {
|
||||
var track = element.videoTracks[i];
|
||||
if (track.selected == true) {
|
||||
noVideoSelected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (selected) {
|
||||
is(element.videoTracks.selectedIndex, index,
|
||||
'SelectedIndex shuld be '+index+' if video track is set selected.');
|
||||
} else {
|
||||
if (noVideoSelected) {
|
||||
is(element.videoTracks.selectedIndex, -1,
|
||||
'SelectedIndex shuld be -1 if no video track is set selected.');
|
||||
} else {
|
||||
reject();
|
||||
}
|
||||
}
|
||||
videoOnchange++;
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
element.audioTracks.onaddtrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onaddtrack should be a TrackEvent");
|
||||
ok(true, 'onaddtrack is expected to be called from audioTracks.');
|
||||
verify_event(e, "addtrack");
|
||||
audioOnaddtrack++;
|
||||
}
|
||||
|
||||
element.audioTracks.onremovetrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onremovetrack should be a TrackEvent");
|
||||
ok(true, 'onremovetrack is expected to be called from audioTracks.');
|
||||
verify_event(e, "removetrack");
|
||||
audioOnremovetrack++;
|
||||
}
|
||||
|
||||
element.videoTracks.onaddtrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onaddtrack should be a TrackEvent");
|
||||
ok(true, 'onaddtrack is expected to be called from videoTracks.');
|
||||
verify_event(e, "addtrack");
|
||||
videoOnaddtrack++;
|
||||
}
|
||||
|
||||
element.videoTracks.onremovetrack = function(e) {
|
||||
ok(e instanceof TrackEvent, "Event fired from onremovetrack should be a TrackEvent");
|
||||
ok(true, 'onremovetrack is expected to be called from videoTracks.');
|
||||
verify_event(e, "removetrack");
|
||||
videoOnremovetrack++;
|
||||
}
|
||||
|
||||
|
||||
element.onended = function() {
|
||||
is(audioOnchange, 2, 'change event on audioTracks should fired twice.');
|
||||
is(videoOnchange, 2, 'change event on videoTracks should fired twice.');
|
||||
|
||||
is(audioOnremovetrack, audioStreamTracks.length,
|
||||
'Calls of onremovetrack from audioTracks should match the numbers of AudioStreamTrack.');
|
||||
is(videoOnremovetrack, videoStreamTracks.length,
|
||||
'Calls of onremovetrack from videoTracks should match the numbers of VideoStreamTrack.');
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
element.mozSrcObject = stream;
|
||||
element.play();
|
||||
|
||||
element.onloadedmetadata = function() {
|
||||
is(audioOnaddtrack, audioStreamTracks.length,
|
||||
'Calls of onaddtrack from audioTracks should match the numbers of AudioStreamTrack.');
|
||||
is(videoOnaddtrack, videoStreamTracks.length,
|
||||
'Calls of onaddtrack from videoTracks should match the numbers of VideoStreamTrack.');
|
||||
|
||||
is(element.audioTracks.length, audioStreamTracks.length,
|
||||
'Length of audioTracks should be the same as the length of AudioStreamTrack.');
|
||||
is(element.videoTracks.length, videoStreamTracks.length,
|
||||
'Length of videoTracks should be the same as the length of VideoStreamTrack.');
|
||||
|
||||
for (var i=0; i < audioStreamTracks.length; ++i) {
|
||||
var track = element.audioTracks.getTrackById(audioStreamTracks[i].id);
|
||||
isnot(track, null, 'Successfully get '+ track.id + ' from audioTracks.');
|
||||
}
|
||||
for (var i=0; i < videoStreamTracks.length; ++i) {
|
||||
var track = element.videoTracks.getTrackById(videoStreamTracks[i].id);
|
||||
isnot(track, null, 'Successfully get '+ track.id + ' from videoTracks.');
|
||||
}
|
||||
|
||||
is(element.videoTracks.selectedIndex, 0,
|
||||
'The first video track is set selected as default.');
|
||||
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
|
||||
promise.then(function() {
|
||||
var p1 = setAudioEnabled(false, 0);
|
||||
var p2 = setVideoSelected(false, 0);
|
||||
return Promise.all([p1, p2]);
|
||||
}).catch(function(err) {
|
||||
ok(false, 'Something went wrong in onchange callback.');
|
||||
}).then(function() {
|
||||
var p3 = setAudioEnabled(true, 0);
|
||||
var p4 = setVideoSelected(true, 0);
|
||||
return Promise.all([p3, p4]);
|
||||
}).catch(function(err) {
|
||||
ok(false, 'Something went wrong in onchange callback.');
|
||||
}).then(function() {
|
||||
stream.stop();
|
||||
});
|
||||
},
|
||||
function(err) {
|
||||
ok(false, 'Unexpected error fired with: ' + err);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv(
|
||||
{
|
||||
"set": [
|
||||
["media.track.enabled", true]
|
||||
]
|
||||
}, startTest);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user