Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / webaudio / oscillator-basic.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
3 <!--
4 Create an oscillator of each type and verify that the type is set correctly.
5 -->
6 <html>
7 <head>
8 <script src="resources/compatibility.js"></script>
9 <script type="text/javascript" src="resources/audio-testing.js"></script>
10 <script type="text/javascript" src="../resources/js-test.js"></script>
11 </head>
12
13 <body>
14 <div id="description"></div>
15 <div id="console"></div>
16
17 <script>
18 description("Basic test of setting Oscillator node types.");
19
20 var sampleRate = 44100;
21 var renderLengthSeconds = 0.25;
22
23 var oscTypes = ["sine", "square", "sawtooth", "triangle", "custom"];
24
25 function runTest() 
26 {
27     if (window.testRunner) {
28         testRunner.dumpAsText();
29         testRunner.waitUntilDone();
30     }
31     
32     window.jsTestIsAsync = true;
33         
34     // Create offline audio context.
35     var context = new OfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
36     var osc = context.createOscillator();
37
38     // Set each possible oscillator type (except CUSTOM) and verify that the type is correct.
39     // Here we're setting the type using WebIDL enum values which are strings.
40     for (var k = 0; k < oscTypes.length - 1; ++k) {
41         osc.type = oscTypes[k];
42         if (osc.type == oscTypes[k])
43             testPassed('Oscillator correctly set to "' + oscTypes[k] + '" type.');
44         else
45             testFailed('Oscillator set to "' + oscTypes[k] + '" type, but returns "' + osc.type + '" type.');
46     }
47
48     // Verify that setting a custom type directly does not set the custom type. This test has to be
49     // done before using setPeriodicWave.
50       
51     osc.type = "custom";
52     if (osc.type == "custom") 
53         testFailed('Directly setting oscillator type to "custom" incorrectly succeeded.');
54     else
55         testPassed('Directly setting oscillator type to "custom" correctly failed.');
56
57     // Now set a custom oscillator
58     var coeffA = new Float32Array([0, 1, 0.5]);
59     var coeffB = new Float32Array([0, 0, 0]);        
60     var wave = context.createPeriodicWave(coeffA, coeffB);
61     osc.setPeriodicWave(wave);
62     if (osc.type == "custom")
63         testPassed('Oscillator correctly set to "custom" type using setPeriodicWave.');
64     else
65         testFailed('Oscillator set to "custom" type, but returns "' + osc.type + '" type.');
66
67      
68     // Check that numerical values are no longer supported
69     osc.type = 0;
70     if (osc.type == 0)
71         testFailed("Oscillator incorrectly set to 0.")
72     else
73         testPassed("Oscillator correctly not set to 0.");
74
75     finishJSTest();
76 }
77
78 runTest();
79 successfullyParsed = true;
80
81 </script>
82
83
84 </body>
85 </html>