OLD | NEW |
| (Empty) |
1 <!doctype html> | |
2 <html> | |
3 <head> | |
4 <title>Test AudioContextOptions</title> | |
5 <script src="../resources/testharness.js"></script> | |
6 <script src="../resources/testharnessreport.js"></script> | |
7 <script src="resources/audit.js"></script> | |
8 </head> | |
9 | |
10 <body> | |
11 <script> | |
12 let context; | |
13 let defaultLatency; | |
14 let interactiveLatency; | |
15 let balancedLatency; | |
16 let playbackLatency; | |
17 | |
18 let audit = Audit.createTaskRunner(); | |
19 | |
20 audit.define( | |
21 { | |
22 label : "test-audiocontextoptions-latencyHint-basic", | |
23 description : "Test creating contexts with basic latencyHint types." | |
24 }, | |
25 function(task, should) { | |
26 let closingPromises = []; | |
27 | |
28 // Verify that an AudioContext can be created with default options. | |
29 should(function(){context = new AudioContext()}, | |
30 "context = new AudioContext()") | |
31 .notThrow(); | |
32 | |
33 defaultLatency = context.baseLatency; | |
34 should(defaultLatency, "default baseLatency").beGreaterThan(0); | |
35 | |
36 // Verify that an AudioContext can be created with the expected | |
37 // latency types. | |
38 should(function(){context = new AudioContext( | |
39 {'latencyHint' : 'interactive'})}, | |
40 "context = new AudioContext({'latencyHint': 'interactive'})") | |
41 .notThrow(); | |
42 | |
43 interactiveLatency = context.baseLatency; | |
44 should(interactiveLatency, "interactive baseLatency") | |
45 .beEqualTo(defaultLatency); | |
46 closingPromises.push(context.close()); | |
47 | |
48 should(function(){context = | |
49 new AudioContext({'latencyHint' : 'balanced'})}, | |
50 "context = new AudioContext({'latencyHint': 'balanced'})") | |
51 .notThrow(); | |
52 | |
53 balancedLatency = context.baseLatency; | |
54 should(balancedLatency, "balanced baseLatency") | |
55 .beGreaterThanOrEqualTo(interactiveLatency); | |
56 closingPromises.push(context.close()); | |
57 | |
58 should(function(){context = | |
59 new AudioContext({'latencyHint' : 'playback'})}, | |
60 "context = new AudioContext({'latencyHint': 'playback'})") | |
61 .notThrow(); | |
62 | |
63 playbackLatency = context.baseLatency; | |
64 should(playbackLatency, "playback baseLatency") | |
65 .beGreaterThanOrEqualTo(balancedLatency); | |
66 closingPromises.push(context.close()); | |
67 | |
68 Promise.all(closingPromises).then(function() { task.done(); }); | |
69 }); | |
70 | |
71 audit.define( | |
72 { | |
73 label : "test-audiocontextoptions-latencyHint-double", | |
74 description : | |
75 "Test creating contexts with explicit latencyHint values." | |
76 }, | |
77 function(task, should) { | |
78 var closingPromises = []; | |
79 | |
80 // Verify too small exact latency clamped to 'interactive' | |
81 should(function(){context = new AudioContext( | |
82 {'latencyHint' : interactiveLatency / 2})}, | |
83 "context = new AudioContext({'latencyHint': " + | |
84 "interactiveLatency/2})") | |
85 .notThrow(); | |
86 should(context.baseLatency, "double-constructor baseLatency small") | |
87 .beEqualTo(interactiveLatency); | |
88 closingPromises.push(context.close()); | |
89 | |
90 // Verify that exact latency in range works as expected | |
91 var validLatency = (interactiveLatency + playbackLatency) / 2; | |
92 should(function(){context = new AudioContext( | |
93 {'latencyHint' : validLatency})}, | |
94 "context = new AudioContext({'latencyHint': validLatency})") | |
95 .notThrow(); | |
96 should(context.baseLatency, | |
97 "double-constructor baseLatency inrange 1") | |
98 .beGreaterThanOrEqualTo(interactiveLatency); | |
99 should(context.baseLatency, | |
100 "double-constructor baseLatency inrange 2") | |
101 .beLessThanOrEqualTo(playbackLatency); | |
102 closingPromises.push(context.close()); | |
103 | |
104 // Verify too big exact latency clamped to some value | |
105 var context1; | |
106 var context2; | |
107 should( | |
108 function() { | |
109 context1 = | |
110 new AudioContext({'latencyHint' : playbackLatency * 10}); | |
111 context2 = | |
112 new AudioContext({'latencyHint' : playbackLatency * 20}); | |
113 }, | |
114 "creating two high latency contexts") | |
115 .notThrow(); | |
116 should(context1.baseLatency, "high latency context baseLatency") | |
117 .beEqualTo(context2.baseLatency); | |
118 closingPromises.push(context1.close()); | |
119 closingPromises.push(context2.close()); | |
120 | |
121 // Verify that invalid latencyHint values are rejected. | |
122 should( | |
123 function(){context = new AudioContext({'latencyHint' : 'foo'})}, | |
124 "context = new AudioContext({'latencyHint': 'foo'})") | |
125 .throw("TypeError"); | |
126 | |
127 // Verify that no extra options can be passed into the | |
128 // AudioContextOptions. | |
129 should(function(){context = new AudioContext('latencyHint')}, | |
130 "context = new AudioContext('latencyHint')") | |
131 .throw("TypeError"); | |
132 | |
133 Promise.all(closingPromises).then(function() { task.done(); }); | |
134 }); | |
135 | |
136 audit.run(); | |
137 </script> | |
138 </body> | |
139 </html> | |
OLD | NEW |