Bug 1276119 - part2: add test.
authorAlastor Wu <alwu@mozilla.com>
Tue, 31 May 2016 10:17:53 +0800
changeset 299624 ba07e25e6d1d12276609a02d241d90fc01421c23
parent 299623 c27e49247fe28294d7f04e54d00ab389b5e57378
child 299625 00e04e27ccdd804fe49185f49028a04d14c95f01
push id30299
push usercbook@mozilla.com
push dateTue, 31 May 2016 10:00:19 +0000
treeherdermozilla-central@864cdd00360c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1276119
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1276119 - part2: add test. MozReview-Commit-ID: 4fRCzlJXK41
dom/base/test/file_pluginAudioNonAutoStart.html
dom/base/test/mochitest.ini
dom/base/test/test_pluginMutedBeforePlay.html
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>
+