Title: [225265] trunk
Revision
225265
Author
grao...@webkit.org
Date
2017-11-29 05:31:36 -0800 (Wed, 29 Nov 2017)

Log Message

Pressing the space bar while watching a fullscreen video doesn't play or pause
https://bugs.webkit.org/show_bug.cgi?id=180033
<rdar://problem/33610443>

Reviewed by Eric Carlson.

Source/WebCore:

We register a "keydown" event to track when the space bar is pressed, and if the media is playing
in fullscreen, we toggle playback. This does not interfere with full keyboard access since activating
one of the media controls using the keyboard will not let the events we register for be dispatched
this far along the event dispatch phase.

Test: media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html

* Modules/modern-media-controls/media/media-controller.js:
(MediaController):
(MediaController.prototype.togglePlayback): Add a catch() statement since calling play() could sometime
lead to some extraneous unhandled promise console logging that pollutes test output.
(MediaController.prototype.handleEvent):

LayoutTests:

Adding a new macOS-only test that checks that pressing the space bar while playing fullscreen
pauses the media and resumes it when pressing the space bar again.

* media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt: Added.
* media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html: Added.
* media/video-test.js:
(runWithKeyDown): Update the key to not be space since this would cause media to be paused when entering fullscreen.
* platform/ios-simulator/TestExpectations:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (225264 => 225265)


--- trunk/LayoutTests/ChangeLog	2017-11-29 07:52:47 UTC (rev 225264)
+++ trunk/LayoutTests/ChangeLog	2017-11-29 13:31:36 UTC (rev 225265)
@@ -1,3 +1,20 @@
+2017-11-29  Antoine Quint  <grao...@apple.com>
+
+        Pressing the space bar while watching a fullscreen video doesn't play or pause
+        https://bugs.webkit.org/show_bug.cgi?id=180033
+        <rdar://problem/33610443>
+
+        Reviewed by Eric Carlson.
+
+        Adding a new macOS-only test that checks that pressing the space bar while playing fullscreen
+        pauses the media and resumes it when pressing the space bar again.
+
+        * media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt: Added.
+        * media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html: Added.
+        * media/video-test.js:
+        (runWithKeyDown): Update the key to not be space since this would cause media to be paused when entering fullscreen.
+        * platform/ios-simulator/TestExpectations:
+
 2017-11-28  Zan Dobersek  <zdober...@igalia.com>
 
         [Cairo] Limit the number of active contexts in GraphicsContext3DCairo

Added: trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt (0 => 225265)


--- trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt	2017-11-29 13:31:36 UTC (rev 225265)
@@ -0,0 +1,29 @@
+Testing media is paused and resumed when pressing the space bar in fullscreen.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+Obtained a 'play' event.
+
+Entering fullscreen.
+
+Obtained a 'webkitfullscreenchange' event.
+media.webkitDisplayingFullscreen = true.
+PASS media.paused is false
+
+Pressing the space bar.
+
+Obtained a 'pause' event.
+
+Pressing the space bar.
+
+Obtained a 'play' event.
+
+Obtained a 'webkitfullscreenchange' event.
+media.webkitDisplayingFullscreen = false.
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html (0 => 225265)


--- trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html	                        (rev 0)
+++ trunk/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html	2017-11-29 13:31:36 UTC (rev 225265)
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<script src=""
+<script src="" type="text/_javascript_"></script>
+<body>
+<video src="" style="width: 320px; height: 240px;" controls autoplay></video>
+<script type="text/_javascript_">
+
+window.jsTestIsAsync = true;
+
+description("Testing media is paused and resumed when pressing the space bar in fullscreen.");
+
+const media = document.querySelector("video");
+const button = document.body.appendChild(document.createElement("button"));
+button.textContent = "Enter Fullscreen";
+
+media.addEventListener("webkitfullscreenchange", () => {
+    debug("");
+    debug("Obtained a 'webkitfullscreenchange' event.");
+    debug(`media.webkitDisplayingFullscreen = ${media.webkitDisplayingFullscreen}.`);
+
+    if (media.webkitDisplayingFullscreen) {
+        shouldBeFalse("media.paused");
+        pressSpace();
+    } else
+        endTest();
+});
+
+let playCount = 0;
+media.addEventListener("play", () => {
+    playCount++;
+
+    debug("");
+    debug("Obtained a 'play' event.");
+
+    if (playCount == 1)
+        startTest();
+    else
+        media.webkitExitFullscreen();
+});
+
+media.addEventListener("pause", () => {
+    debug("");
+    debug("Obtained a 'pause' event.");
+
+    // Test pressing the space bar while the media is paused.
+    pressSpace();
+});
+
+
+function enterFullscreen() {
+    debug("");
+    debug("Entering fullscreen.");
+    button.addEventListener("click", () => {
+        try {
+            media.webkitEnterFullscreen();
+        } catch(e) {
+            debug("Toggling fullscreen failed.");
+            finishJSTest();
+        }
+    });
+
+    pressOnElement(button);
+}
+
+function pressSpace()
+{
+    debug("");
+    debug("Pressing the space bar.");
+    eventSender.keyDown(" ");
+}
+
+function startTest()
+{
+    enterFullscreen();
+}
+
+function endTest()
+{
+    debug("");
+    button.remove();
+    media.remove();
+    finishJSTest();
+}
+
+</script>
+<script src=""
+</body>

