Loosen audio playback restrictions when the volume is 0.
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2017 01:44:21 +0000 (01:44 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Mar 2017 01:44:21 +0000 (01:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169897

Reviewed by Eric Carlson.

Source/WebCore:

Added API tests.

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::playbackPermitted):

Tools:

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/autoplay-zero-volume-check.html: Added.
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(TEST):

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

Source/WebCore/ChangeLog
Source/WebCore/html/MediaElementSession.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/autoplay-zero-volume-check.html [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

index 9bbe14c..313f809 100644 (file)
@@ -1,3 +1,15 @@
+2017-03-20  Matt Rajca  <mrajca@apple.com>
+
+        Loosen audio playback restrictions when the volume is 0.
+        https://bugs.webkit.org/show_bug.cgi?id=169897
+
+        Reviewed by Eric Carlson.
+
+        Added API tests.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::playbackPermitted):
+
 2017-03-21  Brady Eidson  <beidson@apple.com>
 
         Disable all virtual tables.
 2017-03-21  Brady Eidson  <beidson@apple.com>
 
         Disable all virtual tables.
index bcec194..7f39040 100644 (file)
@@ -169,7 +169,7 @@ SuccessOr<MediaPlaybackDenialReason> MediaElementSession::playbackPermitted(cons
         return MediaPlaybackDenialReason::UserGestureRequired;
     }
 
         return MediaPlaybackDenialReason::UserGestureRequired;
     }
 
-    if (m_restrictions & RequireUserGestureForAudioRateChange && (!element.isVideo() || element.hasAudio()) && !element.muted() && !ScriptController::processingUserGestureForMedia()) {
+    if (m_restrictions & RequireUserGestureForAudioRateChange && (!element.isVideo() || element.hasAudio()) && !element.muted() && element.volume() && !ScriptController::processingUserGestureForMedia()) {
         LOG(Media, "MediaElementSession::playbackPermitted - returning FALSE because of audio rate change restriction");
         return MediaPlaybackDenialReason::UserGestureRequired;
     }
         LOG(Media, "MediaElementSession::playbackPermitted - returning FALSE because of audio rate change restriction");
         return MediaPlaybackDenialReason::UserGestureRequired;
     }
index 4b3df6e..f95724c 100644 (file)
@@ -1,3 +1,15 @@
+2017-03-20  Matt Rajca  <mrajca@apple.com>
+
+        Loosen audio playback restrictions when the volume is 0.
+        https://bugs.webkit.org/show_bug.cgi?id=169897
+
+        Reviewed by Eric Carlson.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/autoplay-zero-volume-check.html: Added.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (TEST):
+
 2017-03-21  Aakash Jain  <aakash_jain@apple.com>
 
         EWS fails to parse_bug_id_from_attachment_page after bugzilla upgrade
 2017-03-21  Aakash Jain  <aakash_jain@apple.com>
 
         EWS fails to parse_bug_id_from_attachment_page after bugzilla upgrade
index c301a6f..ed108ea 100644 (file)
                C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */; };
                C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */; };
                C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */; };
                C99B675C1E39721A00FC6C80 /* autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */; };
                C99B675D1E39722000FC6C80 /* js-play-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */; };
                C99B675F1E39736F00FC6C80 /* no-autoplay-with-controls.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */; };
+               C99BDF891E80980400C7170E /* autoplay-zero-volume-check.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */; };
                C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
                C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
                C9C60E651E53A9DC006DA181 /* autoplay-check-frame.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */; };
                C9C60E661E53A9DC006DA181 /* autoplay-check-in-iframe.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */; };
                CD321B041E3A85FA00EB21C8 /* video-with-muted-audio-and-webaudio.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CD321B031E3A84B700EB21C8 /* video-with-muted-audio-and-webaudio.html */; };
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
                        dstPath = TestWebKitAPI.resources;
                        dstSubfolderSpec = 7;
                        files = (
+                               C99BDF891E80980400C7170E /* autoplay-zero-volume-check.html in Copy Resources */,
                                A14AAB651E78DC5400C1ADC2 /* encrypted.pdf in Copy Resources */,
                                A1409AD91E7254D4004949D9 /* password-protected.pages in Copy Resources */,
                                5120C83E1E67678F0025B250 /* WebsiteDataStoreCustomPaths.html in Copy Resources */,
                                A14AAB651E78DC5400C1ADC2 /* encrypted.pdf in Copy Resources */,
                                A1409AD91E7254D4004949D9 /* password-protected.pages in Copy Resources */,
                                5120C83E1E67678F0025B250 /* WebsiteDataStoreCustomPaths.html in Copy Resources */,
                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-with-controls.html"; sourceTree = "<group>"; };
                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "js-play-with-controls.html"; sourceTree = "<group>"; };
                C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "no-autoplay-with-controls.html"; sourceTree = "<group>"; };
                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-with-controls.html"; sourceTree = "<group>"; };
                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "js-play-with-controls.html"; sourceTree = "<group>"; };
                C99B675E1E39735C00FC6C80 /* no-autoplay-with-controls.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "no-autoplay-with-controls.html"; sourceTree = "<group>"; };
+               C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-zero-volume-check.html"; sourceTree = "<group>"; };
                C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
                C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
                CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
                C9C60E631E53A9BA006DA181 /* autoplay-check-frame.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-frame.html"; sourceTree = "<group>"; };
                C9C60E641E53A9BA006DA181 /* autoplay-check-in-iframe.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = "autoplay-check-in-iframe.html"; sourceTree = "<group>"; };
                CD225C071C45A69200140761 /* ParsedContentRange.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParsedContentRange.cpp; sourceTree = "<group>"; };
                                C95984F21E36BC55002C0D45 /* autoplay-check.html */,
                                C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */,
                                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */,
                                C95984F21E36BC55002C0D45 /* autoplay-check.html */,
                                C95984F31E36BC55002C0D45 /* autoplay-no-audio-check.html */,
                                C99B675A1E3971FC00FC6C80 /* autoplay-with-controls.html */,
