Commit 5946acdc authored by Reilly Grant's avatar Reilly Grant Committed by Commit Bot

Switch the MediaSession LayoutTests to the new Mojo JS bindings

This change enables generation of both Mojo JS bindings styles in the
//third_party/WebKit/public:android_mojo_bindings target and updates the
LayoutTests for the MediaSession API to use the new style.

Bug: 699569
Change-Id: Ifebdcbe5cffffd61d3dfcb48b590c447416d8d7a
Reviewed-on: https://chromium-review.googlesource.com/563704Reviewed-by: default avatardanakj <danakj@chromium.org>
Reviewed-by: default avatarYuzhu Shen <yzshen@chromium.org>
Commit-Queue: Reilly Grant <reillyg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485452}
parent 02da93cc
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
<title>Test that setting MediaSession callbacks are alive after garbage-collection</title> <title>Test that setting MediaSession callbacks are alive after garbage-collection</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.js"></script>
<script src="../../../resources/gc.js"></script> <script src="../../../resources/gc.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -11,8 +12,7 @@ ...@@ -11,8 +12,7 @@
var mock; var mock;
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let mock = mediaSessionServiceMock;
mock = m;
mock.setClientCallback(_ => { mock.setClientCallback(_ => {
gc(); gc();
setTimeout(_ => { setTimeout(_ => {
...@@ -20,6 +20,5 @@ async_test(function(t) { ...@@ -20,6 +20,5 @@ async_test(function(t) {
}); });
}); });
window.navigator.mediaSession.setActionHandler("play", _ => { t.done(); }); window.navigator.mediaSession.setActionHandler("play", _ => { t.done(); });
});
}); });
</script> </script>
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
var metadata = new MediaMetadata({ var metadata = new MediaMetadata({
artwork: [ artwork: [
{ src: "file:///foo/bar.jpg", type: "image/jpeg"} { src: "file:///foo/bar.jpg", type: "image/jpeg"}
...@@ -20,7 +21,6 @@ async_test(function(t) { ...@@ -20,7 +21,6 @@ async_test(function(t) {
t.done(); t.done();
})); }));
window.navigator.mediaSession.metadata = metadata; window.navigator.mediaSession.metadata = metadata;
});
}, "test that null MediaMetadata is correctly propagated"); }, "test that null MediaMetadata is correctly propagated");
</script> </script>
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -52,12 +53,10 @@ function runTests(t) { ...@@ -52,12 +53,10 @@ function runTests(t) {
// Use async_test to do asynchronous setup since setup() only works for // Use async_test to do asynchronous setup since setup() only works for
// synchronous setup. // synchronous setup.
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { mock = mediaSessionServiceMock;
mock = m;
mock.setClientCallback(t.step_func(runTests.bind(null, t))); mock.setClientCallback(t.step_func(runTests.bind(null, t)));
// Touch window.navigator.mediaSession to start the service. // Touch window.navigator.mediaSession to start the service.
window.navigator.mediaSession.metadata = null; window.navigator.mediaSession.metadata = null;
});
}, "test that the mock service is setup"); }, "test that the mock service is setup");
</script> </script>
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<title>Test that setting MediaSession event handler should notify the service</title> <title>Test that setting MediaSession event handler should notify the service</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -39,7 +40,7 @@ function getExpectations() { ...@@ -39,7 +40,7 @@ function getExpectations() {
} }
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
m.setEnableDisableActionCallback(t.step_func(function(action, isEnabled) { m.setEnableDisableActionCallback(t.step_func(function(action, isEnabled) {
var expectedAction = getExpectations()[nextExpectation][0]; var expectedAction = getExpectations()[nextExpectation][0];
var expectedIsEnabled = getExpectations()[nextExpectation][1]; var expectedIsEnabled = getExpectations()[nextExpectation][1];
...@@ -88,7 +89,6 @@ async_test(function(t) { ...@@ -88,7 +89,6 @@ async_test(function(t) {
window.navigator.mediaSession.setActionHandler("nexttrack", _ => {}); window.navigator.mediaSession.setActionHandler("nexttrack", _ => {});
window.navigator.mediaSession.setActionHandler("seekbackward", _ => {}); window.navigator.mediaSession.setActionHandler("seekbackward", _ => {});
window.navigator.mediaSession.setActionHandler("seekforward", _ => {}); window.navigator.mediaSession.setActionHandler("seekforward", _ => {});
});
}, "test that setting event handler notifies the mojo service"); }, "test that setting event handler notifies the mojo service");
</script> </script>
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<title>MediaMetadata Mojo Test</title> <title>MediaMetadata Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -38,7 +39,7 @@ async_test(t => { ...@@ -38,7 +39,7 @@ async_test(t => {
]; ];
var resultId = 0; var resultId = 0;
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
m.setMetadataCallback(t.step_func(receivedMetadata => { m.setMetadataCallback(t.step_func(receivedMetadata => {
assert_metadata_equals(receivedMetadata, results[resultId]); assert_metadata_equals(receivedMetadata, results[resultId]);
++resultId; ++resultId;
...@@ -66,7 +67,6 @@ async_test(t => { ...@@ -66,7 +67,6 @@ async_test(t => {
window.navigator.mediaSession.metadata.title = 'second timeout'; window.navigator.mediaSession.metadata.title = 'second timeout';
}); });
}); });
});
}, "test that MediaMetadata is correctly propagated twice"); }, "test that MediaMetadata is correctly propagated twice");
</script> </script>
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
var dontCareMetadata = new MediaMetadata({}); var dontCareMetadata = new MediaMetadata({});
m.setMetadataCallback(t.step_func(function() { m.setMetadataCallback(t.step_func(function() {
...@@ -27,7 +28,6 @@ async_test(function(t) { ...@@ -27,7 +28,6 @@ async_test(function(t) {
window.navigator.mediaSession.metadata = metadata; window.navigator.mediaSession.metadata = metadata;
})); }));
window.navigator.mediaSession.metadata = dontCareMetadata; window.navigator.mediaSession.metadata = dontCareMetadata;
});
}, "test that MediaMetadata is correctly propagated twice"); }, "test that MediaMetadata is correctly propagated twice");
</script> </script>
...@@ -2,13 +2,14 @@ ...@@ -2,13 +2,14 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
var metadata = new MediaMetadata({ var metadata = new MediaMetadata({
title: "title1", title: "title1",
artist: "artist1", artist: "artist1",
...@@ -22,7 +23,6 @@ async_test(function(t) { ...@@ -22,7 +23,6 @@ async_test(function(t) {
t.done(); t.done();
})); }));
window.navigator.mediaSession.metadata = metadata; window.navigator.mediaSession.metadata = metadata;
});
}, "test that MediaMetadata is correctly propagated"); }, "test that MediaMetadata is correctly propagated");
</script> </script>
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<title>MediaMetadata / MediaSession link Mojo Test</title> <title>MediaMetadata / MediaSession link Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -23,7 +24,7 @@ async_test(t => { ...@@ -23,7 +24,7 @@ async_test(t => {
]; ];
var resultId = 0; var resultId = 0;
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
m.setMetadataCallback(t.step_func(receivedMetadata => { m.setMetadataCallback(t.step_func(receivedMetadata => {
assert_metadata_equals(receivedMetadata, results[resultId]); assert_metadata_equals(receivedMetadata, results[resultId]);
++resultId; ++resultId;
...@@ -55,7 +56,6 @@ async_test(t => { ...@@ -55,7 +56,6 @@ async_test(t => {
// This one will be received. // This one will be received.
otherMetadata.title = 'the right change'; otherMetadata.title = 'the right change';
}); });
});
}, "test that MediaMetadata is correctly propagated twice"); }, "test that MediaMetadata is correctly propagated twice");
</script> </script>
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
...@@ -25,7 +26,7 @@ function getExpectations() { ...@@ -25,7 +26,7 @@ function getExpectations() {
} }
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
m.setPlaybackStateCallback(t.step_func(function(state) { m.setPlaybackStateCallback(t.step_func(function(state) {
assert_equals(state, getExpectations()[nextExpectation++]); assert_equals(state, getExpectations()[nextExpectation++]);
if (nextExpectation == getExpectations().length) if (nextExpectation == getExpectations().length)
...@@ -33,7 +34,6 @@ async_test(function(t) { ...@@ -33,7 +34,6 @@ async_test(function(t) {
})); }));
for (let state of inputStates) for (let state of inputStates)
window.navigator.mediaSession.playbackState = state; window.navigator.mediaSession.playbackState = state;
});
}, "test that MediaSession.playbackState is correctly propagated"); }, "test that MediaSession.playbackState is correctly propagated");
</script> </script>
...@@ -4,9 +4,6 @@ ...@@ -4,9 +4,6 @@
"use strict"; "use strict";
var MediaSessionAction;
var MediaSessionPlaybackState;
function mojoString16ToJS(mojoString16) { function mojoString16ToJS(mojoString16) {
return String.fromCharCode.apply(null, mojoString16.data); return String.fromCharCode.apply(null, mojoString16.data);
} }
...@@ -39,25 +36,20 @@ function mojoMetadataToJS(mojoMetadata) { ...@@ -39,25 +36,20 @@ function mojoMetadataToJS(mojoMetadata) {
return new MediaMetadata({title: title, artist: artist, album: album, artwork: artwork}); return new MediaMetadata({title: title, artist: artist, album: album, artwork: artwork});
} }
let mediaSessionServiceMock = loadMojoModules( var MediaSessionAction = blink.mojom.MediaSessionAction;
'mediaSessionServiceMock', var MediaSessionPlaybackState = blink.mojom.MediaSessionPlaybackState;
['third_party/WebKit/public/platform/modules/mediasession/media_session.mojom',
'mojo/public/js/bindings', class MediaSessionServiceMock {
]).then(mojo => { constructor() {
let [mediaSessionService, bindings] = mojo.modules;
MediaSessionAction = mediaSessionService.MediaSessionAction;
MediaSessionPlaybackState = mediaSessionService.MediaSessionPlaybackState;
class MediaSessionServiceMock {
constructor(interfaceProvider) {
interfaceProvider.addInterfaceOverrideForTesting(
mediaSessionService.MediaSessionService.name,
handle => this.bindingSet_.addBinding(this, handle));
this.interfaceProvider_ = interfaceProvider;
this.pendingResponse_ = null; this.pendingResponse_ = null;
this.bindingSet_ = new bindings.BindingSet( this.bindingSet_ = new mojo.BindingSet(
mediaSessionService.MediaSessionService); blink.mojom.MediaSessionService);
this.interceptor_ =
new MojoInterfaceInterceptor(blink.mojom.MediaSessionService.name);
this.interceptor_.oninterfacerequest =
e => this.bindingSet_.addBinding(this, e.handle);
this.interceptor_.start();
} }
setMetadata(metadata) { setMetadata(metadata) {
...@@ -105,7 +97,6 @@ let mediaSessionServiceMock = loadMojoModules( ...@@ -105,7 +97,6 @@ let mediaSessionServiceMock = loadMojoModules(
getClient() { getClient() {
return this.client_; return this.client_;
} }
} }
return new MediaSessionServiceMock(mojo.frameInterfaces); let mediaSessionServiceMock = new MediaSessionServiceMock();
});
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
<title>MediaSession Mojo Test</title> <title>MediaSession Mojo Test</title>
<script src="../../../resources/testharness.js"></script> <script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script> <script src="../../../resources/testharnessreport.js"></script>
<script src="../../../resources/mojo-helpers.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/mediasessionservice-mock.js"></script>
<script src="resources/utils.js"></script> <script src="resources/utils.js"></script>
<script> <script>
async_test(function(t) { async_test(function(t) {
mediaSessionServiceMock.then(m => { let m = mediaSessionServiceMock;
m.setMetadataCallback(t.step_func(function(receivedMetadata) { m.setMetadataCallback(t.step_func(function(receivedMetadata) {
assert_equals(receivedMetadata, null); assert_equals(receivedMetadata, null);
t.done(); t.done();
})); }));
window.navigator.mediaSession.metadata = null; window.navigator.mediaSession.metadata = null;
});
}, "test that null MediaMetadata is correctly propagated"); }, "test that null MediaMetadata is correctly propagated");
</script> </script>
...@@ -806,7 +806,7 @@ mojom("android_mojo_bindings") { ...@@ -806,7 +806,7 @@ mojom("android_mojo_bindings") {
export_header_blink = "third_party/WebKit/public/platform/WebCommon.h" export_header_blink = "third_party/WebKit/public/platform/WebCommon.h"
# TODO(crbug.com/699569): Convert to use the new JS bindings. # TODO(crbug.com/699569): Convert to use the new JS bindings.
use_new_js_bindings = false js_bindings_mode = "both"
} }
# The offscreen_canvas_mojo_bindings is separated from the rest of mojom files # The offscreen_canvas_mojo_bindings is separated from the rest of mojom files
......
...@@ -10,9 +10,6 @@ mojom("mojo") { ...@@ -10,9 +10,6 @@ mojom("mojo") {
sources = [ sources = [
"geometry.mojom", "geometry.mojom",
] ]
# TODO(crbug.com/699569): Convert to use the new JS bindings.
js_bindings_mode = "both"
} }
mojom("test_interfaces") { mojom("test_interfaces") {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment