Pressing the space bar while watching a fullscreen video doesn't play or pause
authorgraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 12:31:21 +0000 (12:31 +0000)
committergraouts@webkit.org <graouts@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Nov 2017 12:31:21 +0000 (12:31 +0000)
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.
* platform/ios-simulator/TestExpectations:

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

LayoutTests/ChangeLog
LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt [new file with mode: 0644]
LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html [new file with mode: 0644]
LayoutTests/platform/ios-simulator/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/modern-media-controls/media/media-controller.js

index 73a3cd2..28e236a 100644 (file)
@@ -1,3 +1,18 @@
+2017-11-28  Antoine Quint  <graouts@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.
+        * platform/ios-simulator/TestExpectations:
+
 2017-11-27  Matt Lewis  <jlewis3@apple.com>
 
         Unreviewed, rolling out r225201.
diff --git a/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt b/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback-expected.txt
new file mode 100644 (file)
index 0000000..ca1a3dc
--- /dev/null
@@ -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
+
diff --git a/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html b/LayoutTests/media/modern-media-controls/media-controller/media-controller-space-bar-toggle-playback.html
new file mode 100644 (file)
index 0000000..f305f1e
--- /dev/null
@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<script src="../../../resources/js-test-pre.js"></script>
+<script src="../resources/media-controls-utils.js" type="text/javascript"></script>
+<body>
+<video src="../../content/test.mp4" 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="../../../resources/js-test-post.js"></script>
+</body>
index 1c253a0..d2738c1 100644 (file)
@@ -127,6 +127,7 @@ media/modern-media-controls/media-controller/media-controller-auto-hide-rewind-w
 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 ]
index d7b7ed5..2d3d7b7 100644 (file)
@@ -1,3 +1,24 @@
+2017-11-28  Antoine Quint  <graouts@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-27  Tim Horton  <timothy_horton@apple.com>
 
         Web Content process crashes when dragging a link in recovery mode
index f351552..c2f0808 100644 (file)
@@ -57,6 +57,8 @@ class MediaController
         media.videoTracks.addEventListener("removetrack", this);
 
         media.addEventListener(this.fullscreenChangeEventType, this);
+
+        window.addEventListener("keydown", this);
     }
 
     // Public
@@ -100,7 +102,7 @@ class MediaController
     togglePlayback()
     {
         if (this.media.paused)
-            this.media.play();
+            this.media.play().catch(e => {});
         else
             this.media.pause();
     }
@@ -158,6 +160,9 @@ class MediaController
             this._updateControlsIfNeeded();
             if (event.type === "webkitpresentationmodechanged")
                 this._returnMediaLayerToInlineIfNeeded();
+        } else if (event.type === "keydown" && this.isFullscreen && event.key === " ") {
+            this.togglePlayback();
+            event.preventDefault();
         }
     }