Indicate presence of audio when handling autoplay events.
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Apr 2017 00:02:59 +0000 (00:02 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 26 Apr 2017 00:02:59 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171227

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::handleAutoplayEvent):
(WebCore::HTMLMediaElement::playInternal):
(WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
(WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
(WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):
(WebCore::HTMLMediaElement::setPlaybackWithoutUserGesture):
* html/HTMLMediaElement.h:
* page/AutoplayEvent.h:
* page/ChromeClient.h:

Source/WebKit2:

* UIProcess/API/APIUIClient.h:
(API::UIClient::handleAutoplayEvent):
* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageUIClient):
* UIProcess/API/C/WKPageUIClient.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::handleAutoplayEvent):
* UIProcess/WebPageProxy.h:
* UIProcess/WebPageProxy.messages.in:
* WebProcess/WebCoreSupport/WebChromeClient.cpp:
(WebKit::WebChromeClient::handleAutoplayEvent):
* WebProcess/WebCoreSupport/WebChromeClient.h:

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

17 files changed:
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/AutoplayEvent.h
Source/WebCore/page/ChromeClient.h
Source/WebKit2/ChangeLog
Source/WebKit2/Scripts/webkit/messages.py
Source/WebKit2/Shared/WebCoreArgumentCoders.h
Source/WebKit2/UIProcess/API/APIUIClient.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPageUIClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/WebPageProxy.messages.in
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp
Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

index 57168b3..da211e5 100644 (file)
@@ -1,3 +1,23 @@
+2017-04-24  Matt Rajca  <mrajca@apple.com>
+
+        Indicate presence of audio when handling autoplay events.
+        https://bugs.webkit.org/show_bug.cgi?id=171227
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::handleAutoplayEvent):
+        (WebCore::HTMLMediaElement::playInternal):
+        (WebCore::HTMLMediaElement::mediaPlayerTimeChanged):
+        (WebCore::HTMLMediaElement::stopWithoutDestroyingMediaPlayer):
+        (WebCore::HTMLMediaElement::userDidInterfereWithAutoplay):
+        (WebCore::HTMLMediaElement::setPlaybackWithoutUserGesture):
+        * html/HTMLMediaElement.h:
+        * page/AutoplayEvent.h:
+        * page/ChromeClient.h:
+
 2017-04-25  Aakash Jain  <aakash_jain@apple.com>
 
         WebCore.framework should restrict allowable_clients
index c9c4906..a8fb206 100644 (file)
@@ -3242,8 +3242,7 @@ bool HTMLMediaElement::playInternal()
 
     if (ScriptController::processingUserGestureForMedia()) {
         if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Prevented) {
-            if (Page* page = document().page())
-                page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
+            handleAutoplayEvent(AutoplayEvent::DidPlayMediaPreventedFromPlaying);
             setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
         }
     } else
