HTMLMediaElement::isPlayingAudio() should return false if the element is explicitly...
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jan 2015 18:50:55 +0000 (18:50 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 19 Jan 2015 18:50:55 +0000 (18:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=140524

Reviewed by Andreas Kling.

Source/WebCore:

Test: media/muted-video-is-playing-audio.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::setMuted):
Call Document::updateIsPlayingAudio() to recalculate the overall audio playing state.
(WebCore::HTMLMediaElement::isPlayingAudio):
HTMLMediaElement::isPlayingAudio() should return false if the media element is explicitly muted.

LayoutTests:

The test contains a looping video. It makes sure initially Page::isPlayingAudio() returns true.
It should return false after the video is muted, and true again after the video is unmuted.

* media/muted-video-is-playing-audio-expected.txt: Added.
* media/muted-video-is-playing-audio.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/media/muted-video-is-playing-audio-expected.txt [new file with mode: 0644]
LayoutTests/media/muted-video-is-playing-audio.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/html/HTMLMediaElement.cpp

index abf21ab..386918f 100644 (file)
@@ -1,3 +1,16 @@
+2015-01-16  Ada Chan  <adachan@apple.com>
+
+        HTMLMediaElement::isPlayingAudio() should return false if the element is explicitly muted by script.
+        https://bugs.webkit.org/show_bug.cgi?id=140524
+
+        Reviewed by Andreas Kling.
+
+        The test contains a looping video. It makes sure initially Page::isPlayingAudio() returns true.
+        It should return false after the video is muted, and true again after the video is unmuted.
+
+        * media/muted-video-is-playing-audio-expected.txt: Added.
+        * media/muted-video-is-playing-audio.html: Added.
+
 2015-01-19  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [SVG -> OTF Converter] Flip the switch on
diff --git a/LayoutTests/media/muted-video-is-playing-audio-expected.txt b/LayoutTests/media/muted-video-is-playing-audio-expected.txt
new file mode 100644 (file)
index 0000000..90790ac
--- /dev/null
@@ -0,0 +1,15 @@
+Testing that muting a video element should result in page's audio playing state to become false
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS window.internals.isPagePlayingAudio() became true
+PASS window.internals.isPagePlayingAudio() became false
+PASS window.internals.isPagePlayingAudio() became true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+RUN(video.muted = true)
+RUN(video.muted = false)
+
diff --git a/LayoutTests/media/muted-video-is-playing-audio.html b/LayoutTests/media/muted-video-is-playing-audio.html
new file mode 100644 (file)
index 0000000..3c08179
--- /dev/null
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src="../resources/js-test-pre.js"></script>
+    </head>
+    <body>
+        <video src="content/audio-tracks.mp4" controls autoplay loop></video>
+        <script src="media-file.js"></script>
+        <script src="video-test.js"></script>
+        <script>
+            description("Testing that muting a video element should result in page's audio playing state to become false");
+
+            jsTestIsAsync = true;
+
+            function testUnmutingVideo()
+            {
+                run("video.muted = false");
+                shouldBecomeEqual("window.internals.isPagePlayingAudio()", "true", finishJSTest);
+            }
+
+            function testMutingVideo()
+            {
+                run("video.muted = true");
+                shouldBecomeEqual("window.internals.isPagePlayingAudio()", "false", testUnmutingVideo);
+            }
+
+            shouldBecomeEqual("window.internals.isPagePlayingAudio()", "true", testMutingVideo);
+        </script>
+        <script src="../resources/js-test-post.js"></script>
+    </body>
+</html>
index 1745eef..08149d7 100644 (file)
@@ -1,3 +1,18 @@
+2015-01-16  Ada Chan  <adachan@apple.com>
+
+        HTMLMediaElement::isPlayingAudio() should return false if the element is explicitly muted by script.
+        https://bugs.webkit.org/show_bug.cgi?id=140524
+
+        Reviewed by Andreas Kling.
+
+        Test: media/muted-video-is-playing-audio.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::setMuted):
+        Call Document::updateIsPlayingAudio() to recalculate the overall audio playing state.
+        (WebCore::HTMLMediaElement::isPlayingAudio):
+        HTMLMediaElement::isPlayingAudio() should return false if the media element is explicitly muted.
+
 2015-01-19  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [SVG -> OTF Converter] Flip the switch on
index 1b5f67d..e4b8acd 100644 (file)
@@ -3033,6 +3033,7 @@ void HTMLMediaElement::setMuted(bool muted)
             }
         }
         scheduleEvent(eventNames().volumechangeEvent);
+        document().updateIsPlayingAudio();
     }
 #endif
 }
@@ -6107,7 +6108,7 @@ bool HTMLMediaElement::overrideBackgroundPlaybackRestriction() const
 
 bool HTMLMediaElement::isPlayingAudio()
 {
-    return isPlaying() && hasAudio();
+    return isPlaying() && hasAudio() && !muted();
 }
 
 void HTMLMediaElement::pageMutedStateDidChange()