Title: [281134] trunk
Revision
281134
Author
[email protected]
Date
2021-08-17 06:09:28 -0700 (Tue, 17 Aug 2021)

Log Message

Implement API to ensure MediaRemote key mapping is correct
https://bugs.webkit.org/show_bug.cgi?id=229070
<rdar://problem/81894480>

Reviewed by Eric Carlson.

Source/WebCore:

This change adds Internals entries to test bug 229068.
While we do not mock the MediaRemote service, we still go one step further in
ensuring that the mappings between MediaSession action handlers and
PlatformMediaSession are correct.

Test: media/media-session/actionHandlerInternalMappings.html

* platform/NowPlayingManager.cpp:
(WebCore::NowPlayingManager::supportedCommands const):
* platform/NowPlayingManager.h:
* platform/audio/PlatformMediaSession.h:
* platform/audio/PlatformMediaSessionManager.h:
(WebCore::PlatformMediaSessionManager::supportedCommands const):
* platform/audio/cocoa/MediaSessionManagerCocoa.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::supportedCommands const):
* testing/Internals.cpp:
(WebCore::Internals::platformSupportedCommands const):
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/media-session/actionHandlerInternalMappings-expected.txt: Added.
* media/media-session/actionHandlerInternalMappings.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (281133 => 281134)


--- trunk/LayoutTests/ChangeLog	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/LayoutTests/ChangeLog	2021-08-17 13:09:28 UTC (rev 281134)
@@ -1,3 +1,14 @@
+2021-08-17  Jean-Yves Avenard  <[email protected]>
+
+        Implement API to ensure MediaRemote key mapping is correct
+        https://bugs.webkit.org/show_bug.cgi?id=229070
+        <rdar://problem/81894480>
+
+        Reviewed by Eric Carlson.
+
+        * media/media-session/actionHandlerInternalMappings-expected.txt: Added.
+        * media/media-session/actionHandlerInternalMappings.html: Added.
+
 2021-08-16  Diego Pino Garcia  <[email protected]>
 
         [GLIB] Unreviewed test gardening. Update baselines after r277970.

Added: trunk/LayoutTests/media/media-session/actionHandlerInternalMappings-expected.txt (0 => 281134)


