Make MediaStream/MediaStreamTrack page cache friendly
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Nov 2019 21:41:09 +0000 (21:41 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 Nov 2019 21:41:09 +0000 (21:41 +0000)
https://bugs.webkit.org/show_bug.cgi?id=204030

Reviewed by Chris Dumez.

Source/WebCore:

Test: http/tests/navigation/page-cache-mediastream.html

* Modules/mediastream/MediaStream.cpp:
Remove the unnneeded opt-out of page cache in case of MediaStream.
* Modules/mediastream/MediaStream.h:
* Modules/mediastream/MediaStreamTrack.cpp:
(WebCore::MediaStreamTrack::suspend):
In case of a capture track, end it at suspend time  but fire ended event at resume time.
* Modules/mediastream/MediaStreamTrack.h:

LayoutTests:

* platform/mac-wk1/TestExpectations: Disabled test for WK1.
* http/tests/navigation/page-cache-mediastream-expected.txt: Added.
* http/tests/navigation/page-cache-mediastream.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/http/tests/navigation/page-cache-mediastream-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/navigation/page-cache-mediastream.html [new file with mode: 0644]
LayoutTests/platform/mac-wk1/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/MediaStream.cpp
Source/WebCore/Modules/mediastream/MediaStream.h
Source/WebCore/Modules/mediastream/MediaStreamTrack.cpp
Source/WebCore/Modules/mediastream/MediaStreamTrack.h

index 607e816..692a346 100644 (file)
@@ -1,3 +1,14 @@
+2019-11-11  Youenn Fablet  <youenn@apple.com>
+
+        Make MediaStream/MediaStreamTrack page cache friendly
+        https://bugs.webkit.org/show_bug.cgi?id=204030
+
+        Reviewed by Chris Dumez.
+
+        * platform/mac-wk1/TestExpectations: Disabled test for WK1.
+        * http/tests/navigation/page-cache-mediastream-expected.txt: Added.
+        * http/tests/navigation/page-cache-mediastream.html: Added.
+
 2019-11-11  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r252076.
diff --git a/LayoutTests/http/tests/navigation/page-cache-mediastream-expected.txt b/LayoutTests/http/tests/navigation/page-cache-mediastream-expected.txt
new file mode 100644 (file)
index 0000000..150da52
--- /dev/null
@@ -0,0 +1,13 @@
+Tests that a page with a capture track goes into the page cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the page cache
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/http/tests/navigation/page-cache-mediastream.html b/LayoutTests/http/tests/navigation/page-cache-mediastream.html
new file mode 100644 (file)
index 0000000..ef9c351
--- /dev/null
@@ -0,0 +1,54 @@
+<!-- webkit-test-runner [ enableBackForwardCache=true ] -->
+<!DOCTYPE html>
+<html>
+<body>
+<canvas id="myCanvas"></canvas>
+<script src="/resources/js-test-pre.js"></script>
+<script>
+description('Tests that a page with a capture track goes into the page cache.');
+window.jsTestIsAsync = true;
+
+var restoredFromPageCache = false;
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+
+    if (event.persisted) {
+        testPassed("Page did enter and was restored from the page cache");
+        restoredFromPageCache = true;
+
+        if (!canvasStream.active)
+            testFailed("Canvas stream is not active");
+
+        if (gumStream.active)
+            testFailed("GUM stream is active");
+    }
+}, false);
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        testFailed("Page did not enter the page cache.");
+        finishJSTest();
+    }
+}, false);
+
+var gumStream;
+var canvasStream;
+
+window.addEventListener('load', async function() {
+    gumStream = await navigator.mediaDevices.getUserMedia({ audio: true });
+    gumStream.getAudioTracks()[0].onended = finishJSTest;
+    canvasStream = myCanvas.captureStream();
+    // This needs to happen in a setTimeout because a navigation inside the onload handler would
+    // not create a history entry.
+    setTimeout(function() {
+      // Force a back navigation back to this page.
+      window.location.href = "resources/page-cache-helper.html";
+    }, 0);
+}, false);
+
+</script>
+<script src="/resources/js-test-post.js"></script>
+</body>
+</html>
index 7c32c83..43191a7 100644 (file)
@@ -60,6 +60,7 @@ http/tests/media/media-stream
 http/tests/ssl/media-stream
 inspector/page/overrideSetting-MockCaptureDevicesEnabled.html [ Skip ]
 http/tests/navigation/page-cache-getUserMedia-pending-promise.html [ Skip ]
