Skip to content

Truly independent web browser

2.5 KB
Raw Blame
<!DOCTYPE html>
<html>
  <head>
    <title>
      AudioNode: Basic Interface Tests
    </title>
    <script src="../../../resources/testharness.js"></script>
    <script src="../../../resources/testharnessreport.js"></script>
  </head>
  <body>
    <script>
      test(() => {
        let context = new AudioContext();

        let audioNode = new AudioBufferSourceNode(context);

        // Check input and output numbers of AudioSourceNode.
        assert_equals(
            audioNode.numberOfInputs, 0,
            'AudioBufferSource.numberOfInputs');
        assert_equals(
            audioNode.numberOfOutputs, 1,
            'AudioBufferSource.numberOfOutputs');

        // Check input and output numbers of AudioDestinationNode
        assert_equals(
            context.destination.numberOfInputs, 1,
            'AudioContext.destination.numberOfInputs');
        assert_equals(
            context.destination.numberOfOutputs, 1,
            'AudioContext.destination.numberOfOutputs');

        // Try calling connect() method with illegal values.
        assert_throws_js(
            TypeError, () => audioNode.connect(0, 0, 0),
            'audioNode.connect(0, 0, 0)');
        assert_throws_js(
            TypeError, () => audioNode.connect(null, 0, 0),
            'audioNode.connect(null, 0, 0)');
        assert_throws_dom(
            'IndexSizeError',
            () => audioNode.connect(context.destination, 5, 0),
            'audioNode.connect(context.destination, 5, 0)');
        assert_throws_dom(
            'IndexSizeError',
            () => audioNode.connect(context.destination, 0, 5),
            'audioNode.connect(context.destination, 0, 5)');

        audioNode.connect(context.destination, 0, 0);

        // Create a new context and try to connect the other context's node
        // to this one.
        let context2 = new AudioContext();
        assert_throws_dom(
            'InvalidAccessError',
            () => audioNode.connect(context2.destination),
            'Connecting a node to a different context');

        // 3-arg AudioContext doesn't create an offline context anymore.
        assert_throws_js(
            TypeError,
            () => {let context3 = new AudioContext(1, 44100, 44100);},
            'context3 = new AudioContext(1, 44100, 44100)');

        // Ensure it is an EventTarget
        assert_true(
            audioNode instanceof EventTarget,
            'AudioNode is an EventTarget');
      }, 'Basic tests for AudioNode API.');
    </script>
  </body>
</html>