@@ -3383,16 +3382,16 @@ void HTMLMediaElement::setMuted(bool muted)
 
     bool mutedStateChanged = m_muted != muted;
     if (mutedStateChanged || !m_explicitlyMuted) {
-        m_muted = muted;
-        m_explicitlyMuted = true;
-
         if (ScriptController::processingUserGestureForMedia()) {
             removeBehaviorsRestrictionsAfterFirstUserGesture(MediaElementSession::AllRestrictions & ~MediaElementSession::RequireUserGestureToControlControlsManager);
 
-            if (hasAudio() && m_muted)
+            if (hasAudio() && muted)
                 userDidInterfereWithAutoplay();
         }
 
+        m_muted = muted;
+        m_explicitlyMuted = true;
+
         // Avoid recursion when the player reports volume changes.
         if (!processingMediaPlayerCallback()) {
             if (m_player) {
@@ -4467,10 +4466,9 @@ void HTMLMediaElement::mediaPlayerTimeChanged(MediaPlayer*)
                 if (!wasSeeking)
                     addBehaviorRestrictionsOnEndIfNecessary();
 
-                if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
-                    if (Page* page = document().page())
-                        page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
-                }
+                if (m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started)
+                    handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
+
                 setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
             }
             // If the media element has a current media controller, then report the controller state
@@ -5230,18 +5228,17 @@ void HTMLMediaElement::stopWithoutDestroyingMediaPlayer()
     setPausedInternal(true);
     m_mediaSession->clientWillPausePlayback();
 
-    if (Page* page = document().page()) {
-        switch (m_playbackWithoutUserGesture) {
-        case PlaybackWithoutUserGesture::Started:
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
-            break;
-        case PlaybackWithoutUserGesture::Prevented:
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
-            break;
-        case PlaybackWithoutUserGesture::None:
-            break;
-        }
+    switch (m_playbackWithoutUserGesture) {
+    case PlaybackWithoutUserGesture::Started:
+        handleAutoplayEvent(AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference);
+        break;
+    case PlaybackWithoutUserGesture::Prevented:
+        handleAutoplayEvent(AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying);
+        break;
+    case PlaybackWithoutUserGesture::None:
+        break;
     }
+
     setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
 
     userCancelledLoad();
@@ -7184,6 +7181,14 @@ MediaProducer::MediaStateFlags HTMLMediaElement::mediaState() const
     return state;
 }
 
+void HTMLMediaElement::handleAutoplayEvent(AutoplayEvent event)
+{
+    if (Page* page = document().page()) {
+        bool hasAudio = this->hasAudio() && !muted() && volume();
+        page->chrome().client().handleAutoplayEvent(event, hasAudio ? AutoplayEventFlags::HasAudio : OptionSet<AutoplayEventFlags>());
+    }
+}
+
 void HTMLMediaElement::userDidInterfereWithAutoplay()
 {
     if (m_playbackWithoutUserGesture != PlaybackWithoutUserGesture::Started)
@@ -7193,9 +7198,7 @@ void HTMLMediaElement::userDidInterfereWithAutoplay()
     if (currentTime() - m_playbackWithoutUserGestureStartedTime->toDouble() > 10)
         return;
 
-    if (Page* page = document().page())
-        page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
-
+    handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
     setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture::None);
 }
 
@@ -7214,9 +7217,7 @@ void HTMLMediaElement::setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture
         m_playbackWithoutUserGestureStartedTime = std::nullopt;
 
         dispatchPlayPauseEventsIfNeedsQuirks();
-
-        if (Page* page = document().page())
-            page->chrome().client().handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
+        handleAutoplayEvent(AutoplayEvent::DidPreventMediaFromPlaying);
 
         break;
     }
index 3fed9b1..96e0a95 100644 (file)
@@ -28,6 +28,7 @@
 #if ENABLE(VIDEO)
 
 #include "ActiveDOMObject.h"
+#include "AutoplayEvent.h"
 #include "GenericEventQueue.h"
 #include "GenericTaskQueue.h"
 #include "HTMLElement.h"
@@ -755,6 +756,7 @@ private:
     enum class PlaybackWithoutUserGesture { None, Started, Prevented };
     void setPlaybackWithoutUserGesture(PlaybackWithoutUserGesture);
     void userDidInterfereWithAutoplay();
+    void handleAutoplayEvent(AutoplayEvent);
 
     MediaTime minTimeSeekable() const;
     MediaTime maxTimeSeekable() const;
index 866f437..6931039 100644 (file)
@@ -35,4 +35,8 @@ enum class AutoplayEvent {
     UserNeverPlayedMediaPreventedFromPlaying,
 };
 
+enum class AutoplayEventFlags {
+    HasAudio = 1 << 0,
+};
+
 } // namespace WebCore
index b6fdc9a..90aa090 100644 (file)
@@ -422,7 +422,7 @@ public:
     virtual bool shouldUseTiledBackingForFrameView(const FrameView&) const { return false; }
 
     virtual void isPlayingMediaDidChange(MediaProducer::MediaStateFlags, uint64_t) { }
