summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/webaudio/audionode.html
blob: 0b049a280f8c80c234d62b240fde8762e36706b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>

<html>
<head>
<script src="../fast/js/resources/js-test-pre.js"></script>
<script type="text/javascript" src="resources/audio-testing.js"></script>
</head>

<body>
<div id="description"></div>
<div id="console"></div>

<script>
description("Basic tests for AudioNode API.");

var context = 0;
var context2 = 0;
var context3 = 0;

function runTest() {
    if (window.testRunner) {
        testRunner.dumpAsText();
        testRunner.waitUntilDone();
    }
    
    window.jsTestIsAsync = true;

    context = new webkitAudioContext();
    window.audioNode = context.createBufferSource();

    shouldThrow("audioNode.noteOn()");
    shouldThrow("audioNode.noteGrainOn()");
    shouldThrow("audioNode.noteOff()");

    // Check input and output numbers of AudioSourceNode.
    if (audioNode.numberOfInputs === 0)
        testPassed("Source AudioNode has no inputs.");
    else
        testFailed("Source AudioNode should not have inputs.");
    
    if (audioNode.numberOfOutputs === 1)
        testPassed("Source AudioNode has one output.");
    else
        testFailed("Source AudioNode should have one output.");

    // Check input and output numbers of AudioDestinationNode
    if (context.destination.numberOfInputs === 1)
        testPassed("Destination AudioNode has one input.");
    else
        testFailed("Destination AudioNode should have one input.");

    if (context.destination.numberOfOutputs === 0)
        testPassed("Destination AudioNode has no outputs.");
    else
        testFailed("Destination AudioNode should have no outputs.");

    // Try calling connect() method with illegal values.

    try {
        audioNode.connect(0, 0, 0);
        testFailed("connect() exception should be thrown for illegal destination AudioNode.");
    } catch(e) {
        testPassed("connect() exception thrown for illegal destination AudioNode.");
    }

    try {
        audioNode.connect(context.destination, 5, 0);
        testFailed("connect() exception should be thrown for illegal output index.");
    } catch(e) {
        testPassed("connect() exception thrown for illegal output index.");
    }

    try {
        audioNode.connect(context.destination, 0, 5);
        testFailed("connect() exception should be thrown for illegal input index.");
    } catch(e) {
        testPassed("connect() exception thrown for illegal input index.");
    }

    // Try calling connect() with proper values.
    try {
        audioNode.connect(context.destination, 0, 0);
        testPassed("audioNode.connect(context.destination) succeeded.");
    } catch(e) {
        testFailed("audioNode.connect(context.destination) failed.");
    }
    
    // Create a new context and try to connect the other context's node to this one.
    try {
        context2 = new webkitAudioContext();
        window.audioNode.connect(context2.destination);
        testFailed("exception should be thrown when connecting to other context's node.");
    } catch(e) {
        testPassed("exception thrown when connecting to other context's node.");
    }

    // Create a new context with not enough arguments
    try {
        context2 = new webkitAudioContext(0, 0);
        testFailed("exception should be thrown when creating audio context with not enough arguments.");
    } catch(e) {
        testPassed("exception thrown when creating audio context with not enough arguments.");
    }

    // Create a new offline audio context using the deprecated AudioContext constructor.
    shouldNotThrow("context3 = new webkitAudioContext(1, 44100, 44100)");

    // Ensure it is an EventTarget
    try {
        audioNode.addEventListener('testEvent', function(){
            testPassed("AudioNode is an EventTarget");
        });
        audioNode.dispatchEvent(new Event('testEvent'));
    } catch(e) {
        testFailed("exception shouldn't be thrown when testing whether audio node is an event target");
    }

    finishJSTest();
}

runTest();

</script>

</body>
</html>