Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/audiocontextoptions.html

Issue 2750543003: Support AudioContextOptions latencyHint as double. (Closed)
Patch Set: Update baseLatency to equal HW latency. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
hongchan 2017/04/11 17:27:37 Can you consider to use |audit.js|? We are depreca
Andrew MacPherson 2017/04/12 12:43:41 Done, I've updated the tests to use the new audit.
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 var defaultLatency;
15 var interactiveLatency;
16 var balancedLatency;
17 var playbackLatency;
14 18
15 // Task: test AudioContextOptions (1). 19 // Task: test AudioContextOptions (1).
16 audit.defineTask('test-audiocontextoptions-1', function (done) { 20 audit.defineTask('test-audiocontextoptions-1', function (done) {
17
18 // Verify that an AudioContext can be created with default options. 21 // Verify that an AudioContext can be created with default options.
19 Should("context = new AudioContext()", function () { 22 Should("context = new AudioContext()", function () {
20 context = new AudioContext(); 23 context = new AudioContext();
21 }).notThrow(); 24 }).notThrow();
22 25
23 var defaultLatency = context.baseLatency; 26 defaultLatency = context.baseLatency;
24 Should("default baseLatency", defaultLatency).beGreaterThan(0); 27 Should("default baseLatency", defaultLatency).beGreaterThan(0);
25 28
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. 29 // Verify that an AudioContext can be created with the expected latency ty pes.
33 Should("context = new AudioContext({'latencyHint': 'interactive'})", funct ion () { 30 Should("context = new AudioContext({'latencyHint': 'interactive'})", funct ion () {
34 context = new AudioContext({'latencyHint': 'interactive'}); 31 context = new AudioContext({'latencyHint': 'interactive'});
35 }).notThrow(); 32 }).notThrow();
36 33
37 var interactiveLatency = context.baseLatency; 34 interactiveLatency = context.baseLatency;
38 Should("interactive baseLatency", interactiveLatency).beEqualTo(defaultLat ency); 35 Should("interactive baseLatency", interactiveLatency).beEqualTo(defaultLat ency);
36 context.close();
39 37
40 Should("context = new AudioContext({'latencyHint': 'balanced'})", function () { 38 Should("context = new AudioContext({'latencyHint': 'balanced'})", function () {
41 context = new AudioContext({'latencyHint': 'balanced'}); 39 context = new AudioContext({'latencyHint': 'balanced'});
42 }).notThrow(); 40 }).notThrow();
43 41
44 var balancedLatency = context.baseLatency; 42 balancedLatency = context.baseLatency;
45 Should("balanced baseLatency", balancedLatency).beGreaterThanOrEqualTo(int eractiveLatency); 43 Should("balanced baseLatency", balancedLatency).beGreaterThanOrEqualTo(int eractiveLatency);
44 context.close();
46 45
47 Should("context = new AudioContext({'latencyHint': 'playback'})", function () { 46 Should("context = new AudioContext({'latencyHint': 'playback'})", function () {
48 context = new AudioContext({'latencyHint': 'playback'}); 47 context = new AudioContext({'latencyHint': 'playback'});
49 }).notThrow(); 48 }).notThrow();
50 49
51 var playbackLatency = context.baseLatency; 50 playbackLatency = context.baseLatency;
52 Should("playback baseLatency", playbackLatency).beGreaterThanOrEqualTo(bal ancedLatency); 51 Should("playback baseLatency", playbackLatency).beGreaterThanOrEqualTo(bal ancedLatency);
52 context.close();
53
54 done();
55 });
56
57 // Task: test AudioContextOptions (2).
hongchan 2017/04/11 17:27:37 Nit: please wrap by 80 column. I suggest to apply
Andrew MacPherson 2017/04/12 12:43:41 Neat, I didn't realize that clang-format could be
58 audit.defineTask('test-audiocontextoptions-2', function (done) {
59 // Verify too small exact latency clamped to 'interactive'
60 Should("context = new AudioContext({'latencyHint': interactiveLatency/2})" , function () {
61 context = new AudioContext({'latencyHint': interactiveLatency/2});
hongchan 2017/04/11 17:27:37 The try bots do not have an actual audio hardware.
Andrew MacPherson 2017/04/12 12:43:40 I assumed that the layout_test_content_renderer_cl
62 }).notThrow();
63 Should("double-constructor baseLatency small", context.baseLatency).beEqua lTo(interactiveLatency);
64 context.close();
65
66 // Verify that exact latency in range works as expected
67 var validLatency = (interactiveLatency + playbackLatency) / 2;
68 Should("context = new AudioContext({'latencyHint': validLatency})", functi on () {
69 context = new AudioContext({'latencyHint': validLatency});
70 }).notThrow();
71 Should("double-constructor baseLatency inrange 1", context.baseLatency).be GreaterThanOrEqualTo(interactiveLatency);
72 Should("double-constructor baseLatency inrange 2", context.baseLatency).be LessThanOrEqualTo(playbackLatency);
73 context.close();
74
75 // Verify too big exact latency clamped to some value
76 var context1;
77 var context2;
78 Should("creating two high latency contexts", function () {
79 context1 = new AudioContext({'latencyHint': playbackLatency*10});
80 context2 = new AudioContext({'latencyHint': playbackLatency*20});
81 }).notThrow();
82 Should("high latency context baseLatency", context1.baseLatency).beEqualTo (context2.baseLatency);
83 context1.close();
84 context2.close();
53 85
54 // Verify that invalid latencyHint values are rejected. 86 // Verify that invalid latencyHint values are rejected.
55 Should("context = new AudioContext({'latencyHint': 'foo'})", function () { 87 Should("context = new AudioContext({'latencyHint': 'foo'})", function () {
56 context = new AudioContext({'latencyHint': 'foo'}); 88 context = new AudioContext({'latencyHint': 'foo'});
57 }).throw("TypeError"); 89 }).throw("TypeError");
58 90
59 // Verify that no extra options can be passed into the AudioContextOptions . 91 // Verify that no extra options can be passed into the AudioContextOptions .
60 Should("context = new AudioContext('latencyHint')", function () { 92 Should("context = new AudioContext('latencyHint')", function () {
61 context = new AudioContext('latencyHint'); 93 context = new AudioContext('latencyHint');
62 }).throw("TypeError"); 94 }).throw("TypeError");
63 95
64 done(); 96 done();
hongchan 2017/04/11 17:27:37 I am slightly concerned that you're creating more
Andrew MacPherson 2017/04/12 12:43:41 I've added a Promise.all() at the end of each test
65 }); 97 });
66 98
67 audit.runTasks(); 99 audit.runTasks();
68 </script> 100 </script>
69 </body> 101 </body>
70 </html> 102 </html>
OLDNEW
« no previous file with comments | « media/base/audio_latency.cc ('k') | third_party/WebKit/Source/modules/webaudio/AudioContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698