Modified: trunk/LayoutTests/media/video-test.js (225264 => 225265)


--- trunk/LayoutTests/media/video-test.js	2017-11-29 07:52:47 UTC (rev 225264)
+++ trunk/LayoutTests/media/video-test.js	2017-11-29 13:31:36 UTC (rev 225265)
@@ -414,7 +414,7 @@
 
     if (window.testRunner) {
         if (eventSender.keyDown)
-            eventSender.keyDown(" ", []);
+            eventSender.keyDown("a", []);
         else
             eventSender.mouseDown();
     }

Modified: trunk/LayoutTests/platform/ios-simulator/TestExpectations (225264 => 225265)


--- trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-29 07:52:47 UTC (rev 225264)
+++ trunk/LayoutTests/platform/ios-simulator/TestExpectations	2017-11-29 13:31:36 UTC (rev 225265)
@@ -128,6 +128,7 @@
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-should-pause-fullscreen.html [ Skip ]
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-should-pause.html [ Skip ]
 media/modern-media-controls/media-controller/media-controller-click-on-video-background-to-dismiss-tracks-panel-should-not-toggle-playback.html [ Skip ]
+media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html [ Skip ]
 media/modern-media-controls/media-documents/media-document-audio-mac-sizing.html [ Skip ]
 media/modern-media-controls/media-documents/media-document-video-mac-sizing.html [ Skip ]
 media/modern-media-controls/playback-support/playback-support-button-click.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (225264 => 225265)


--- trunk/Source/WebCore/ChangeLog	2017-11-29 07:52:47 UTC (rev 225264)
+++ trunk/Source/WebCore/ChangeLog	2017-11-29 13:31:36 UTC (rev 225265)
@@ -1,3 +1,24 @@
+2017-11-29  Antoine Quint  <grao...@apple.com>
+
+        Pressing the space bar while watching a fullscreen video doesn't play or pause
+        https://bugs.webkit.org/show_bug.cgi?id=180033
+        <rdar://problem/33610443>
+
+        Reviewed by Eric Carlson.
+
+        We register a "keydown" event to track when the space bar is pressed, and if the media is playing
+        in fullscreen, we toggle playback. This does not interfere with full keyboard access since activating
+        one of the media controls using the keyboard will not let the events we register for be dispatched
+        this far along the event dispatch phase.
+
+        Test: media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html
+
+        * Modules/modern-media-controls/media/media-controller.js:
+        (MediaController):
+        (MediaController.prototype.togglePlayback): Add a catch() statement since calling play() could sometime
+        lead to some extraneous unhandled promise console logging that pollutes test output.
+        (MediaController.prototype.handleEvent):
+
 2017-11-28  Brent Fulgham  <bfulg...@apple.com>
 
         Adopt updated NSKeyed[Un]Archiver API when available

Modified: trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js (225264 => 225265)


--- trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js	2017-11-29 07:52:47 UTC (rev 225264)
+++ trunk/Source/WebCore/Modules/modern-media-controls/media/media-controller.js	2017-11-29 13:31:36 UTC (rev 225265)
@@ -57,6 +57,8 @@
         media.videoTracks.addEventListener("removetrack", this);
 
         media.addEventListener(this.fullscreenChangeEventType, this);
+
+        window.addEventListener("keydown", this);
     }
 
     // Public
@@ -100,7 +102,7 @@
     togglePlayback()
     {
         if (this.media.paused)
-            this.media.play();
+            this.media.play().catch(e => {});
         else
             this.media.pause();
     }
@@ -158,6 +160,9 @@
             this._updateControlsIfNeeded();
             if (event.type === "webkitpresentationmodechanged")
                 this._returnMediaLayerToInlineIfNeeded();
+        } else if (event.type === "keydown" && this.isFullscreen && event.key === " ") {
+            this.togglePlayback();
+            event.preventDefault();
         }
     }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to