<!DOCTYPE html>
<html>
<head>
<title>
Test Event Constructors
</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="resources/audit-util.js"></script>
<script src="resources/audit.js"></script>
</head>
<body>
<script id="layout-test-code">
let audit = Audit.createTaskRunner();
audit.define('offline-constructor', (task, should) => {
should(function() {
new OfflineAudioCompletionEvent();
}, 'new OfflineAudioCompletionEvent()').throw(TypeError);
should(function() {
new OfflineAudioCompletionEvent('complete');
}, 'new OfflineAudioCompletionEvent("complete")').throw(TypeError);
should(
function() {
new OfflineAudioCompletionEvent('complete', {});
},
'new OfflineAudioCompletionEvent("complete", {})')
.throw(TypeError);
should(
function() {
new OfflineAudioCompletionEvent('complete', {foo: 42});
},
'new OfflineAudioCompletionEvent("complete", {foo: 42})')
.throw(TypeError);
let context = new OfflineAudioContext(1, 100, 48000);
let buffer = new AudioBuffer(context, {length: 42});
should(
function() {
new OfflineAudioCompletionEvent(
'complete', {renderedBuffer: buffer});
},
'new OfflineAudioCompletionEvent("complete", {renderedBuffer: buffer})')
.notThrow();
task.done();
});
audit.define('offline-event', (task, should) => {
// Only need the context for constructing the AudioBuffers for the
// tests.
let context = new OfflineAudioContext(1, 100, 48000);
// Just an arbitrary AudioBuffer.
let buffer = new AudioBuffer(context, {length: 10});
let event;
should(function() {
event =
new OfflineAudioCompletionEvent('foo', {renderedBuffer: buffer});
}, 'new OfflineAudioCompletionEvent()').notThrow();
should(event.renderedBuffer == buffer, 'event.renderedBuffer == buffer')
.beEqualTo(true);
task.done();
});
audit.define('audio-processing', (task, should) => {
// Only need the context for constructing the AudioBuffers for the
// tests.
let context = new OfflineAudioContext(1, 100, 48000);
// Fairly arbitrary buffers and time
let input = new AudioBuffer(context, {length: 10});
let output = new AudioBuffer(context, {length: 20});
let time = Math.PI;
// Verify required arguments.
should(function() {
new AudioProcessingEvent();
}, 'new AudioProcessingEvent()').throw(TypeError);
should(function() {
new AudioProcessingEvent('proc');
}, 'new AudioProcessingEvent("proc")').throw(TypeError);
should(function() {
new AudioProcessingEvent('proc', {foo: 99});
}, 'new AudioProcessingEvent("proc", {foo: 99})').throw(TypeError);
should(
function() {
new AudioProcessingEvent(
'proc', {inputBuffer: input, outputBuffer: output});
},
'new AudioProcessingEvent("proc", ' +
'{inputBuffer: input, outputBuffer: output})')
.throw(TypeError);
should(
function() {
new AudioProcessingEvent(
'proc', {inputBuffer: input, playbackTime: time});
},
'new AudioProcessingEvent("proc", ' +
'{inputBuffer: input, playbackTime: time})')
.throw(TypeError);
should(
function() {
new AudioProcessingEvent(
'proc', {outputBuffer: output, playbackTime: time});
},
'new AudioProcessingEvent("proc", ' +
'{outputBuffer: output, playbackTime: time})')
.throw(TypeError);
// Finally test valid call
let event;
should(
function() {
event = new AudioProcessingEvent('proc', {
inputBuffer: input,
outputBuffer: output,
playbackTime: time
});
},
'new AudioProcessingEvent("proc", ' +
'{inputBuffer: input, outputBuffer: output, playbackTime: time})')
.notThrow();
should(event.playbackTime, 'event.playbackTime').beEqualTo(time);
should(event.inputBuffer == input, 'event.inputBuffer == input')
.beEqualTo(true);
should(event.outputBuffer == output, 'event.outputBuffer == output')
.beEqualTo(true);
task.done();
});
audit.run();
</script>
</body>
</html>