Title: [206771] trunk
Revision
206771
Author
[email protected]
Date
2016-10-04 08:35:30 -0700 (Tue, 04 Oct 2016)

Log Message

Media controls are displayed in the incorrect state momentarily after switching between tabs playing media
https://bugs.webkit.org/show_bug.cgi?id=162766
<rdar://problem/28533523>

Reviewed by Jer Noble.

Source/WebCore:

When showing Now Playing controls for a media session, we should first set up the Now Playing info and
playback state before telling MediaRemote to make the session visible. This is WebKit work in ensuring that
when switching Now Playing sessions by switching tabs, we do not first display an invalid Now Playing state
before updating to the expected state.

Adds 2 new WebKit API tests in NowPlayingControlsTests: NowPlayingControlsHideAfterShowingClearsInfo and
NowPlayingControlsClearInfoAfterSessionIsNoLongerValid.

* platform/audio/PlatformMediaSessionManager.h:
(WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingTitle):
(WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingDuration):
(WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingElapsedTime):
(WebCore::PlatformMediaSessionManager::hasActiveNowPlayingSession): Deleted.
* platform/audio/mac/MediaSessionManagerMac.h:
* platform/audio/mac/MediaSessionManagerMac.mm:
(WebCore::MediaSessionManagerMac::updateNowPlayingInfo):

Source/WebKit2:

Plumbs some more Now Playing information from the web process to the UI process for testing purposes. See
WebCore ChangeLog for more details.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _handleActiveNowPlayingSessionInfoResponse:title:duration:elapsedTime:]):
(-[WKWebView _handleActiveNowPlayingSessionInfoResponse:]): Deleted.
* UIProcess/API/Cocoa/WKWebViewPrivate.h:
* UIProcess/PageClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleActiveNowPlayingSessionInfoResponse):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::handleActiveNowPlayingSessionInfoResponse):
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::requestActiveNowPlayingSessionInfo):

Tools:

Adds new tests and tweaks existing tests to verify last updated Now Playing information.

* TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm:
(-[NowPlayingTestWebView _handleActiveNowPlayingSessionInfoResponse:title:duration:elapsedTime:]):
(TestWebKitAPI::TEST):
(-[NowPlayingTestWebView _handleActiveNowPlayingSessionInfoResponse:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (206770 => 206771)


--- trunk/Source/WebCore/ChangeLog	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebCore/ChangeLog	2016-10-04 15:35:30 UTC (rev 206771)
@@ -1,3 +1,28 @@
+2016-10-04  Wenson Hsieh  <[email protected]>
+
+        Media controls are displayed in the incorrect state momentarily after switching between tabs playing media
+        https://bugs.webkit.org/show_bug.cgi?id=162766
+        <rdar://problem/28533523>
+
+        Reviewed by Jer Noble.
+
+        When showing Now Playing controls for a media session, we should first set up the Now Playing info and
+        playback state before telling MediaRemote to make the session visible. This is WebKit work in ensuring that
+        when switching Now Playing sessions by switching tabs, we do not first display an invalid Now Playing state
+        before updating to the expected state.
+
+        Adds 2 new WebKit API tests in NowPlayingControlsTests: NowPlayingControlsHideAfterShowingClearsInfo and
+        NowPlayingControlsClearInfoAfterSessionIsNoLongerValid.
+
+        * platform/audio/PlatformMediaSessionManager.h:
+        (WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingTitle):
+        (WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingDuration):
+        (WebCore::PlatformMediaSessionManager::lastUpdatedNowPlayingElapsedTime):
+        (WebCore::PlatformMediaSessionManager::hasActiveNowPlayingSession): Deleted.
+        * platform/audio/mac/MediaSessionManagerMac.h:
+        * platform/audio/mac/MediaSessionManagerMac.mm:
+        (WebCore::MediaSessionManagerMac::updateNowPlayingInfo):
+
 2016-10-04  Youenn Fablet  <[email protected]>
 
         [Fetch API] ReadableStream should be errored with TypeError values

Modified: trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (206770 => 206771)


--- trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebCore/platform/audio/PlatformMediaSessionManager.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -58,6 +58,9 @@
     bool canProduceAudio() const;
 
     WEBCORE_EXPORT virtual bool hasActiveNowPlayingSession() const { return false; }
+    WEBCORE_EXPORT virtual String lastUpdatedNowPlayingTitle() const { return emptyString(); }
+    WEBCORE_EXPORT virtual double lastUpdatedNowPlayingDuration() const { return NAN; }
+    WEBCORE_EXPORT virtual double lastUpdatedNowPlayingElapsedTime() const { return NAN; }
 
     bool willIgnoreSystemInterruptions() const { return m_willIgnoreSystemInterruptions; }
     void setWillIgnoreSystemInterruptions(bool ignore) { m_willIgnoreSystemInterruptions = ignore; }

Modified: trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h (206770 => 206771)


--- trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -37,6 +37,9 @@
     virtual ~MediaSessionManagerMac();
 
     bool hasActiveNowPlayingSession() const override { return m_nowPlayingActive; }
+    String lastUpdatedNowPlayingTitle() const override { return m_lastUpdatedNowPlayingTitle; }
+    double lastUpdatedNowPlayingDuration() const override { return m_lastUpdatedNowPlayingDuration; }
+    double lastUpdatedNowPlayingElapsedTime() const override { return m_lastUpdatedNowPlayingElapsedTime; }
 
 private:
     friend class PlatformMediaSessionManager;
@@ -57,6 +60,12 @@
 
     bool m_nowPlayingActive { false };
     bool m_isInBackground { false };
+
+    // For testing purposes only.
+    String m_lastUpdatedNowPlayingTitle;
+    double m_lastUpdatedNowPlayingDuration { NAN };
+    double m_lastUpdatedNowPlayingElapsedTime { NAN };
+
     GenericTaskQueue<Timer> m_nowPlayingUpdateTaskQueue;
 };
 

Modified: trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (206770 => 206771)


--- trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm	2016-10-04 15:35:30 UTC (rev 206771)
@@ -136,6 +136,9 @@
             LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - clearing now playing info");
             MRMediaRemoteSetNowPlayingInfo(nullptr);
             m_nowPlayingActive = false;
+            m_lastUpdatedNowPlayingTitle = emptyString();
+            m_lastUpdatedNowPlayingDuration = NAN;
+            m_lastUpdatedNowPlayingElapsedTime = NAN;
             MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), kMRPlaybackStateStopped, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
 #if LOG_DISABLED
                 UNUSED_PARAM(error);
@@ -153,20 +156,20 @@
         MRMediaRemoteSetCanBeNowPlayingApplication(true);
     });
 
-    if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility())
-        MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityAlwaysVisible);
-
     String title = currentSession->title();
     double duration = currentSession->duration();
     double rate = currentSession->state() == PlatformMediaSession::Playing ? 1 : 0;
     auto info = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
 
-    if (!title.isEmpty())
+    if (!title.isEmpty()) {
         CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoTitle, title.createCFString().get());
+        m_lastUpdatedNowPlayingTitle = title;
+    }
 
     if (std::isfinite(duration) && duration != MediaPlayer::invalidTime()) {
         auto cfDuration = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &duration));
         CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoDuration, cfDuration.get());
+        m_lastUpdatedNowPlayingDuration = duration;
     }
 
     auto cfRate = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &rate);
@@ -176,6 +179,7 @@
     if (std::isfinite(currentTime) && currentTime != MediaPlayer::invalidTime()) {
         auto cfCurrentTime = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &currentTime));
         CFDictionarySetValue(info.get(), kMRMediaRemoteNowPlayingInfoElapsedTime, cfCurrentTime.get());
+        m_lastUpdatedNowPlayingElapsedTime = currentTime;
     }
 
     LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - title = \"%s\", rate = %f, duration = %f, now = %f",
@@ -195,6 +199,9 @@
 #endif
     });
     MRMediaRemoteSetNowPlayingInfo(info.get());
+
+    if (canLoad_MediaRemote_MRMediaRemoteSetNowPlayingVisibility())
+        MRMediaRemoteSetNowPlayingVisibility(MRMediaRemoteGetLocalOrigin(), MRNowPlayingClientVisibilityAlwaysVisible);
 #endif
 }
 

