From 4621cc94e1170310d25473490cbe52e4af7ad227 Mon Sep 17 00:00:00 2001 From: Alastor Wu Date: Mon, 11 Jan 2016 10:48:18 +0800 Subject: [PATCH] Bug 1225425 - [Testcase] Do not unregister the AudioChannelAgent during seeking. r=baku. --HG-- extra : transplant_source : %FF%A2%5D%94%91%B7%7E%91%B9%EA%2AGt%D5%23%04%C9%F0%FDD --- .../browserElement_AudioChannelSeeking.js | 130 ++++++++++++++++++ ...le_browserElement_AudioChannelSeeking.html | 62 +++++++++ .../mochitest/mochitest-oop.ini | 1 + dom/browser-element/mochitest/mochitest.ini | 3 + ...serElement_inproc_AudioChannelSeeking.html | 13 ++ ...rowserElement_oop_AudioChannelSeeking.html | 13 ++ 6 files changed, 222 insertions(+) create mode 100644 dom/browser-element/mochitest/browserElement_AudioChannelSeeking.js create mode 100644 dom/browser-element/mochitest/file_browserElement_AudioChannelSeeking.html create mode 100644 dom/browser-element/mochitest/test_browserElement_inproc_AudioChannelSeeking.html create mode 100644 dom/browser-element/mochitest/test_browserElement_oop_AudioChannelSeeking.html diff --git a/dom/browser-element/mochitest/browserElement_AudioChannelSeeking.js b/dom/browser-element/mochitest/browserElement_AudioChannelSeeking.js new file mode 100644 index 000000000000..929d51642e88 --- /dev/null +++ b/dom/browser-element/mochitest/browserElement_AudioChannelSeeking.js @@ -0,0 +1,130 @@ +"use strict"; + +SimpleTest.waitForExplicitFinish(); +browserElementTestHelpers.setEnabledPref(true); +browserElementTestHelpers.addPermission(); + +var fileURL = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AudioChannelSeeking.html'; +var generator = runTests(); +var testFrame; +var ac; + +function alertListener(e) { + var message = e.detail.message + if (/^OK/.exec(message)) { + ok(true, "Message from file : " + message); + continueTest(); + } else if (/^KO/.exec(message)) { + error(message); + } else if (/^INFO/.exec(message)) { + info("Message from file : " + message); + } else { + error("Undefined event."); + } +} + +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() { + testFrame.removeEventListener('mozbrowsershowmodalprompt', alertListener); + ok(true, "Remove event-listener."); + document.body.removeChild(testFrame); + ok(true, "Remove test-frame from document."); + SimpleTest.finish(); +} + +function setCommand(aArg) { + assert(!!ac, "Audio channel doesn't exist!"); + info("# Command = " + aArg); + testFrame.src = fileURL + '#' + aArg; + + switch (aArg) { + case 'play': + ac.onactivestatechanged = () => { + ac.onactivestatechanged = null; + ok(true, "Receive onactivestatechanged after audio started."); + continueTest(); + }; + break; + case 'seeking': + ac.onactivestatechanged = () => { + ac.onactivestatechanged = null; + error("Should not receive onactivestatechanged during seeking!"); + }; + break; + case 'pause': + ac.onactivestatechanged = null; + break; + default : + error("Undefined command!"); + } +} + +function runTests() { + setCommand('play'); + yield undefined; + + setCommand('seeking'); + yield undefined; + + setCommand('seeking'); + yield undefined; + + setCommand('seeking'); + 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("onactivestatechanged" in ac, "onactivestatechanged exists"); + + continueTest(); + } + + testFrame.addEventListener('mozbrowsershowmodalprompt', alertListener); + testFrame.addEventListener('mozbrowserloadend', loadend); + ok(true, "Add event-listeners."); + + document.body.appendChild(testFrame); + ok(true, "Append test-frame to document."); +} + +addEventListener('testready', function() { + SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"]]}, + function() { + SimpleTest.executeSoon(setupTestFrame); + }); +}); \ No newline at end of file diff --git a/dom/browser-element/mochitest/file_browserElement_AudioChannelSeeking.html b/dom/browser-element/mochitest/file_browserElement_AudioChannelSeeking.html new file mode 100644 index 000000000000..293f6cadc484 --- /dev/null +++ b/dom/browser-element/mochitest/file_browserElement_AudioChannelSeeking.html @@ -0,0 +1,62 @@ + + + + + + \ 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 ea887a509766..64c702bcfb6f 100644 --- a/dom/browser-element/mochitest/mochitest-oop.ini +++ b/dom/browser-element/mochitest/mochitest-oop.ini @@ -12,6 +12,7 @@ support-files = browserElement_Find.js browserElement_OpenTab.js +[test_browserElement_oop_AudioChannelSeeking.html] [test_browserElement_oop_getStructuredData.html] [test_browserElement_oop_Viewmode.html] [test_browserElement_oop_ThemeColor.html] diff --git a/dom/browser-element/mochitest/mochitest.ini b/dom/browser-element/mochitest/mochitest.ini index 7c537bc03daa..7fa6bfcd9158 100644 --- a/dom/browser-element/mochitest/mochitest.ini +++ b/dom/browser-element/mochitest/mochitest.ini @@ -11,6 +11,7 @@ support-files = browserElement_AllowEmbedAppsInNestedOOIframe.js browserElement_AppFramePermission.js browserElement_AppWindowNamespace.js + browserElement_AudioChannelSeeking.js browserElement_AudioChannelMutedByDefault.js browserElement_AudioPlayback.js browserElement_Auth.js @@ -92,6 +93,7 @@ support-files = file_browserElement_AllowEmbedAppsInNestedOOIframe.html file_browserElement_AppFramePermission.html file_browserElement_AppWindowNamespace.html + file_browserElement_AudioChannelSeeking.html file_browserElement_AudioChannel_nested.html file_browserElement_AudioChannelMutedByDefault.html file_browserElement_Viewmode.html @@ -157,6 +159,7 @@ support-files = [test_browserElement_NoPref.html] [test_browserElement_NoPermission.html] [test_browserElement_inproc_Alert.html] +[test_browserElement_inproc_AudioChannelSeeking.html] [test_browserElement_inproc_Viewmode.html] [test_browserElement_inproc_ThemeColor.html] skip-if = buildapp == 'b2g' diff --git a/dom/browser-element/mochitest/test_browserElement_inproc_AudioChannelSeeking.html b/dom/browser-element/mochitest/test_browserElement_inproc_AudioChannelSeeking.html new file mode 100644 index 000000000000..54c3a1fb4b08 --- /dev/null +++ b/dom/browser-element/mochitest/test_browserElement_inproc_AudioChannelSeeking.html @@ -0,0 +1,13 @@ + + + + Bug 1225425 - Do not unregister the AudioChannelAgent during seeking + + + + + + + + \ No newline at end of file diff --git a/dom/browser-element/mochitest/test_browserElement_oop_AudioChannelSeeking.html b/dom/browser-element/mochitest/test_browserElement_oop_AudioChannelSeeking.html new file mode 100644 index 000000000000..54c3a1fb4b08 --- /dev/null +++ b/dom/browser-element/mochitest/test_browserElement_oop_AudioChannelSeeking.html @@ -0,0 +1,13 @@ + + + + Bug 1225425 - Do not unregister the AudioChannelAgent during seeking + + + + + + + + \ No newline at end of file