Skip to content

Commit

Permalink
Update the wpt test with chapterInfo
Browse files Browse the repository at this point in the history
Bug: b/316044047
Change-Id: Iaaa16b5229d5e23ab9612bb0b93b237496113884
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5516503
Reviewed-by: Tommy Steimel <[email protected]>
Commit-Queue: Jiaming Cheng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1296983}
  • Loading branch information
Jiaming Cheng authored and chromium-wpt-export-bot committed May 6, 2024
1 parent 1eedf3f commit 1cf03ce
Showing 1 changed file with 161 additions and 4 deletions.
165 changes: 161 additions & 4 deletions mediasession/mediametadata.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,27 @@
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 chapter1_image1 = { src: 'http://chapterexample.com/1', sizes: '128x128', type: 'image/png' };
var chapter1_image2 = { src: 'http://chapterexample.com/2', sizes: '512x512', type: 'image/png' };
var chapter2_image1 = { src: 'http://chapterexample.com/3', sizes: '128x128', type: 'image/png' };
var chapter2_image2 = { src: 'http://chapterexample.com/4', sizes: '512x512', type: 'image/png' };
var metadata = new MediaMetadata({
title: 'foo', album: 'bar', artist: 'plop', artwork: [ image1, image2 ]
title: 'foo', album: 'bar', artist: 'plop', artwork: [image1, image2],
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [
chapter1_image1,
chapter1_image2
]
}, {
title: 'Chapter 2',
startTime: 16,
artwork: [
chapter2_image1,
chapter2_image2,
]
}]
});

assert_equals(metadata.title, 'foo');
Expand All @@ -64,6 +83,22 @@
assert_equals(metadata.artwork[1].src, image2.src);
assert_equals(metadata.artwork[1].sizes, image2.sizes);
assert_equals(metadata.artwork[1].type, image2.type);
assert_equals(metadata.chapterInfo[0].title, 'Chapter 1');
assert_equals(metadata.chapterInfo[0].startTime, 0);
assert_equals(metadata.chapterInfo[0].artwork[0].src, chapter1_image1.src);
assert_equals(metadata.chapterInfo[0].artwork[1].src, chapter1_image2.src);
assert_equals(metadata.chapterInfo[0].artwork[0].sizes, chapter1_image1.sizes);
assert_equals(metadata.chapterInfo[0].artwork[1].sizes, chapter1_image2.sizes);
assert_equals(metadata.chapterInfo[0].artwork[0].type, chapter1_image1.type);
assert_equals(metadata.chapterInfo[0].artwork[1].type, chapter1_image2.type);
assert_equals(metadata.chapterInfo[1].title, 'Chapter 2');
assert_equals(metadata.chapterInfo[1].startTime, 16);
assert_equals(metadata.chapterInfo[1].artwork[0].src, chapter2_image1.src);
assert_equals(metadata.chapterInfo[1].artwork[1].src, chapter2_image2.src);
assert_equals(metadata.chapterInfo[1].artwork[0].sizes, chapter2_image1.sizes);
assert_equals(metadata.chapterInfo[1].artwork[1].sizes, chapter2_image2.sizes);
assert_equals(metadata.chapterInfo[1].artwork[0].type, chapter2_image1.type);
assert_equals(metadata.chapterInfo[1].artwork[1].type, chapter2_image2.type);
}, 'Test the different values allowed in MediaMetadata init dictionary');

test(function() {
Expand All @@ -72,6 +107,7 @@
assert_equals(metadata.artist, '');
assert_equals(metadata.album, '');
assert_equals(0, metadata.artwork.length);
assert_equals(0, metadata.chapterInfo.length);
}, 'Test the default values for MediaMetadata with empty init dictionary');

test(function() {
Expand All @@ -80,6 +116,7 @@
assert_equals(metadata.artist, '');
assert_equals(metadata.album, '');
assert_equals(0, metadata.artwork.length);
assert_equals(0, metadata.chapterInfo.length);
}, 'Test the default values for MediaMetadata with no init dictionary');

test(function() {
Expand All @@ -90,8 +127,28 @@
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 chapter1_image1 = { src: 'http://chapterexample.com/1', sizes: '128x128', type: 'image/png' };
var chapter1_image2 = { src: 'http://chapterexample.com/2', sizes: '512x512', type: 'image/png' };
var chapter2_image1 = { src: 'http://chapterexample.com/3', sizes: '128x128', type: 'image/png' };
var chapter2_image2 = { src: 'http://chapterexample.com/4', sizes: '512x512', type: 'image/png' };

var metadata = new MediaMetadata({
title: 'foo', album: 'bar', artist: 'plop', artwork: [ image1, image2 ]
title: 'foo', album: 'bar', artist: 'plop', artwork: [image1, image2],
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [
chapter1_image1,
chapter1_image2
]
}, {
title: 'Chapter 2',
startTime: 16,
artwork: [
chapter2_image1,
chapter2_image2,
]
}]
});

metadata.title = 'something else';
Expand All @@ -109,6 +166,18 @@
assert_equals(metadata.artwork[0].src, 'http://example.com/');
assert_equals(metadata.artwork[0].sizes, '40x40');
assert_equals(metadata.artwork[0].type, 'image/png');

