diff --git a/dom/browser-element/mochitest/browserElement_AudioChannel.js b/dom/browser-element/mochitest/browserElement_AudioChannel.js index d5e8a3da9c03..4219ff6d601f 100644 --- a/dom/browser-element/mochitest/browserElement_AudioChannel.js +++ b/dom/browser-element/mochitest/browserElement_AudioChannel.js @@ -10,6 +10,7 @@ browserElementTestHelpers.setEnabledPref(true); browserElementTestHelpers.addPermission(); function noaudio() { + info("Test : no-audio"); var iframe = document.createElement('iframe'); iframe.setAttribute('mozbrowser', 'true'); iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp'); @@ -143,6 +144,7 @@ function noaudio() { } function audio() { + info("Test : audio"); var iframe = document.createElement('iframe'); iframe.setAttribute('mozbrowser', 'true'); iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp'); @@ -179,7 +181,59 @@ function audio() { document.body.appendChild(iframe); } -var tests = [ noaudio, audio ]; +function audioMutedByDefault() { + info("Test : audio-muted-by-default"); + SpecialPowers.pushPrefEnv( + {'set': [["dom.audiochannel.mutedByDefault", true]]}, function () { + var iframe = document.createElement('iframe'); + iframe.setAttribute('mozbrowser', 'true'); + iframe.setAttribute('mozapp', 'http://example.org/manifest.webapp'); + iframe.src = 'http://example.org/tests/dom/browser-element/mochitest/file_processingAudioSample.html'; + + function audio_loadend_MutedByDefault() { + ok("allowedAudioChannels" in iframe, "allowedAudioChannels exist"); + var channels = iframe.allowedAudioChannels; + is(channels.length, 1, "1 audio channel by default"); + + var ac = channels[0]; + + ok(ac instanceof BrowserElementAudioChannel, "Correct class"); + ok("getMuted" in ac, "ac.getMuted exists"); + ok("setMuted" in ac, "ac.setMuted exists"); + + ac.onactivestatechanged = function() { + ok(true, "activestatechanged event received."); + ac.onactivestatechanged = null; + + new Promise(function(r, rr) { + ac.getMuted().onsuccess = function(e) { + is(e.target.result, true, "Muted channel by default"); + r(); + } + }) + .then(function() { + ac.setMuted(false).onsuccess = function(e) { + ok(true, "Unmuted the channel."); + } + }) + } + + var complete = false; + iframe.addEventListener("mozbrowsershowmodalprompt", function (e) { + is(e.detail.message, "playback-success", "Audio playback success!"); + if (!complete) { + SpecialPowers.popPrefEnv(runTests); + complete = true; + } + }); + } + + iframe.addEventListener('mozbrowserloadend', audio_loadend_MutedByDefault); + document.body.appendChild(iframe); + }); +} + +var tests = [ noaudio, audio, audioMutedByDefault ]; function runTests() { if (tests.length == 0) { @@ -191,8 +245,6 @@ function runTests() { test(); } - addEventListener('load', function() { SimpleTest.executeSoon(runTests); }); - diff --git a/dom/browser-element/mochitest/file_processingAudioSample.html b/dom/browser-element/mochitest/file_processingAudioSample.html new file mode 100644 index 000000000000..258951a3d7cf --- /dev/null +++ b/dom/browser-element/mochitest/file_processingAudioSample.html @@ -0,0 +1,45 @@ + + + + + diff --git a/dom/browser-element/mochitest/mochitest.ini b/dom/browser-element/mochitest/mochitest.ini index 065e2a564fc5..ab99b69c735b 100644 --- a/dom/browser-element/mochitest/mochitest.ini +++ b/dom/browser-element/mochitest/mochitest.ini @@ -140,6 +140,7 @@ support-files = file_web_manifest.html file_web_manifest.json file_illegal_web_manifest.html + file_processingAudioSample.html # Note: browserElementTestHelpers.js looks at the test's filename to determine # whether the test should be OOP. "_oop_" signals OOP, "_inproc_" signals in