+http/tests/navigation/page-cache-mediastream.html [ Skip ]
 
 # Datalist is unsupported in WK1
 accessibility/datalist.html [ WontFix ]
index 14ceafb..82eccf9 100644 (file)
@@ -1,3 +1,20 @@
+2019-11-11  Youenn Fablet  <youenn@apple.com>
+
+        Make MediaStream/MediaStreamTrack page cache friendly
+        https://bugs.webkit.org/show_bug.cgi?id=204030
+
+        Reviewed by Chris Dumez.
+
+        Test: http/tests/navigation/page-cache-mediastream.html
+
+        * Modules/mediastream/MediaStream.cpp:
+        Remove the unnneeded opt-out of page cache in case of MediaStream.
+        * Modules/mediastream/MediaStream.h:
+        * Modules/mediastream/MediaStreamTrack.cpp:
+        (WebCore::MediaStreamTrack::suspend):
+        In case of a capture track, end it at suspend time  but fire ended event at resume time.
+        * Modules/mediastream/MediaStreamTrack.h:
+
 2019-11-11  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r252076.
index 504d117..cc73464 100644 (file)
@@ -400,12 +400,6 @@ const char* MediaStream::activeDOMObjectName() const
     return "MediaStream";
 }
 
-// FIXME: This should never prevent entering the back/forward cache.
-bool MediaStream::shouldPreventEnteringBackForwardCache_DEPRECATED() const
-{
-    return hasPendingActivity();
-}
-
 bool MediaStream::hasPendingActivity() const
 {
     return m_isActive;
index 41da762..18e56e8 100644 (file)
@@ -146,7 +146,6 @@ private:
     // ActiveDOMObject API.
     void stop() final;
     const char* activeDOMObjectName() const final;
-    bool shouldPreventEnteringBackForwardCache_DEPRECATED() const final;
 
     void updateActiveState();
     void activityEventTimerFired();
index 44bfa9b..893b5a7 100644 (file)
@@ -556,10 +556,18 @@ const char* MediaStreamTrack::activeDOMObjectName() const
     return "MediaStreamTrack";
 }
 
-// FIXME: This should never prevent entering the back/forward cache.
-bool MediaStreamTrack::shouldPreventEnteringBackForwardCache_DEPRECATED() const
+void MediaStreamTrack::suspend(ReasonForSuspension reason)
 {
-    return hasPendingActivity();
+    if (reason != ReasonForSuspension::BackForwardCache)
+        return;
+
+    // We only end capture tracks, other tracks (capture canvas, remote tracks) can still continue working.
+    if (m_ended || !isCaptureTrack())
+        return;
+
+    stopTrack();
+
+    queueTaskToDispatchEvent(*this, TaskSource::Networking, Event::create(eventNames().endedEvent, Event::CanBubble::No, Event::IsCancelable::No));
 }
 
 bool MediaStreamTrack::hasPendingActivity() const
index 692f083..f58041f 100644 (file)
@@ -177,7 +177,7 @@ private:
     // ActiveDOMObject API.
     void stop() final;
     const char* activeDOMObjectName() const final;
-    bool shouldPreventEnteringBackForwardCache_DEPRECATED() const final;
+    void suspend(ReasonForSuspension) final;
 
     // EventTarget
     void refEventTarget() final { ref(); }