diff --git a/dom/browser-element/mochitest/browserElement_ActiveStateChangeOnChangingMutedOrVolume.js b/dom/browser-element/mochitest/browserElement_ActiveStateChangeOnChangingMutedOrVolume.js new file mode 100644 index 000000000000..d3d29f859667 --- /dev/null +++ b/dom/browser-element/mochitest/browserElement_ActiveStateChangeOnChangingMutedOrVolume.js @@ -0,0 +1,126 @@ +"use strict"; + +SimpleTest.waitForExplicitFinish(); +browserElementTestHelpers.setEnabledPref(true); +browserElementTestHelpers.addPermission(); + +var fileURL = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html'; +var generator = runTests(); +var testFrame; +var ac; + +function assert(aVal, aMessage) { + return (!aVal) ? error(aMessage) : 0; +} + +function error(aMessage) { + ok(false, "Error : " + aMessage); + finish(); +} + +function continueTest() { + try { + generator.next(); + } catch (e if e instanceof StopIteration) { + error("Stop test because of exception!"); + } +} + +function finish() { + document.body.removeChild(testFrame); + SimpleTest.finish(); +} + +function setCommand(aArg) { + assert(!!ac, "Audio channel doesn't exist!"); + info("# Command = " + aArg); + + testFrame.src = fileURL + '#' + aArg; + var expectedActive = false; + switch (aArg) { + case 'play': + case 'unmute': + case 'volume-1': + expectedActive = true; + break; + case 'pause': + case 'mute': + case 'volume-0': + expectedActive = false; + break; + default : + error("Undefined command!"); + } + + ac.onactivestatechanged = () => { + ac.onactivestatechanged = null; + ac.isActive().onsuccess = (e) => { + is(expectedActive, e.target.result, + "Correct active state = " + expectedActive); + continueTest(); + } + }; +} + +function runTests() { + setCommand('play'); + yield undefined; + + setCommand('mute'); + yield undefined; + + setCommand('unmute'); + yield undefined; + + setCommand('volume-0'); + yield undefined; + + setCommand('volume-1'); + yield undefined; + + setCommand('pause'); + yield undefined; + + finish(); + yield undefined; +} + +function setupTestFrame() { + testFrame = document.createElement('iframe'); + testFrame.setAttribute('mozbrowser', 'true'); + testFrame.setAttribute('mozapp', 'http://example.org/manifest.webapp'); + testFrame.src = fileURL; + + function loadend() { + testFrame.removeEventListener('mozbrowserloadend', loadend); + ok("allowedAudioChannels" in testFrame, "allowedAudioChannels exist"); + var channels = testFrame.allowedAudioChannels; + is(channels.length, 1, "1 audio channel by default"); + + ac = channels[0]; + + ok(ac instanceof BrowserElementAudioChannel, "Correct class"); + ok("isActive" in ac, "isActive exists"); + ok("onactivestatechanged" in ac, "onactivestatechanged exists"); + + generator.next(); + } + + function alertError(e) { + testFrame.removeEventListener('mozbrowsershowmodalprompt', alertError); + var message = e.detail.message + error(message); + } + + testFrame.addEventListener('mozbrowserloadend', loadend); + testFrame.addEventListener('mozbrowsershowmodalprompt', alertError); + document.body.appendChild(testFrame); +} + +addEventListener('testready', function() { + SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]}, + function() { + SimpleTest.executeSoon(setupTestFrame); + }); +}); + diff --git a/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html b/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html new file mode 100644 index 000000000000..5422c96b4b69 --- /dev/null +++ b/dom/browser-element/mochitest/file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html @@ -0,0 +1,37 @@ + + +
+ + + \ No newline at end of file diff --git a/dom/browser-element/mochitest/mochitest-oop.ini b/dom/browser-element/mochitest/mochitest-oop.ini index c6bd79789714..214867e22574 100644 --- a/dom/browser-element/mochitest/mochitest-oop.ini +++ b/dom/browser-element/mochitest/mochitest-oop.ini @@ -124,3 +124,4 @@ disabled = bug 924771 [test_browserElement_oop_getWebManifest.html] [test_browserElement_oop_OpenWindowEmpty.html] skip-if = (toolkit == 'gonk') # Test doesn't work on B2G emulator +[test_browserElement_oop_ActiveStateChangeOnChangingMutedOrVolume.html] diff --git a/dom/browser-element/mochitest/mochitest.ini b/dom/browser-element/mochitest/mochitest.ini index 519a714790f3..4b106768a91c 100644 --- a/dom/browser-element/mochitest/mochitest.ini +++ b/dom/browser-element/mochitest/mochitest.ini @@ -5,6 +5,7 @@ support-files = ../../../dom/media/test/short-video.ogv async.js browserElementTestHelpers.js + browserElement_ActiveStateChangeOnChangingMutedOrVolume.js browserElement_Alert.js browserElement_AlertInFrame.js browserElement_AllowEmbedAppsInNestedOOIframe.js @@ -84,6 +85,7 @@ support-files = browserElement_GetContentDimensions.js browserElement_AudioChannel.js browserElement_AudioChannel_nested.js + file_browserElement_ActiveStateChangeOnChangingMutedOrVolume.html file_browserElement_AlertInFrame.html file_browserElement_AlertInFrame_Inner.html file_browserElement_AllowEmbedAppsInNestedOOIframe.html @@ -258,3 +260,4 @@ disabled = bug 774100 [test_browserElement_inproc_getStructuredData.html] [test_browserElement_inproc_OpenWindowEmpty.html] skip-if = (toolkit == 'gonk') # Test doesn't work on B2G emulator +[test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html] \ No newline at end of file diff --git a/dom/browser-element/mochitest/test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html b/dom/browser-element/mochitest/test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html new file mode 100644 index 000000000000..3a0de8b6a70d --- /dev/null +++ b/dom/browser-element/mochitest/test_browserElement_inproc_ActiveStateChangeOnChangingMutedOrVolume.html @@ -0,0 +1,13 @@ + + + +