Update API availability for autoplay event
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2020 02:21:56 +0000 (02:21 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Jan 2020 02:21:56 +0000 (02:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=202214
<rdar://problem/55710395>

Patch by Luming Yin <luming_yin@apple.com> on 2020-01-14
Reviewed by Tim Horton.

Source/WebKit:

* UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
Make enums and WKUIDelegate method related to autoplay event available on iOS.

* UIProcess/Cocoa/UIDelegate.h:
* UIProcess/Cocoa/UIDelegate.mm:
(WebKit::UIDelegate::setDelegate):
(WebKit::toWKAutoplayEventFlags):
(WebKit::toWKAutoplayEvent):
(WebKit::UIDelegate::UIClient::handleAutoplayEvent):
Make delegate methods related to autoplay events available on iOS.

Tools:

* TestWebKitAPI/Tests/WebKit/js-play-with-controls.html:
* TestWebKitAPI/Tests/WebKitCocoa/audio-with-play-button.html:
* TestWebKitAPI/Tests/WebKitCocoa/video-with-play-button.html:
Provide an id for each play button on various testing pages so that they can be triggered on iOS.

* TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
(-[AutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
(-[AsyncAutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
(TEST):
Enable tests related to autoplay policy on iOS.

* TestWebKitAPI/cocoa/TestWKWebView.h:
* TestWebKitAPI/cocoa/TestWKWebView.mm:
(-[TestWKWebView clickOnElementID:]):
Helper method that performs a click on a given element ID.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/Cocoa/WKUIDelegatePrivate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.h
Source/WebKit/UIProcess/Cocoa/UIDelegate.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit/js-play-with-controls.html
Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm
Tools/TestWebKitAPI/Tests/WebKitCocoa/audio-with-play-button.html
Tools/TestWebKitAPI/Tests/WebKitCocoa/video-with-play-button.html
Tools/TestWebKitAPI/cocoa/TestWKWebView.h
Tools/TestWebKitAPI/cocoa/TestWKWebView.mm

index 6983641..680fb43 100644 (file)
@@ -1,3 +1,22 @@
+2020-01-14  Luming Yin  <luming_yin@apple.com>
+
+        Update API availability for autoplay event
+        https://bugs.webkit.org/show_bug.cgi?id=202214
+        <rdar://problem/55710395>
+
+        Reviewed by Tim Horton.
+
+        * UIProcess/API/Cocoa/WKUIDelegatePrivate.h:
+        Make enums and WKUIDelegate method related to autoplay event available on iOS.
+
+        * UIProcess/Cocoa/UIDelegate.h:
+        * UIProcess/Cocoa/UIDelegate.mm:
+        (WebKit::UIDelegate::setDelegate):
+        (WebKit::toWKAutoplayEventFlags):
+        (WebKit::toWKAutoplayEvent):
+        (WebKit::UIDelegate::UIClient::handleAutoplayEvent):
+        Make delegate methods related to autoplay events available on iOS.
+
 2020-01-14  Tim Horton  <timothy_horton@apple.com>
 
         REGRESSION (r253394): After swiping back during a navigation, WKWebView gets stuck with the forward content, stops repainting
index 259078f..9b80d5b 100644 (file)
 @protocol UIDragSession;
 @protocol UIDropSession;
 #else
-typedef NS_ENUM(NSInteger, _WKAutoplayEvent) {
-    _WKAutoplayEventDidPreventFromAutoplaying,
-    _WKAutoplayEventDidPlayMediaWithUserGesture,
-    _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference,
-    _WKAutoplayEventUserDidInterfereWithPlayback,
-} WK_API_AVAILABLE(macos(10.13.4));
-
 typedef NS_ENUM(NSInteger, _WKResourceLimit) {
     _WKResourceLimitMemory,
     _WKResourceLimitCPU,
@@ -67,14 +60,21 @@ typedef NS_ENUM(NSInteger, _WKPlugInUnavailabilityReason) {
     _WKPlugInUnavailabilityReasonPluginCrashed,
     _WKPlugInUnavailabilityReasonInsecurePluginVersion
 } WK_API_AVAILABLE(macos(10.13.4));
+#endif
+
+typedef NS_ENUM(NSInteger, _WKAutoplayEvent) {
+    _WKAutoplayEventDidPreventFromAutoplaying,
+    _WKAutoplayEventDidPlayMediaWithUserGesture,
+    _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference,
+    _WKAutoplayEventUserDidInterfereWithPlayback,
+} WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
 
 typedef NS_OPTIONS(NSUInteger, _WKAutoplayEventFlags) {
     _WKAutoplayEventFlagsNone = 0,
     _WKAutoplayEventFlagsHasAudio = 1 << 0,
     _WKAutoplayEventFlagsPlaybackWasPrevented = 1 << 1,
     _WKAutoplayEventFlagsMediaIsMainContent = 1 << 2,
-} WK_API_AVAILABLE(macos(10.13.4));
-#endif
+} WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
 
 typedef NS_ENUM(NSInteger, _WKFocusDirection) {
     _WKFocusDirectionBackward,
@@ -140,6 +140,8 @@ struct UIEdgeInsets;
 
 - (void)_webView:(WKWebView *)webView runWebAuthenticationPanel:(_WKWebAuthenticationPanel *)panel initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(_WKWebAuthenticationPanelResult))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA));
 
+- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA));
+
 #if TARGET_OS_IPHONE
 - (BOOL)_webView:(WKWebView *)webView shouldIncludeAppLinkActionsForElement:(_WKActivatedElementInfo *)element WK_API_AVAILABLE(ios(9.0));
 - (NSArray *)_webView:(WKWebView *)webView actionsForElement:(_WKActivatedElementInfo *)element defaultActions:(NSArray<_WKElementAction *> *)defaultActions;
@@ -217,7 +219,6 @@ struct UIEdgeInsets;
 - (void)_webViewDidScroll:(WKWebView *)webView WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webViewRunModal:(WKWebView *)webView WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView didNotHandleWheelEvent:(NSEvent *)event WK_API_AVAILABLE(macos(10.13.4));
-- (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView didClickAutoFillButtonWithUserInfo:(id <NSSecureCoding>)userInfo WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView getToolbarsAreVisibleWithCompletionHandler:(void(^)(BOOL))completionHandler WK_API_AVAILABLE(macos(10.13.4));
 - (void)_webView:(WKWebView *)webView saveDataToFile:(NSData *)data suggestedFilename:(NSString *)suggestedFilename mimeType:(NSString *)mimeType originatingURL:(NSURL *)url WK_API_AVAILABLE(macos(10.13.4));
index c9498f9..a3593ad 100644 (file)
@@ -100,6 +100,7 @@ private:
         void reachedApplicationCacheOriginQuota(WebPageProxy*, const WebCore::SecurityOrigin&, uint64_t currentQuota, uint64_t totalBytesNeeded, Function<void(unsigned long long)>&& completionHandler) final;
         void didResignInputElementStrongPasswordAppearance(WebPageProxy&, API::Object*) final;
         bool takeFocus(WebPageProxy*, WKFocusDirection) final;
+        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
 #if PLATFORM(MAC)
         void showPage(WebPageProxy*) final;
         void focus(WebPageProxy*) final;
@@ -116,7 +117,6 @@ private:
         void drawHeader(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
         void drawFooter(WebPageProxy&, WebFrameProxy&, WebCore::FloatRect&&) final;
         void decidePolicyForNotificationPermissionRequest(WebPageProxy&, API::SecurityOrigin&, Function<void(bool)>&&) final;
-        void handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent, OptionSet<WebCore::AutoplayEventFlags>) final;
         void unavailablePluginButtonClicked(WebPageProxy&, WKPluginUnavailabilityReason, API::Dictionary&) final;
         void mouseDidMoveOverElement(WebPageProxy&, const WebHitTestResultData&, OptionSet<WebEvent::Modifier>, API::Object*);
         void didClickAutoFillButton(WebPageProxy&, API::Object*) final;
@@ -176,6 +176,7 @@ private:
         bool webViewRequestGeolocationPermissionForFrameDecisionHandler : 1;
         bool webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo : 1;
         bool webViewTakeFocus : 1;
+        bool webViewHandleAutoplayEventWithFlags : 1;
 #if PLATFORM(MAC)
         bool showWebView : 1;
         bool focusWebView : 1;
@@ -187,7 +188,6 @@ private:
         bool webViewSetResizable : 1;
         bool webViewSetWindowFrame : 1;
         bool webViewDidNotHandleWheelEvent : 1;
-        bool webViewHandleAutoplayEventWithFlags : 1;
         bool webViewUnavailablePlugInButtonClicked : 1;
         bool webViewDidClickAutoFillButtonWithUserInfo : 1;
         bool webViewDrawHeaderInRectForPageWithTitleURL : 1;
index ea9a9ca..a3d0ded 100644 (file)
@@ -109,6 +109,7 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewRequestGeolocationPermissionForFrameDecisionHandler = [delegate respondsToSelector:@selector(_webView:requestGeolocationPermissionForFrame:decisionHandler:)];
     m_delegateMethods.webViewDidResignInputElementStrongPasswordAppearanceWithUserInfo = [delegate respondsToSelector:@selector(_webView:didResignInputElementStrongPasswordAppearanceWithUserInfo:)];
     m_delegateMethods.webViewTakeFocus = [delegate respondsToSelector:@selector(_webView:takeFocus:)];
+    m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
 
 #if PLATFORM(MAC)
     m_delegateMethods.showWebView = [delegate respondsToSelector:@selector(_showWebView:)];
@@ -122,7 +123,6 @@ void UIDelegate::setDelegate(id <WKUIDelegate> delegate)
     m_delegateMethods.webViewGetWindowFrameWithCompletionHandler = [delegate respondsToSelector:@selector(_webView:getWindowFrameWithCompletionHandler:)];
     m_delegateMethods.webViewSetWindowFrame = [delegate respondsToSelector:@selector(_webView:setWindowFrame:)];
     m_delegateMethods.webViewUnavailablePlugInButtonClicked = [delegate respondsToSelector:@selector(_webView:unavailablePlugInButtonClickedWithReason:plugInInfo:)];
-    m_delegateMethods.webViewHandleAutoplayEventWithFlags = [delegate respondsToSelector:@selector(_webView:handleAutoplayEvent:withFlags:)];
     m_delegateMethods.webViewDidClickAutoFillButtonWithUserInfo = [delegate respondsToSelector:@selector(_webView:didClickAutoFillButtonWithUserInfo:)];
     m_delegateMethods.webViewDrawHeaderInRectForPageWithTitleURL = [delegate respondsToSelector:@selector(_webView:drawHeaderInRect:forPageWithTitle:URL:)];
     m_delegateMethods.webViewDrawFooterInRectForPageWithTitleURL = [delegate respondsToSelector:@selector(_webView:drawFooterInRect:forPageWithTitle:URL:)];
@@ -486,6 +486,47 @@ bool UIDelegate::UIClient::takeFocus(WebPageProxy*, WKFocusDirection direction)
     return true;
 }
 
+static _WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
+{
+    _WKAutoplayEventFlags wkFlags = _WKAutoplayEventFlagsNone;
+    if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
+        wkFlags |= _WKAutoplayEventFlagsHasAudio;
+    if (flags.contains(WebCore::AutoplayEventFlags::PlaybackWasPrevented))
+        wkFlags |= _WKAutoplayEventFlagsPlaybackWasPrevented;
+    if (flags.contains(WebCore::AutoplayEventFlags::MediaIsMainContent))
+        wkFlags |= _WKAutoplayEventFlagsMediaIsMainContent;
+    
+    return wkFlags;
+}
+
+static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
+{
+    switch (event) {
+    case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
+        return _WKAutoplayEventDidPreventFromAutoplaying;
+    case WebCore::AutoplayEvent::DidPlayMediaWithUserGesture:
+        return _WKAutoplayEventDidPlayMediaWithUserGesture;
+    case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference:
+        return _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference;
+    case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
+        return _WKAutoplayEventUserDidInterfereWithPlayback;
+    }
+    ASSERT_NOT_REACHED();
+    return _WKAutoplayEventDidPlayMediaWithUserGesture;
+}
+
+void UIDelegate::UIClient::handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
+{
+    if (!m_uiDelegate.m_delegateMethods.webViewHandleAutoplayEventWithFlags)
+        return;
+    
+    auto delegate = m_uiDelegate.m_delegate.get();
+    if (!delegate)
+        return;
+    
+    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)];
+}
+
 #if PLATFORM(MAC)
 bool UIDelegate::UIClient::canRunModal() const
 {
@@ -704,35 +745,6 @@ void UIDelegate::UIClient::mouseDidMoveOverElement(WebPageProxy&, const WebHitTe
     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView mouseDidMoveOverElement:wrapper(apiHitTestResult.get()) withFlags:WebEventFactory::toNSEventModifierFlags(modifiers) userInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
 }
 
-static _WKAutoplayEventFlags toWKAutoplayEventFlags(OptionSet<WebCore::AutoplayEventFlags> flags)
-{
-    _WKAutoplayEventFlags wkFlags = _WKAutoplayEventFlagsNone;
-    if (flags.contains(WebCore::AutoplayEventFlags::HasAudio))
-        wkFlags |= _WKAutoplayEventFlagsHasAudio;
-    if (flags.contains(WebCore::AutoplayEventFlags::PlaybackWasPrevented))
-        wkFlags |= _WKAutoplayEventFlagsPlaybackWasPrevented;
-    if (flags.contains(WebCore::AutoplayEventFlags::MediaIsMainContent))
-        wkFlags |= _WKAutoplayEventFlagsMediaIsMainContent;
-    
-    return wkFlags;
-}
-
-static _WKAutoplayEvent toWKAutoplayEvent(WebCore::AutoplayEvent event)
-{
-    switch (event) {
-    case WebCore::AutoplayEvent::DidPreventMediaFromPlaying:
-        return _WKAutoplayEventDidPreventFromAutoplaying;
-    case WebCore::AutoplayEvent::DidPlayMediaWithUserGesture:
-        return _WKAutoplayEventDidPlayMediaWithUserGesture;
-    case WebCore::AutoplayEvent::DidAutoplayMediaPastThresholdWithoutUserInterference:
-        return _WKAutoplayEventDidAutoplayMediaPastThresholdWithoutUserInterference;
-    case WebCore::AutoplayEvent::UserDidInterfereWithPlayback:
-        return _WKAutoplayEventUserDidInterfereWithPlayback;
-    }
-    ASSERT_NOT_REACHED();
-    return _WKAutoplayEventDidPlayMediaWithUserGesture;
-}
-
 void UIDelegate::UIClient::toolbarsAreVisible(WebPageProxy&, Function<void(bool)>&& completionHandler)
 {
     if (!m_uiDelegate.m_delegateMethods.webViewGetToolbarsAreVisibleWithCompletionHandler)
@@ -762,18 +774,6 @@ void UIDelegate::UIClient::didClickAutoFillButton(WebPageProxy&, API::Object* us
     [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView didClickAutoFillButtonWithUserInfo:userInfo ? static_cast<id <NSSecureCoding>>(userInfo->wrapper()) : nil];
 }
 
-void UIDelegate::UIClient::handleAutoplayEvent(WebPageProxy&, WebCore::AutoplayEvent event, OptionSet<WebCore::AutoplayEventFlags> flags)
-{
-    if (!m_uiDelegate.m_delegateMethods.webViewHandleAutoplayEventWithFlags)
-        return;
-    
-    auto delegate = m_uiDelegate.m_delegate.get();
-    if (!delegate)
-        return;
-    
-    [(id <WKUIDelegatePrivate>)delegate _webView:m_uiDelegate.m_webView handleAutoplayEvent:toWKAutoplayEvent(event) withFlags:toWKAutoplayEventFlags(flags)];
-}
-
 void UIDelegate::UIClient::showPage(WebPageProxy*)
 {
     if (!m_uiDelegate.m_delegateMethods.showWebView)
index 1381b11..fee0eb4 100644 (file)
@@ -1,3 +1,27 @@
+2020-01-14  Luming Yin  <luming_yin@apple.com>
+
+        Update API availability for autoplay event
+        https://bugs.webkit.org/show_bug.cgi?id=202214
+        <rdar://problem/55710395>
+
+        Reviewed by Tim Horton.
+
+        * TestWebKitAPI/Tests/WebKit/js-play-with-controls.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/audio-with-play-button.html:
+        * TestWebKitAPI/Tests/WebKitCocoa/video-with-play-button.html:
+        Provide an id for each play button on various testing pages so that they can be triggered on iOS.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+        (-[AutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
+        (-[AsyncAutoplayPoliciesDelegate _webView:handleAutoplayEvent:withFlags:]):
+        (TEST):
+        Enable tests related to autoplay policy on iOS.
+
+        * TestWebKitAPI/cocoa/TestWKWebView.h:
+        * TestWebKitAPI/cocoa/TestWKWebView.mm:
+        (-[TestWKWebView clickOnElementID:]):
+        Helper method that performs a click on a given element ID.
+
 2020-01-14  Jonathan Bedard  <jbedard@apple.com>
 
         EWS: Run webkitpy tests with Python 2 and 3
index 87fad35..d4ec45d 100644 (file)
@@ -34,8 +34,8 @@
         </script>
     </head>
     <body onload="pageLoaded()">
-        <button onclick="play()">Play</button>
-        <button onclick="mute()">Mute</button>
+        <button id="playButton" onclick="play()">Play</button>
+        <button id="muteButton" onclick="mute()">Mute</button>
         <video id="video" onplaying=beganPlaying() onended=endedPlaying() src="test.mp4" />
     </body>
 </html>
index 3449ea3..dd79c5d 100644 (file)
@@ -63,10 +63,8 @@ static bool doneCompiling;
 static bool receivedAlert;
 static bool finishedNavigation;
 
-#if PLATFORM(MAC)
 static Optional<_WKAutoplayEvent> receivedAutoplayEvent;
 static Optional<_WKAutoplayEventFlags> receivedAutoplayEventFlags;
-#endif
 
 static size_t alertCount;
 
@@ -198,13 +196,11 @@ TEST(WebpagePreferences, WebsitePoliciesContentBlockersEnabled)
     decisionHandler(WKNavigationActionPolicyAllow, websitePolicies);
 }
 
-#if PLATFORM(MAC)
 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags
 {
     receivedAutoplayEventFlags = flags;
     receivedAutoplayEvent = event;
 }
-#endif
 
 @end
 
@@ -234,13 +230,11 @@ TEST(WebpagePreferences, WebsitePoliciesContentBlockersEnabled)
     });
 }
 
-#if PLATFORM(MAC)
 - (void)_webView:(WKWebView *)webView handleAutoplayEvent:(_WKAutoplayEvent)event withFlags:(_WKAutoplayEventFlags)flags
 {
     receivedAutoplayEventFlags = flags;
     receivedAutoplayEvent = event;
 }
-#endif
 
 @end
 
@@ -265,7 +259,8 @@ TEST(WebpagePreferences, WebsitePoliciesAutoplayEnabled)
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
 
 #if PLATFORM(IOS_FAMILY)
-    [configuration setAllowsInlineMediaPlayback:YES];
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
 #endif
 
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
@@ -354,13 +349,13 @@ TEST(WebpagePreferences, WebsitePoliciesAutoplayEnabled)
     [webView waitForMessage:@"did-not-play"];
 }
 
