зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1235535 - Part 2: Create muted-by-default test in another new file. r=baku
--HG-- extra : transplant_source : %B4%0C%21%22%06%AA%EB%06%F1%B9pH%5E%AB%15%CD%FF%E4Y%99
This commit is contained in:
Родитель
f1f4a99a37
Коммит
74af78fbf0
|
@ -0,0 +1,105 @@
|
|||
"use strict";
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
browserElementTestHelpers.setEnabledPref(true);
|
||||
browserElementTestHelpers.addPermission();
|
||||
|
||||
var fileURL = 'http://example.org/tests/dom/browser-element/mochitest/file_browserElement_AudioChannelMutedByDefault.html';
|
||||
var testFrame;
|
||||
var ac;
|
||||
|
||||
function alertListener(e) {
|
||||
var message = e.detail.message
|
||||
if (/^OK/.exec(message)) {
|
||||
ok(true, "Message from file : " + message);
|
||||
} else if (/^KO/.exec(message)) {
|
||||
error(message);
|
||||
} else if (/DONE/.exec(message)) {
|
||||
ok(true, "Audio playback success!");
|
||||
finish();
|
||||
} else {
|
||||
error("Undefined event.");
|
||||
}
|
||||
}
|
||||
|
||||
function assert(aVal, aMessage) {
|
||||
return (!aVal) ? error(aMessage) : 0;
|
||||
}
|
||||
|
||||
function error(aMessage) {
|
||||
ok(false, "Error : " + aMessage);
|
||||
finish();
|
||||
}
|
||||
|
||||
function finish() {
|
||||
testFrame.removeEventListener('mozbrowsershowmodalprompt', alertListener);
|
||||
document.body.removeChild(testFrame);
|
||||
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, "activestatechanged event received.");
|
||||
|
||||
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.");
|
||||
}
|
||||
});
|
||||
};
|
||||
break;
|
||||
default :
|
||||
error("Undefined command!");
|
||||
}
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
setCommand('play');
|
||||
}
|
||||
|
||||
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("getMuted" in ac, "ac.getMuted exists");
|
||||
ok("setMuted" in ac, "ac.setMuted exists");
|
||||
ok("onactivestatechanged" in ac, "onactivestatechanged exists");
|
||||
|
||||
runTests();
|
||||
}
|
||||
|
||||
info("Set EventListeners.");
|
||||
testFrame.addEventListener('mozbrowsershowmodalprompt', alertListener);
|
||||
testFrame.addEventListener('mozbrowserloadend', loadend);
|
||||
document.body.appendChild(testFrame);
|
||||
}
|
||||
|
||||
addEventListener('testready', function() {
|
||||
SpecialPowers.pushPrefEnv({'set': [["b2g.system_manifest_url", "http://mochi.test:8888/manifest.webapp"],
|
||||
["dom.audiochannel.mutedByDefault", true]]},
|
||||
function() {
|
||||
SimpleTest.executeSoon(setupTestFrame);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,65 @@
|
|||
<html>
|
||||
<body>
|
||||
<script>
|
||||
var audio = new Audio("audio.ogg");
|
||||
var context = new AudioContext();
|
||||
var node = context.createMediaElementSource(audio);
|
||||
var sp = context.createScriptProcessor(2048, 1);
|
||||
node.connect(sp);
|
||||
var expectedSamplesCount;
|
||||
var nonzeroSamplesCount = 0;
|
||||
var isStarted = false;
|
||||
|
||||
function ok(aVal, aMsg) {
|
||||
alert((!!aVal ? "OK" : "KO") + ", " + aMsg);
|
||||
}
|
||||
|
||||
function finish() {
|
||||
audio.onended = null;
|
||||
audio.pause();
|
||||
alert("DONE");
|
||||
}
|
||||
|
||||
function processSamples(e) {
|
||||
var buf = e.inputBuffer.getChannelData(0);
|
||||
for (var i = 0; i < buf.length; ++i) {
|
||||
if (buf[i] != 0) {
|
||||
if (!isStarted) {
|
||||
isStarted = true;
|
||||
ok(true, "Start process audio sample.");
|
||||
}
|
||||
nonzeroSamplesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (nonzeroSamplesCount >= expectedSamplesCount) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
audio.oncanplaythrough = function() {
|
||||
var testDuration = audio.duration > 1.0 ? 1.0 : audio.duration * 0.5;
|
||||
expectedSamplesCount = Math.floor(testDuration * context.sampleRate);
|
||||
sp.onaudioprocess = processSamples;
|
||||
};
|
||||
|
||||
function runCommands()
|
||||
{
|
||||
switch(location.hash) {
|
||||
case '#play':
|
||||
ok(true, "Audio starts playing.")
|
||||
audio.play();
|
||||
audio.onended = () => {
|
||||
audio.onended = null;
|
||||
ok(false, "Audio shouldn't go ended in this test!")
|
||||
};
|
||||
break;
|
||||
default :
|
||||
ok(false, "Undefined command!");
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('hashchange', runCommands);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -27,6 +27,7 @@ skip-if = toolkit=='gonk'
|
|||
skip-if = (toolkit == 'gonk' && !debug)
|
||||
[test_browserElement_oop_AppWindowNamespace.html]
|
||||
skip-if = (toolkit == 'gonk' && !debug)
|
||||
[test_browserElement_oop_AudioChannelMutedByDefault.html]
|
||||
[test_browserElement_oop_Auth.html]
|
||||
skip-if = (toolkit == 'gonk' && !debug)
|
||||
[test_browserElement_oop_BackForward.html]
|
||||
|
|
|
@ -10,6 +10,7 @@ support-files =
|
|||
browserElement_AllowEmbedAppsInNestedOOIframe.js
|
||||
browserElement_AppFramePermission.js
|
||||
browserElement_AppWindowNamespace.js
|
||||
browserElement_AudioChannelMutedByDefault.js
|
||||
browserElement_AudioPlayback.js
|
||||
browserElement_Auth.js
|
||||
browserElement_BackForward.js
|
||||
|
@ -90,6 +91,7 @@ support-files =
|
|||
file_browserElement_AppFramePermission.html
|
||||
file_browserElement_AppWindowNamespace.html
|
||||
file_browserElement_AudioChannel_nested.html
|
||||
file_browserElement_AudioChannelMutedByDefault.html
|
||||
file_browserElement_Viewmode.html
|
||||
file_browserElement_ThemeColor.html
|
||||
file_browserElement_BrowserWindowNamespace.html
|
||||
|
@ -161,6 +163,8 @@ skip-if = buildapp == 'b2g'
|
|||
skip-if = toolkit == 'android' || buildapp == 'b2g'
|
||||
[test_browserElement_inproc_AppWindowNamespace.html]
|
||||
skip-if = toolkit == 'android' || buildapp == 'b2g' # android(TIMED_OUT, bug 783509) androidx86(TIMED_OUT, bug 783509)
|
||||
[test_browserElement_inproc_AudioChannelMutedByDefault.html]
|
||||
skip-if = toolkit == 'android'
|
||||
[test_browserElement_inproc_AudioPlayback.html]
|
||||
[test_browserElement_inproc_Auth.html]
|
||||
skip-if = buildapp == 'b2g'
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bug 1235535 - Audio Channel Muted-By-Default.</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_AudioChannelMutedByDefault.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Bug 1235535 - Audio Channel Muted-By-Default.</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_AudioChannelMutedByDefault.js">
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче