[Cocoa] Don't clear NowPlaying state unless it was set
authoreric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 May 2020 20:38:44 +0000 (20:38 +0000)
committereric.carlson@apple.com <eric.carlson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 May 2020 20:38:44 +0000 (20:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=211899
<rdar://problem/62249870>

Reviewed by Jer Noble.

Source/WebCore:

Test: media/now-playing-status-without-media.html

* platform/audio/PlatformMediaSessionManager.h:
(WebCore::PlatformMediaSessionManager::haveEverRegisteredAsNowPlayingApplication const): Method
added for testing.

* platform/audio/cocoa/MediaSessionManagerCocoa.h:
* platform/audio/cocoa/MediaSessionManagerCocoa.mm:
(WebCore::MediaSessionManagerCocoa::updateNowPlayingInfo): Don't clear NowPlaying state unless
it was setup in the first place.

* testing/Internals.cpp:
(WebCore::Internals::nowPlayingState const): Add new property.
* testing/Internals.h:
* testing/Internals.idl:

LayoutTests:

* media/now-playing-status-without-media-expected.txt: Added.
* media/now-playing-status-without-media.html: Added.

* gpu-process/TestExpectations: Skip test because media session isn't fully functional in GPUP.
* platform/mac-wk1/TestExpectations: Skip test because media session manager is a singleton.
* platform/gtk/TestExpectations: Skip Cocoa-only test.
* platform/win/TestExpectations: Ditto.
* platform/wpe/TestExpectations: Ditto.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261709 268f45cc-cd09-0410-ab3c-d52691b4dbfc

15 files changed:
LayoutTests/ChangeLog
LayoutTests/gpu-process/TestExpectations
LayoutTests/media/now-playing-status-without-media-expected.txt [new file with mode: 0644]
LayoutTests/media/now-playing-status-without-media.html [new file with mode: 0644]
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/mac-wk1/TestExpectations
LayoutTests/platform/win/TestExpectations
LayoutTests/platform/wpe/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/audio/PlatformMediaSessionManager.h
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.h
Source/WebCore/platform/audio/cocoa/MediaSessionManagerCocoa.mm
Source/WebCore/testing/Internals.cpp
Source/WebCore/testing/Internals.h
Source/WebCore/testing/Internals.idl

index 37708f8..582b9b8 100644 (file)
@@ -1,3 +1,20 @@
+2020-05-14  Eric Carlson  <eric.carlson@apple.com>
+
+        [Cocoa] Don't clear NowPlaying state unless it was set
+        https://bugs.webkit.org/show_bug.cgi?id=211899
+        <rdar://problem/62249870>
+
+        Reviewed by Jer Noble.
+
+        * media/now-playing-status-without-media-expected.txt: Added.
+        * media/now-playing-status-without-media.html: Added.
+
+        * gpu-process/TestExpectations: Skip test because media session isn't fully functional in GPUP.
+        * platform/mac-wk1/TestExpectations: Skip test because media session manager is a singleton.
+        * platform/gtk/TestExpectations: Skip Cocoa-only test.
+        * platform/win/TestExpectations: Ditto.
+        * platform/wpe/TestExpectations: Ditto.
+
 2020-05-14  Myles C. Maxfield  <mmaxfield@apple.com>
 
         fast/text/multiple-codeunit-vertical-upright.html is failing
index 157f16b..e31049e 100644 (file)
@@ -248,6 +248,7 @@ media/modern-media-controls/tracks-support/tracks-support-off-text-track.html [
 
 media/muted-video-is-playing-audio.html [ Skip ]
 media/navigate-with-pip-should-not-crash.html [ Skip ]
+media/now-playing-status-without-media.html [ Skip ]
 media/picture-in-picture/picture-in-picture-api-css-selector.html [ Skip ]
 media/picture-in-picture/picture-in-picture-api-enter-pip-4.html [ Skip ]
 media/picture-in-picture/picture-in-picture-api-events.html [ Skip ]
diff --git a/LayoutTests/media/now-playing-status-without-media-expected.txt b/LayoutTests/media/now-playing-status-without-media-expected.txt
new file mode 100644 (file)
index 0000000..ca49ddf
--- /dev/null
@@ -0,0 +1,16 @@
+
+NowPlaying status should not be updated when no media is active.
+
+
+** Check state initially.
+EXPECTED (state.haveEverRegisteredAsNowPlayingApplication == 'false') OK
+
+** Suspend process.
+RUN(internals.applicationWillBecomeInactive())
+EXPECTED (state.haveEverRegisteredAsNowPlayingApplication == 'false') OK
+
+** Activate process.
+RUN(internals.applicationDidBecomeActive())
+EXPECTED (state.haveEverRegisteredAsNowPlayingApplication == 'false') OK
+END OF TEST
+
diff --git a/LayoutTests/media/now-playing-status-without-media.html b/LayoutTests/media/now-playing-status-without-media.html
new file mode 100644 (file)
index 0000000..0b1e760
--- /dev/null
@@ -0,0 +1,38 @@
+<html>
+    <head>
+        <script src=video-test.js></script>
+        <script>
+
+            let state;
+
+            window.addEventListener('load', async event => {
+
+                if (!window.internals) {
+                    failTest(`<br>This test requires internals!`);
+                    return;
+                }
+
+                consoleWrite("<br>** Check state initially.")
+                state = internals.nowPlayingState;
+                testExpected('state.haveEverRegisteredAsNowPlayingApplication', false);
+
+                consoleWrite("<br>** Suspend process.")
+                run('internals.applicationWillBecomeInactive()');
+                state = internals.nowPlayingState;
+                testExpected('state.haveEverRegisteredAsNowPlayingApplication', false);
+
+                consoleWrite("<br>** Activate process.")
+                run('internals.applicationDidBecomeActive()');
+                state = internals.nowPlayingState;
+                testExpected('state.haveEverRegisteredAsNowPlayingApplication', false);
+
+                endTest();
+            });
+
+        </script>
+    </head>
+    <body>
+        <video controls></video>
+        <p>NowPlaying status should not be updated when no media is active.</p>
+    </body>
+</html>
index 8e02f61..4b0f85b 100644 (file)
@@ -1162,6 +1162,7 @@ webkit.org/b/168466 http/tests/security/bypassing-cors-checks-for-extension-urls
 
 # Currently enabled on Mac only
 media/media-usage-state.html [ Skip ]
+media/now-playing-status-without-media.html [ Skip ]
 
 # No support for WebGPU yet
 webkit.org/b/191005 webgpu/ [ Skip ]
index 12b4a39..1a3b863 100644 (file)
@@ -196,8 +196,9 @@ fast/css/read-only-read-write-input-basics.html [ ImageOnlyFailure ]
 fast/forms/color [ Skip ]
 imported/w3c/web-platform-tests/html/semantics/forms/the-input-element/color.html [ Skip ]
 
-# Audio session is a singleton
+# Audio session and media session manager are a singletons
 platform/mac/media/media-source/media-source-change-source.html [ Skip ]
+media/now-playing-status-without-media.html [ Skip ]
 
 #//////////////////////////////////////////////////////////////////////////////////////////
 # End features not supported in WebKit1
index 03a35e3..80267db 100644 (file)
@@ -1163,6 +1163,7 @@ media/track/track-in-band-cues-added-once.html [ Skip ] # Timeout
 
 # Currently enabled on Mac only
 media/media-usage-state.html [ Skip ]
+media/now-playing-status-without-media.html [ Skip ]
 
 ################################################################################
 ############################   End Media Failures   ############################
index 1e5b76a..f96ef60 100644 (file)
@@ -724,6 +724,7 @@ webkit.org/b/210263 fast/layoutformattingcontext/out-of-flow-positioned-line-bre
 
 # Currently enabled on Mac only
 media/media-usage-state.html [ Skip ]
+media/now-playing-status-without-media.html [ Skip ]
 
 webkit.org/b/210487 http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction-database.php [ Failure ]
 webkit.org/b/210487 http/tests/resourceLoadStatistics/switch-session-on-navigation-to-prevalent-with-interaction.php [ Failure ]
index 5fa7aaf..eb70438 100644 (file)
@@ -1,3 +1,27 @@
+2020-05-14  Eric Carlson  <eric.carlson@apple.com>
+
+        [Cocoa] Don't clear NowPlaying state unless it was set
+        https://bugs.webkit.org/show_bug.cgi?id=211899
+        <rdar://problem/62249870>
+
+        Reviewed by Jer Noble.
+
+        Test: media/now-playing-status-without-media.html
+
+        * platform/audio/PlatformMediaSessionManager.h:
+        (WebCore::PlatformMediaSessionManager::haveEverRegisteredAsNowPlayingApplication const): Method
+        added for testing.
+
+        * platform/audio/cocoa/MediaSessionManagerCocoa.h:
+        * platform/audio/cocoa/MediaSessionManagerCocoa.mm:
+        (WebCore::MediaSessionManagerCocoa::updateNowPlayingInfo): Don't clear NowPlaying state unless
+        it was setup in the first place.
+
+        * testing/Internals.cpp:
+        (WebCore::Internals::nowPlayingState const): Add new property.
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2020-05-14  Andres Gonzalez  <andresg_22@apple.com>
 
         AXCoreObject font comparison methods should take another AXCoreObject instead of a RenderObject.
index c66d487..34299b1 100644 (file)
@@ -72,6 +72,7 @@ public:
     virtual double lastUpdatedNowPlayingElapsedTime() const { return NAN; }
     virtual MediaSessionIdentifier lastUpdatedNowPlayingInfoUniqueIdentifier() const { return { }; }
     virtual bool registeredAsNowPlayingApplication() const { return false; }
+    virtual bool haveEverRegisteredAsNowPlayingApplication() const { return false; }
     virtual void prepareToSendUserMediaPermissionRequest() { }
 
     bool willIgnoreSystemInterruptions() const { return m_willIgnoreSystemInterruptions; }
index 76399ff..27516de 100644 (file)
@@ -55,6 +55,8 @@ public:
     double lastUpdatedNowPlayingElapsedTime() const final { return m_lastUpdatedNowPlayingElapsedTime; }
     MediaSessionIdentifier lastUpdatedNowPlayingInfoUniqueIdentifier() const final { return m_lastUpdatedNowPlayingInfoUniqueIdentifier; }
     bool registeredAsNowPlayingApplication() const final { return m_registeredAsNowPlayingApplication; }
+    bool haveEverRegisteredAsNowPlayingApplication() const final { return m_haveEverRegisteredAsNowPlayingApplication; }
+
     void prepareToSendUserMediaPermissionRequest() final;
 
     static WEBCORE_EXPORT void clearNowPlayingInfo();
@@ -100,6 +102,7 @@ private:
 
     bool m_nowPlayingActive { false };
     bool m_registeredAsNowPlayingApplication { false };
+    bool m_haveEverRegisteredAsNowPlayingApplication { false };
 
     // For testing purposes only.
     String m_lastUpdatedNowPlayingTitle;
index 8852ed2..c80f2b9 100644 (file)
@@ -322,8 +322,11 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
         nowPlayingInfo = session->nowPlayingInfo();
 
     if (!nowPlayingInfo) {
-        ALWAYS_LOG(LOGIDENTIFIER, "clearing now playing info");
-        platformStrategies()->mediaStrategy().clearNowPlayingInfo();
+
+        if (m_registeredAsNowPlayingApplication) {
+            ALWAYS_LOG(LOGIDENTIFIER, "clearing now playing info");
+            platformStrategies()->mediaStrategy().clearNowPlayingInfo();
+        }
 
         m_registeredAsNowPlayingApplication = false;
         m_nowPlayingActive = false;
@@ -335,8 +338,7 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
         return;
     }
 
-    ALWAYS_LOG(LOGIDENTIFIER, "title = \"", nowPlayingInfo->title, "\", isPlaying = ", nowPlayingInfo->isPlaying, ", duration = ", nowPlayingInfo->duration, ", now = ", nowPlayingInfo->currentTime, ", id = ", nowPlayingInfo->uniqueIdentifier.toUInt64(), ", registered = ", m_registeredAsNowPlayingApplication);
-
+    m_haveEverRegisteredAsNowPlayingApplication = true;
     platformStrategies()->mediaStrategy().setNowPlayingInfo(!m_registeredAsNowPlayingApplication, *nowPlayingInfo);
 
     if (!m_registeredAsNowPlayingApplication) {
@@ -344,6 +346,8 @@ void MediaSessionManagerCocoa::updateNowPlayingInfo()
         providePresentingApplicationPIDIfNecessary();
     }
 
+    ALWAYS_LOG(LOGIDENTIFIER, "title = \"", nowPlayingInfo->title, "\", isPlaying = ", nowPlayingInfo->isPlaying, ", duration = ", nowPlayingInfo->duration, ", now = ", nowPlayingInfo->currentTime, ", id = ", nowPlayingInfo->uniqueIdentifier.toUInt64(), ", registered = ", m_registeredAsNowPlayingApplication);
+
     if (!nowPlayingInfo->title.isEmpty())
         m_lastUpdatedNowPlayingTitle = nowPlayingInfo->title;
 
index b2a0013..6ec7b48 100644 (file)
@@ -4282,7 +4282,8 @@ ExceptionOr<Internals::NowPlayingState> Internals::nowPlayingState() const
         PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingElapsedTime(),
         PlatformMediaSessionManager::sharedManager().lastUpdatedNowPlayingInfoUniqueIdentifier().toUInt64(),
         PlatformMediaSessionManager::sharedManager().hasActiveNowPlayingSession(),
-        PlatformMediaSessionManager::sharedManager().registeredAsNowPlayingApplication()
+        PlatformMediaSessionManager::sharedManager().registeredAsNowPlayingApplication(),
+        PlatformMediaSessionManager::sharedManager().haveEverRegisteredAsNowPlayingApplication()
     } };
 #else
     return Exception { InvalidAccessError };
index d5e06a2..11971bd 100644 (file)
@@ -830,6 +830,7 @@ public:
         uint64_t uniqueIdentifier;
         bool hasActiveSession;
         bool registeredAsNowPlayingApplication;
+        bool haveEverRegisteredAsNowPlayingApplication;
     };
     ExceptionOr<NowPlayingState> nowPlayingState() const;
 
index a912ecc..c02b4dd 100644 (file)
@@ -105,12 +105,13 @@ enum CompositingPolicy {
     Conditional=VIDEO,
     JSGenerateToJSObject,
 ] dictionary NowPlayingState {
-    boolean hasActiveSession;
-    boolean registeredAsNowPlayingApplication;
     DOMString title;
     unrestricted double duration;
     unrestricted double elapsedTime;
     unsigned long long uniqueIdentifier;
+    boolean hasActiveSession;
+    boolean registeredAsNowPlayingApplication;
+    boolean haveEverRegisteredAsNowPlayingApplication;
 };
 
 [