-#if PLATFORM(MAC)
 static void runUntilReceivesAutoplayEvent(WKAutoplayEvent event)
 {
     while (!receivedAutoplayEvent || *receivedAutoplayEvent != event)
         CFRunLoopRunInMode(kCFRunLoopDefaultMode, 0.1, true);
 }
 
+#if PLATFORM(MAC)
 TEST(WebpagePreferences, WebsitePoliciesPlayAfterPreventedAutoplay)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -431,10 +426,16 @@ TEST(WebpagePreferences, WebsitePoliciesPlayAfterPreventedAutoplay)
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsPlaybackWasPrevented);
 }
+#endif
 
 TEST(WebpagePreferences, WebsitePoliciesPlayingWithUserGesture)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+#if PLATFORM(IOS_FAMILY)
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+#endif
+
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
@@ -446,13 +447,20 @@ TEST(WebpagePreferences, WebsitePoliciesPlayingWithUserGesture)
 
     receivedAutoplayEvent = WTF::nullopt;
 
+#if PLATFORM(MAC)
     NSPoint playButtonClickPoint = NSMakePoint(20, 580);
+#endif
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"audio-with-play-button" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
     [webView waitForMessage:@"loaded"];
+
+#if PLATFORM(MAC)
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
+#else
+    [webView clickOnElementID:@"playButton"];
+#endif
 
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
@@ -463,8 +471,13 @@ TEST(WebpagePreferences, WebsitePoliciesPlayingWithUserGesture)
     request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"video-with-play-button" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
     [webView waitForMessage:@"loaded"];
