summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/common/media.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/common/media.js
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/common/media.js')
-rw-r--r--testing/web-platform/tests/common/media.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/testing/web-platform/tests/common/media.js b/testing/web-platform/tests/common/media.js
new file mode 100644
index 0000000000..f2dc861266
--- /dev/null
+++ b/testing/web-platform/tests/common/media.js
@@ -0,0 +1,55 @@
+/**
+ * Returns the URL of a supported video source based on the user agent
+ * @param {string} base - media URL without file extension
+ * @returns {string}
+ */
+function getVideoURI(base)
+{
+ var extension = '.mp4';
+
+ var videotag = document.createElement("video");
+
+ if ( videotag.canPlayType &&
+ videotag.canPlayType('video/ogg; codecs="theora, vorbis"') )
+ {
+ extension = '.ogv';
+ }
+
+ return base + extension;
+}
+
+/**
+ * Returns the URL of a supported audio source based on the user agent
+ * @param {string} base - media URL without file extension
+ * @returns {string}
+ */
+function getAudioURI(base)
+{
+ var extension = '.mp3';
+
+ var audiotag = document.createElement("audio");
+
+ if ( audiotag.canPlayType &&
+ audiotag.canPlayType('audio/ogg') )
+ {
+ extension = '.oga';
+ }
+
+ return base + extension;
+}
+
+/**
+ * Returns the MIME type for a media URL based on the file extension.
+ * @param {string} url
+ * @returns {string}
+ */
+function getMediaContentType(url) {
+ var extension = new URL(url, location).pathname.split(".").pop();
+ var map = {
+ "mp4": "video/mp4",
+ "ogv": "application/ogg",
+ "mp3": "audio/mp3",
+ "oga": "application/ogg",
+ };
+ return map[extension];
+}