summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/webaudio/dom-exceptions.html
blob: 60b06087bdb4d4307d57656b1f8a65f2c15c1a94 (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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
<script src="resources/audio-testing.js"></script>
<script src="../fast/js/resources/js-test-pre.js"></script>
<script src="resources/biquad-testing.js"></script>
</head>

<body>

<div id="description"></div>
<div id="console"></div>
<script>
description("Tests DOM exception messages");

var context;
var otherContext;
var node;
var node2;
var mode;

function runTest() {
    if (window.testRunner) {
        testRunner.dumpAsText();
    }
    
    context = new webkitAudioContext();
    otherContext = new webkitAudioContext();

    // Test creation of various objects

    // Invalid number of channels: NotSupportedError
    shouldThrow("context.createBuffer(99, 1, context.sampleRate)");
    // Invalid sample rate: NotSupportedError
    shouldThrow("context.createBuffer(1, 1, 1)");
    shouldThrow("context.createBuffer(1, 1, 1e6)");
    // Invalid number of frames: NotSupportedError
    shouldThrow("context.createBuffer(1, 0, context.sampleRate)");
    // Invalid ArrayBuffer (unspecified error)
    shouldThrow("context.createBuffer(new ArrayBuffer(100), true)");
    // Invalid ArrayBuffer (unspecified error)
    shouldThrow("context.decodeAudioData(null, function() {}, function () {})");
    // Invalid sources (unspecified error)
    shouldThrow("context.createMediaElementSource(null)");
    shouldThrow("context.createMediaStreamSource(null)");
    // Invalid buffer size: IndexSizeError
    shouldThrow("context.createScriptProcessor(1, 1, 1)");
    // Invalid number of inputs and outputs: IndexSizeError
    shouldThrow("context.createScriptProcessor(4096, 100, 1)");
    shouldThrow("context.createScriptProcessor(4096, 1, 100)");
    shouldNotThrow("context.createScriptProcessor()");
    shouldNotThrow("context.createScriptProcessor(0)");

    // Invalid number of channels: IndexSizeError
    shouldThrow("context.createChannelSplitter(0)");
    shouldThrow("context.createChannelSplitter(99)");
    shouldThrow("context.createChannelMerger(0)");
    shouldThrow("context.createChannelMerger(99)");
    // Invalid real/imag arrays: IndexSizeError
    shouldThrow("context.createPeriodicWave(null, null)");
    shouldThrow("context.createPeriodicWave(new Float32Array(10), null)");
    shouldThrow("context.createPeriodicWave(new Float32Array(4100), new Float32Array(4100))");
    // Real and imaginary arrays must have the same size: IndexSizeError
    shouldThrow("context.createPeriodicWave(new Float32Array(10), new Float32Array(7))");
    

    // Analysers
    node = context.createAnalyser();
    // Invalid fftSize: IndexSizeError
    shouldThrow("node.fftSize = 42");
    shouldThrow("node.fftSize = 16");
    shouldThrow("node.fftSize = 4096");

    shouldThrow("node.minDecibels = -10");
    shouldThrow("node.maxDecibels = -150");
    shouldThrow("node.smoothingTimeConstant = -0.1");
    shouldThrow("node.smoothingTimeConstant = 1.5");

    // AudioBuffers
    node = context.createBuffer(1,1, context.sampleRate);
    // Invalid channel index: IndexSizeError
    shouldThrow("node.getChannelData(2)");

    // AudioNode connections
    node = context.createGain();
    node2 = context.createGain();
    // Invalid destination node (unspecified error)
    shouldThrow("node.connect(null, 0, 0)");
    // Invalid input or output index: IndexSizeError
    shouldThrow("node.connect(context.destination, 100, 0)");
    shouldThrow("node.connect(context.destination, 0, 100)");
    shouldThrow("node.connect(node2.gain, 100)");
    shouldThrow("node.disconnect(99)");
    // Can't connect to a different context (unspecified error)
    shouldThrow("node.connect(otherContext.destination)");

    // Invalid channel count: NotSupportedError
    shouldThrow("node.channelCount = 99");
    // Invalid mode or interpretation (unspecified error)
    mode = "fancy";
    shouldThrow("node.channelCountMode = mode");
    shouldThrow("node.channelInterpretation = mode");

    // Destination: IndexSizeError
    shouldThrow("context.destination.channelCount = 99");

    // Delay nodes are tested elsewhere, so don't duplicate that work here.

    // OfflineAudioContext
    // Invalid number of channels (unspecified error)
    shouldThrow("new webkitOfflineAudioContext(99, 100, context.sampleRate)");
    // Invalid sample rate. (unspecified error)
    shouldThrow("new webkitOfflineAudioContext(1, 100, 1)");
    shouldThrow("new webkitOfflineAudioContext(1, 100, 1e6)");

    // WaveShaper types
    node = context.createWaveShaper();
    shouldThrow("node.oversample = '9x'");

    // Start/stop for AudioBufferSourceNodes
    buffer = context.createBuffer(1,1, context.sampleRate);
    shouldNotThrow("source = context.createBufferSource()");
    shouldNotThrow("source.buffer = buffer");
    shouldNotThrow("source.start()");
    shouldNotThrow("source.stop()");

    // It's not clear from the spec, but I think it's valid to call start(). The spec is silent on
    // what happens if we call stop() afterwards, so don't call it.
    shouldNotThrow("source = context.createBufferSource()");
    shouldNotThrow("source.start()");

    buffer = context.createBuffer(1,1, context.sampleRate);
    shouldNotThrow("source = context.createBufferSource()");
    shouldNotThrow("source.buffer = buffer");
    shouldThrow("source.stop()");

    buffer = context.createBuffer(1,1, context.sampleRate);
    shouldNotThrow("source = context.createBufferSource()");
    shouldNotThrow("source.buffer = buffer");
    shouldNotThrow("source.start()");
    shouldThrow("source.start()");

    buffer = context.createBuffer(1,1, context.sampleRate);
    shouldNotThrow("source = context.createBufferSource()");
    shouldNotThrow("source.buffer = buffer");
    shouldNotThrow("source.start()");
    shouldNotThrow("source.stop()");
    shouldThrow("source.stop()");

    
    // Start/stop for OscillatorNodes
    shouldNotThrow("source = context.createOscillator()");
    shouldNotThrow("source.start()");
    shouldNotThrow("source.stop()");

    shouldNotThrow("osc = context.createOscillator()");
    shouldThrow("osc.stop()");
    shouldNotThrow("osc1 = context.createOscillator()");
    shouldNotThrow("osc1.start()");
    shouldNotThrow("osc1.stop()");
    shouldThrow("osc1.stop()");

}

runTest();
successfullyParsed = true;

</script>    
</body>
</html>