+
+#if PLATFORM(MAC)
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
+#else
+    [webView clickOnElementID:@"playButton"];
+#endif
 
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPlayMediaWithUserGesture);
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
@@ -474,6 +487,11 @@ TEST(WebpagePreferences, WebsitePoliciesPlayingWithUserGesture)
 TEST(WebpagePreferences, WebsitePoliciesPlayingWithoutInterference)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+#if PLATFORM(IOS_FAMILY)
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+#endif
+
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
 
     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
@@ -493,6 +511,11 @@ TEST(WebpagePreferences, WebsitePoliciesPlayingWithoutInterference)
 TEST(WebpagePreferences, WebsitePoliciesUserInterferenceWithPlaying)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+#if PLATFORM(IOS_FAMILY)
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+#endif
+
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 336, 276) configuration:configuration.get()]);
 
     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
@@ -517,9 +540,14 @@ TEST(WebpagePreferences, WebsitePoliciesUserInterferenceWithPlaying)
     [webView waitForMessage:@"playing"];
     ASSERT_TRUE(receivedAutoplayEvent == WTF::nullopt);
 
+#if PLATFORM(MAC)
     const NSPoint muteButtonClickPoint = NSMakePoint(80, 256);
     [webView mouseDownAtPoint:muteButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:muteButtonClickPoint];
