1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.htmlunit.javascript.host.media;
16
17 import org.htmlunit.WebDriverTestCase;
18 import org.htmlunit.junit.BrowserRunner;
19 import org.htmlunit.junit.annotation.Alerts;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22
23
24
25
26
27
28 @RunWith(BrowserRunner.class)
29 public class GainNodeTest extends WebDriverTestCase {
30
31
32
33
34 @Test
35 @Alerts("true")
36 public void inWindow() throws Exception {
37 final String html = DOCTYPE_HTML
38 + "<html>\n"
39 + "<head>\n"
40 + " <script>\n"
41 + LOG_TITLE_FUNCTION
42 + " function test() {\n"
43 + " log('GainNode' in window);\n"
44 + " }\n"
45 + " </script>\n"
46 + "</head>\n"
47 + "<body onload='test()'>\n"
48 + "</body>\n"
49 + "</html>";
50
51 loadPageVerifyTitle2(html);
52 }
53
54
55
56
57 @Test
58 @Alerts({"1", "-3.4028234663852886e+38", "3.4028234663852886e+38", "1", "0.5"})
59 public void ctor() throws Exception {
60 final String html = DOCTYPE_HTML
61 + "<html>\n"
62 + "<head>\n"
63 + " <script>\n"
64 + LOG_TEXTAREA_FUNCTION
65
66 + " function test() {\n"
67 + " if (!('AudioContext' in window)) {\n"
68 + " log('AudioContext not available');\n"
69 + " return;\n"
70 + " }\n"
71
72 + " var audioCtx = new AudioContext();\n"
73 + " var gainNode = new GainNode(audioCtx);\n"
74
75 + " log(gainNode.gain.defaultValue);\n"
76 + " log(gainNode.gain.minValue);\n"
77 + " log(gainNode.gain.maxValue);\n"
78 + " log(gainNode.gain.value);\n"
79
80 + " gainNode.gain.value = 0.5;\n"
81 + " log(gainNode.gain.value);\n"
82 + " }\n"
83 + " </script>\n"
84 + "</head>\n"
85 + "<body onload='test()'>\n"
86 + LOG_TEXTAREA
87 + "</body>\n"
88 + "</html>";
89
90 loadPageVerifyTextArea2(html);
91 }
92
93
94
95
96 @Test
97 @Alerts({"Error 1", "Error 2", "Error 3", "Error 4"})
98 public void ctorAudiocontextMissing() throws Exception {
99 final String html = DOCTYPE_HTML
100 + "<html>\n"
101 + "<head>\n"
102 + " <script>\n"
103 + LOG_TEXTAREA_FUNCTION
104
105 + " function test() {\n"
106 + " if (!('AudioContext' in window)) {\n"
107 + " log('AudioContext not available');\n"
108 + " return;\n"
109 + " }\n"
110
111 + " var audioCtx = new AudioContext();\n"
112 + " try {\n"
113 + " gainNode = new GainNode();\n"
114 + " } catch(e) { log('Error 1'); }\n"
115
116 + " try {\n"
117 + " gainNode = new GainNode(undefined);\n"
118 + " } catch(e) { log('Error 2'); }\n"
119
120 + " try {\n"
121 + " gainNode = new GainNode(null);\n"
122 + " } catch(e) { log('Error 3'); }\n"
123
124 + " try {\n"
125 + " gainNode = new GainNode('wrong');\n"
126 + " } catch(e) { log('Error 4'); }\n"
127
128 + " }\n"
129 + " </script>\n"
130 + "</head>\n"
131 + "<body onload='test()'>\n"
132 + LOG_TEXTAREA
133 + "</body>\n"
134 + "</html>";
135
136 loadPageVerifyTextArea2(html);
137 }
138 }