forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Media Session: move all tests but mojo/ ones to external/wpt/.
A couple of tests have been merged and/or moved to idlharness.html BUG=688222 [email protected] Review-Url: https://codereview.chromium.org/2674793003 Cr-Commit-Position: refs/heads/master@{#448998}
- Loading branch information
1 parent
ec88aa2
commit 7b4c042
Showing
5 changed files
with
352 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Media Session IDL tests</title> | ||
<link rel="help" href="https://wicg.github.io/mediasession/"/> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/WebIDLParser.js"></script> | ||
<script src="/resources/idlharness.js"></script> | ||
</head> | ||
<body> | ||
<h1>Media Session IDL tests</h1> | ||
|
||
<pre id='untested_idl' style='display:none'> | ||
[PrimaryGlobal] | ||
interface Window { | ||
}; | ||
|
||
interface Navigator { | ||
}; | ||
</pre> | ||
|
||
<pre id='idl'> | ||
[Exposed=Window] | ||
partial interface Navigator { | ||
[SameObject] readonly attribute MediaSession mediaSession; | ||
}; | ||
|
||
enum MediaSessionPlaybackState { | ||
"none", | ||
"paused", | ||
"playing" | ||
}; | ||
|
||
enum MediaSessionAction { | ||
"play", | ||
"pause", | ||
"seekbackward", | ||
"seekforward", | ||
"previoustrack", | ||
"nexttrack", | ||
}; | ||
|
||
callback MediaSessionActionHandler = void(); | ||
|
||
[Exposed=Window] | ||
interface MediaSession { | ||
attribute MediaMetadata? metadata; | ||
|
||
attribute MediaSessionPlaybackState playbackState; | ||
|
||
void setActionHandler(MediaSessionAction action, MediaSessionActionHandler? handler); | ||
}; | ||
|
||
[Constructor(optional MediaMetadataInit init), Exposed=Window] | ||
interface MediaMetadata { | ||
attribute DOMString title; | ||
attribute DOMString artist; | ||
attribute DOMString album; | ||
attribute FrozenArray<MediaImage> artwork; | ||
}; | ||
|
||
dictionary MediaMetadataInit { | ||
DOMString title = ""; | ||
DOMString artist = ""; | ||
DOMString album = ""; | ||
sequence<MediaImage> artwork = []; | ||
}; | ||
|
||
dictionary MediaImage { | ||
required USVString src; | ||
DOMString sizes = ""; | ||
DOMString type = ""; | ||
}; | ||
</pre> | ||
<script> | ||
var idl_array = new IdlArray(); | ||
idl_array.add_untested_idls(document.getElementById("untested_idl").textContent); | ||
idl_array.add_idls(document.getElementById("idl").textContent); | ||
idl_array.add_objects({ | ||
MediaMetadata: [new MediaMetadata()], | ||
Navigator: ["navigator"] | ||
}); | ||
idl_array.test(); | ||
</script> | ||
<div id="log"></div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,192 @@ | ||
<!DOCTYPE html> | ||
<title>MediaMetadata interface</title> | ||
<script src=/resources/testharness.js></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script> | ||
|
||
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(new TypeError(), _ => new MediaMetadata('foobar')); | ||
assert_throws(new 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(new 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(new TypeError(), _ => { | ||
metadata | ||
new MediaMetadata({ artwork: [ { src: 'http://[example.com]' }] }); | ||
}); | ||
assert_equals(metadata, 42); | ||
|
||
metadata = new MediaMetadata(); | ||
assert_throws(new 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(new TypeError(), _ => { | ||
new MediaMetadata({ artwork: [ {} ] }); | ||
}); | ||
|
||
var metadata = new MediaMetadata(); | ||
assert_throws(new TypeError(), _ => { | ||
metadata.artwork = [ { type: 'image/png', sizes: '40x40' } ]; | ||
}); | ||
}, "Test that MediaImage.src is required") | ||
|
||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!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> | ||
|
||
test(function(t) { | ||
window.navigator.mediaSession.setActionHandler("play", null); | ||
window.navigator.mediaSession.setActionHandler("pause", null); | ||
window.navigator.mediaSession.setActionHandler("previoustrack", null); | ||
window.navigator.mediaSession.setActionHandler("nexttrack", null); | ||
window.navigator.mediaSession.setActionHandler("seekbackward", null); | ||
window.navigator.mediaSession.setActionHandler("seekforward", null); | ||
}, "Test that setActionHandler() can be executed for supported actions"); | ||
|
||
test(function(t) { | ||
assert_throws( | ||
new TypeError("Failed to execute 'setActionHandler' on 'MediaSession':" + | ||
"The provided value 'invalid' is not a valid enum value" + | ||
"of type MediaSessionAction."), | ||
_ => { window.navigator.mediaSession.setActionHandler("invalid", null); }); | ||
}, "Test that setActionHandler() throws exception for unsupported actions"); | ||
|
||
</script> |