Diff
Deleted: trunk/LayoutTests/media/document-level-media-user-gesture-quirk-expected.txt (239829 => 239830)
--- trunk/LayoutTests/media/document-level-media-user-gesture-quirk-expected.txt 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/media/document-level-media-user-gesture-quirk-expected.txt 2019-01-10 17:31:27 UTC (rev 239830)
@@ -1,13 +0,0 @@
-
-RUN(internals.setMediaElementRestrictions(video1, "RequireUserGestureForAudioRateChange"))
-RUN(internals.setMediaElementRestrictions(video2, "RequireUserGestureForAudioRateChange"))
-RUN(internals.settings.setNeedsSiteSpecificQuirks(true))
-Trying to play the first video without a user gesture
-RUN(video1.play().then(failTest).catch(playFirstVideoWithUserGesture))
-Playback was denied - trying to play the first video with a user gesture
-RUN(video1.play().then(playedFirstVideo).catch(failTest))
-The first video played with a user gesture - trying to play the second video
-The second video should play unconditionally on Mac with quirks enabled
-RUN(video2.play().then(endTest).catch(failTest))
-END OF TEST
-
Deleted: trunk/LayoutTests/media/document-level-media-user-gesture-quirk.html (239829 => 239830)
--- trunk/LayoutTests/media/document-level-media-user-gesture-quirk.html 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/media/document-level-media-user-gesture-quirk.html 2019-01-10 17:31:27 UTC (rev 239830)
@@ -1,38 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
- <title>document-level-media-user-gesture-quirk</title>
- <script src=""
- <script src=""
- <script>
- function runTest() {
- var video1 = document.getElementById('video1');
- var video2 = document.getElementById('video2');
-
- run('internals.setMediaElementRestrictions(video1, "RequireUserGestureForAudioRateChange")');
- run('internals.setMediaElementRestrictions(video2, "RequireUserGestureForAudioRateChange")');
- run('internals.settings.setNeedsSiteSpecificQuirks(true)');
-
- consoleWrite("Trying to play the first video without a user gesture");
- run('video1.play().then(failTest).catch(playFirstVideoWithUserGesture)');
- }
-
- function playFirstVideoWithUserGesture() {
- consoleWrite("Playback was denied - trying to play the first video with a user gesture");
- runWithKeyDown(() => {
- run('video1.play().then(playedFirstVideo).catch(failTest)');
- });
- }
-
- function playedFirstVideo() {
- consoleWrite("The first video played with a user gesture - trying to play the second video");
- consoleWrite("The second video should play unconditionally on Mac with quirks enabled");
- run('video2.play().then(endTest).catch(failTest)');
- }
- </script>
-</head>
-<body _onload_="runTest()">
- <video id="video1" src=""
- <video id="video2" src=""
-</body>
-</html>
Modified: trunk/LayoutTests/platform/gtk/TestExpectations (239829 => 239830)
--- trunk/LayoutTests/platform/gtk/TestExpectations 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/platform/gtk/TestExpectations 2019-01-10 17:31:27 UTC (rev 239830)
@@ -944,9 +944,6 @@
# Media controls tests are OS X only
media/controls [ Skip ]
-# This test relies on Mac-specific quirks
-media/document-level-media-user-gesture-quirk.html [ Skip ]
-
# WIRELESS_PLAYBACK_TARGET not enabled.
media/airplay-target-availability.html
Modified: trunk/LayoutTests/platform/ios/TestExpectations (239829 => 239830)
--- trunk/LayoutTests/platform/ios/TestExpectations 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/platform/ios/TestExpectations 2019-01-10 17:31:27 UTC (rev 239830)
@@ -2491,7 +2491,6 @@
webkit.org/b/136708 media/media-fullscreen-not-in-document.html
-media/document-level-media-user-gesture-quirk.html
media/media-controls-accessibility.html [ Timeout ]
media/media-fullscreen-return-to-inline.html
media/no-autoplay-with-user-gesture-requirement.html
Modified: trunk/LayoutTests/platform/win/TestExpectations (239829 => 239830)
--- trunk/LayoutTests/platform/win/TestExpectations 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/platform/win/TestExpectations 2019-01-10 17:31:27 UTC (rev 239830)
@@ -3720,9 +3720,6 @@
# Only Mac has implemented DictionaryLookup
fast/layers/prevent-hit-test-during-layout.html [ Skip ]
-# This test relies on Mac-specific quirks
-media/document-level-media-user-gesture-quirk.html [ Skip ]
-
# webrtc not supported
imported/w3c/web-platform-tests/webrtc [ Skip ]
webrtc [ Skip ]
Modified: trunk/LayoutTests/platform/wincairo/TestExpectations (239829 => 239830)
--- trunk/LayoutTests/platform/wincairo/TestExpectations 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/platform/wincairo/TestExpectations 2019-01-10 17:31:27 UTC (rev 239830)
@@ -408,9 +408,6 @@
# These are Mac specific for now.
fast/url/user-visible [ Skip ]
-# This test relies on Mac-specific quirks
-media/document-level-media-user-gesture-quirk.html [ Skip ]
-
# These tests reference specific fonts on Mac port.
Bug(GTK) fast/text/font-weights.html [ WontFix ]
Bug(GTK) fast/text/font-weights-zh.html [ WontFix ]
Modified: trunk/LayoutTests/platform/wpe/TestExpectations (239829 => 239830)
--- trunk/LayoutTests/platform/wpe/TestExpectations 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/LayoutTests/platform/wpe/TestExpectations 2019-01-10 17:31:27 UTC (rev 239830)
@@ -298,9 +298,6 @@
fast/canvas/webmetal [ Skip ]
webgpu [ Skip ]
-# This test relies on Mac-specific quirks
-media/document-level-media-user-gesture-quirk.html [ Skip ]
-
# Skipped due to untestable DRM key system. ClearKey counterparts are tested instead.
imported/w3c/web-platform-tests/encrypted-media/drm-check-initdata-type.https.html [ Skip ]
imported/w3c/web-platform-tests/encrypted-media/drm-events.https.html [ Skip ]
Modified: trunk/Source/WebCore/ChangeLog (239829 => 239830)
--- trunk/Source/WebCore/ChangeLog 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebCore/ChangeLog 2019-01-10 17:31:27 UTC (rev 239830)
@@ -1,3 +1,21 @@
+2019-01-09 Matt Rajca <mra...@apple.com>
+
+ Put per-document autoplay behavior behind runtime website policies quirk instead of a compile time flag
+ https://bugs.webkit.org/show_bug.cgi?id=193301
+
+ Reviewed by Jer Noble.
+
+ Instead of unconditionally enabling this with a compile-time flag, let clients
+ enable the quirk on a per-load basis.
+
+ Tests: added API tests in favor of the current layout test as this behavior is no
+ longer on by default unless a client opts in.
+
+ * html/MediaElementSession.cpp:
+ (WebCore::needsPerDocumentAutoplayBehaviorQuirk):
+ (WebCore::MediaElementSession::playbackPermitted const):
+ * loader/DocumentLoader.h:
+
2019-01-10 Zalan Bujtas <za...@apple.com>
[LFC][BFC][MarginCollapsing] Take collapsed through siblings into account when computing vertical position
Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (239829 => 239830)
--- trunk/Source/WebCore/html/MediaElementSession.cpp 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp 2019-01-10 17:31:27 UTC (rev 239830)
@@ -255,6 +255,15 @@
}
#endif // PLATFORM(MAC)
+static bool needsPerDocumentAutoplayBehaviorQuirk(const Document& document)
+{
+ if (!document.settings().needsSiteSpecificQuirks())
+ return false;
+
+ auto loader = makeRefPtr(document.loader());
+ return loader && loader->allowedAutoplayQuirks().contains(AutoplayQuirk::PerDocumentAutoplayBehavior);
+}
+
SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackPermitted() const
{
if (m_element.isSuspended()) {
@@ -290,12 +299,11 @@
}
#endif
-#if PLATFORM(MAC)
- // FIXME <https://webkit.org/b/175856>: Make this dependent on a runtime flag for desktop autoplay restrictions.
const auto& topDocument = document.topDocument();
- if (topDocument.mediaState() & MediaProducer::HasUserInteractedWithMediaElement && topDocument.settings().needsSiteSpecificQuirks())
+ if (topDocument.mediaState() & MediaProducer::HasUserInteractedWithMediaElement && needsPerDocumentAutoplayBehaviorQuirk(topDocument))
return { };
+#if PLATFORM(MAC)
if (document.hasHadUserInteraction() && needsArbitraryUserGestureAutoplayQuirk(document))
return { };
#endif
Modified: trunk/Source/WebCore/loader/DocumentLoader.h (239829 => 239830)
--- trunk/Source/WebCore/loader/DocumentLoader.h 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebCore/loader/DocumentLoader.h 2019-01-10 17:31:27 UTC (rev 239830)
@@ -103,6 +103,7 @@
SynthesizedPauseEvents = 1 << 0,
InheritedUserGestures = 1 << 1,
ArbitraryUserGestures = 1 << 2,
+ PerDocumentAutoplayBehavior = 1 << 3,
};
enum class PopUpPolicy {
Modified: trunk/Source/WebKit/ChangeLog (239829 => 239830)
--- trunk/Source/WebKit/ChangeLog 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/ChangeLog 2019-01-10 17:31:27 UTC (rev 239830)
@@ -1,3 +1,25 @@
+2019-01-09 Matt Rajca <mra...@apple.com>
+
+ Put per-document autoplay behavior behind runtime website policies quirk instead of a compile time flag
+ https://bugs.webkit.org/show_bug.cgi?id=193301
+
+ Reviewed by Jer Noble.
+
+ Register a new quirk that can be configured per-load for per-document media
+ autoplay behaviors.
+
+ * Shared/WebsiteAutoplayQuirk.h:
+ * Shared/WebsitePoliciesData.cpp:
+ (WebKit::WebsitePoliciesData::applyToDocumentLoader):
+ * UIProcess/API/C/WKWebsitePolicies.cpp:
+ (WKWebsitePoliciesSetAllowedAutoplayQuirks):
+ (WKWebsitePoliciesGetAllowedAutoplayQuirks):
+ * UIProcess/API/C/WKWebsitePolicies.h:
+ * UIProcess/API/Cocoa/_WKWebsitePolicies.h:
+ * UIProcess/API/Cocoa/_WKWebsitePolicies.mm:
+ (-[_WKWebsitePolicies setAllowedAutoplayQuirks:]):
+ (-[_WKWebsitePolicies allowedAutoplayQuirks]):
+
2019-01-10 Tim Horton <timothy_hor...@apple.com>
Rename some entitlements files to be more clear about their target platform
Modified: trunk/Source/WebKit/Shared/WebsiteAutoplayQuirk.h (239829 => 239830)
--- trunk/Source/WebKit/Shared/WebsiteAutoplayQuirk.h 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/Shared/WebsiteAutoplayQuirk.h 2019-01-10 17:31:27 UTC (rev 239830)
@@ -31,6 +31,7 @@
SynthesizedPauseEvents = 1 << 0,
InheritedUserGestures = 1 << 1,
ArbitraryUserGestures = 1 << 2,
+ PerDocumentAutoplayBehavior = 1 << 3,
};
}
Modified: trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp (239829 => 239830)
--- trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/Shared/WebsitePoliciesData.cpp 2019-01-10 17:31:27 UTC (rev 239830)
@@ -130,6 +130,9 @@
if (allowedQuirks.contains(WebsiteAutoplayQuirk::ArbitraryUserGestures))
quirks.add(WebCore::AutoplayQuirk::ArbitraryUserGestures);
+ if (allowedQuirks.contains(WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
+ quirks.add(WebCore::AutoplayQuirk::PerDocumentAutoplayBehavior);
+
documentLoader.setAllowedAutoplayQuirks(quirks);
switch (websitePolicies.autoplayPolicy) {
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp (239829 => 239830)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.cpp 2019-01-10 17:31:27 UTC (rev 239830)
@@ -91,6 +91,9 @@
if (allowedQuirks & kWKWebsiteAutoplayQuirkArbitraryUserGestures)
quirks.add(WebsiteAutoplayQuirk::ArbitraryUserGestures);
+ if (allowedQuirks & kWKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior)
+ quirks.add(WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior);
+
toImpl(websitePolicies)->setAllowedAutoplayQuirks(quirks);
}
@@ -108,6 +111,9 @@
if (allowedQuirks.contains(WebsiteAutoplayQuirk::ArbitraryUserGestures))
quirks |= kWKWebsiteAutoplayQuirkArbitraryUserGestures;
+ if (allowedQuirks.contains(WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
+ quirks |= kWKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
+
return quirks;
}
Modified: trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h (239829 => 239830)
--- trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/UIProcess/API/C/WKWebsitePolicies.h 2019-01-10 17:31:27 UTC (rev 239830)
@@ -45,6 +45,7 @@
kWKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
kWKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
kWKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
+ kWKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior = 1 << 3,
};
enum WKWebsitePopUpPolicy {
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h (239829 => 239830)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.h 2019-01-10 17:31:27 UTC (rev 239830)
@@ -38,6 +38,7 @@
_WKWebsiteAutoplayQuirkSynthesizedPauseEvents = 1 << 0,
_WKWebsiteAutoplayQuirkInheritedUserGestures = 1 << 1,
_WKWebsiteAutoplayQuirkArbitraryUserGestures = 1 << 2,
+ _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior = 1 << 3,
} WK_API_AVAILABLE(macosx(10.13), ios(11.0));
typedef NS_OPTIONS(NSUInteger, _WKWebsitePopUpPolicy) {
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm (239829 => 239830)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/_WKWebsitePolicies.mm 2019-01-10 17:31:27 UTC (rev 239830)
@@ -82,6 +82,9 @@
if (allowedQuirks & _WKWebsiteAutoplayQuirkArbitraryUserGestures)
quirks.add(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures);
+ if (allowedQuirks & _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior)
+ quirks.add(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior);
+
_websitePolicies->setAllowedAutoplayQuirks(quirks);
}
@@ -99,6 +102,9 @@
if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::ArbitraryUserGestures))
quirks |= _WKWebsiteAutoplayQuirkArbitraryUserGestures;
+ if (allowedQuirks.contains(WebKit::WebsiteAutoplayQuirk::PerDocumentAutoplayBehavior))
+ quirks |= _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
+
return quirks;
}
Modified: trunk/Tools/ChangeLog (239829 => 239830)
--- trunk/Tools/ChangeLog 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Tools/ChangeLog 2019-01-10 17:31:27 UTC (rev 239830)
@@ -1,3 +1,17 @@
+2019-01-09 Matt Rajca <mra...@apple.com>
+
+ Put per-document autoplay behavior behind runtime website policies quirk instead of a compile time flag
+ https://bugs.webkit.org/show_bug.cgi?id=193301
+
+ Reviewed by Jer Noble.
+
+ Added API tests.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm:
+ (TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/autoplaying-multiple-media-elements.html: Added.
+
2019-01-10 Zalan Bujtas <za...@apple.com>
[LFC][BFC][MarginCollapsing] Take collapsed through siblings into account when computing vertical position
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (239829 => 239830)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2019-01-10 17:31:27 UTC (rev 239830)
@@ -739,6 +739,7 @@
C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
C9C9A91B21DED28700FDE96E /* audio-with-play-button.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C9A91A21DED24D00FDE96E /* audio-with-play-button.html */; };
C9C9A91D21DED7A000FDE96E /* video-with-play-button.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C9A91C21DED79400FDE96E /* video-with-play-button.html */; };
+ C9C9CD4321E6A6860019DB96 /* autoplaying-multiple-media-elements.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C9CD4221E6A6670019DB96 /* autoplaying-multiple-media-elements.html */; };
C9E6DD351EA97D0800DD78AA /* FirstResponderSuppression.mm in Sources */ = {isa = PBXBuildFile; fileRef = C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */; };
C9E8EE7521DED94300797765 /* long-test.mp4 in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9E8EE7421DED91E00797765 /* long-test.mp4 */; };
CA38459620AE17A900990D3B /* LocalStorageDatabaseTracker.mm in Sources */ = {isa = PBXBuildFile; fileRef = CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */; };
@@ -1015,6 +1016,7 @@
C95984F51E36BC6B002C0D45 /* autoplay-no-audio-check.html in Copy Resources */,
C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */,
C99BDF891E80980400C7170E /* autoplay-zero-volume-check.html in Copy Resources */,
+ C9C9CD4321E6A6860019DB96 /* autoplaying-multiple-media-elements.html in Copy Resources */,
2E14A5291D3FE96B0010F35B /* autoplaying-video-with-audio.html in Copy Resources */,
F41AB9A01EF4696B0083FA08 /* background-image-link-and-input.html in Copy Resources */,
2DE71B001D49C3ED00904094 /* blinking-div.html in Copy Resources */,
@@ -2028,6 +2030,7 @@
C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
C9C9A91A21DED24D00FDE96E /* audio-with-play-button.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = "audio-with-play-button.html"; path = "Tests/WebKitCocoa/audio-with-play-button.html"; sourceTree = SOURCE_ROOT; };
C9C9A91C21DED79400FDE96E /* video-with-play-button.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; name = "video-with-play-button.html"; path = "Tests/WebKitCocoa/video-with-play-button.html"; sourceTree = SOURCE_ROOT; };
+ C9C9CD4221E6A6670019DB96 /* autoplaying-multiple-media-elements.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = "autoplaying-multiple-media-elements.html"; sourceTree = "<group>"; };
C9E6DD311EA972D800DD78AA /* FirstResponderSuppression.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = FirstResponderSuppression.mm; sourceTree = "<group>"; };
C9E8EE7421DED91E00797765 /* long-test.mp4 */ = {isa = PBXFileReference; lastKnownFileType = file; path = "long-test.mp4"; sourceTree = "<group>"; };
CA38459520AE012E00990D3B /* LocalStorageDatabaseTracker.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = LocalStorageDatabaseTracker.mm; sourceTree = "<group>"; };
@@ -2788,6 +2791,7 @@
CD57779A211CE6B7001B371E /* audio-with-web-audio.html */,
F41AB9981EF4692C0083FA08 /* autofocus-contenteditable.html */,
93CFA8661CEB9DE1000565A8 /* autofocused-text-input.html */,
+ C9C9CD4221E6A6670019DB96 /* autoplaying-multiple-media-elements.html */,
2E14A5281D3FE8B80010F35B /* autoplaying-video-with-audio.html */,
F41AB9971EF4692C0083FA08 /* background-image-link-and-input.html */,
2DE71AFF1D49C2F000904094 /* blinking-div.html */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm (239829 => 239830)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-01-10 16:45:51 UTC (rev 239829)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WebsitePolicies.mm 2019-01-10 17:31:27 UTC (rev 239830)
@@ -741,6 +741,69 @@
[webView waitForMessage:@"playing"];
}
+TEST(WebKit, WebsitePoliciesPerDocumentAutoplayBehaviorQuirks)
+{
+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+ auto webView = adoptNS([[TestWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+ auto delegate = adoptNS([[AutoplayPoliciesDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ WKRetainPtr<WKPreferencesRef> preferences(AdoptWK, WKPreferencesCreate());
+ WKPreferencesSetNeedsSiteSpecificQuirks(preferences.get(), true);
+ WKPageGroupSetPreferences(WKPageGetPageGroup([webView _pageForTesting]), preferences.get());
+
+ receivedAutoplayEvent = WTF::nullopt;
+
+ NSURLRequest *requestWithMultipleMediaElements = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplaying-multiple-media-elements" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+
+ [delegate setAllowedAutoplayQuirksForURL:^_WKWebsiteAutoplayQuirk(NSURL *url) {
+ return _WKWebsiteAutoplayQuirkPerDocumentAutoplayBehavior;
+ }];
+ [delegate setAutoplayPolicyForURL:^(NSURL *) {
+ return _WKWebsiteAutoplayPolicyDeny;
+ }];
+ [webView loadRequest:requestWithMultipleMediaElements];
+ [webView waitForMessage:@"loaded"];
+
+ // We should not be allowed to play without a user gesture.
+ [webView _evaluateJavaScriptWithoutUserGesture:@"playVideo('video1')" completionHandler:nil];
+ [webView waitForMessage:@"did-not-play-video1"];
+
+ // Now try again with a user gesture...
+ const NSPoint playButtonClickPoint = NSMakePoint(20, 580);
+ [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
+ [webView mouseUpAtPoint:playButtonClickPoint];
+ [webView waitForMessage:@"did-play-video1"];
+
+ // Now video2 should also be allowed to autoplay without a user gesture because of the quirk.
+ [webView _evaluateJavaScriptWithoutUserGesture:@"playVideo('video2')" completionHandler:nil];
+ [webView waitForMessage:@"did-play-video2"];
+
+ // Now let's test this without the quirk.
+ [webView loadHTMLString:@"" baseURL:nil];
+ receivedAutoplayEvent = WTF::nullopt;
+
+ [delegate setAllowedAutoplayQuirksForURL:^_WKWebsiteAutoplayQuirk(NSURL *url) {
+ return 0;
+ }];
+ [webView loadRequest:requestWithMultipleMediaElements];
+ [webView waitForMessage:@"loaded"];
+
+ // We should not be allowed to play without a user gesture.
+ [webView _evaluateJavaScriptWithoutUserGesture:@"playVideo('video1')" completionHandler:nil];
+ [webView waitForMessage:@"did-not-play-video1"];
+
+ // Now try again with a user gesture...
+ [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
+ [webView mouseUpAtPoint:playButtonClickPoint];
+ [webView waitForMessage:@"did-play-video1"];
+
+ // Now video2 should not be allowed to autoplay without a user gesture.
+ [webView _evaluateJavaScriptWithoutUserGesture:@"playVideo('video2')" completionHandler:nil];
+ [webView waitForMessage:@"did-not-play-video2"];
+}
+
TEST(WebKit, WebsitePoliciesAutoplayQuirksAsyncPolicyDelegate)
{
auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/autoplaying-multiple-media-elements.html (0 => 239830)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/autoplaying-multiple-media-elements.html (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/autoplaying-multiple-media-elements.html 2019-01-10 17:31:27 UTC (rev 239830)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <script>
+
+ function pageLoaded() {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage('loaded');
+ } catch(e) { }
+ }
+
+ function playVideo(identifier) {
+ document.getElementById(identifier).play().catch(function() {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage("did-not-play-" + identifier);
+ } catch(e) { }
+ });
+ }
+
+ function didPlayVideo(identifier) {
+ try {
+ window.webkit.messageHandlers.testHandler.postMessage("did-play-" + identifier);
+ } catch(e) { }
+ }
+
+ </script>
+</head>
+<body _onload_="pageLoaded()">
+ <button _onclick_="playVideo('video1')">Play Video 1</button>
+ <br />
+ <video id="video1" _onplaying_="didPlayVideo('video1')" src=""
+ <video id="video2" _onplaying_="didPlayVideo('video2')" src=""
+</body>
+</html>