| <!DOCTYPE html> |
| <title>MediaMetadata / MediaSession link Mojo Test</title> |
| <script src="../../../resources/testharness.js"></script> |
| <script src="../../../resources/testharnessreport.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/third_party/WebKit/public/platform/modules/mediasession/media_session.mojom.js"></script> |
| <script src="resources/mediasessionservice-mock.js"></script> |
| <script src="resources/utils.js"></script> |
| <script> |
| |
| async_test(t => { |
| // The following are expected results. |
| var results = [ |
| new MediaMetadata({}), |
| new MediaMetadata({ |
| title: 'new title', |
| }), |
| new MediaMetadata({ |
| title: 'other', |
| }), |
| new MediaMetadata({ |
| title: 'the right change', |
| }), |
| ]; |
| var resultId = 0; |
| |
| let m = mediaSessionServiceMock; |
| m.setMetadataCallback(t.step_func(receivedMetadata => { |
| assert_metadata_equals(receivedMetadata, results[resultId]); |
| ++resultId; |
| |
| if (results.length == resultId) |
| t.done(); |
| })); |
| |
| // Setting the metadata property will update the mojo service. |
| var currentMetadata = new MediaMetadata({}); |
| window.navigator.mediaSession.metadata = currentMetadata; |
| |
| // `currentMetadata` is still associated to MediaSession. |
| currentMetadata.title = 'new title'; |
| |
| // De-associate them. |
| setTimeout(_ => { |
| // This change will trigger an asynchronous request for an update. It is |
| // Followed by another change that will prevent the former to work. |
| currentMetadata.title = 'should not be received'; |
| |
| var otherMetadata = new MediaMetadata({ title: 'other' }); |
| window.navigator.mediaSession.metadata = otherMetadata; |
| |
| // `currentMetadata` is no longer linked with the session so changes |
| // should have no effect. |
| currentMetadata.title = 'another attempt'; |
| |
| // This one will be received. |
| otherMetadata.title = 'the right change'; |
| }); |
| }, "test that MediaMetadata is correctly propagated twice"); |
| |
| </script> |