4 <title>Test frame for triggering media session's action handler
</title>
5 <script src=
"MediaSessionTestUtils.js"></script>
8 <video id=
"testVideo" src=
"gizmo.mp4" loop
></video>
11 const video
= document
.getElementById("testVideo");
12 const w
= window
.opener
|| window
.parent
;
14 window
.onmessage
= async event
=> {
15 if (event
.data
== "play") {
17 // As we can't observe `media-displayed-playback-changed` notification,
18 // that can only be observed in the chrome process. Therefore, we use a
19 // workaround instead which is to wait for a while to ensure that the
20 // controller has already been created in the chrome process.
21 let timeupdatecount
= 0;
22 await
new Promise(r
=> video
.ontimeupdate
= () => {
23 if (++timeupdatecount
== 3) {
24 video
.ontimeupdate
= null;
28 w
.postMessage("played", "*");
32 // Setup the action handlers which would post the result back to the main window.
33 for (const action
of gMediaSessionActions
) {
34 navigator
.mediaSession
.setActionHandler(action
, () => {
35 w
.postMessage(action
, "*");