-    virtual void handleAutoplayEvent(AutoplayEvent) { }
+    virtual void handleAutoplayEvent(AutoplayEvent, OptionSet<AutoplayEventFlags>) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void hasMediaSessionWithActiveMediaElementsDidChange(bool) { }
index 8a909ed..00338cd 100644 (file)
@@ -1,3 +1,23 @@
+2017-04-24  Matt Rajca  <mrajca@apple.com>
+
+        Indicate presence of audio when handling autoplay events.
+        https://bugs.webkit.org/show_bug.cgi?id=171227
+
+        Reviewed by Alex Christensen.
+
+        * UIProcess/API/APIUIClient.h:
+        (API::UIClient::handleAutoplayEvent):
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageUIClient):
+        * UIProcess/API/C/WKPageUIClient.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::handleAutoplayEvent):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/WebPageProxy.messages.in:
+        * WebProcess/WebCoreSupport/WebChromeClient.cpp:
+        (WebKit::WebChromeClient::handleAutoplayEvent):
+        * WebProcess/WebCoreSupport/WebChromeClient.h:
+
 2017-04-25  Daniel Bates  <dabates@apple.com>
 
         [Cocoa][Win] Enable of X-Content-Type-Options: nosniff header
index 6f86e05..e45ce17 100644 (file)
@@ -348,6 +348,7 @@ def headers_for_type(type):
 
     special_cases = {
         'String': ['<wtf/text/WTFString.h>'],
+        'WebCore::AutoplayEventFlags': ['<WebCore/AutoplayEvent.h>'],
         'WebCore::CompositionUnderline': ['<WebCore/Editor.h>'],
         'WebCore::ExceptionDetails': ['<WebCore/JSDOMExceptionHandling.h>'],
         'WebCore::FileChooserSettings': ['<WebCore/FileChooser.h>'],
index bf8dd75..0f55b8a 100644 (file)
@@ -26,6 +26,7 @@
 #pragma once
 
 #include "ArgumentCoders.h"
+#include <WebCore/AutoplayEvent.h>
 #include <WebCore/CaptureDevice.h>
 #include <WebCore/ColorSpace.h>
 #include <WebCore/DiagnosticLoggingClient.h>
@@ -686,6 +687,17 @@ template<> struct EnumTraits<WebCore::HasInsecureContent> {
     >;
 };
 
+template<> struct EnumTraits<WebCore::AutoplayEvent> {
+    using values = EnumValues<
+        WebCore::AutoplayEvent,
+        WebCore::AutoplayEvent::DidPreventMediaFromPlaying,
+        WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying,
+        WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference,
+        WebCore::AutoplayEvent::UserDidInterfereWithPlayback,
+        WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying
+    >;
+};
+
 template<> struct EnumTraits<WebCore::ShouldSample> {
     using values = EnumValues<
         WebCore::ShouldSample,
index 27d6690..b99677a 100644 (file)
@@ -150,7 +150,7 @@ public:
 
     virtual void isPlayingAudioDidChange(WebKit::WebPageProxy&) { }
     virtual void mediaCaptureStateDidChange(WebCore::MediaProducer::MediaStateFlags) { }
-    virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent) { }
+    virtual void handleAutoplayEvent(WebKit::WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) { }
 
 #if ENABLE(MEDIA_SESSION)
     virtual void mediaSessionMetadataDidChange(WebKit::WebPageProxy&, WebKit::WebMediaSessionMetadata*) { }
index b9a4e07..07b94cf 100644 (file)
@@ -2251,12 +2251,37 @@ void WKPageSetPageUIClient(WKPageRef pageRef, const WKPageUIClientBase* wkClient
         }
 #endif
 
-        void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event) override
+        static WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
+        {
+            WKAutoplayEventFlags wkFlags = kWKAutoplayEventFlagsNone;
+            if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
+                wkFlags |= kWKAutoplayEventFlagsHasAudio;
+
+            return wkFlags;
+        }
+
+        static WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
+        {
+            switch (event) {
+            case WebCore::AutoplayEvent::DidEndMediaPlaybackWithoutUserInterference:
+                return kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference;
+            case WebCore::AutoplayEvent::DidPlayMediaPreventedFromPlaying:
+                return kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying;
+            case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
+                return kWKAutoplayEventDidPreventFromAutoplaying;
+            case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
+                return kWKAutoplayEventUserDidInterfereWithPlayback;
+            case WebCore::AutoplayEvent::UserNeverPlayedMediaPreventedFromPlaying:
+                return kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying;
+            }
+        }
+
+        void handleAutoplayEvent(WebPageProxy& page, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags) override
         {
             if (!m_client.handleAutoplayEvent)
                 return;
 
-            m_client.handleAutoplayEvent(toAPI(&page), static_cast<WKAutoplayEvent>(event), m_client.base.clientInfo);
+            m_client.handleAutoplayEvent(toAPI(&page), toWKAutoplayEvent(event), toWKAutoplayEventFlags(flags), m_client.base.clientInfo);
         }
     };
 