// The chapterInfo cannot be modified.
var chapter_image = { src: 'http://example.com/', sizes: '40x40', type: 'image/png' };
var chapter = {
title: 'Chapter 3',
startTime: 22,
artwork: [chapter_image]
};
metadata.chapterInfo = [chapter];
assert_equals(metadata.chapterInfo[0].title, 'Chapter 1');
assert_equals(metadata.chapterInfo[0].startTime, 0);
assert_equals(metadata.chapterInfo.length, 2);
}, "Test that MediaMetadata is read/write");

test(function() {
Expand All @@ -121,7 +190,7 @@

metadata.artwork[0].src = 'bar';
assert_equals(metadata.artwork[0].src, 'http://foo.com/');
}, "Test that MediaMetadat.artwork can't be modified");
}, "Test that MediaMetadata.artwork can't be modified");

test(function() {
var metadata = new MediaMetadata({ artwork: [{
Expand All @@ -148,6 +217,34 @@
assert_true(Object.isFrozen(metadata.artwork[i]));
}, "Test that MediaMetadata.artwork is Frozen");

test(function() {
var chapter1_image1 = { src: 'http://chapterexample.com/1', sizes: '128x128', type: 'image/png' };
var chapter1_image2 = { src: 'http://chapterexample.com/2', sizes: '512x512', type: 'image/png' };
var chapter2_image1 = { src: 'http://chapterexample.com/3', sizes: '128x128', type: 'image/png' };
var chapter2_image2 = { src: 'http://chapterexample.com/4', sizes: '512x512', type: 'image/png' };
var metadata = new MediaMetadata({
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [
chapter1_image1,
chapter1_image2
]
}, {
title: 'Chapter 2',
startTime: 16,
artwork: [
chapter2_image1,
chapter2_image2,
]
}]
});

assert_true(Object.isFrozen(metadata.chapterInfo));
for (var i = 0; i < metadata.chapterInfo.length; ++i)
assert_true(Object.isFrozen(metadata.chapterInfo[i]));
}, "Test that MediaMetadata.chapterInfo is Frozen");

test(function() {
var metadata = new MediaMetadata({ artwork: [
{ src: 'http://example.com', sizes: '40x40', type: 'image/png' },
Expand All @@ -160,6 +257,39 @@
assert_equals(metadata.artwork[2].src, new URL('/foo/bar', document.URL).href)
}, "Test that MediaMetadata.artwork returns parsed urls");

test(function() {
var chapter1_image1 = { src: 'http://chapterexample.com/1', sizes: '128x128', type: 'image/png' };
var chapter1_image2 = { src: 'http://chapterexample.com/2', sizes: '512x512', type: 'image/png' };
var chapter2_image1 = { src: 'http://chapterexample.com/3', sizes: '128x128', type: 'image/png' };
var chapter2_image2 = { src: 'http://chapterexample.com/4', sizes: '512x512', type: 'image/png' };
var metadata = new MediaMetadata({
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [
chapter1_image1,
chapter1_image2
]
}, {
title: 'Chapter 2',
startTime: 16,
artwork: [
chapter2_image1,
chapter2_image2,
]
}]
});

assert_equals(metadata.chapterInfo[0].artwork[0].src,
new URL('http://chapterexample.com/1', document.URL).href)
assert_equals(metadata.chapterInfo[0].artwork[1].src,
new URL('http://chapterexample.com/2', document.URL).href)
assert_equals(metadata.chapterInfo[1].artwork[0].src,
new URL('http://chapterexample.com/3', document.URL).href)
assert_equals(metadata.chapterInfo[1].artwork[1].src,
new URL('http://chapterexample.com/4', document.URL).href)
}, "Test that MediaMetadata.chapterInfo's artwork returns parsed urls");

test(function() {
var metadata = 42;

Expand All @@ -180,6 +310,22 @@
});
assert_equals(metadata.artwork.length, 0);

assert_throws_js(TypeError, _ => {
metadata
new MediaMetadata({
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [
// Valid url.
{ src: 'http://example.com' },
// Invalid url.
{ src: 'http://example.com:demo' },
]
}]
});
});
assert_equals(metadata.chapterInfo.length, 0);
}, "Test that MediaMetadata throws when setting an invalid url");

test(function() {
Expand All @@ -190,13 +336,24 @@

test(function() {
assert_throws_js(TypeError, _ => {
new MediaMetadata({ artwork: [ {} ] });
new MediaMetadata({ artwork: [ {} ] })
});

var metadata = new MediaMetadata();
assert_throws_js(TypeError, _ => {
metadata.artwork = [ { type: 'image/png', sizes: '40x40' } ];
});

assert_throws_js(TypeError, _ => {
metadata
new MediaMetadata({
chapterInfo: [{
title: 'Chapter 1',
startTime: 0,
artwork: [{ type: 'image/png', sizes: '40x40' }]
}]
});
});
}, "Test that MediaImage.src is required")

promise_test(async t => {
Expand Down

0 comments on commit 1cf03ce

Please sign in to comment.