Videos allowed to play through the Main Content restriction should not pause when...
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 May 2016 16:20:20 +0000 (16:20 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 11 May 2016 16:20:20 +0000 (16:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=157555

Reviewed by Eric Carlson.

Source/WebCore:

Test: media/video-main-content-allow-then-scroll.html

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

LayoutTests:

* media/video-main-content-allow-then-scroll-expected.txt: Added.
* media/video-main-content-allow-then-scroll.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/video-main-content-allow-then-scroll-expected.txt [new file with mode: 0644]
LayoutTests/media/video-main-content-allow-then-scroll.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/MediaElementSession.cpp

index b5484e0..8686035 100644 (file)
@@ -1,3 +1,13 @@
+2016-05-11  Jer Noble  <jer.noble@apple.com>
+
+        Videos allowed to play through the Main Content restriction should not pause when scrolled off-screen.
+        https://bugs.webkit.org/show_bug.cgi?id=157555
+
+        Reviewed by Eric Carlson.
+
+        * media/video-main-content-allow-then-scroll-expected.txt: Added.
+        * media/video-main-content-allow-then-scroll.html: Added.
+
 2016-05-11  Pranjal Jumde  <pjumde@apple.com>
 
         Sites served over insecure connections should not be allowed to use geolocation.
diff --git a/LayoutTests/media/video-main-content-allow-then-scroll-expected.txt b/LayoutTests/media/video-main-content-allow-then-scroll-expected.txt
new file mode 100644 (file)
index 0000000..8ac79c8
--- /dev/null
@@ -0,0 +1,8 @@
+RUN(internals.setMediaElementRestrictions(video, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent"))
+EVENT(canplaythrough)
+EVENT(playing)
+RUN(document.body.scrollTop = document.body.clientHeight)
+EXPECTED (video.paused == 'false') OK
+END OF TEST
+
+
diff --git a/LayoutTests/media/video-main-content-allow-then-scroll.html b/LayoutTests/media/video-main-content-allow-then-scroll.html
new file mode 100644 (file)
index 0000000..22d8933
--- /dev/null
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <title>video-main-content-allow</title>
+    <script src="video-test.js"></script>
+    <script src="media-file.js"></script>
+    <script>
+    function go() {
+        video = document.createElement('video');
+        run('internals.setMediaElementRestrictions(video, "RequireUserGestureForVideoRateChange,OverrideUserGestureRequirementForMainContent")');
+        document.body.appendChild(video);
+        var spacer = document.body.appendChild(document.createElement('div'));
+        spacer.id = 'spacer';
+
+        video.src = findMediaFile('video', 'content/test');
+        waitForEvent('canplaythrough', canPlayThrough);
+    }
+
+    function canPlayThrough() {
+        video.play();
+        waitForEvent('playing', playing);
+    }
+
+    function playing() {
+        run('document.body.scrollTop = document.body.clientHeight');
+        waitForEventAndFail('pause');
+        setTimeout(afterPlaying, 100);
+    }
+
+    function afterPlaying() {
+        testExpected('video.paused', false);
+        endTest();
+    }
+    </script>
+    <style>
+    html, body, #spacer {
+        height: 100%;
+    }
+    video {
+        width: 600px;
+        height: 400px;
+    }
+    </style>
+</head>
+<body onload="go()">
+</body>
+</html>
\ No newline at end of file
index ff7a5b8..0add0d4 100644 (file)
@@ -1,3 +1,15 @@
+2016-05-11  Jer Noble  <jer.noble@apple.com>
+
+        Videos allowed to play through the Main Content restriction should not pause when scrolled off-screen.
+        https://bugs.webkit.org/show_bug.cgi?id=157555
+
+        Reviewed by Eric Carlson.
+
+        Test: media/video-main-content-allow-then-scroll.html
+
+        * html/MediaElementSession.cpp:
+        (WebCore::isMainContent):
+
 2016-05-11  Fujii Hironori  <Hironori.Fujii@sony.com>
 
         [curl] curl_easy_setopt(CURLOPT_CONNECT_ONLY) should take a long parameter
index 00b8ae0..95b729d 100644 (file)
@@ -511,9 +511,13 @@ static bool isMainContent(const HTMLMediaElement& element)
         return false;
 
     // Elements which are hidden by style, or have been scrolled out of view, cannot be main content.
+    // But elements which have audio & video and are already playing should not stop playing because
+    // they are scrolled off the page.
     if (renderer->style().visibility() != VISIBLE
-        || renderer->visibleInViewportState() != RenderElement::VisibleInViewport)
+        || (renderer->visibleInViewportState() != RenderElement::VisibleInViewport && !element.isPlaying())
+        ) {
         return false;
+    }
 
     // Main content elements must be in the main frame.
     Document& document = element.document();