OLD | NEW |
1 <!doctype html> | 1 <!doctype html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>Test AudioContextOptions</title> | 4 <title>Test AudioContextOptions</title> |
5 <script src="../resources/testharness.js"></script> | 5 <script src="../resources/testharness.js"></script> |
6 <script src="../resources/testharnessreport.js"></script> | 6 <script src="../resources/testharnessreport.js"></script> |
7 <script src="resources/audio-testing.js"></script> | 7 <script src="resources/audio-testing.js"></script> |
8 </head> | 8 </head> |
9 | 9 |
10 <body> | 10 <body> |
11 <script> | 11 <script> |
12 var context; | 12 var context; |
13 var audit = Audit.createTaskRunner(); | 13 var audit = Audit.createTaskRunner(); |
14 | 14 |
15 // Task: test AudioContextOptions (1). | 15 // Task: test AudioContextOptions (1). |
16 audit.defineTask('test-audiocontextoptions-1', function (done) { | 16 audit.defineTask('test-audiocontextoptions-1', function (done) { |
17 | 17 |
18 // Verify that an AudioContext can be created with default options. | 18 // Verify that an AudioContext can be created with default options. |
19 Should("context = new AudioContext()", function () { | 19 Should("context = new AudioContext()", function () { |
20 context = new AudioContext(); | 20 context = new AudioContext(); |
21 }).notThrow(); | 21 }).notThrow(); |
22 | 22 |
23 var defaultLatency = context.baseLatency; | 23 var defaultLatency = context.baseLatency; |
24 Should("default baseLatency", defaultLatency).beGreaterThan(0); | 24 Should("default baseLatency", defaultLatency).beGreaterThan(0); |
25 | 25 |
26 // Verify that any double can be passed and that it results in interactive
latency | |
27 Should("context = new AudioContext({'latencyHint': 0.05})", function () { | |
28 context = new AudioContext({'latencyHint': 0.05}); | |
29 }).notThrow(); | |
30 Should("double-constructor baseLatency", context.baseLatency).beEqualTo(de
faultLatency); | |
31 | |
32 // Verify that an AudioContext can be created with the expected latency ty
pes. | 26 // Verify that an AudioContext can be created with the expected latency ty
pes. |
33 Should("context = new AudioContext({'latencyHint': 'interactive'})", funct
ion () { | 27 Should("context = new AudioContext({'latencyHint': 'interactive'})", funct
ion () { |
34 context = new AudioContext({'latencyHint': 'interactive'}); | 28 context = new AudioContext({'latencyHint': 'interactive'}); |
35 }).notThrow(); | 29 }).notThrow(); |
36 | 30 |
37 var interactiveLatency = context.baseLatency; | 31 var interactiveLatency = context.baseLatency; |
38 Should("interactive baseLatency", interactiveLatency).beEqualTo(defaultLat
ency); | 32 Should("interactive baseLatency", interactiveLatency).beEqualTo(defaultLat
ency); |
| 33 context.close(); |
39 | 34 |
40 Should("context = new AudioContext({'latencyHint': 'balanced'})", function
() { | 35 Should("context = new AudioContext({'latencyHint': 'balanced'})", function
() { |
41 context = new AudioContext({'latencyHint': 'balanced'}); | 36 context = new AudioContext({'latencyHint': 'balanced'}); |
42 }).notThrow(); | 37 }).notThrow(); |
43 | 38 |
44 var balancedLatency = context.baseLatency; | 39 var balancedLatency = context.baseLatency; |
45 Should("balanced baseLatency", balancedLatency).beGreaterThanOrEqualTo(int
eractiveLatency); | 40 Should("balanced baseLatency", balancedLatency).beGreaterThanOrEqualTo(int
eractiveLatency); |
| 41 context.close(); |
46 | 42 |
47 Should("context = new AudioContext({'latencyHint': 'playback'})", function
() { | 43 Should("context = new AudioContext({'latencyHint': 'playback'})", function
() { |
48 context = new AudioContext({'latencyHint': 'playback'}); | 44 context = new AudioContext({'latencyHint': 'playback'}); |
49 }).notThrow(); | 45 }).notThrow(); |
50 | 46 |
51 var playbackLatency = context.baseLatency; | 47 var playbackLatency = context.baseLatency; |
52 Should("playback baseLatency", playbackLatency).beGreaterThanOrEqualTo(bal
ancedLatency); | 48 Should("playback baseLatency", playbackLatency).beGreaterThanOrEqualTo(bal
ancedLatency); |
| 49 context.close(); |
| 50 |
| 51 // Verify too small exact latency clamped to 'interactive' |
| 52 Should("context = new AudioContext({'latencyHint': interactiveLatency/4})"
, function () { |
| 53 context = new AudioContext({'latencyHint': interactiveLatency/4}); |
| 54 }).notThrow(); |
| 55 Should("double-constructor baseLatency small", context.baseLatency).beEqua
lTo(defaultLatency); |
| 56 context.close(); |
| 57 |
| 58 // Verify that exact latency in range works as expected |
| 59 var validLatency = (interactiveLatency + playbackLatency) / 4; |
| 60 Should("context = new AudioContext({'latencyHint': validLatency})", functi
on () { |
| 61 context = new AudioContext({'latencyHint': validLatency}); |
| 62 }).notThrow(); |
| 63 Should("double-constructor baseLatency inrange 1", context.baseLatency).be
GreaterThanOrEqualTo(defaultLatency); |
| 64 Should("double-constructor baseLatency inrange 2", context.baseLatency).be
LessThanOrEqualTo(playbackLatency); |
| 65 context.close(); |
| 66 |
| 67 // Verify too big exact latency clamped to 'playback' |
| 68 Should("context = new AudioContext({'latencyHint': playbackLatency*2})", f
unction () { |
| 69 context = new AudioContext({'latencyHint': playbackLatency*2}); |
| 70 }).notThrow(); |
| 71 Should("double-constructor baseLatency big", context.baseLatency).beEqualT
o(playbackLatency); |
| 72 context.close(); |
53 | 73 |
54 // Verify that invalid latencyHint values are rejected. | 74 // Verify that invalid latencyHint values are rejected. |
55 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { | 75 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { |
56 context = new AudioContext({'latencyHint': 'foo'}); | 76 context = new AudioContext({'latencyHint': 'foo'}); |
57 }).throw("TypeError"); | 77 }).throw("TypeError"); |
58 | 78 |
59 // Verify that no extra options can be passed into the AudioContextOptions
. | 79 // Verify that no extra options can be passed into the AudioContextOptions
. |
60 Should("context = new AudioContext('latencyHint')", function () { | 80 Should("context = new AudioContext('latencyHint')", function () { |
61 context = new AudioContext('latencyHint'); | 81 context = new AudioContext('latencyHint'); |
62 }).throw("TypeError"); | 82 }).throw("TypeError"); |
63 | 83 |
64 done(); | 84 done(); |
65 }); | 85 }); |
66 | 86 |
67 audit.runTasks(); | 87 audit.runTasks(); |
68 </script> | 88 </script> |
69 </body> | 89 </body> |
70 </html> | 90 </html> |
OLD | NEW |