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
This commit is contained in:
Alastor Wu 2016-01-11 10:48:18 +08:00
Родитель 0be5e80e7b
Коммит 4621cc94e1
6 изменённых файлов: 222 добавлений и 0 удалений

Просмотреть файл

@ -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);
});
});

Просмотреть файл

@ -0,0 +1,62 @@
<!DOCTYPE HTML>
<html>
<body>
<script type="application/javascript;version=1.7">
var audio = new Audio();
audio.src = "audio.ogg";
audio.loop = true;
function assert(aVal, aMessage) {
return (!aVal) ? ok(false, aMessage) : 0;
}
function ok(aVal, aMsg) {
alert((!!aVal ? "OK" : "KO") + ", " + aMsg);
}
function info(aMsg) {
alert("INFO" + ", " + aMsg);
}
function randomSeeking() {
var seekingPosition = Math.random() * audio.duration;
assert(seekingPosition < audio.duration, "Seeking position out of range!")
audio.currentTime = seekingPosition;
audio.onseeked = () => {
audio.onseeked = null;
location.hash = '#idle';
ok(true, "Seeking complete, position = " + seekingPosition);
};
}
function runCommands()
{
switch(location.hash) {
case '#play':
audio.play();
audio.onplay = () => {
audio.onplay = null;
info("Start playing, duration = " + audio.duration);
};
break;
case '#seeking':
randomSeeking();
break;
case '#pause':
audio.pause();
audio.onpause = () => {
audio.onpause = null;
ok(true, "Stop playing.");
};
break;
case '#idle':
break;
default :
ok(false, "Undefined command!");
}
}
window.addEventListener('hashchange', runCommands);
</script>
</body>
</html>

Просмотреть файл

@ -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]

Просмотреть файл

@ -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'

Просмотреть файл

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1225425 - Do not unregister the AudioChannelAgent during seeking</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_AudioChannelSeeking.js">
</script>
</body>
</html>

Просмотреть файл

@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1225425 - Do not unregister the AudioChannelAgent during seeking</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="browserElementTestHelpers.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<script type="application/javascript;version=1.7" src="browserElement_AudioChannelSeeking.js">
</script>
</body>
</html>