Merge "[Release] Webkit2-efl-123997_0.11.77" into tizen_2.2
[framework/web/webkit-efl.git] / 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 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css"/>
9 <script type="text/javascript" src="resources/audio-testing.js"></script>
10 <script type="text/javascript" src="../fast/js/resources/js-test-pre.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 = [{type: "sine", integerType: 0, name: "SINE"},
24                 {type: "square", integerType: 1, name: "SQUARE"},
25                 {type: "sawtooth", integerType: 2, name: "SAWTOOTH"},
26                 {type: "triangle", integerType: 3, name: "TRIANGLE"},
27                 {type: "custom", integerType: 4, name: "CUSTOM"}];
28
29 function runTest() 
30 {
31     if (window.testRunner) {
32         testRunner.dumpAsText();
33         testRunner.waitUntilDone();
34     }
35     
36     window.jsTestIsAsync = true;
37         
38     // Create offline audio context.
39     var context = new webkitOfflineAudioContext(2, sampleRate * renderLengthSeconds, sampleRate);
40     var osc = context.createOscillator();
41
42     // Set each possible oscillator type (except CUSTOM) and verify that the type is correct.
43     // Here we're setting the type using WebIDL enum values which are strings.
44     for (var k = 0; k < oscTypes.length - 1; ++k) {
45         osc.type = oscTypes[k].type;
46         if (osc.type == oscTypes[k].type)
47             testPassed("Oscillator correctly set to " + oscTypes[k].name + " type.");
48         else
49             testFailed("Oscillator set to " + oscTypes[k].name + " type, but returns " + oscTypes[osc.type].name + " type.");
50     }
51
52     // For legacy support, verify that we can set the type attribute as an integer value and
53     // verify that this translates correctly to the WebIDL enum value.
54     for (var k = 0; k < oscTypes.length - 1; ++k) {
55         osc.type = oscTypes[k].integerType;
56         if (osc.type == oscTypes[k].type)
57             testPassed("Oscillator correctly set to " + oscTypes[k].name + " type using legacy integer value.");
58         else
59             testFailed("Oscillator set to " + oscTypes[k].name + " type, but returns " + oscTypes[osc.type].name + " type using legacy integer value.");
60     }
61
62     // Now set a custom oscillator
63     var coeffA = new Float32Array([0, 1, 0.5]);
64     var coeffB = new Float32Array([0, 0, 0]);        
65     var wavetable = context.createWaveTable(coeffA, coeffB);
66     osc.setWaveTable(wavetable);
67     if (osc.type == "custom")
68         testPassed("Oscillator correctly set to CUSTOM type using setWaveTable.");
69     else
70         testFailed("Oscillator set to CUSTOM type, but returns " + oscTypes[osc.type].name + " type.");
71
72     // Try setting some invalid types
73     try {
74         osc.type = "custom";
75         testFailed("Directly setting oscillator type to CUSTOM did not throw exception.");
76     } catch (e) {
77         testPassed("Directly setting oscillator type to CUSTOM correctly throws exception.");
78     }
79
80     var oscType = osc.CUSTOM + 1;
81     try {
82         osc.type = oscType;
83         testFailed("Setting oscillator to invalid type " + oscType + " did not throw exception.");
84     } catch (e) {
85         testPassed("Setting oscillator to invalid type " + oscType + " correctly throws exception.");
86     }
87
88     // Check specifically that we throw a TypeError.
89     shouldThrowTypeError(function() { osc.type = "xyz12349jfksd"; }, "Setting .type to illegal string value");
90     shouldThrowTypeError(function() { osc.type = new Float32Array(1); }, "Setting .type to illegal type of Float32Array");
91
92     finishJSTest();
93 }
94
95 runTest();
96 successfullyParsed = true;
97
98 </script>
99
100 <script src="../fast/js/resources/js-test-post.js"></script>
101
102 </body>
103 </html>