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': 0.000001})", function ( ) { | |
53 context = new AudioContext({'latencyHint': 0.000001}); | |
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 Should("context = new AudioContext({'latencyHint': 0.01})", function () { | |
60 context = new AudioContext({'latencyHint': 0.01}); | |
61 }).notThrow(); | |
62 Should("double-constructor baseLatency ok", context.baseLatency).beEqualTo (0.02); | |
Raymond Toy
2017/03/14 15:19:39
Doesn't this really depend on the actual sampleRat
Andrew MacPherson
2017/03/15 15:08:17
Hmm, I think I may not understand where the values
| |
63 context.close(); | |
64 | |
65 // Verify too big exact latency clamped to 'playback' | |
66 Should("context = new AudioContext({'latencyHint': 5})", function () { | |
Raymond Toy
2017/03/14 15:19:39
Nit: I think it would be slightly better to comput
Andrew MacPherson
2017/03/15 15:08:18
Done!
| |
67 context = new AudioContext({'latencyHint': 5}); | |
68 }).notThrow(); | |
69 Should("double-constructor baseLatency big", context.baseLatency).beEqualT o(playbackLatency); | |
70 context.close(); | |
53 | 71 |
54 // Verify that invalid latencyHint values are rejected. | 72 // Verify that invalid latencyHint values are rejected. |
55 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { | 73 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { |
56 context = new AudioContext({'latencyHint': 'foo'}); | 74 context = new AudioContext({'latencyHint': 'foo'}); |
57 }).throw("TypeError"); | 75 }).throw("TypeError"); |
58 | 76 |
59 // Verify that no extra options can be passed into the AudioContextOptions . | 77 // Verify that no extra options can be passed into the AudioContextOptions . |
60 Should("context = new AudioContext('latencyHint')", function () { | 78 Should("context = new AudioContext('latencyHint')", function () { |
61 context = new AudioContext('latencyHint'); | 79 context = new AudioContext('latencyHint'); |
62 }).throw("TypeError"); | 80 }).throw("TypeError"); |
63 | 81 |
64 done(); | 82 done(); |
65 }); | 83 }); |
66 | 84 |
67 audit.runTasks(); | 85 audit.runTasks(); |
68 </script> | 86 </script> |
69 </body> | 87 </body> |
70 </html> | 88 </html> |
OLD | NEW |