Modified: trunk/Source/WebKit2/ChangeLog (206770 => 206771)


--- trunk/Source/WebKit2/ChangeLog	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/ChangeLog	2016-10-04 15:35:30 UTC (rev 206771)
@@ -1,3 +1,29 @@
+2016-10-04  Wenson Hsieh  <[email protected]>
+
+        Media controls are displayed in the incorrect state momentarily after switching between tabs playing media
+        https://bugs.webkit.org/show_bug.cgi?id=162766
+        <rdar://problem/28533523>
+
+        Reviewed by Jer Noble.
+
+        Plumbs some more Now Playing information from the web process to the UI process for testing purposes. See
+        WebCore ChangeLog for more details.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _handleActiveNowPlayingSessionInfoResponse:title:duration:elapsedTime:]):
+        (-[WKWebView _handleActiveNowPlayingSessionInfoResponse:]): Deleted.
+        * UIProcess/API/Cocoa/WKWebViewPrivate.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleActiveNowPlayingSessionInfoResponse):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::handleActiveNowPlayingSessionInfoResponse):
+        * WebProcess/WebPage/mac/WebPageMac.mm:
+        (WebKit::WebPage::requestActiveNowPlayingSessionInfo):
+
 2016-10-04  Zan Dobersek  <[email protected]>
 
         Unreviewed GTK+ build fix.

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-04 15:35:30 UTC (rev 206771)
@@ -4591,7 +4591,7 @@
         _page->requestActiveNowPlayingSessionInfo();
 }
 
-- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime
 {
     // Overridden by subclasses.
 }

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -282,7 +282,7 @@
 - (void)_didUpdateCandidateListVisibility:(BOOL)visible WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 @property (nonatomic, readonly) BOOL _shouldRequestCandidates WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 - (void)_requestActiveNowPlayingSessionInfo WK_API_AVAILABLE(macosx(WK_MAC_TBA));
-- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession WK_API_AVAILABLE(macosx(WK_MAC_TBA));
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime WK_API_AVAILABLE(macosx(WK_MAC_TBA));
 #endif
 
 - (void)_doAfterNextPresentationUpdate:(void (^)(void))updateBlock WK_API_AVAILABLE(macosx(10.12), ios(10.0));

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -248,7 +248,7 @@
     virtual void recommendedScrollbarStyleDidChange(WebCore::ScrollbarStyle) = 0;
     virtual void removeNavigationGestureSnapshot() = 0;
     virtual void handleControlledElementIDResponse(const String&) = 0;
-    virtual void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) = 0;
+    virtual void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime) = 0;
 
     virtual CGRect boundsOfLayerInLayerBackedWindowCoordinates(CALayer *) const = 0;
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-04 15:35:30 UTC (rev 206771)
@@ -6387,9 +6387,9 @@
     m_process->send(Messages::WebPage::RequestActiveNowPlayingSessionInfo(), m_pageID);
 }
 
-void WebPageProxy::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) const
+void WebPageProxy::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime) const
 {
-    m_pageClient.handleActiveNowPlayingSessionInfoResponse(hasActiveSession);
+    m_pageClient.handleActiveNowPlayingSessionInfoResponse(hasActiveSession, title, duration, elapsedTime);
 }
 
 void WebPageProxy::handleControlledElementIDResponse(const String& identifier) const

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -1036,7 +1036,7 @@
     void requestControlledElementID() const;
     void handleControlledElementIDResponse(const String&) const;
     void requestActiveNowPlayingSessionInfo();
-    void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) const;
+    void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime) const;
     bool isPlayingVideoInEnhancedFullscreen() const;
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.messages.in	2016-10-04 15:35:30 UTC (rev 206771)
@@ -470,6 +470,6 @@
 
 #if PLATFORM(MAC)
     DidHandleAcceptedCandidate()
-    HandleActiveNowPlayingSessionInfoResponse(bool hasActiveSession)
+    HandleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, String title, double duration, double elapsedTime)
 #endif
 }

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2016-10-04 15:35:30 UTC (rev 206771)
@@ -207,7 +207,7 @@
     void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType) override;
     void removeNavigationGestureSnapshot() override;
     void handleControlledElementIDResponse(const String&) override;