index 23c9988..572cb6a 100644 (file)
@@ -57,6 +57,12 @@ enum {
 };
 typedef uint32_t WKAutoplayEvent;
 
+enum {
+    kWKAutoplayEventFlagsNone = 0,
+    kWKAutoplayEventFlagsHasAudio = 1 << 0,
+};
+typedef uint32_t WKAutoplayEventFlags;
+
 WK_EXPORT WKTypeID WKPageRunBeforeUnloadConfirmPanelResultListenerGetTypeID();
 WK_EXPORT void WKPageRunBeforeUnloadConfirmPanelResultListenerCall(WKPageRunBeforeUnloadConfirmPanelResultListenerRef listener, bool result);
 
@@ -111,7 +117,7 @@ typedef void (*WKPageDecidePolicyForUserMediaPermissionRequestCallback)(WKPageRe
 typedef void (*WKCheckUserMediaPermissionCallback)(WKPageRef page, WKFrameRef frame, WKSecurityOriginRef userMediaDocumentOrigin, WKSecurityOriginRef topLevelDocumentOrigin, WKUserMediaPermissionCheckRef devicesRequest, const void *clientInfo);
 typedef void (*WKPageDidClickAutoFillButtonCallback)(WKPageRef page, WKTypeRef userData, const void *clientInfo);
 typedef void (*WKPageMediaSessionMetadataDidChangeCallback)(WKPageRef page, WKMediaSessionMetadataRef metadata, const void* clientInfo);
-typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, const void* clientInfo);
+typedef void (*WKHandleAutoplayEventCallback)(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo);
 typedef void (*WKFullscreenMayReturnToInlineCallback)(WKPageRef page, const void* clientInfo);
 
 typedef void (*WKRequestPointerLockCallback)(WKPageRef page, const void* clientInfo);
index 1dbec45..74cd4c9 100644 (file)
@@ -6567,9 +6567,9 @@ void WebPageProxy::focusedContentMediaElementDidChange(uint64_t elementID)
 }
 #endif
 
-void WebPageProxy::handleAutoplayEvent(uint32_t event)
+void WebPageProxy::handleAutoplayEvent(WebCore::AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
 {
-    m_uiClient->handleAutoplayEvent(*this, static_cast<AutoplayEvent>(event));
+    m_uiClient->handleAutoplayEvent(*this, event, flags);
 }
 
 #if PLATFORM(MAC)
index 04c35c5..8ae32e0 100644 (file)
@@ -168,6 +168,7 @@ struct TextCheckingResult;
 struct ViewportAttributes;
 struct WindowFeatures;
 
+enum class AutoplayEvent;
 enum class HasInsecureContent;
 enum class ShouldSample;
 
@@ -1070,7 +1071,7 @@ public:
     bool hasActiveAudioStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveAudioCaptureDevice; }
     bool hasActiveVideoStream() const { return m_mediaState & WebCore::MediaProducer::HasActiveVideoCaptureDevice; }
     WebCore::MediaProducer::MediaStateFlags mediaStateFlags() const { return m_mediaState; }
