[Modern Media Controls] Captions do not default to Auto when language is changed
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Mar 2017 17:40:59 +0000 (17:40 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 15 Mar 2017 17:40:59 +0000 (17:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=169675
<rdar://problem/30423369>

Patch by Antoine Quint <graouts@apple.com> on 2017-03-15
Reviewed by Eric Carlson.

Source/WebCore:

Ensure we correctly mark the Off and Auto items as selected when we are using the
Off and Auto tracks.

Tests: media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html
       media/modern-media-controls/tracks-support/tracks-support-off-text-track.html

* Modules/modern-media-controls/media/tracks-support.js:
(TracksSupport.prototype.tracksPanelIsTrackInSectionSelected):
(TracksSupport.prototype.tracksPanelSelectionDidChange):

LayoutTests:

Add new tests that check the cases where the expected selected track should be "Off" or "Auto".

* media/modern-media-controls/tracks-support/tracks-support-auto-text-track-expected.txt: Added.
* media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html: Added.
* media/modern-media-controls/tracks-support/tracks-support-off-text-track-expected.txt: Added.
* media/modern-media-controls/tracks-support/tracks-support-off-text-track.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track-expected.txt [new file with mode: 0644]
LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html [new file with mode: 0644]
LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track-expected.txt [new file with mode: 0644]
LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/modern-media-controls/media/tracks-support.js

index 43ec085..24d059b 100644 (file)
@@ -1,3 +1,18 @@
+2017-03-15  Antoine Quint  <graouts@apple.com>
+
+        [Modern Media Controls] Captions do not default to Auto when language is changed
+        https://bugs.webkit.org/show_bug.cgi?id=169675
+        <rdar://problem/30423369>
+
+        Reviewed by Eric Carlson.
+
+        Add new tests that check the cases where the expected selected track should be "Off" or "Auto".
+
+        * media/modern-media-controls/tracks-support/tracks-support-auto-text-track-expected.txt: Added.
+        * media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html: Added.
+        * media/modern-media-controls/tracks-support/tracks-support-off-text-track-expected.txt: Added.
+        * media/modern-media-controls/tracks-support/tracks-support-off-text-track.html: Added.
+
 2017-03-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Mark http/tests/media/modern-media-controls/time-labels-support/long-time.html as flaky on mac-wk1.
diff --git a/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track-expected.txt b/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track-expected.txt
new file mode 100644 (file)
index 0000000..adac0b7
--- /dev/null
@@ -0,0 +1,14 @@
+Ensure we have the Auto text track selected by default.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS shadowRoot.querySelector('button.tracks') became different from null
+PASS shadowRoot.querySelector('button.tracks').getBoundingClientRect().width became different from 0
+PASS shadowRoot.querySelector('.tracks-panel') became different from null
+PASS shadowRoot.querySelectorAll('li.selected')[1].textContent is "Auto (Recommended)"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html b/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html
new file mode 100644 (file)
index 0000000..1b3c3e6
--- /dev/null
@@ -0,0 +1,35 @@
+<!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/CC+Subtitles.mov" style="position: absolute; left: 0; top: 0; width: 640px; height: 360px;" controls autoplay></video>
+<script type="text/javascript">
+
+window.jsTestIsAsync = true;
+
+description("Ensure we have the Auto text track selected by default.");
+
+const media = document.querySelector("video");
+const shadowRoot = window.internals.shadowRoot(media);
+
+media.addEventListener("play", () => {
+    media.pause();
+
+    shouldBecomeDifferent("shadowRoot.querySelector('button.tracks')", "null", () => {
+        shouldBecomeDifferent("shadowRoot.querySelector('button.tracks').getBoundingClientRect().width", "0", () => {
+            window.internals.setCaptionDisplayMode("automatic");
+            pressOnElement(shadowRoot.querySelector("button.tracks"));
+            shouldBecomeDifferent("shadowRoot.querySelector('.tracks-panel')", "null", () => {
+                shouldBeEqualToString("shadowRoot.querySelectorAll('li.selected')[1].textContent", "Auto (Recommended)");
+                debug("");
+                window.internals.setCaptionDisplayMode("forcedonly");
+                media.remove();
+                finishJSTest();
+            });
+        });
+    });
+});
+
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
diff --git a/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track-expected.txt b/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track-expected.txt
new file mode 100644 (file)
index 0000000..fb3e318
--- /dev/null
@@ -0,0 +1,14 @@
+Ensure we have the Off text track selected by default.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS shadowRoot.querySelector('button.tracks') became different from null
+PASS shadowRoot.querySelector('button.tracks').getBoundingClientRect().width became different from 0
+PASS shadowRoot.querySelector('.tracks-panel') became different from null
+PASS shadowRoot.querySelectorAll('li.selected')[1].textContent is "Off"
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track.html b/LayoutTests/media/modern-media-controls/tracks-support/tracks-support-off-text-track.html
new file mode 100644 (file)
index 0000000..ecb9d6e
--- /dev/null
@@ -0,0 +1,33 @@
+<!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/CC+Subtitles.mov" style="position: absolute; left: 0; top: 0; width: 640px; height: 360px;" controls autoplay></video>
+<script type="text/javascript">
+
+window.jsTestIsAsync = true;
+
+description("Ensure we have the Off text track selected by default.");
+
+const media = document.querySelector("video");
+const shadowRoot = window.internals.shadowRoot(media);
+
+media.addEventListener("play", () => {
+    media.pause();
+
+    shouldBecomeDifferent("shadowRoot.querySelector('button.tracks')", "null", () => {
+        shouldBecomeDifferent("shadowRoot.querySelector('button.tracks').getBoundingClientRect().width", "0", () => {
+            pressOnElement(shadowRoot.querySelector("button.tracks"));
+            shouldBecomeDifferent("shadowRoot.querySelector('.tracks-panel')", "null", () => {
+                shouldBeEqualToString("shadowRoot.querySelectorAll('li.selected')[1].textContent", "Off");
+                debug("");
+                media.remove();
+                finishJSTest();
+            });
+        });
+    });
+});
+
+</script>
+<script src="../../../resources/js-test-post.js"></script>
+</body>
index ce27d33..e31a4b8 100644 (file)
@@ -1,3 +1,21 @@
+2017-03-15  Antoine Quint  <graouts@apple.com>
+
+        [Modern Media Controls] Captions do not default to Auto when language is changed
+        https://bugs.webkit.org/show_bug.cgi?id=169675
+        <rdar://problem/30423369>
+
+        Reviewed by Eric Carlson.
+
+        Ensure we correctly mark the Off and Auto items as selected when we are using the
+        Off and Auto tracks.
+
+        Tests: media/modern-media-controls/tracks-support/tracks-support-auto-text-track.html
+               media/modern-media-controls/tracks-support/tracks-support-off-text-track.html
+
+        * Modules/modern-media-controls/media/tracks-support.js:
+        (TracksSupport.prototype.tracksPanelIsTrackInSectionSelected):
+        (TracksSupport.prototype.tracksPanelSelectionDidChange):
+
 2017-03-15  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r213977.
index d0bdf4b..ab57d92 100644 (file)
@@ -100,13 +100,24 @@ class TracksSupport extends MediaControllerSupport
     {
         if (sectionIndex == 0 && this._canPickAudioTracks())
             return this._audioTracks()[trackIndex].enabled;
-        return this._textTracks()[trackIndex].mode !== "disabled";
+
+        const trackItem = this._textTracks()[trackIndex];
+        const host = this.mediaController.host;
+        const usesAutomaticTrack = host ? host.captionDisplayMode === "automatic" : false;
+
+        if (host && trackItem === host.captionMenuOffItem && (host.captionDisplayMode === "forced-only" || host.captionDisplayMode === "manual"))
+            return true;
+        if (host && trackItem === host.captionMenuAutomaticItem && usesAutomaticTrack)
+            return true;
+        return !usesAutomaticTrack && trackItem.mode !== "disabled";
     }
 
     tracksPanelSelectionDidChange(trackIndex, sectionIndex)
     {
         if (sectionIndex == 0 && this._canPickAudioTracks())
             this._audioTracks().forEach((audioTrack, index) => audioTrack.enabled = index === trackIndex);
+        else if (this.mediaController.host)
+            this.mediaController.host.setSelectedTextTrack(this._textTracks()[trackIndex]);
         else
             this._textTracks().forEach((textTrack, index) => textTrack.mode = index === trackIndex ? "showing" : "disabled");