+                               C99BDF881E8097E300C7170E /* autoplay-zero-volume-check.html */,
                                7C486BA01AA1254B003F6F9B /* bundle-file.html */,
                                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,
                                1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */,
                                7C486BA01AA1254B003F6F9B /* bundle-file.html */,
                                9BD4239B1E04BFD000200395 /* chinese-character-with-image.html */,
                                1A50AA1F1A2A4EA500F4C345 /* close-from-within-create-page.html */,
                                BCBD372E125ABBE600D2C29F /* icon.png */,
                                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */,
                                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */,
                                BCBD372E125ABBE600D2C29F /* icon.png */,
                                CE3524F51B142BBB0028A7C5 /* input-focus-blur.html */,
                                C99B675B1E3971FC00FC6C80 /* js-play-with-controls.html */,
-                               8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */,
                                8361F1771E610B2100759B25 /* link-with-download-attribute-with-slashes.html */,
                                8361F1771E610B2100759B25 /* link-with-download-attribute-with-slashes.html */,
+                               8349D3C31DB9724F004A9F65 /* link-with-download-attribute.html */,
                                378E647816326FDF00B6C676 /* link-with-title.html */,
                                9361002814DC957B0061379D /* lots-of-iframes.html */,
                                93AF4ECF1506F123007FD57E /* lots-of-images.html */,
                                378E647816326FDF00B6C676 /* link-with-title.html */,
                                9361002814DC957B0061379D /* lots-of-iframes.html */,
                                93AF4ECF1506F123007FD57E /* lots-of-images.html */,
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-zero-volume-check.html b/Tools/TestWebKitAPI/Tests/WebKit2/autoplay-zero-volume-check.html
new file mode 100644 (file)
index 0000000..8ffb0c5
--- /dev/null
@@ -0,0 +1,22 @@
+<html>
+    <head>
+        <script>
+            function pageLoaded() {
+                var video = document.getElementById("video");
+                video.volume = 0;
+                video.play().then(function() {
+                    try {
+                        window.webkit.messageHandlers.testHandler.postMessage("autoplayed");
+                    } catch(e) { }
+                }).catch(function() {
+                    try {
+                        window.webkit.messageHandlers.testHandler.postMessage("did-not-play");
+                    } catch(e) { }
+                });
+            }
+        </script>
+    </head>
+    <body onload="pageLoaded()">
+        <video id="video" playsinline src="test.mp4" />
+    </body>
+</html>
index 9b041d4..1de93a1 100644 (file)
@@ -214,6 +214,7 @@ TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
 
     NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     NSURLRequest *requestWithoutAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-no-audio-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
 
     NSURLRequest *requestWithAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     NSURLRequest *requestWithoutAudio = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-no-audio-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    NSURLRequest *requestWithoutVolume = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-zero-volume-check" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     
     [delegate setAutoplayPolicyForURL:^(NSURL *) {
         return _WKWebsiteAutoplayPolicyAllowWithoutSound;
     
     [delegate setAutoplayPolicyForURL:^(NSURL *) {
         return _WKWebsiteAutoplayPolicyAllowWithoutSound;
@@ -224,9 +225,15 @@ TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
 
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
 
+    [webView loadRequest:requestWithoutVolume];
+    [webView waitForMessage:@"autoplayed"];
+
     [delegate setAutoplayPolicyForURL:^(NSURL *) {
         return _WKWebsiteAutoplayPolicyDeny;
     }];
     [delegate setAutoplayPolicyForURL:^(NSURL *) {
         return _WKWebsiteAutoplayPolicyDeny;
     }];
+    [webView loadRequest:requestWithoutVolume];
+    [webView waitForMessage:@"did-not-play"];
+
     [webView loadRequest:requestWithAudio];
     [webView waitForMessage:@"did-not-play"];
 
     [webView loadRequest:requestWithAudio];
     [webView waitForMessage:@"did-not-play"];
 
@@ -249,6 +256,9 @@ TEST(WebKit2, WebsitePoliciesAutoplayEnabled)
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
 
     [webView loadRequest:requestWithoutAudio];
     [webView waitForMessage:@"autoplayed"];
 
+    [webView loadRequest:requestWithoutVolume];
+    [webView waitForMessage:@"autoplayed"];
+
     NSURLRequest *requestWithAudioInIFrame = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check-in-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
 
     // If the top-level document allows autoplay, any iframes should also autoplay.
     NSURLRequest *requestWithAudioInIFrame = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"autoplay-check-in-iframe" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
 
     // If the top-level document allows autoplay, any iframes should also autoplay.