-    void handleAutoplayEvent(uint32_t);
+    void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>);
 
 #if PLATFORM(MAC)
     void videoControlsManagerDidChange();
index e99beb8..b4b9810 100644 (file)
@@ -438,7 +438,7 @@ messages -> WebPageProxy {
 #endif
 
     IsPlayingMediaDidChange(unsigned state, uint64_t sourceElementID)
-    HandleAutoplayEvent(uint32_t event)
+    HandleAutoplayEvent(enum WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
 
 #if ENABLE(MEDIA_SESSION)
     HasMediaSessionWithActiveMediaElementsDidChange(bool state)
index 3593d90..80fe6ae 100644 (file)
@@ -1088,9 +1088,9 @@ void WebChromeClient::isPlayingMediaDidChange(MediaProducer::MediaStateFlags sta
     m_page.send(Messages::WebPageProxy::IsPlayingMediaDidChange(state, sourceElementID));
 }
 
-void WebChromeClient::handleAutoplayEvent(AutoplayEvent event)
+void WebChromeClient::handleAutoplayEvent(AutoplayEvent event, OptionSet<AutoplayEventFlags> flags)
 {
-    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(static_cast<uint32_t>(event)));
+    m_page.send(Messages::WebPageProxy::HandleAutoplayEvent(event, flags));
 }
 
 #if ENABLE(MEDIA_SESSION)
index 576cd79..1c4d6bb 100644 (file)
@@ -297,7 +297,7 @@ private:
     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) const final;
 
     void isPlayingMediaDidChange(WebCore::MediaProducer::MediaStateFlags, uint64_t) final;
-    void handleAutoplayEvent(WebCore::AutoplayEvent) final;
+    void handleAutoplayEvent(WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
 
 #if ENABLE(MEDIA_SESSION)
     void hasMediaSessionWithActiveMediaElementsDidChange(bool) final;
index cb7e8c0..ddb1972 100644 (file)
@@ -51,6 +51,7 @@ static bool receivedAlert;
 
 #if PLATFORM(MAC)
 static std::optional<WKAutoplayEvent> receivedAutoplayEvent;
+static std::optional<WKAutoplayEventFlags> receivedAutoplayEventFlags;
 #endif
 
 static size_t alertCount;
@@ -280,8 +281,9 @@ TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
 }
 
 #if PLATFORM(MAC)
-static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, const void* clientInfo)
+static void handleAutoplayEvent(WKPageRef page, WKAutoplayEvent event, WKAutoplayEventFlags flags, const void* clientInfo)
 {
+    receivedAutoplayEventFlags = flags;
     receivedAutoplayEvent = event;
 }
 
@@ -320,6 +322,7 @@ TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -328,10 +331,12 @@ TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
     [webView loadRequest:autoplayRequest];
     [webView waitForMessage:@"loaded"];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadHTMLString:@"" baseURL:nil];
@@ -359,6 +364,7 @@ TEST(WebKit2, WebsitePoliciesPlayAfterPreventedAutoplay)
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaPreventedFromAutoplaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesPlayingWithoutInterference)
@@ -389,11 +395,13 @@ TEST(WebKit2, WebsitePoliciesPlayingWithoutInterference)
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
     [webView waitForMessage:@"ended"];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidEndMediaPlaybackWithoutUserInterference);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
@@ -423,6 +431,7 @@ TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
 
     WKPageSetMuted([webView _pageForTesting], kWKMediaAudioMuted);
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -433,6 +442,7 @@ TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
     [webView mouseDownAtPoint:muteButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:muteButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
     receivedAutoplayEvent = std::nullopt;
     [webView loadRequest:jsPlayRequest];
@@ -443,6 +453,7 @@ TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesUserNeverPlayedMediaPreventedFromPlaying)
@@ -472,6 +483,7 @@ TEST(WebKit2, WebsitePoliciesUserNeverPlayedMediaPreventedFromPlaying)
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserNeverPlayedMediaPreventedFromPlaying);
+    ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
 TEST(WebKit2, WebsitePoliciesAutoplayQuirks)