+#else
+    [webView clickOnElementID:@"muteButton"];
+#endif
+
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 
@@ -528,13 +556,19 @@ TEST(WebpagePreferences, WebsitePoliciesUserInterferenceWithPlaying)
     [webView waitForMessage:@"playing"];
     ASSERT_TRUE(receivedAutoplayEvent == WTF::nullopt);
 
+#if PLATFORM(MAC)
     const NSPoint playButtonClickPoint = NSMakePoint(20, 256);
     [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:playButtonClickPoint];
+#else
+    [webView clickOnElementID:@"playButton"];
+#endif
+
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
     ASSERT_TRUE(*receivedAutoplayEventFlags & kWKAutoplayEventFlagsHasAudio);
 }
 
+#if PLATFORM(MAC)
 TEST(WebpagePreferences, WebsitePoliciesPerDocumentAutoplayBehaviorMediaLoading)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -713,10 +747,16 @@ TEST(WebpagePreferences, WebsitePoliciesDuringRedirect)
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"test:///should-redirect"]]];
     [webView waitForMessage:@"autoplayed"];
 }
+#endif // PLATFORM(MAC)
 
 TEST(WebpagePreferences, WebsitePoliciesUpdates)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+#if PLATFORM(IOS_FAMILY)
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+#endif
+
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
@@ -750,6 +790,7 @@ TEST(WebpagePreferences, WebsitePoliciesUpdates)
     runUntilReceivesAutoplayEvent(kWKAutoplayEventDidPreventFromAutoplaying);
 }
 