-    void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession) override;
+    void handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime) override;
 
     void didPerformImmediateActionHitTest(const WebHitTestResultData&, bool contentPreventsDefault, API::Object*) override;
     void* immediateActionAnimationControllerForHitTestResult(RefPtr<API::HitTestResult>, uint64_t, RefPtr<API::Object>) override;

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (206770 => 206771)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2016-10-04 15:35:30 UTC (rev 206771)
@@ -759,10 +759,10 @@
 #endif
 }
 
-void PageClientImpl::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession)
+void PageClientImpl::handleActiveNowPlayingSessionInfoResponse(bool hasActiveSession, const String& title, double duration, double elapsedTime)
 {
 #if WK_API_ENABLED
-    [m_webView _handleActiveNowPlayingSessionInfoResponse:hasActiveSession];
+    [m_webView _handleActiveNowPlayingSessionInfoResponse:hasActiveSession title:nsStringFromWebCoreString(title) duration:duration elapsedTime:elapsedTime];
 #endif
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm (206770 => 206771)


--- trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Source/WebKit2/WebProcess/WebPage/mac/WebPageMac.mm	2016-10-04 15:35:30 UTC (rev 206771)
@@ -164,10 +164,17 @@
 void WebPage::requestActiveNowPlayingSessionInfo()
 {
     bool hasActiveSession = false;
-    if (auto* sharedManager = WebCore::PlatformMediaSessionManager::sharedManagerIfExists())
+    String title = emptyString();
+    double duration = NAN;
+    double elapsedTime = NAN;
+    if (auto* sharedManager = WebCore::PlatformMediaSessionManager::sharedManagerIfExists()) {
         hasActiveSession = sharedManager->hasActiveNowPlayingSession();
+        title = sharedManager->lastUpdatedNowPlayingTitle();
+        duration = sharedManager->lastUpdatedNowPlayingDuration();
+        elapsedTime = sharedManager->lastUpdatedNowPlayingElapsedTime();
+    }
 
-    send(Messages::WebPageProxy::HandleActiveNowPlayingSessionInfoResponse(hasActiveSession));
+    send(Messages::WebPageProxy::HandleActiveNowPlayingSessionInfoResponse(hasActiveSession, title, duration, elapsedTime));
 }
 
 NSObject *WebPage::accessibilityObjectForMainFramePlugin()

Modified: trunk/Tools/ChangeLog (206770 => 206771)


--- trunk/Tools/ChangeLog	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Tools/ChangeLog	2016-10-04 15:35:30 UTC (rev 206771)
@@ -1,3 +1,19 @@
+2016-10-04  Wenson Hsieh  <[email protected]>
+
+        Media controls are displayed in the incorrect state momentarily after switching between tabs playing media
+        https://bugs.webkit.org/show_bug.cgi?id=162766
+        <rdar://problem/28533523>
+
+        Reviewed by Jer Noble.
+
+        Adds new tests and tweaks existing tests to verify last updated Now Playing information.
+
+        * TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm:
+        (-[NowPlayingTestWebView _handleActiveNowPlayingSessionInfoResponse:title:duration:elapsedTime:]):
+        (TestWebKitAPI::TEST):
+        (-[NowPlayingTestWebView _handleActiveNowPlayingSessionInfoResponse:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html:
+
 2016-10-03  Alex Christensen  <[email protected]>
 
         URLParser should ignore tabs at all locations

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm (206770 => 206771)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/NowPlayingControlsTests.mm	2016-10-04 15:35:30 UTC (rev 206771)
@@ -35,6 +35,9 @@
 
 @interface NowPlayingTestWebView : TestWKWebView
 @property (nonatomic, readonly) BOOL hasActiveNowPlayingSession;
+@property (readonly) NSString *lastUpdatedTitle;
+@property (readonly) double lastUpdatedDuration;
+@property (readonly) double lastUpdatedElapsedTime;
 @end
 
 @implementation NowPlayingTestWebView {
@@ -59,9 +62,13 @@
     }
 }
 
-- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession
+- (void)_handleActiveNowPlayingSessionInfoResponse:(BOOL)hasActiveSession title:(NSString *)title duration:(double)duration elapsedTime:(double)elapsedTime
 {
     _hasActiveNowPlayingSession = hasActiveSession;
+    _lastUpdatedTitle = [title copy];
+    _lastUpdatedDuration = duration;
+    _lastUpdatedElapsedTime = elapsedTime;
+
     _receivedNowPlayingInfoResponse = true;
 }
 @end
@@ -79,6 +86,10 @@
     [webView.window setIsVisible:YES];
     [webView.window makeKeyWindow];
     [webView expectHasActiveNowPlayingSession:NO];
+
+    ASSERT_STREQ("", webView.lastUpdatedTitle.UTF8String);
+    ASSERT_TRUE(isnan(webView.lastUpdatedDuration));
+    ASSERT_TRUE(isnan(webView.lastUpdatedElapsedTime));
 }
 
 TEST(NowPlayingControlsTests, NowPlayingControlsShowForBackgroundPage)
@@ -92,8 +103,54 @@
     [webView.window setIsVisible:NO];
     [webView.window resignKeyWindow];
     [webView expectHasActiveNowPlayingSession:YES];
+
+    ASSERT_STREQ("foo", webView.lastUpdatedTitle.UTF8String);
+    ASSERT_EQ(10, webView.lastUpdatedDuration);
+    ASSERT_GE(webView.lastUpdatedElapsedTime, 0);
 }
 
