Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / webaudio / audionode.html
1 <!DOCTYPE html>
2
3 <html>
4 <head>
5 <script src="../resources/js-test.js"></script>
6 <script src="resources/compatibility.js"></script>
7 <script type="text/javascript" src="resources/audio-testing.js"></script>
8 </head>
9
10 <body>
11 <div id="description"></div>
12 <div id="console"></div>
13
14 <script>
15 description("Basic tests for AudioNode API.");
16
17 var context = 0;
18 var context2 = 0;
19 var context3 = 0;
20
21 function runTest() {
22     if (window.testRunner) {
23         testRunner.dumpAsText();
24         testRunner.waitUntilDone();
25     }
26     
27     window.jsTestIsAsync = true;
28
29     context = new AudioContext();
30     window.audioNode = context.createBufferSource();
31
32     // Check input and output numbers of AudioSourceNode.
33     if (audioNode.numberOfInputs === 0)
34         testPassed("Source AudioNode has no inputs.");
35     else
36         testFailed("Source AudioNode should not have inputs.");
37     
38     if (audioNode.numberOfOutputs === 1)
39         testPassed("Source AudioNode has one output.");
40     else
41         testFailed("Source AudioNode should have one output.");
42
43     // Check input and output numbers of AudioDestinationNode
44     if (context.destination.numberOfInputs === 1)
45         testPassed("Destination AudioNode has one input.");
46     else
47         testFailed("Destination AudioNode should have one input.");
48
49     if (context.destination.numberOfOutputs === 0)
50         testPassed("Destination AudioNode has no outputs.");
51     else
52         testFailed("Destination AudioNode should have no outputs.");
53
54     // Try calling connect() method with illegal values.
55
56     try {
57         audioNode.connect(0, 0, 0);
58         testFailed("connect() exception should be thrown for illegal destination AudioNode.");
59     } catch(e) {
60         testPassed("connect() exception thrown for illegal destination AudioNode.");
61     }
62
63     try {
64         audioNode.connect(context.destination, 5, 0);
65         testFailed("connect() exception should be thrown for illegal output index.");
66     } catch(e) {
67         testPassed("connect() exception thrown for illegal output index.");
68     }
69
70     try {
71         audioNode.connect(context.destination, 0, 5);
72         testFailed("connect() exception should be thrown for illegal input index.");
73     } catch(e) {
74         testPassed("connect() exception thrown for illegal input index.");
75     }
76
77     // Try calling connect() with proper values.
78     try {
79         audioNode.connect(context.destination, 0, 0);
80         testPassed("audioNode.connect(context.destination) succeeded.");
81     } catch(e) {
82         testFailed("audioNode.connect(context.destination) failed.");
83     }
84     
85     // Create a new context and try to connect the other context's node to this one.
86     try {
87         context2 = new AudioContext();
88         window.audioNode.connect(context2.destination);
89         testFailed("exception should be thrown when connecting to other context's node.");
90     } catch(e) {
91         testPassed("exception thrown when connecting to other context's node.");
92     }
93
94     // 3-arg AudioContext doesn't create an offline context anymore.
95     shouldNotThrow("context3 = new AudioContext(1, 44100, 44100)");
96     if (context3 instanceof OfflineAudioContext)
97         testFailed("context3 should not be an OfflineAudioContext");
98     else
99         testPassed("context3 is not an OfflineAudioContext");
100
101     // Ensure it is an EventTarget
102     try {
103         audioNode.addEventListener('testEvent', function(){
104             testPassed("AudioNode is an EventTarget");
105         });
106         audioNode.dispatchEvent(new Event('testEvent'));
107     } catch(e) {
108         testFailed("exception shouldn't be thrown when testing whether audio node is an event target");
109     }
110
111     finishJSTest();
112 }
113
114 runTest();
115
116 </script>
117
118 </body>
119 </html>