Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 31 additions & 56 deletions webaudio/the-audio-api/the-gainnode-interface/ctor-gain.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,74 +6,49 @@
</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/webaudio/resources/audit-util.js"></script>
<script src="/webaudio/resources/audit.js"></script>
<script src="/webaudio/resources/audionodeoptions.js"></script>
</head>
<body>
<script id="layout-test-code">
let context;
<script>
const context = new AudioContext();

let audit = Audit.createTaskRunner();
test(() => {
testInvalidConstructor_W3CTH('GainNode', context);
}, 'GainNode: invalid constructor');

audit.define('initialize', (task, should) => {
context = initializeContext(should);
task.done();
});

audit.define('invalid constructor', (task, should) => {
testInvalidConstructor(should, 'GainNode', context);
task.done();
});

audit.define('default constructor', (task, should) => {
let prefix = 'node0';
let node = testDefaultConstructor(should, 'GainNode', context, {
prefix: prefix,
test(() => {
const prefix = 'node0';
const node = testDefaultConstructor_W3CTH('GainNode', context, {
prefix,
numberOfInputs: 1,
numberOfOutputs: 1,
channelCount: 2,
channelCountMode: 'max',
channelInterpretation: 'speakers'
});

testDefaultAttributes(should, node, prefix, [{name: 'gain', value: 1}]);

task.done();
});

audit.define('test AudioNodeOptions', (task, should) => {
testAudioNodeOptions(should, context, 'GainNode');
task.done();
});

audit.define('constructor with options', (task, should) => {
let node;
let options = {
gain: -2,
};

should(
() => {
node = new GainNode(context, options);
},
'node1 = new GainNode(c, ' + JSON.stringify(options) + ')')
.notThrow();
should(node instanceof GainNode, 'node1 instanceof GainNode')
.beEqualTo(true);

should(node.gain.value, 'node1.gain.value').beEqualTo(options.gain);

should(node.channelCount, 'node1.channelCount').beEqualTo(2);
should(node.channelCountMode, 'node1.channelCountMode')
.beEqualTo('max');
should(node.channelInterpretation, 'node1.channelInterpretation')
.beEqualTo('speakers');

task.done();
});

audit.run();
testDefaultAttributes_W3CTH(
node,
prefix,
[{ name: 'gain', value: 1 }]);
}, 'GainNode: default constructor and default attributes');

test(() => {
testAudioNodeOptions_W3CTH(context, 'GainNode');
}, 'GainNode: AudioNodeOptions are applied');

test(() => {
const options = { gain: -2 };
const node = new GainNode(context, options);
assert_true(node instanceof GainNode, 'instanceof GainNode');
assert_equals(node.gain.value, options.gain, 'node.gain.value');
assert_equals(node.channelCount, 2, 'node.channelCount');
assert_equals(node.channelCountMode, 'max', 'node.channelCountMode');
assert_equals(
node.channelInterpretation,
'speakers',
'node.channelInterpretation');
}, 'GainNode: constructor with options');
</script>
</body>
</html>