--- trunk/LayoutTests/media/media-session/actionHandlerInternalMappings-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/media-session/actionHandlerInternalMappings-expected.txt	2021-08-17 13:09:28 UTC (rev 281134)
@@ -0,0 +1,37 @@
+
+RUN(video.src = "" "../content/test"))
+EVENT(loadeddata)
+Test that action handlers properly register with correct PlatformMediaSession RemoteControlCommandType
+ACTION: play
+Command: PlayCommand
+ACTION: pause
+Command: PauseCommand
+ACTION: seekbackward
+Command: SkipBackwardCommand
+ACTION: seekforward
+Command: SkipForwardCommand
+ACTION: previoustrack
+Command: PreviousTrackCommand
+ACTION: nexttrack
+Command: NextTrackCommand
+ACTION: skipad
+Command: NextTrackCommand
+ACTION: stop
+Command: StopCommand
+ACTION: seekto
+Command: SeekToPlaybackPositionCommand
+Iterate over all possible actions
+Command: PauseCommand
+Command: SkipBackwardCommand
+Command: SkipForwardCommand
+Command: NextTrackCommand
+Command: PreviousTrackCommand
+Command: SeekToPlaybackPositionCommand
+Command: PlayCommand
+Command: StopCommand
+Iterate over possible actions after video element src is cleared
+RUN(video.src = ""
+EVENT(loadstart)
+EXPECTED (internals.platformSupportedCommands().length == '0') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/media-session/actionHandlerInternalMappings.html (0 => 281134)


--- trunk/LayoutTests/media/media-session/actionHandlerInternalMappings.html	                        (rev 0)
+++ trunk/LayoutTests/media/media-session/actionHandlerInternalMappings.html	2021-08-17 13:09:28 UTC (rev 281134)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>default-actionHandlers</title>
+    <script src=""
+    <script src=""
+    <script>
+
+    const mediaSessionActions = [ "play", "pause", "seekbackward", "seekforward", "previoustrack", "nexttrack", "skipad", "stop", "seekto" ];
+    async function runTest() {
+        if (!window.internals) {
+            failTest('This test requires Internals');
+            return;
+        }
+
+        findMediaElement();
+        run('video.src = "" "../content/test")');
+        await waitFor(video, 'loadeddata');
+
+        consoleWrite('Test that action handlers properly register with correct PlatformMediaSession RemoteControlCommandType');
+
+        mediaSessionActions.forEach(value => {
+            consoleWrite(`ACTION: ${value}`);
+            navigator.mediaSession.setActionHandler(value, actionDetails => { });
+            internals.platformSupportedCommands().forEach(value => consoleWrite(`Command: ${value}`));
+            navigator.mediaSession.setActionHandler(value, null);
+        });
+
+        consoleWrite('Iterate over all possible actions');
+        mediaSessionActions.forEach(value => {
+            navigator.mediaSession.setActionHandler(value, actionDetails => { });
+        });
+        internals.platformSupportedCommands().forEach(value => consoleWrite(`Command: ${value}`));
+
+        consoleWrite('Iterate over possible actions after video element src is cleared');
+        run('video.src = ""
+        await waitFor(video, "loadstart");
+
+        testExpected('internals.platformSupportedCommands().length', 0);
+        internals.platformSupportedCommands().forEach(value => consoleWrite(`Command: ${value}`));
+
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="runTest()">
+    <video controls preload='auto'></video>
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (281133 => 281134)


--- trunk/Source/WebCore/ChangeLog	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/ChangeLog	2021-08-17 13:09:28 UTC (rev 281134)
@@ -1,3 +1,32 @@
+2021-08-17  Jean-Yves Avenard  <[email protected]>
+
+        Implement API to ensure MediaRemote key mapping is correct
+        https://bugs.webkit.org/show_bug.cgi?id=229070
+        <rdar://problem/81894480>
+
+        Reviewed by Eric Carlson.
+
+        This change adds Internals entries to test bug 229068.
+        While we do not mock the MediaRemote service, we still go one step further in
+        ensuring that the mappings between MediaSession action handlers and
+        PlatformMediaSession are correct.
+
+        Test: media/media-session/actionHandlerInternalMappings.html
+
+        * platform/NowPlayingManager.cpp:
+        (WebCore::NowPlayingManager::supportedCommands const):
+        * platform/NowPlayingManager.h:
+        * platform/audio/PlatformMediaSession.h:
+        * platform/audio/PlatformMediaSessionManager.h:
+        (WebCore::PlatformMediaSessionManager::supportedCommands const):
+        * platform/audio/cocoa/MediaSessionManagerCocoa.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (WebCore::MediaSessionManagerCocoa::supportedCommands const):
+        * testing/Internals.cpp:
+        (WebCore::Internals::platformSupportedCommands const):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2021-08-17  Philippe Normand  <[email protected]>
 
         REGRESSION(r278981): [GStreamer][Debug] Assert crashes when running media/track tests

Modified: trunk/Source/WebCore/platform/NowPlayingManager.cpp (281133 => 281134)


--- trunk/Source/WebCore/platform/NowPlayingManager.cpp	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/NowPlayingManager.cpp	2021-08-17 13:09:28 UTC (rev 281134)
@@ -126,6 +126,13 @@
         m_remoteCommandListener->removeSupportedCommand(command);
 }
 
+RemoteCommandListener::RemoteCommandsSet NowPlayingManager::supportedCommands() const
+{
+    if (!m_remoteCommandListener)
+        return { };
+    return m_remoteCommandListener->supportedCommands();
+}
+
 void NowPlayingManager::setSupportedRemoteCommands(const RemoteCommandListener::RemoteCommandsSet& commands)
 {
     if (m_remoteCommandListener)

Modified: trunk/Source/WebCore/platform/NowPlayingManager.h (281133 => 281134)


--- trunk/Source/WebCore/platform/NowPlayingManager.h	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/NowPlayingManager.h	2021-08-17 13:09:28 UTC (rev 281134)
@@ -50,6 +50,7 @@
 
     void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType);
     void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType);
+    RemoteCommandListener::RemoteCommandsSet supportedCommands() const;
 
     void addClient(Client&);
     void removeClient(Client&);

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSession.h (281133 => 281134)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSession.h	2021-08-17 13:09:28 UTC (rev 281134)
@@ -282,7 +282,7 @@
 
 String convertEnumerationToString(PlatformMediaSession::State);
 String convertEnumerationToString(PlatformMediaSession::InterruptionType);
-String convertEnumerationToString(PlatformMediaSession::RemoteControlCommandType);
+WEBCORE_EXPORT String convertEnumerationToString(PlatformMediaSession::RemoteControlCommandType);
 
 template<class Encoder> inline void PlatformMediaSession::RemoteCommandArgument::encode(Encoder& encoder) const
 {

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (281133 => 281134)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2021-08-17 13:09:28 UTC (rev 281134)
@@ -28,6 +28,7 @@
 
 #include "MediaUniqueIdentifier.h"
 #include "PlatformMediaSession.h"
+#include "RemoteCommandListener.h"
 #include "Timer.h"
 #include <wtf/AggregateLogger.h>
 #include <wtf/Vector.h>
@@ -37,7 +38,6 @@
 namespace WebCore {
 
 class PlatformMediaSession;
-class RemoteCommandListener;
 
 class PlatformMediaSessionManager
 #if !RELEASE_LOG_DISABLED
@@ -162,6 +162,7 @@
 
     virtual void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType) { };
     virtual void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType) { };
+    virtual RemoteCommandListener::RemoteCommandsSet supportedCommands() const { return { }; };
 
     WEBCORE_EXPORT void processSystemWillSleep();
     WEBCORE_EXPORT void processSystemDidWake();

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h (281133 => 281134)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h	2021-08-17 13:09:28 UTC (rev 281134)
@@ -84,6 +84,7 @@
 
     void addSupportedCommand(PlatformMediaSession::RemoteControlCommandType) final;
     void removeSupportedCommand(PlatformMediaSession::RemoteControlCommandType) final;
+    RemoteCommandListener::RemoteCommandsSet supportedCommands() const final;
 
     void resetHaveEverRegisteredAsNowPlayingApplicationForTesting() final { m_haveEverRegisteredAsNowPlayingApplication = false; };
 

Modified: trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm (281133 => 281134)


--- trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm	2021-08-17 13:09:28 UTC (rev 281134)
@@ -264,6 +264,11 @@
     m_nowPlayingManager->removeSupportedCommand(command);
 }
 