+#if PLATFORM(MAC)
 TEST(WebpagePreferences, WebsitePoliciesArbitraryUserGestureQuirk)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
@@ -903,19 +944,21 @@ TEST(WebpagePreferences, WebsitePoliciesPerDocumentAutoplayBehaviorQuirks)
     [webView _evaluateJavaScriptWithoutUserGesture:@"playVideo('video2')" completionHandler:nil];
     [webView waitForMessage:@"did-not-play-video2"];
 }
+#endif
 
 TEST(WebpagePreferences, WebsitePoliciesAutoplayQuirksAsyncPolicyDelegate)
 {
     auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+#if PLATFORM(IOS_FAMILY)
+    configuration.get().allowsInlineMediaPlayback = YES;
+    configuration.get()._inlineMediaPlaybackRequiresPlaysInlineAttribute = NO;
+#endif
+    [configuration preferences]._needsSiteSpecificQuirks = YES;
     auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
     auto delegate = adoptNS([[AsyncAutoplayPoliciesDelegate alloc] init]);
     [webView setNavigationDelegate:delegate.get()];
 
-    WKRetainPtr<WKPreferencesRef> preferences = adoptWK(WKPreferencesCreate());
-    WKPreferencesSetNeedsSiteSpecificQuirks(preferences.get(), true);
-    WKPageGroupSetPreferences(WKPageGetPageGroup([webView _pageForTesting]), preferences.get());
-
     NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
 
     [delegate setAllowedAutoplayQuirksForURL:^_WKWebsiteAutoplayQuirk(NSURL *url) {
@@ -946,7 +989,6 @@ TEST(WebpagePreferences, WebsitePoliciesAutoplayQuirksAsyncPolicyDelegate)
     [webView waitForMessage:@"did-not-play"];
     [webView waitForMessage:@"on-pause"];
 }
-#endif // PLATFORM(MAC)
 
 TEST(WebpagePreferences, InvalidCustomHeaders)
 {
index 7f3ede5..b990531 100644 (file)
@@ -21,7 +21,7 @@
         </script>
     </head>
     <body onload="pageLoaded()">
-        <button onclick="play()">Play</button>
+        <button id="playButton" onclick="play()">Play</button>
         <br />
         <audio controls id="audio" onplaying="beganPlaying()" src="silence-long.m4a" />
     </body>
index c0a1ab2..358fae6 100644 (file)
@@ -21,7 +21,7 @@
         </script>
     </head>
     <body onload="pageLoaded()">
-        <button onclick="play()">Play</button>
+        <button id="playButton" onclick="play()">Play</button>
         <br />
         <video controls id="video" onplaying="beganPlaying()" src="long-test.mp4"></video>
     </body>
index 3cc434a..d8e75dc 100644 (file)
@@ -86,6 +86,7 @@
 - (void)collapseToEnd;
 - (void)addToTestWindow;
 - (BOOL)selectionRangeHasStartOffset:(int)start endOffset:(int)end;
+- (void)clickOnElementID:(NSString *)elementID;
 @end
 
 #if PLATFORM(IOS_FAMILY)
index 74ad581..f873a66 100644 (file)
@@ -515,6 +515,11 @@ static UICalloutBar *suppressUICalloutBar()
     return matches;
 }
 
+- (void)clickOnElementID:(NSString *)elementID
+{
+    [self evaluateJavaScript:[NSString stringWithFormat:@"document.getElementById('%@').click();", elementID] completionHandler:nil];
+}
+
 #if PLATFORM(IOS_FAMILY)
 
 - (void)didStartFormControlInteraction