summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/mediasession
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/mediasession')
-rw-r--r--testing/web-platform/tests/mediasession/META.yml3
-rw-r--r--testing/web-platform/tests/mediasession/README.md20
-rw-r--r--testing/web-platform/tests/mediasession/helper/artwork-generator.html18
-rw-r--r--testing/web-platform/tests/mediasession/idlharness.window.js18
-rw-r--r--testing/web-platform/tests/mediasession/mediametadata.html219
-rw-r--r--testing/web-platform/tests/mediasession/playbackstate.html27
-rw-r--r--testing/web-platform/tests/mediasession/positionstate.html106
-rw-r--r--testing/web-platform/tests/mediasession/setactionhandler.html34
-rw-r--r--testing/web-platform/tests/mediasession/setcameraactive.html12
-rw-r--r--testing/web-platform/tests/mediasession/setmicrophoneactive.html12
10 files changed, 469 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mediasession/META.yml b/testing/web-platform/tests/mediasession/META.yml
new file mode 100644
index 0000000000..8eb7fa0261
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/META.yml
@@ -0,0 +1,3 @@
+spec: https://w3c.github.io/mediasession/
+suggested_reviewers:
+ - mounirlamouri
diff --git a/testing/web-platform/tests/mediasession/README.md b/testing/web-platform/tests/mediasession/README.md
new file mode 100644
index 0000000000..7c7c9f8d57
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/README.md
@@ -0,0 +1,20 @@
+# Media Session specification Tests
+
+The Media Session specification is available here: https://wicg.github.io/mediasession
+
+GitHub repository: https://github.com/WICG/mediasession
+
+File an issue: https://github.com/WICG/mediasession/issues/new
+
+## Device/system dependency
+
+The Media Session specification defines behaviors related to device or system
+features such as the actions to run when a software/hardware media key is used.
+These behaviors are not tested because they would depend on user agent specific
+implementations and device specific features.
+
+## Status of these tests
+
+These tests are not complete and only reflect the Blink tests that could be
+exported. If a reader find a behavior that could be tested and is not, they
+should feel free to file a bug.
diff --git a/testing/web-platform/tests/mediasession/helper/artwork-generator.html b/testing/web-platform/tests/mediasession/helper/artwork-generator.html
new file mode 100644
index 0000000000..5a2fbb151d
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/helper/artwork-generator.html
@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<title>MediaImage</title>
+<script>
+function createArtworkFromURLs(sources) {
+ let artwork = [];
+ for (const source of sources) {
+ artwork.push({
+ src: source
+ });
+ }
+
+ let metadata = new MediaMetadata({
+ artwork: artwork
+ });
+ return metadata.artwork;
+}
+
+</script>
diff --git a/testing/web-platform/tests/mediasession/idlharness.window.js b/testing/web-platform/tests/mediasession/idlharness.window.js
new file mode 100644
index 0000000000..e4d914544e
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/idlharness.window.js
@@ -0,0 +1,18 @@
+// META: script=/resources/WebIDLParser.js
+// META: script=/resources/idlharness.js
+
+// https://w3c.github.io/mediasession/
+
+'use strict';
+
+idl_test(
+ ['mediasession'],
+ ['html'],
+ idl_array => {
+ idl_array.add_objects({
+ MediaMetadata: ['new MediaMetadata()'],
+ MediaSession: ['navigator.mediaSession'],
+ Navigator: ['navigator']
+ });
+ }
+);
diff --git a/testing/web-platform/tests/mediasession/mediametadata.html b/testing/web-platform/tests/mediasession/mediametadata.html
new file mode 100644
index 0000000000..ff00e54ee7
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/mediametadata.html
@@ -0,0 +1,219 @@
+<!DOCTYPE html>
+<title>MediaMetadata interface</title>
+<script src=/resources/testharness.js></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+function load_iframe(src) {
+ return new Promise(resolve => {
+ const iframe = document.createElement('iframe');
+ iframe.onload = () => { resolve(iframe); };
+ iframe.src = src;
+ iframe.style.display = 'none';
+ document.documentElement.appendChild(iframe);
+ });
+}
+
+test(function() {
+ var metadata = new MediaMetadata({});
+ navigator.mediaSession.metadata = metadata;
+ assert_equals(navigator.mediaSession.metadata, metadata);
+}, "Test that mediaSession.metadata is properly set");
+
+test(function() {
+ var metadata = new MediaMetadata({});
+ navigator.mediaSession.metadata = metadata;
+ metadata.title = 'foo';
+ assert_equals(navigator.mediaSession.metadata.title, 'foo');
+}, "Test that changes to metadata propagate properly");
+
+test(function() {
+ var metadata = new MediaMetadata({});
+ navigator.mediaSession.metadata = metadata;
+ navigator.mediaSession.metadata = null;
+ assert_equals(navigator.mediaSession.metadata, null);
+}, "Test that resetting metadata to null is reflected");
+
+test(function() {
+ var metadata = new MediaMetadata({});
+ assert_not_equals(metadata, null);
+
+ assert_throws_js(TypeError, _ => new MediaMetadata('foobar'));
+ assert_throws_js(TypeError, _ => new MediaMetadata(42));
+}, 'Test that MediaMetadata is constructed using a dictionary');
+
+test(function() {
+ var metadata = new MediaMetadata();
+ assert_not_equals(metadata, null);
+}, "Test that MediaMetadata constructor can take no parameter");
+
+test(function() {
+ var image1 = { src: 'http://example.com/1', sizes: 'sizes1', type: 'type1' };
+ var image2 = { src: 'http://example.com/2', sizes: 'sizes2', type: 'type2' };
+ var metadata = new MediaMetadata({
+ title: 'foo', album: 'bar', artist: 'plop', artwork: [ image1, image2 ]
+ });
+
+ assert_equals(metadata.title, 'foo');
+ assert_equals(metadata.album, 'bar');
+ assert_equals(metadata.artist, 'plop');
+ assert_equals(metadata.artwork.length, 2);
+ assert_equals(metadata.artwork[0].src, image1.src);
+ assert_equals(metadata.artwork[0].sizes, image1.sizes);
+ assert_equals(metadata.artwork[0].type, image1.type);
+ assert_equals(metadata.artwork[1].src, image2.src);
+ assert_equals(metadata.artwork[1].sizes, image2.sizes);
+ assert_equals(metadata.artwork[1].type, image2.type);
+}, 'Test the different values allowed in MediaMetadata init dictionary');
+
+test(function() {
+ var metadata = new MediaMetadata({});
+ assert_equals(metadata.title, '');
+ assert_equals(metadata.artist, '');
+ assert_equals(metadata.album, '');
+ assert_equals(0, metadata.artwork.length);
+}, 'Test the default values for MediaMetadata with empty init dictionary');
+
+test(function() {
+ var metadata = new MediaMetadata();
+ assert_equals(metadata.title, '');
+ assert_equals(metadata.artist, '');
+ assert_equals(metadata.album, '');
+ assert_equals(0, metadata.artwork.length);
+}, 'Test the default values for MediaMetadata with no init dictionary');
+
+test(function() {
+ var metadata = new MediaMetadata({ randomValueThatWillNotBeAdded: '... hopefully ;)' });
+ assert_equals(metadata.randomValueThatWillNotBeAdded, undefined);
+}, 'Test that passing unknown values to the dictionary is a no-op');
+
+test(function() {
+ var image1 = { src: 'http://example.com/1', sizes: 'sizes1', type: 'type1' };
+ var image2 = { src: 'http://example.com/2', sizes: 'sizes2', type: 'type2' };
+ var metadata = new MediaMetadata({
+ title: 'foo', album: 'bar', artist: 'plop', artwork: [ image1, image2 ]
+ });
+
+ metadata.title = 'something else';
+ assert_equals(metadata.title, 'something else');
+
+ metadata.album = 'other value';
+ assert_equals(metadata.album, 'other value');
+
+ metadata.artist = 'someone else';
+ assert_equals(metadata.artist, 'someone else');
+
+ var image = { src: 'http://example.com/', sizes: '40x40', type: 'image/png' };
+ metadata.artwork = [ image ];
+ assert_equals(metadata.artwork.length, 1);
+ assert_equals(metadata.artwork[0].src, 'http://example.com/');
+ assert_equals(metadata.artwork[0].sizes, '40x40');
+ assert_equals(metadata.artwork[0].type, 'image/png');
+}, "Test that MediaMetadata is read/write");
+
+test(function() {
+ var metadata = new MediaMetadata({ artwork: [ { src: 'http://foo.com/' } ] });
+ assert_throws_js(TypeError, _ => {
+ metadata.artwork.push({
+ src: 'http://example.com/', sizes: '40x40', type: 'image/png',
+ });
+ });
+
+ metadata.artwork[0].src = 'bar';
+ assert_equals(metadata.artwork[0].src, 'http://foo.com/');
+}, "Test that MediaMetadat.artwork can't be modified");
+
+test(function() {
+ var metadata = new MediaMetadata({ artwork: [{
+ src: 'http://example.com/', sizes: '40x40', type: 'image/png',
+ some_other_value: 'foo',
+ }]});
+ assert_equals(metadata.artwork[0].src, 'http://example.com/');
+ assert_equals(metadata.artwork[0].sizes, '40x40');
+ assert_equals(metadata.artwork[0].type, 'image/png');
+ assert_false('some_other_value' in metadata.artwork[0]);
+
+ metadata.artwork[0].something_else = 'bar';
+ assert_false('something_else' in metadata.artwork[0]);
+}, "Test that MediaMetadata.artwork will not expose unknown properties");
+
+test(function() {
+ var metadata = new MediaMetadata({ artwork: [
+ { src: 'http://example.com/1', sizes: '40x40', type: 'image/png' },
+ { src: 'http://example.com/2', sizes: '40x40', type: 'image/png' },
+ ]});
+
+ assert_true(Object.isFrozen(metadata.artwork));
+ for (var i = 0; i < metadata.artwork.length; ++i)
+ assert_true(Object.isFrozen(metadata.artwork[i]));
+}, "Test that MediaMetadata.artwork is Frozen");
+
+test(function() {
+ var metadata = new MediaMetadata({ artwork: [
+ { src: 'http://example.com', sizes: '40x40', type: 'image/png' },
+ { src: '../foo', sizes: '40x40', type: 'image/png' },
+ { src: '/foo/bar', sizes: '40x40', type: 'image/png' },
+ ]});
+
+ assert_equals(metadata.artwork[0].src, new URL('http://example.com', document.URL).href)
+ assert_equals(metadata.artwork[1].src, new URL('../foo', document.URL).href)
+ assert_equals(metadata.artwork[2].src, new URL('/foo/bar', document.URL).href)
+}, "Test that MediaMetadata.artwork returns parsed urls");
+
+test(function() {
+ var metadata = 42;
+
+ assert_throws_js(TypeError, _ => {
+ metadata
+ new MediaMetadata({ artwork: [ { src: 'http://[example.com]' }] });
+ });
+ assert_equals(metadata, 42);
+
+ metadata = new MediaMetadata();
+ assert_throws_js(TypeError, _ => {
+ metadata.artwork = [
+ // Valid url.
+ { src: 'http://example.com' },
+ // Invalid url.
+ { src: 'http://example.com:demo' },
+ ];
+ });
+ assert_equals(metadata.artwork.length, 0);
+
+}, "Test that MediaMetadata throws when setting an invalid url");
+
+test(function() {
+ var metadata = new MediaMetadata({ artwork: [ { src: 'foo.jpg' } ] });
+ assert_equals(metadata.artwork[0].type, '');
+ assert_equals(metadata.artwork[0].sizes, '');
+}, "Test MediaImage default values");
+
+test(function() {
+ assert_throws_js(TypeError, _ => {
+ new MediaMetadata({ artwork: [ {} ] });
+ });
+
+ var metadata = new MediaMetadata();
+ assert_throws_js(TypeError, _ => {
+ metadata.artwork = [ { type: 'image/png', sizes: '40x40' } ];
+ });
+}, "Test that MediaImage.src is required")
+
+promise_test(async t => {
+ const URLs = [
+ 'http://example.com',
+ '../foo',
+ './foo/bar',
+ '/foo/bar',
+ ];
+ const subframe = await load_iframe('helper/artwork-generator.html');
+ // createArtworkFromURLs is a function in the subframe.
+ const artwork = subframe.contentWindow.createArtworkFromURLs(URLs);
+
+ assert_equals(artwork.length, URLs.length);
+ for (let i = 0 ; i < artwork.length ; ++i) {
+ assert_equals(artwork[i].src, new URL(URLs[i], document.URL).href);
+ }
+}, 'Test that the base URL of MediaImage is the base URL of entry setting object');
+
+</script>
diff --git a/testing/web-platform/tests/mediasession/playbackstate.html b/testing/web-platform/tests/mediasession/playbackstate.html
new file mode 100644
index 0000000000..63f3548d94
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/playbackstate.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<title>MediaSession.playbackState attribute</title>
+<script src=/resources/testharness.js></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+test(function() {
+ assert_equals(window.navigator.mediaSession.playbackState, "none");
+}, 'Test that playbackState is initialized as "none"');
+
+test(function() {
+ var states = [ "paused", "playing", "none" ];
+ for (let state of states) {
+ window.navigator.mediaSession.playbackState = state;
+ assert_equals(window.navigator.mediaSession.playbackState, state);
+ }
+}, 'Test that playbackState is read/write');
+
+test(function() {
+ var invalidStates = [ "invalid", "" ];
+ for (let state of invalidStates) {
+ window.navigator.mediaSession.playbackState = state;
+ assert_equals(window.navigator.mediaSession.playbackState, "none");
+ }
+}, 'Test that warning is thrown when setting invalid playbackState');
+
+</script>
diff --git a/testing/web-platform/tests/mediasession/positionstate.html b/testing/web-platform/tests/mediasession/positionstate.html
new file mode 100644
index 0000000000..9141091a90
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/positionstate.html
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<title>MediaSession.setPositionState</title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<script>
+test(() => {
+ window.navigator.mediaSession.setPositionState(null);
+}, 'Test setPositionState with a null value');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9,
+ position: 10.1,
+ playbackRate: 1.5
+ });
+}, 'Test setPositionState with a valid value for forward playback');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9,
+ playbackRate: 1.0
+ });
+}, 'Test setPositionState with optional position');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9,
+ position: 10.1
+ });
+}, 'Test setPositionState with optional playback rate');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9
+ });
+}, 'Test setPositionState with only duration');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 0
+ });
+}, 'Test setPositionState with zero duration');
+
+test(() => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9,
+ position: 10.1,
+ playbackRate: -2.0
+ });
+}, 'Test setPositionState with negative playback rate');
+
+test(() => {
+ assert_throws_js(
+ TypeError,
+ _ => {
+ window.navigator.mediaSession.setPositionState({
+ duration: -1
+ });
+ });
+}, 'Test setPositionState throws a TypeError if duration is negative');
+
+test(() => {
+ assert_throws_js(
+ TypeError,
+ _ => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 10,
+ position: -1
+ });
+ });
+}, 'Test setPositionState throws a TypeError if position is negative');
+
+test(() => {
+ assert_throws_js(
+ TypeError,
+ _ => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 10,
+ position: 20
+ });
+ });
+}, 'Test setPositionState throws a TypeError if duration is less than position');
+
+test(() => {
+ assert_throws_js(
+ TypeError,
+ _ => {
+ window.navigator.mediaSession.setPositionState({
+ duration: 60.9,
+ position: 10.1,
+ playbackRate: 0.0
+ });
+ });
+}, 'Test setPositionState throws a TypeError if playback rate is zero');
+
+test(() => {
+ assert_throws_js(
+ TypeError,
+ _ => {
+ window.navigator.mediaSession.setPositionState({
+ position: 10.1,
+ playbackRate: 1.0
+ });
+ });
+}, 'Test setPositionState throws a TypeError if duration is not specified');
+</script>
diff --git a/testing/web-platform/tests/mediasession/setactionhandler.html b/testing/web-platform/tests/mediasession/setactionhandler.html
new file mode 100644
index 0000000000..a9df51968c
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/setactionhandler.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<title>Test that setting MediaSession event handler should notify the service</title>
+<script src=/resources/testharness.js></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+[
+ "play",
+ "pause",
+ "previoustrack",
+ "nexttrack",
+ "seekbackward",
+ "seekforward",
+ "stop",
+ "seekto",
+ "skipad",
+ "togglemicrophone",
+ "togglecamera",
+ "hangup",
+ "previousslide",
+ "nextslide",
+].forEach((action) =>
+ test((t) => {
+ window.navigator.mediaSession.setActionHandler(action, null);
+ }, `Test that setActionHandler("${action}") succeeds`)
+);
+
+test(function(t) {
+ assert_throws_js(
+ TypeError,
+ _ => { window.navigator.mediaSession.setActionHandler("invalid", null); });
+}, "Test that setActionHandler() throws exception for unsupported actions");
+
+</script>
diff --git a/testing/web-platform/tests/mediasession/setcameraactive.html b/testing/web-platform/tests/mediasession/setcameraactive.html
new file mode 100644
index 0000000000..d5cd6a93f1
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/setcameraactive.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<title>MediaSession.setCameraActive</title>
+<script src=/resources/testharness.js></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+test(function(t) {
+ window.navigator.mediaSession.setCameraActive(true);
+ window.navigator.mediaSession.setCameraActive(false);
+}, "Test that setCameraActive() can be executed for boolean values");
+
+</script>
diff --git a/testing/web-platform/tests/mediasession/setmicrophoneactive.html b/testing/web-platform/tests/mediasession/setmicrophoneactive.html
new file mode 100644
index 0000000000..fbb4c612d9
--- /dev/null
+++ b/testing/web-platform/tests/mediasession/setmicrophoneactive.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<title>MediaSession.setMicrophoneActive</title>
+<script src=/resources/testharness.js></script>
+<script src="/resources/testharnessreport.js"></script>
+<script>
+
+test(function(t) {
+ window.navigator.mediaSession.setMicrophoneActive(true);
+ window.navigator.mediaSession.setMicrophoneActive(false);
+}, "Test that setMicrophoneActive() can be executed for boolean values");
+
+</script>