Media: send "did interfere with playback" events when the user pauses an autoplaying...
authormrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Mar 2017 23:50:59 +0000 (23:50 +0000)
committermrajca@apple.com <mrajca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Mar 2017 23:50:59 +0000 (23:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169006

Reviewed by Alex Christensen.

Source/WebCore:

Added API tests.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::pauseInternal):

Tools:

* TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html:
* TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
(TEST): Added.

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

Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm

index 8988849..bfb43bd 100644 (file)
@@ -1,3 +1,15 @@
+2017-02-28  Matt Rajca  <mrajca@apple.com>
+
+        Media: send "did interfere with playback" events when the user pauses an autoplaying element
+        https://bugs.webkit.org/show_bug.cgi?id=169006
+
+        Reviewed by Alex Christensen.
+
+        Added API tests.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::pauseInternal):
+
 2017-03-02  Chris Dumez  <cdumez@apple.com>
 
         We should prevent load of subframes inserted during FrameTree deconstruction
index f84a088..8b9a8c0 100644 (file)
@@ -3256,6 +3256,12 @@ void HTMLMediaElement::pauseInternal()
     }
 
     m_autoplaying = false;
+
+    if (ScriptController::processingUserGestureForMedia() && m_playbackWithoutUserGesture == PlaybackWithoutUserGesture::Started) {
+        if (Page* page = document().page())
+            page->chrome().client().handleAutoplayEvent(AutoplayEvent::UserDidInterfereWithPlayback);
+    }
+
     m_playbackWithoutUserGesture = PlaybackWithoutUserGesture::None;
 
     if (!m_paused) {
index 6f5ad94..3723c44 100644 (file)
@@ -1,3 +1,14 @@
+2017-02-28  Matt Rajca  <mrajca@apple.com>
+
+        Media: send "did interfere with playback" events when the user pauses an autoplaying element
+        https://bugs.webkit.org/show_bug.cgi?id=169006
+
+        Reviewed by Alex Christensen.
+
+        * TestWebKitAPI/Tests/WebKit2/js-play-with-controls.html:
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WebsitePolicies.mm:
+        (TEST): Added.
+
 2017-03-02  Srinivasan Vijayaraghavan  <svijayaraghavan@apple.com>
 
         Refactor test results classes in webkitpy to enable faster EWS iteration
index 815507b..87fad35 100644 (file)
@@ -9,7 +9,11 @@
             }
 
             function play() {
-                document.getElementById("video").play();
+                var video = document.getElementById("video");
+                if (video.paused)
+                    video.play();
+                else
+                    video.pause();
             }
 
             function mute() {
index 22f7554..eca9b7a 100644 (file)
@@ -390,6 +390,16 @@ TEST(WebKit2, WebsitePoliciesUserInterferenceWithPlaying)
     [webView mouseDownAtPoint:muteButtonClickPoint simulatePressure:NO];
     [webView mouseUpAtPoint:muteButtonClickPoint];
     runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
+
+    receivedAutoplayEvent = std::nullopt;
+    [webView loadRequest:jsPlayRequest];
+    [webView waitForMessage:@"playing"];
+    ASSERT_TRUE(receivedAutoplayEvent == std::nullopt);
+
+    const NSPoint playButtonClickPoint = NSMakePoint(20, 256);
+    [webView mouseDownAtPoint:playButtonClickPoint simulatePressure:NO];
+    [webView mouseUpAtPoint:playButtonClickPoint];
+    runUntilReceivesAutoplayEvent(kWKAutoplayEventUserDidInterfereWithPlayback);
 }
 #endif