+RemoteCommandListener::RemoteCommandsSet MediaSessionManagerCocoa::supportedCommands() const
+{
+    return m_nowPlayingManager->supportedCommands();
+}
+
 void MediaSessionManagerCocoa::clearNowPlayingInfo()
 {
     if (!isMediaRemoteFrameworkAvailable())

Modified: trunk/Source/WebCore/testing/Internals.cpp (281133 => 281134)


--- trunk/Source/WebCore/testing/Internals.cpp	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/testing/Internals.cpp	2021-08-17 13:09:28 UTC (rev 281134)
@@ -154,6 +154,7 @@
 #include "PathUtilities.h"
 #include "PictureInPictureSupport.h"
 #include "PlatformKeyboardEvent.h"
+#include "PlatformMediaSession.h"
 #include "PlatformMediaSessionManager.h"
 #include "PlatformScreen.h"
 #include "PlatformStrategies.h"
@@ -6351,6 +6352,19 @@
     });
     m_artworkLoader->requestImageResource();
 }
+
+ExceptionOr<Vector<String>> Internals::platformSupportedCommands() const
+{
+    if (!contextDocument())
+        return Exception { InvalidAccessError };
+    auto commands = PlatformMediaSessionManager::sharedManager().supportedCommands();
+    Vector<String> commandStrings;
+    for (auto command : commands)
+        commandStrings.append(convertEnumerationToString(command));
+
+    return commandStrings;
+}
+
 #endif
 
 #if ENABLE(MEDIA_SESSION_COORDINATOR)

Modified: trunk/Source/WebCore/testing/Internals.h (281133 => 281134)


--- trunk/Source/WebCore/testing/Internals.h	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/testing/Internals.h	2021-08-17 13:09:28 UTC (rev 281134)
@@ -1160,6 +1160,7 @@
 
         using ArtworkImagePromise = DOMPromiseDeferred<IDLInterface<ImageData>>;
     void loadArtworkImage(String&&, ArtworkImagePromise&&);
+    ExceptionOr<Vector<String>> platformSupportedCommands() const;
 
 #if ENABLE(MEDIA_SESSION_COORDINATOR)
     ExceptionOr<void> registerMockMediaSessionCoordinator(ScriptExecutionContext&, RefPtr<StringCallback>&&);

Modified: trunk/Source/WebCore/testing/Internals.idl (281133 => 281134)


--- trunk/Source/WebCore/testing/Internals.idl	2021-08-17 10:16:41 UTC (rev 281133)
+++ trunk/Source/WebCore/testing/Internals.idl	2021-08-17 13:09:28 UTC (rev 281134)
@@ -1042,7 +1042,8 @@
     [Conditional=MEDIA_SESSION] double currentMediaSessionPosition(MediaSession session);
     [Conditional=MEDIA_SESSION] undefined sendMediaSessionAction(MediaSession session, MediaSessionActionDetails actionDetails);
     [Conditional=MEDIA_SESSION] Promise<ImageData> loadArtworkImage(DOMString url);
-    
+    [Conditional=MEDIA_SESSION] sequence<DOMString> platformSupportedCommands();
+
     [Conditional=MEDIA_SESSION_COORDINATOR, CallWith=ScriptExecutionContext] undefined registerMockMediaSessionCoordinator(StringCallback callback);
     [Conditional=MEDIA_SESSION_COORDINATOR] undefined setMockMediaSessionCoordinatorCommandsShouldFail(boolean shouldFail);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to