Bug 1276119 - part2: add test.
MozReview-Commit-ID: 2IHpARlnl2c
new file mode 100644
--- /dev/null
+++ b/dom/base/test/file_pluginAudioNonAutoStart.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<embed type="application/x-test" width="200" height="200"></embed>
+<script>
+var plugin = document.querySelector("embed");
+
+function startAudio() {
+ plugin.startAudioPlayback();
+}
+
+function stopAudio() {
+ plugin.stopAudioPlayback();
+}
+
+function pluginMuted() {
+ return plugin.audioMuted();
+}
+
+function toggleMuteState(muted) {
+ var Ci = SpecialPowers.Ci;
+ var utils = SpecialPowers.wrap(window).top
+ .QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+ utils.audioMuted = muted;
+}
+</script>
--- a/dom/base/test/mochitest.ini
+++ b/dom/base/test/mochitest.ini
@@ -246,16 +246,17 @@ support-files =
file_nonascii_blob_url.html
referrerHelper.js
test_performance_user_timing.js
img_referrer_testserver.sjs
file_audioLoop.html
file_webaudioLoop.html
file_webaudioLoop2.html
file_pluginAudio.html
+ file_pluginAudioNonAutoStart.html
noaudio.webm
referrer_helper.js
referrer_testserver.sjs
script_postmessages_fileList.js
iframe_postMessages.html
test_performance_observer.js
performance_observer.html
test_anonymousContent_style_csp.html^headers^
@@ -801,16 +802,19 @@ skip-if = toolkit != 'gonk'
skip-if = toolkit != 'gonk'
[test_performance_observer.html]
[test_performance_user_timing.html]
[test_plugin_freezing.html]
skip-if = buildapp == 'b2g' || toolkit == 'android' #CLICK_TO_PLAY
[test_pluginAudioNotification.html]
tags = audiochannel
skip-if = (buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android') # Plugins don't work on Android and/or B2G/Mulet
+[test_pluginMutedBeforePlay.html]
+tags = audiochannel
+skip-if = (buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android') # Plugins don't work on Android and/or B2G/Mulet
[test_postMessage_solidus.html]
[test_postMessages.html]
support-files = worker_postMessages.js
[test_processing_instruction_update_stylesheet.xhtml]
[test_progress_events_for_gzip_data.html]
[test_range_bounds.html]
skip-if = toolkit == 'android'
[test_reentrant_flush.html]
new file mode 100644
--- /dev/null
+++ b/dom/base/test/test_pluginMutedBeforePlay.html
@@ -0,0 +1,76 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <title>Mute window before the plugin starts playing</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<pre id="test">
+</pre>
+<iframe></iframe>
+
+<script type="application/javascript">
+
+// Copied from /dom/plugins/test/mochitest/utils.js
+function getTestPlugin(pluginName) {
+ var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"]
+ .getService(SpecialPowers.Ci.nsIPluginHost);
+ var tags = ph.getPluginTags();
+ var name = pluginName || "Test Plug-in";
+ for (var tag of tags) {
+ if (tag.name == name) {
+ return tag;
+ }
+ }
+
+ ok(false, "Could not find plugin tag with plugin name '" + name + "'");
+ return null;
+}
+// Copied from /dom/plugins/test/mochitest/utils.js
+function setTestPluginEnabledState(newEnabledState, pluginName) {
+ var oldEnabledState = SpecialPowers.setTestPluginEnabledState(newEnabledState, pluginName);
+ if (!oldEnabledState) {
+ return;
+ }
+ var plugin = getTestPlugin(pluginName);
+ while (plugin.enabledState != newEnabledState) {
+ // Run a nested event loop to wait for the preference change to
+ // propagate to the child. Yuck!
+ SpecialPowers.Services.tm.currentThread.processNextEvent(true);
+ }
+ SimpleTest.registerCleanupFunction(function() {
+ SpecialPowers.setTestPluginEnabledState(oldEnabledState, pluginName);
+ });
+}
+setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+ var iframe = document.querySelector("iframe");
+ iframe.src = "file_pluginAudioNonAutoStart.html";
+
+ function muteBeforePlay() {
+ ok(!iframe.contentWindow.pluginMuted(), "Plugin should not be muted");
+ iframe.contentWindow.toggleMuteState(true);
+
+ iframe.contentWindow.startAudio();
+ ok(iframe.contentWindow.pluginMuted(), "Plugin should still be muted after playing");
+
+ iframe.contentWindow.stopAudio();
+ SimpleTest.finish();
+ }
+
+ iframe.onload = function() {
+ ok(true, "Already load iframe.");
+ muteBeforePlay();
+ }
+}
+
+onload = runTest;
+
+</script>
+</body>
+</html>
+