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(); | |
Raymond Toy
2017/04/06 17:31:59
Are we running out of online contexts without this
Andrew MacPherson
2017/04/07 06:59:03
Yes that's the reason for this. I've split the tes
| |
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; | |
Raymond Toy
2017/04/06 17:32:00
Why divide by 4? Don't you want to divide by 2 so
Andrew MacPherson
2017/04/07 06:59:03
Currently AudioContext.baseLatency is returning th
| |
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); | |
Raymond Toy
2017/04/06 17:32:00
defaultLatency or interactiveLatency?
Andrew MacPherson
2017/04/07 06:59:03
Done.
| |
64 Should("double-constructor baseLatency inrange 2", context.baseLatency).be LessThanOrEqualTo(playbackLatency); | |
65 context.close(); | |
66 | |
67 // Verify too big exact latency clamped to some value | |
68 var context1; | |
69 var context2; | |
70 Should("creating two high latency contexts", function () { | |
71 context1 = new AudioContext({'latencyHint': playbackLatency*2}); | |
72 context2 = new AudioContext({'latencyHint': playbackLatency*20}); | |
73 }).notThrow(); | |
74 Should("high latency context baseLatency", context1.baseLatency).beEqualTo (context2.baseLatency); | |
75 context1.close(); | |
76 context2.close(); | |
53 | 77 |
54 // Verify that invalid latencyHint values are rejected. | 78 // Verify that invalid latencyHint values are rejected. |
55 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { | 79 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { |
56 context = new AudioContext({'latencyHint': 'foo'}); | 80 context = new AudioContext({'latencyHint': 'foo'}); |
57 }).throw("TypeError"); | 81 }).throw("TypeError"); |
58 | 82 |
59 // Verify that no extra options can be passed into the AudioContextOptions . | 83 // Verify that no extra options can be passed into the AudioContextOptions . |
60 Should("context = new AudioContext('latencyHint')", function () { | 84 Should("context = new AudioContext('latencyHint')", function () { |
61 context = new AudioContext('latencyHint'); | 85 context = new AudioContext('latencyHint'); |
62 }).throw("TypeError"); | 86 }).throw("TypeError"); |
63 | 87 |
64 done(); | 88 done(); |
65 }); | 89 }); |
66 | 90 |
67 audit.runTasks(); | 91 audit.runTasks(); |
68 </script> | 92 </script> |
69 </body> | 93 </body> |
70 </html> | 94 </html> |
OLD | NEW |