diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /dom/media/test/test_mediatrack_events.html | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/test/test_mediatrack_events.html')
-rw-r--r-- | dom/media/test/test_mediatrack_events.html | 135 |
1 files changed, 135 insertions, 0 deletions
diff --git a/dom/media/test/test_mediatrack_events.html b/dom/media/test/test_mediatrack_events.html new file mode 100644 index 0000000000..5eae94f804 --- /dev/null +++ b/dom/media/test/test_mediatrack_events.html @@ -0,0 +1,135 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test events of media track interfaces</title> + <script 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> + <script type="text/javascript" src="gUM_support.js"></script> +</head> +<body> +<pre id="test"> +<script class="testbody" type="text/javascript"> +async function startTest() { + let steps = 0; + let element = document.createElement("video"); + let stream; + try { + await setupGetUserMediaTestPrefs(); + stream = await navigator.mediaDevices.getUserMedia({audio: true, video: true}); + } catch (err) { + ok(false, 'Unexpected error fired with: ' + err); + SimpleTest.finish(); + return; + } + + 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"); + }; + + element.onended = function() { + ok(true, 'Event ended is expected to be fired on element.'); + element.onended = null; + element.onplaying = null; + element.onpause = null; + //This helps to prevent these events from firing after SimpleTest.finish() + //on B2G ICS Emulator, but not sure they have been run at all, then + element.audioTracks.onremovetrack = null; + element.audioTracks.onaddtrack = null; + element.audioTracks.onchange = null; + element.videoTracks.onremovetrack = null; + element.videoTracks.onaddtrack = null; + element.videoTracks.onchange = 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.getTracks().forEach(t => t.stop()); + } + } + + element.onplaying = onplaying; + element.srcObject = stream; + + isnot(element.audioTracks, undefined, + 'HTMLMediaElement::AudioTracks() property should be available.'); + isnot(element.videoTracks, undefined, + 'HTMLMediaElement::VideoTracks() property should be available.'); + + steps++; + await element.play(); +} + +SimpleTest.waitForExplicitFinish(); +SpecialPowers.pushPrefEnv( + { + "set": [ + ["media.track.enabled", true] + ] + }, startTest); + +</script> +</pre> +</body> +</html> |