+TEST(NowPlayingControlsTests, NowPlayingControlsHideAfterShowingClearsInfo)
+{
+    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
+    configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    NowPlayingTestWebView *webView = [[NowPlayingTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration];
+    [webView loadTestPageNamed:@"large-video-test-now-playing"];
+    [webView waitForMessage:@"playing"];
+
+    [webView.window setIsVisible:NO];
+    [webView.window resignKeyWindow];
+
+    [webView expectHasActiveNowPlayingSession:YES];
+
+    [webView.window setIsVisible:YES];
+    [webView.window makeKeyWindow];
+
+    [webView expectHasActiveNowPlayingSession:NO];
+
+    ASSERT_STREQ("", webView.lastUpdatedTitle.UTF8String);
+    ASSERT_TRUE(isnan(webView.lastUpdatedDuration));
+    ASSERT_TRUE(isnan(webView.lastUpdatedElapsedTime));
+}
+
+TEST(NowPlayingControlsTests, NowPlayingControlsClearInfoAfterSessionIsNoLongerValid)
+{
+    WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc] init];
+    configuration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
+    NowPlayingTestWebView *webView = [[NowPlayingTestWebView alloc] initWithFrame:NSMakeRect(0, 0, 480, 320) configuration:configuration];
+    [webView loadTestPageNamed:@"large-video-test-now-playing"];
+    [webView waitForMessage:@"playing"];
+
+    [webView mouseDownAtPoint:NSMakePoint(240, 160) simulatePressure:YES];
+    [webView.window setIsVisible:NO];
+    [webView.window resignKeyWindow];
+
+    [webView expectHasActiveNowPlayingSession:NO];
+
+    ASSERT_STREQ("", webView.lastUpdatedTitle.UTF8String);
+    ASSERT_TRUE(isnan(webView.lastUpdatedDuration));
+    ASSERT_TRUE(isnan(webView.lastUpdatedElapsedTime));
+}
+
 } // namespace TestWebKitAPI
 
 #endif // WK_API_ENABLED && PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101201

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html (206770 => 206771)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html	2016-10-04 15:17:34 UTC (rev 206770)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/large-video-test-now-playing.html	2016-10-04 15:35:30 UTC (rev 206771)
@@ -7,6 +7,10 @@
             height: 320px;
             position: absolute;
         }
+
+        body {
+            margin: 0;
+        }
     </style>
     <script>
         function playing() {
@@ -17,9 +21,13 @@
                 }
             }, 0);
         }
+
+        function mousedown() {
+            document.querySelector("video").muted = true;
+        }
     </script>
 </head>
 <body>
-    <video autoplay _onplaying_=playing()><source src=""
+    <video autoplay title="foo" _onmousedown_=mousedown() _onplaying_=playing()><source src=""
 </body>
 <html>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to